Nominatim icon indicating copy to clipboard operation
Nominatim copied to clipboard

Exclude_place_ids parameter not working with countries

Open oskariot opened this issue 9 years ago • 5 comments

exclude_place_ids parameter seems to not exclude countries from the result. Here are some examples:

  1. Germany, place_id: 159224076, http://nominatim.openstreetmap.org/search?q=germany&format=json&exclude_place_ids=159224076
  2. China, place_id: 158628401, http://nominatim.openstreetmap.org/search?q=china&format=json&exclude_place_ids=158628401
  3. Sweden, place_id: 157696858, http://nominatim.openstreetmap.org/search?q=sweden&format=json&exclude_place_ids=157696858

and others...

As you can see despite being included in exclude_place_ids param they are still present in the result. This issue can be very annoying when dealing with polygons - it is sometimes necessary to exclude countries from the result to slim down the response.

oskariot avatar Nov 01 '16 15:11 oskariot

There might be an issue when we find the admin_center of the countries and return the boundary instead.

Remember that the place_id is an incremental number assigned during a search index build. It is different between servers and different when the server gets reinstalled. You shouldn't store place_ids permanently. It is useful for follow-up queries and pagination though.

For slimming down the response do you mean just the number of results? Or the size of the response if it contains for example polygons?

mtmail avatar Nov 01 '16 15:11 mtmail

I understand that place_id is not a pernament index so probably I shouldn't hardcode them into my issue description. But as I can assume you've noted that some problem occurs.

I meant the size of the response. I'm using exclude_place_ids param in follow-up queries to workaround the following problem: how to get a polygon of an object knowing place_id? (e.g gathered from the result of a previous search) Unfortunately http://nominatim.openstreetmap.org/lookup service doesn't allow to include polygon_* param (maybe it would be a good idea to extend this service?). So I'm using exclude_place_ids to exclude other search results. It works well but there is this issue with countries...

oskariot avatar Nov 01 '16 16:11 oskariot

There's an undocumented polygon_threshold parameter that might help cut down polygon size. Default is 0. Something like 0.01 or 0.05 might work for you depending on what you do with the polygons and screen size.

curl 'http://nominatim.openstreetmap.org/search?q=germany&format=json&polygon_geojson=1' | wc -c
 3310202

curl 'http://nominatim.openstreetmap.org/search?q=germany&format=json&polygon_geojson=1&polygon_threshold=0.05' | wc -c
   11250

There's no reason why the /lookup method doesn't return a polygon. I think nobody has asked for that yet.

mtmail avatar Nov 01 '16 16:11 mtmail

polygon_threshold is indeed a very useful parameter when working with polygons. As for /lookup and polygon_* parameters the same can be achieved by using /reverse method combined with osm_id and osm_type. That solves the problem of getting a polygon based on place_id because place_id must have been retrieved from the previous query so osm_type and osm_id are already known as well. The only advantage of introducing polygon_* params in /lookup method is that it could allow to get polygons of multiple objects as osm_ids parameter (/lookup specific) accepts a list. Finally, there is no need to use exclude_place_ids in this case but in general this issue still exists.

oskariot avatar Nov 02 '16 23:11 oskariot

Have a look at queryCountry() in lib/SearchDescription.php. Also needs a test.

lonvia avatar Feb 22 '18 22:02 lonvia

This is now working in the Python API.

lonvia avatar May 15 '24 10:05 lonvia