Skip to content

Commit f923304

Browse files
committed
add slight preference for locating point POIs over POI areas
1 parent 1a0f851 commit f923304

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

nominatim/api/reverse.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def _find_closest_street_or_poi(self, distance: float) -> Optional[SaRow]:
186186
.where(sa.or_(sa.not_(t.c.geometry.is_area()),
187187
t.c.centroid.ST_Distance(WKT_PARAM) < diststr))
188188
.order_by('distance')
189-
.limit(1))
189+
.limit(2))
190190

191191
if self.has_geometries():
192192
sql = self._add_geometry_columns(sql, t.c.geometry)
@@ -212,7 +212,20 @@ async def _find_closest_street_or_poi(self, distance: float) -> Optional[SaRow]:
212212

213213
sql = sql.where(sa.or_(*restrict))
214214

215-
return (await self.conn.execute(sql, self.bind_params)).one_or_none()
215+
# If the closest object is inside an area, then check if there is a
216+
# POI node nearby and return that.
217+
prev_row = None
218+
for row in await self.conn.execute(sql, self.bind_params):
219+
if prev_row is None:
220+
if row.rank_search <= 27 or row.osm_type == 'N' or row.distance > 0:
221+
return row
222+
prev_row = row
223+
else:
224+
if row.rank_search > 27 and row.osm_type == 'N'\
225+
and row.distance < 0.0001:
226+
return row
227+
228+
return prev_row
216229

217230

218231
async def _find_housenumber_for_street(self, parent_place_id: int) -> Optional[SaRow]:

test/python/api/test_api_reverse.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,24 @@ def test_reverse_ignore_unindexed(apiobj, frontend):
6868
(0.70003, napi.DataLayer.MANMADE | napi.DataLayer.NATURAL, 225),
6969
(5, napi.DataLayer.ADDRESS, 229)])
7070
def test_reverse_rank_30_layers(apiobj, frontend, y, layer, place_id):
71-
apiobj.add_placex(place_id=223, class_='place', type='house',
71+
apiobj.add_placex(place_id=223, osm_type='N', class_='place', type='house',
7272
housenumber='1',
7373
rank_address=30,
7474
rank_search=30,
7575
centroid=(1.3, 0.70001))
76-
apiobj.add_placex(place_id=224, class_='amenity', type='toilet',
76+
apiobj.add_placex(place_id=224, osm_type='N', class_='amenity', type='toilet',
7777
rank_address=30,
7878
rank_search=30,
7979
centroid=(1.3, 0.7))
80-
apiobj.add_placex(place_id=225, class_='man_made', type='tower',
80+
apiobj.add_placex(place_id=225, osm_type='N', class_='man_made', type='tower',
8181
rank_address=0,
8282
rank_search=30,
8383
centroid=(1.3, 0.70003))
84-
apiobj.add_placex(place_id=226, class_='railway', type='station',
84+
apiobj.add_placex(place_id=226, osm_type='N', class_='railway', type='station',
8585
rank_address=0,
8686
rank_search=30,
8787
centroid=(1.3, 0.70004))
88-
apiobj.add_placex(place_id=227, class_='natural', type='cave',
88+
apiobj.add_placex(place_id=227, osm_type='N', class_='natural', type='cave',
8989
rank_address=0,
9090
rank_search=30,
9191
centroid=(1.3, 0.70005))

0 commit comments

Comments
 (0)