]> git.openstreetmap.org Git - nominatim.git/commitdiff
fix lookup polygon output
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 8 Aug 2023 17:42:55 +0000 (19:42 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 8 Aug 2023 19:31:25 +0000 (21:31 +0200)
Fixes #3147.

nominatim/api/lookup.py
test/python/api/test_api_lookup.py

index 0e1fd9cec6303ed188adf5d8e54223e732e3c165..a46cdb69ca91e1b3b49ed58f7f3c316cd129c19e 100644 (file)
@@ -207,16 +207,16 @@ async def get_simple_place(conn: SearchConnection, place: ntyp.PlaceRef,
         out = []
 
         if details.geometry_simplification > 0.0:
-            col = col.ST_SimplifyPreserveTopology(details.geometry_simplification)
+            col = sa.func.ST_SimplifyPreserveTopology(col, details.geometry_simplification)
 
         if details.geometry_output & ntyp.GeometryFormat.GEOJSON:
-            out.append(col.ST_AsGeoJSON().label('geometry_geojson'))
+            out.append(sa.func.ST_AsGeoJSON(col).label('geometry_geojson'))
         if details.geometry_output & ntyp.GeometryFormat.TEXT:
-            out.append(col.ST_AsText().label('geometry_text'))
+            out.append(sa.func.ST_AsText(col).label('geometry_text'))
         if details.geometry_output & ntyp.GeometryFormat.KML:
-            out.append(col.ST_AsKML().label('geometry_kml'))
+            out.append(sa.func.ST_AsKML(col).label('geometry_kml'))
         if details.geometry_output & ntyp.GeometryFormat.SVG:
-            out.append(col.ST_AsSVG().label('geometry_svg'))
+            out.append(sa.func.ST_AsSVG(col).label('geometry_svg'))
 
         return sql.add_columns(*out)
 
index 619bc74710df52a8b241d50c7f908264f26c79ad..8f5dd17c5c256a1c2de65085592a8aa022dc8256 100644 (file)
@@ -100,3 +100,54 @@ def test_lookup_multiple_places(apiobj):
     assert len(result) == 2
 
     assert set(r.place_id for r in result) == {332, 4924}
+
+
+@pytest.mark.parametrize('gtype', list(napi.GeometryFormat))
+def test_simple_place_with_geometry(apiobj, gtype):
+    apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
+                     class_='highway', type='residential',
+                     name={'name': 'Road'}, address={'city': 'Barrow'},
+                     extratags={'surface': 'paved'},
+                     parent_place_id=34, linked_place_id=55,
+                     admin_level=15, country_code='gb',
+                     housenumber='4',
+                     postcode='34425', wikipedia='en:Faa',
+                     rank_search=27, rank_address=26,
+                     importance=0.01,
+                     centroid=(23, 34),
+                     geometry='POLYGON((23 34, 23.1 34, 23.1 34.1, 23 34))')
+
+    result = apiobj.api.lookup([napi.OsmID('W', 4)],
+                               geometry_output=gtype)
+
+    assert len(result) == 1
+    assert result[0].place_id == 332
+
+    if gtype == napi.GeometryFormat.NONE:
+        assert list(result[0].geometry.keys()) == []
+    else:
+        assert list(result[0].geometry.keys()) == [gtype.name.lower()]
+
+
+def test_simple_place_with_geometry_simplified(apiobj):
+    apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
+                     class_='highway', type='residential',
+                     name={'name': 'Road'}, address={'city': 'Barrow'},
+                     extratags={'surface': 'paved'},
+                     parent_place_id=34, linked_place_id=55,
+                     admin_level=15, country_code='gb',
+                     housenumber='4',
+                     postcode='34425', wikipedia='en:Faa',
+                     rank_search=27, rank_address=26,
+                     importance=0.01,
+                     centroid=(23, 34),
+                     geometry='POLYGON((23 34, 22.999 34, 23.1 34, 23.1 34.1, 23 34))')
+
+    result = apiobj.api.lookup([napi.OsmID('W', 4)],
+                               geometry_output=napi.GeometryFormat.TEXT,
+                               geometry_simplification=0.1)
+
+    assert len(result) == 1
+    assert result[0].place_id == 332
+    assert result[0].geometry == {'text': 'POLYGON((23 34,23.1 34,23.1 34.1,23 34))'}
+