osm-search / Nominatim

Open Source search based on OpenStreetMap data
https://nominatim.org
GNU General Public License v3.0
2.98k stars 701 forks source link

Countries are assigned inconsistently when overlapping #3464

Open lonvia opened 2 days ago

lonvia commented 2 days ago

When assigning a country code from location_area_country, there is no special ordering in the query:

https://github.com/osm-search/Nominatim/blob/b63633857ed4c9af7af6f35054569dc79c6cc5a0/lib-sql/functions/utils.sql#L173-L178

This means that the result is essentially random where multiple countries overlap. The fallback code does ordering by area:

https://github.com/osm-search/Nominatim/blob/b63633857ed4c9af7af6f35054569dc79c6cc5a0/lib-sql/functions/utils.sql#L184-L189

This may not end us with a correct result but at least with a consistent one. The area is not easily available in location_area_country.

Some ideas: