NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am coding in Python, using the package osmnx, and in particular the function geocode_to_gdf from osmnx to get the geometry of some cities in Switzerland. If I send the request "Fribourg, Switzerland", I get the canton as first answer. If I send the request "Aarau, Switzerland", the risk is to get the "Bezirk"/district. To avoid these problems, I send the request as a dictionary: "{'city': 'Aarau, Schweiz'}" or "{'city': 'Fribourg'}". Seems safer and is recommended by the author of the osmnx package on Stackoverflow. I have two questions:

  • Why are the results not stable? Depending when I run it and how (in code or in a jupyter notebook), I get different results. "{'city': 'Fribourg'}" sometimes gives as output the city of Fribourg in Switzerland and sometimes "Freiburg City Süd Hotel, 19, Heinrich-von-Stephan-Straße, Unterwiehre-Nord, Wiehre, Freiburg im Breisgau, Baden-Württemberg, 79100, Germany". "{'city': 'Aarau, Schweiz'}" sometimes gives "City Märit, Aarau, Bezirk Aarau, Aargau, 5000, Switzerland".
  • Why are the results sometimes empty? "{'city': 'Fribourg, Switzerland'}" generates 0 answers. Same with "{'city': 'Fribourg, Schweiz'}", as well as "{'city': 'Fribourg, Suisse'}"

I'm not sure if it is more a question about the data structure in OSM, or a question regarding the package osmnx.

asked 24 Jan '23, 09:55

antonind's gravatar image

accept rate: 0%

Sth. like

"{'city': 'Fribourg, Suisse'}"

is semantically wrong, you should use:

"{'city': 'Fribourg','country': 'Suisse'}"

If you only need results from Switzerland, I would also recommend to include 'countrycodes': 'ch'.

If you still get different results for the same request, please trace you requests and check the Nominatim instance that is responding to your requests (e.g. IP address of the responder). Do they differ?

permanent link

answered 24 Jan '23, 11:39

Spiekerooger's gravatar image

accept rate: 16%

edited 24 Jan '23, 11:47

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 24 Jan '23, 09:55

question was seen: 1,284 times

last updated: 24 Jan '23, 11:47

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum