]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 29 Mar 2020 21:14:46 +0000 (23:14 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 29 Mar 2020 21:14:46 +0000 (23:14 +0200)
15 files changed:
lib/ClassTypes.php
lib/Geocode.php
lib/PlaceLookup.php
lib/lib.php
lib/template/details-html.php
lib/template/details-json.php
lib/template/search-batch-json.php
lib/template/search-json.php
lib/template/search-xml.php
sql/functions/address_lookup.sql
test/bdd/api/reverse/params.feature
test/bdd/api/reverse/simple.feature
test/bdd/api/search/params.feature
test/bdd/api/search/simple.feature
test/php/Nominatim/LibTest.php

index d46847f1c7a65d6ec7565070361ac32da0bb5383..91066a1ffb1d3b2dacba3834aa78e9a2221952ea 100644 (file)
@@ -6,6 +6,13 @@ function getInfo($aPlace)
 {
     $aClassType = getList();
 
+    if ($aPlace['type'] == 'administrative' && isset($aPlace['place_type'])) {
+        $sName = 'place:'.$aPlace['place_type'];
+        if (isset($aClassType[$sName])) {
+            return $aClassType[$sName];
+        }
+    }
+
     if (isset($aPlace['admin_level'])) {
         $sName = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level'];
         if (isset($aClassType[$sName])) {
index 0e5d4a53883924b110a054c8afe143759ff213bd..3336790fd650f1536c58d9d0906df391026e0ee0 100644 (file)
@@ -245,7 +245,6 @@ class Geocode
         }
 
         $this->oPlaceLookup->loadParamArray($oParams, $sForceGeometryType);
-        $this->oPlaceLookup->setIncludePolygonAsPoints($oParams->getBool('polygon'));
         $this->oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', false));
     }
 
index 9f4f143ea23dd2c3f4f7bd488d369671c5ac9bf7..8a1a366678652513e37378e15c36c64d18c0e679 100644 (file)
@@ -15,7 +15,6 @@ class PlaceLookup
     protected $bExtraTags = false;
     protected $bNameDetails = false;
 
-    protected $bIncludePolygonAsPoints = false;
     protected $bIncludePolygonAsText = false;
     protected $bIncludePolygonAsGeoJSON = false;
     protected $bIncludePolygonAsKML = false;
@@ -38,11 +37,6 @@ class PlaceLookup
         return $this->bDeDupe;
     }
 
-    public function setIncludePolygonAsPoints($b = true)
-    {
-        $this->bIncludePolygonAsPoints = $b;
-    }
-
     public function setIncludeAddressDetails($b)
     {
         $this->bAddressDetails = $b;
@@ -61,7 +55,6 @@ class PlaceLookup
 
         if ($sGeomType === null || $sGeomType == 'geojson') {
             $this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
-            $this->bIncludePolygonAsPoints = false;
         }
 
         if ($oParams->getString('format', '') !== 'geojson') {
@@ -100,7 +93,6 @@ class PlaceLookup
         if ($this->bExtraTags) $aParams['extratags'] = '1';
         if ($this->bNameDetails) $aParams['namedetails'] = '1';
 
-        if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
         if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
         if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
         if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
@@ -500,7 +492,7 @@ class PlaceLookup
             if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson';
             if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml';
             if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg';
-            if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ',ST_AsText(geometry) as astext';
+            if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext';
             if ($fLonReverse != null && $fLatReverse != null) {
                 $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN ';
                 $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))';
@@ -527,8 +519,6 @@ class PlaceLookup
                 if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml'];
                 if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg'];
                 if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext'];
-                if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius);
-
 
                 if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
                     $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
@@ -551,17 +541,12 @@ class PlaceLookup
 
         // as a fallback we generate a bounding box without knowing the size of the geometry
         if ((!isset($aOutlineResult['aBoundingBox'])) && isset($fLon)) {
-            //
-            if ($this->bIncludePolygonAsPoints) {
-                $sGeometryText = 'POINT('.$fLon.','.$fLat.')';
-                $aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius);
-            }
-
-            $aBounds = array();
-            $aBounds['minlat'] = $fLat - $fRadius;
-            $aBounds['maxlat'] = $fLat + $fRadius;
-            $aBounds['minlon'] = $fLon - $fRadius;
-            $aBounds['maxlon'] = $fLon + $fRadius;
+            $aBounds = array(
+                        'minlat' => $fLat - $fRadius,
+                        'maxlat' => $fLat + $fRadius,
+                        'minlon' => $fLon - $fRadius,
+                        'maxlon' => $fLon + $fRadius
+                       );
 
             $aOutlineResult['aBoundingBox'] = array(
                                                (string)$aBounds['minlat'],
index c90c334c9a7533a7eac65c3180b33d2c3985df7b..a8e6dd70b8e3128e870eb749f3c03733c135dba7 100644 (file)
@@ -165,39 +165,6 @@ function parseLatLon($sQuery)
     return array($sFound, $fQueryLat, $fQueryLon);
 }
 
-
-function geometryText2Points($geometry_as_text, $fRadius)
-{
-    $aPolyPoints = null;
-    if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
-        //
-        preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
-        //
-    } elseif (preg_match('#LINESTRING\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
-        //
-        preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
-        //
-/*    } elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
-        //
-        preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
-        */
-    } elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#', $geometry_as_text, $aMatch)) {
-        //
-        $aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius);
-        //
-    }
-
-    if (isset($aPolyPoints)) {
-        $aResultPoints = array();
-        foreach ($aPolyPoints as $aPoint) {
-            $aResultPoints[] = array($aPoint[1], $aPoint[2]);
-        }
-        return $aResultPoints;
-    }
-
-    return;
-}
-
 function createPointsAroundCenter($fLon, $fLat, $fRadius)
 {
     $iSteps = max(8, min(100, ($fRadius * 40000)^2));
index c043e9b706f7a595c888ae4729e464105783676d..43ec12668ec26a26e0748b24cdce344f1230866c 100644 (file)
 
         echo '<tr class="' . ($bNotUsed?'notused':'') . '">'."\n";
         echo '  <td class="name">'.(trim($aAddressLine['localname'])!==null?$aAddressLine['localname']:'<span class="noname">No Name</span>')."</td>\n";
-        echo '  <td>' . $aAddressLine['class'].':'.$aAddressLine['type'] . "</td>\n";
+        echo '  <td>' . $aAddressLine['class'].':'.$aAddressLine['type'];
+        if ($aAddressLine['type'] == 'administrative'
+            && isset($aAddressLine['place_type']))
+        {
+            echo '('.$aAddressLine['place_type'].')';
+        }
+        echo "</td>\n";
         echo '  <td>' . osmLink($aAddressLine) . "</td>\n";
         echo '  <td>' . (isset($aAddressLine['rank_address']) ? $aAddressLine['rank_address'] : '') . "</td>\n";
         echo '  <td>' . ($aAddressLine['admin_level'] < 15 ? $aAddressLine['admin_level'] : '') . "</td>\n";
index 4afb1b0bc4e717dcd7609d8e5630c6500b566da9..955441add22fccff31451ceb0e81f44a29ac4229 100644 (file)
@@ -47,6 +47,7 @@ $funcMapAddressLine = function ($aFull) {
                 'place_id' => isset($aFull['place_id']) ? (int) $aFull['place_id'] : null,
                 'osm_id' => isset($aFull['osm_id']) ? (int) $aFull['osm_id'] : null,
                 'osm_type' => isset($aFull['osm_type']) ? $aFull['osm_type'] : null,
+                'place_type' => isset($aFull['place_type']) ? $aFull['place_type'] : null,
                 'class' => $aFull['class'],
                 'type' => $aFull['type'],
                 'admin_level' => isset($aFull['admin_level']) ? (int) $aFull['admin_level'] : null,
index 40b27a72e9dc9b607f4de61756b9bc335c6ce7e3..c4bc29cb1df4c0d8160003a698c46340cc2020a2 100644 (file)
@@ -25,10 +25,6 @@ foreach ($aBatchResults as $aSearchResults) {
                                       $aPointDetails['aBoundingBox'][2],
                 $aPointDetails['aBoundingBox'][3]
                                      );
-
-            if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) {
-                $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
-            }
         }
 
         if (isset($aPointDetails['zoom'])) {
index 6108aca4e005582d9446a75ca44737a0ab0ae5c3..4b896d08a6de136207a8e878ff8c2ac73f7e711d 100644 (file)
@@ -15,10 +15,6 @@ foreach ($aSearchResults as $iResNum => $aPointDetails) {
 
     if (isset($aPointDetails['aBoundingBox'])) {
         $aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
-
-        if (isset($aPointDetails['aPolyPoints'])) {
-            $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
-        }
     }
 
     if (isset($aPointDetails['zoom'])) {
index f67ba33bd2b7e56fa6cdfe2b8444dba502f8dd17..68d985f3cc3111fd6f7aece1cce916efb7bb3f73 100644 (file)
@@ -11,7 +11,6 @@ echo " timestamp='".date(DATE_RFC822)."'";
 echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
 echo " querystring='".htmlspecialchars($sQuery, ENT_QUOTES)."'";
 if (isset($aMoreParams['viewbox'])) echo " viewbox='".htmlspecialchars($aMoreParams['viewbox'], ENT_QUOTES)."'";
-echo " polygon='".(isset($aMoreParams['polygon'])?'true':'false')."'";
 if (isset($aMoreParams['exclude_place_ids'])) {
     echo " exclude_place_ids='".htmlspecialchars($aMoreParams['exclude_place_ids'])."'";
 }
@@ -31,12 +30,6 @@ foreach ($aSearchResults as $iResNum => $aResult) {
         echo ' boundingbox="';
         echo join(',', $aResult['aBoundingBox']);
         echo '"';
-
-        if (isset($aResult['aPolyPoints'])) {
-            echo ' polygonpoints=\'';
-            echo json_encode($aResult['aPolyPoints']);
-            echo '\'';
-        }
     }
 
     if (isset($aResult['asgeojson'])) {
index dd096728124d1f4e5d13dae849e893d1ec091eda..ccc982b8e6eaf404d73e517a09cabaf16b768728 100644 (file)
@@ -8,6 +8,7 @@ CREATE TYPE addressline as (
   name HSTORE,
   class TEXT,
   type TEXT,
+  place_type TEXT,
   admin_level INTEGER,
   fromarea BOOLEAN,
   isaddress BOOLEAN,
@@ -193,7 +194,7 @@ BEGIN
       searchcountrycode := NULL;
     END IF;
     countrylocation := ROW(location.place_id, location.osm_type, location.osm_id,
-                           location.name, location.class, location.type,
+                           location.name, location.class, location.type, NULL,
                            location.admin_level, true, location.isaddress,
                            location.rank_address, location.distance)::addressline;
     RETURN NEXT countrylocation;
@@ -201,10 +202,8 @@ BEGIN
   END LOOP;
 
   FOR location IN
-    SELECT placex.place_id, osm_type, osm_id, name,
-           CASE WHEN extratags ? 'place' or extratags ? 'linked_place'
-                THEN 'place' ELSE class END as class,
-           coalesce(extratags->'place', extratags->'linked_place', type) as type,
+    SELECT placex.place_id, osm_type, osm_id, name, class, type,
+           coalesce(extratags->'place', extratags->'linked_place') as place_type,
            admin_level, fromarea, isaddress and linked_place_id is NULL as isaddress,
            CASE WHEN rank_address = 11 THEN 5 ELSE rank_address END as rank_address,
            distance, country_code, postcode
@@ -229,6 +228,7 @@ BEGIN
     END IF;
     countrylocation := ROW(location.place_id, location.osm_type, location.osm_id,
                            location.name, location.class, location.type,
+                           location.place_type,
                            location.admin_level, location.fromarea,
                            location.isaddress, location.rank_address,
                            location.distance)::addressline;
@@ -242,7 +242,7 @@ BEGIN
       WHERE country_code = searchcountrycode LIMIT 1 INTO countryname;
 --RAISE WARNING '% % %',found,searchcountrycode,countryname;
     IF countryname IS NOT NULL THEN
-      location := ROW(null, null, null, countryname, 'place', 'country',
+      location := ROW(null, null, null, countryname, 'place', 'country', NULL,
                       null, true, true, 4, 0)::addressline;
       RETURN NEXT location;
     END IF;
@@ -251,25 +251,25 @@ BEGIN
   -- Finally add some artificial rows.
   IF searchcountrycode IS NOT NULL THEN
     location := ROW(null, null, null, hstore('ref', searchcountrycode),
-                    'place', 'country_code', null, true, false, 4, 0)::addressline;
+                    'place', 'country_code', null, null, true, false, 4, 0)::addressline;
     RETURN NEXT location;
   END IF;
 
   IF searchhousename IS NOT NULL THEN
     location := ROW(in_place_id, null, null, searchhousename, searchclass,
-                    searchtype, null, true, true, 29, 0)::addressline;
+                    searchtype, null, null, true, true, 29, 0)::addressline;
     RETURN NEXT location;
   END IF;
 
   IF searchhousenumber IS NOT NULL THEN
     location := ROW(in_place_id, null, null, hstore('ref', searchhousenumber),
-                    'place', 'house_number', null, true, true, 28, 0)::addressline;
+                    'place', 'house_number', null, null, true, true, 28, 0)::addressline;
     RETURN NEXT location;
   END IF;
 
   IF searchpostcode IS NOT NULL THEN
     location := ROW(null, null, null, hstore('ref', searchpostcode), 'place',
-                    'postcode', null, false, postcode_isaddress, 5, 0)::addressline;
+                    'postcode', null, null, false, postcode_isaddress, 5, 0)::addressline;
     RETURN NEXT location;
   END IF;
 
index f78c4c6a19b6d8ceb6d73c16957dd5462a3b3beb..2a5821e4c3e1385ed11e391ee93378e2b065107f 100644 (file)
@@ -63,18 +63,6 @@ Feature: Parameters for Reverse API
         | json     | geotext |
         | jsonv2   | geotext |
 
-    Scenario Outline: Reverse Geocoding contains polygon-as-points geometry
-        When sending <format> reverse coordinates 47.165989816710066,9.515774846076965
-          | polygon |
-          | 1 |
-        Then result 0 has not attributes <response_attribute>
-
-    Examples:
-        | format   | response_attribute |
-        | xml      | polygonpoints |
-        | json     | polygonpoints |
-        | jsonv2   | polygonpoints |
-
     Scenario Outline: Reverse Geocoding contains SVG geometry
         When sending <format> reverse coordinates 47.165989816710066,9.515774846076965
           | polygon_svg |
@@ -114,8 +102,8 @@ Feature: Parameters for Reverse API
 
     Scenario Outline: Reverse Geocoding in geojson format contains no non-geojson geometry
         When sending geojson reverse coordinates 47.165989816710066,9.515774846076965
-          | polygon_text | polygon | polygon_svg | polygon_geokml |
-          | 1            | 1       | 1           | 1              |
+          | polygon_text | polygon_svg | polygon_geokml |
+          | 1            | 1           | 1              |
         Then result 0 has not attributes <response_attribute>
 
     Examples:
@@ -124,4 +112,3 @@ Feature: Parameters for Reverse API
         | polygonpoints      |
         | svg                |
         | geokml             |
-
index ccd0becdbb8a837fa62dd64e0b66481ee98ca276..b07989eccf09ca6e66cbd0976f75cc3a4e7a2d72 100644 (file)
@@ -55,8 +55,6 @@ Feature: Simple Reverse Tests
 
     Examples:
      | parameter        | value |
-     | polygon          | 1 |
-     | polygon          | 0 |
      | polygon_text     | 1 |
      | polygon_text     | 0 |
      | polygon_kml      | 1 |
index cdea3f69e92ce51385fdcc47277ef2fd31e4c581..6ba22d03a0c56fbb7294104bf286cde7e79982c8 100644 (file)
@@ -303,18 +303,6 @@ Feature: Search queries
         | json     | geotext |
         | jsonv2   | geotext |
 
-    Scenario Outline: Search result contains polygon-as-points geometry
-        When sending <format> search query "Highmore"
-          | polygon |
-          | 1 |
-        Then result has attributes <response_attribute>
-
-    Examples:
-        | format   | response_attribute |
-        | xml      | polygonpoints |
-        | json     | polygonpoints |
-        | jsonv2   | polygonpoints |
-
     Scenario Outline: Search result contains SVG geometry
         When sending <format> search query "Highmore"
           | polygon_svg |
@@ -354,8 +342,8 @@ Feature: Search queries
 
     Scenario Outline: Search result in geojson format contains no non-geojson geometry
         When sending geojson search query "Highmore"
-          | polygon_text | polygon | polygon_svg | polygon_geokml |
-          | 1            | 1       | 1           | 1              |
+          | polygon_text | polygon_svg | polygon_geokml |
+          | 1            | 1           | 1              |
         Then result 0 has not attributes <response_attribute>
 
     Examples:
index c12635972dd29a48afb0cd9ed8f72b871da0334a..fe2d684e8ee285b0bbf72b5bc913cc7bd028c4a3 100644 (file)
@@ -36,8 +36,6 @@ Feature: Simple Tests
      | parameter        | value |
      | addressdetails   | 1 |
      | addressdetails   | 0 |
-     | polygon          | 1 |
-     | polygon          | 0 |
      | polygon_text     | 1 |
      | polygon_text     | 0 |
      | polygon_kml      | 1 |
@@ -98,7 +96,6 @@ Feature: Simple Tests
         Then result header contains
           | attr        | value |
           | querystring | xnznxvcx |
-          | polygon     | false |
           | more_url    | .*q=xnznxvcx.*format=xml |
 
     Scenario: Empty XML search with special XML characters
@@ -106,7 +103,6 @@ Feature: Simple Tests
         Then result header contains
           | attr        | value |
           | querystring | xfdghn&zxn"xvbyx<vxx>cssdex |
-          | polygon     | false |
           | more_url    | .*q=xfdghn%26zxn%22xvbyx%3Cvxx%3Ecssdex.*format=xml |
 
     Scenario: Empty XML search with viewbox
@@ -116,7 +112,6 @@ Feature: Simple Tests
         Then result header contains
           | attr        | value |
           | querystring | xnznxvcx |
-          | polygon     | false |
           | viewbox     | 12,33,77,45.13 |
 
     Scenario: Empty XML search with viewboxlbrt
@@ -126,7 +121,6 @@ Feature: Simple Tests
         Then result header contains
           | attr        | value |
           | querystring | xnznxvcx |
-          | polygon     | false |
           | viewbox     | 12,34.13,77,45 |
 
     Scenario: Empty XML search with viewboxlbrt and viewbox
@@ -136,29 +130,8 @@ Feature: Simple Tests
         Then result header contains
           | attr        | value |
           | querystring | pub |
-          | polygon     | false |
           | viewbox     | 12,33,77,45.13 |
 
-    Scenario Outline: Empty XML search with polygon values
-        When sending xml search query "xnznxvcx"
-          | param   | value |
-          | polygon | <polyval> |
-        Then result header contains
-          | attr        | value |
-          | polygon     | <result> |
-
-    Examples:
-     | result | polyval |
-     | false  | 0 |
-     | true   | 1 |
-     | true   | True |
-     | true   | true |
-     | true   | false |
-     | true   | FALSE |
-     | true   | yes |
-     | true   | no |
-     | true   | '; delete from foobar; select ' |
-
     Scenario: Empty XML search with exluded place ids
         When sending xml search query "jghrleoxsbwjer"
           | exclude_place_ids |
index a80ef73b6fd53f65eca9cfc0d062432f3fa7a9cd..dca2107d7bc07771bf8e969a5094dc10132b2a75 100644 (file)
@@ -35,55 +35,6 @@ class LibTest extends \PHPUnit\Framework\TestCase
         );
     }
 
-
-    public function testGeometryText2Points()
-    {
-        $fRadius = 1;
-        // invalid value
-        $this->assertEquals(
-            null,
-            geometryText2Points('', $fRadius)
-        );
-
-        // POINT
-        $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
-        $this->assertEquals(
-            101,
-            count($aPoints)
-        );
-        $this->assertEquals(
-            array(
-             array(10, 21),
-             array(10.062790519529, 20.998026728428),
-             array(10.125333233564, 20.992114701314)
-            ),
-            array_splice($aPoints, 0, 3)
-        );
-
-        // POLYGON
-        $this->assertEquals(
-            array(
-             array('30', '10'),
-             array('40', '40'),
-             array('20', '40'),
-             array('10', '20'),
-             array('30', '10')
-            ),
-            geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
-        );
-
-        // MULTIPOLYGON
-        $this->assertEquals(
-            array(
-             array('30', '20'), // first polygon only
-             array('45', '40'),
-             array('10', '40'),
-             array('30', '20'),
-            ),
-            geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
-        );
-    }
-
     public function testParseLatLon()
     {
         // no coordinates expected