]> git.openstreetmap.org Git - nominatim.git/commitdiff
get bbox of postcode areas into results
authorSarah Hoffmann <lonvia@denofr.de>
Sat, 28 Sep 2024 12:42:32 +0000 (14:42 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 30 Sep 2024 06:58:40 +0000 (08:58 +0200)
src/nominatim_api/search/db_searches.py
test/python/api/search/test_search_postcode.py

index 35c063fc937701dc4086eb677e826c671a3b7ac4..d2202b2ccfb827d737f19af6aae574ecdb69e622 100644 (file)
@@ -616,6 +616,8 @@ class PostcodeSearch(AbstractSearch):
 
             for prow in await conn.execute(placex_sql, _details_to_bind_params(details)):
                 result = nres.create_from_placex_row(prow, nres.SearchResult)
+                if result is not None:
+                    result.bbox = Bbox.from_wkb(prow.bbox)
                 break
             else:
                 result = nres.create_from_postcode_row(row, nres.SearchResult)
index 633e07bcf8574ea1caaad73b277d0c3978a839ed..369e15045e0fd4ecf11721e67ee342cb661ddef3 100644 (file)
@@ -59,6 +59,19 @@ def test_postcode_with_country(apiobj, frontend):
     assert results[0].place_id == 101
 
 
+def test_postcode_area(apiobj, frontend):
+    apiobj.add_postcode(place_id=100, country_code='ch', postcode='12345')
+    apiobj.add_placex(place_id=200, country_code='ch', postcode='12345',
+                      osm_type='R', osm_id=34, class_='boundary', type='postal_code',
+                      geometry='POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
+
+    results = run_search(apiobj, frontend, 0.3, ['12345'], [0.0])
+
+    assert len(results) == 1
+    assert results[0].place_id == 200
+    assert results[0].bbox.area == 1
+
+
 class TestPostcodeSearchWithAddress:
 
     @pytest.fixture(autouse=True)