]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge pull request #1739 from lonvia/remove-self-from-geojson
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 9 Apr 2020 20:51:20 +0000 (22:51 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Apr 2020 20:51:20 +0000 (22:51 +0200)
Further tweaks to geocodejson output

lib/AddressDetails.php
lib/template/address-geocodejson.php
lib/template/search-geocodejson.php
test/bdd/api/reverse/geocodejson.feature
test/bdd/api/search/geocodejson.feature

index 8d2b3e08b1c2208797f6c8add679df3ecd1d08a7..3322c6b2da8d985f6473a2cecba540cd53d5dd14 100644 (file)
@@ -9,10 +9,13 @@ require_once(CONST_BasePath.'/lib/ClassTypes.php');
  */
 class AddressDetails
 {
+    private $iPlaceID;
     private $aAddressLines;
 
     public function __construct(&$oDB, $iPlaceID, $sHousenumber, $mLangPref)
     {
+        $this->iPlaceID = $iPlaceID;
+
         if (is_array($mLangPref)) {
             $mLangPref = $oDB->getArraySQL($oDB->getDBQuotedList($mLangPref));
         }
@@ -115,7 +118,7 @@ class AddressDetails
      */
     public function addGeocodeJsonAddressParts(&$aJson)
     {
-        foreach ($this->aAddressLines as $aLine) {
+        foreach (array_reverse($this->aAddressLines) as $aLine) {
             if (!$aLine['isaddress']) {
                 continue;
             }
@@ -124,13 +127,19 @@ class AddressDetails
                 continue;
             }
 
-            $iRank = (int)$aLine['rank_address'];
-
             if ($aLine['type'] == 'postcode' || $aLine['type'] == 'postal_code') {
                 $aJson['postcode'] = $aLine['localname'];
             } elseif ($aLine['type'] == 'house_number') {
                 $aJson['housenumber'] = $aLine['localname'];
-            } elseif ($iRank > 25 && $iRank < 28) {
+            }
+
+            if ($this->iPlaceID == $aLine['place_id']) {
+                continue;
+            }
+
+            $iRank = (int)$aLine['rank_address'];
+
+            if ($iRank > 25 && $iRank < 28) {
                 $aJson['street'] = $aLine['localname'];
             } elseif ($iRank >= 22 && $iRank <= 25) {
                 $aJson['locality'] = $aLine['localname'];
index 98c368b324b0342b7cb3d2db804eec02337cde7c..0066e80e29adb13cce8320360c57eafddf7ba87e 100644 (file)
@@ -30,7 +30,9 @@ if (empty($aPlace)) {
 
     $aFilteredPlaces['properties']['geocoding']['label'] = $aPlace['langaddress'];
 
-    $aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
+    if ($aPlace['placename'] !== null) {
+        $aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
+    }
 
     if (isset($aPlace['address'])) {
         $aPlace['address']->addGeocodeJsonAddressParts(
index dfb402bdb2f485a83a37bc99ad6cc674613c4ea6..3e3a31c443c7948b58e6f8c5500fc366b7f34ad0 100644 (file)
@@ -20,7 +20,9 @@ foreach ($aSearchResults as $iResNum => $aPointDetails) {
 
     $aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];
 
-    $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
+    if ($aPointDetails['placename'] !== null) {
+        $aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
+    }
 
     if (isset($aPointDetails['address'])) {
         $aPointDetails['address']->addGeocodeJsonAddressParts(
index b32bf1ca453482f859eac8bb5f65501717f1bed8..44f8288babcb750a932e5b12fef727d5bcab0039 100644 (file)
@@ -11,10 +11,10 @@ Feature: Parameters for Reverse API
     Scenario: Town street-level address with street
         When sending geocodejson reverse coordinates 47.066,9.504
         Then results contain
-          | street  | city    | postcode | country |
+          | name    | city    | postcode | country |
           | Gnetsch | Balzers | 9496     | Liechtenstein |
 
-    Scenario: Town street-level address with footway
+    Scenario: Poi street-level address with footway
         When sending geocodejson reverse coordinates 47.0653,9.5007
         Then results contain
           | street  | city    | postcode | country |
index 97cb220b0b84c6250750a4bcb7288dcd2794e4d8..52c535bbe67c29ff3a1969fc2cf4c5e7f7694405 100644 (file)
@@ -11,7 +11,7 @@ Feature: Parameters for Search API
     Scenario: Town street-level address with street
         When sending geocodejson search query "Gnetsch, Balzers" with address
         Then results contain
-          | street  | city    | postcode | country |
+          | name    | city    | postcode | country |
           | Gnetsch | Balzers | 9496     | Liechtenstein |
 
     Scenario: Town street-level address with footway