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

I am trying to retrieve some cities names from zip codes using Geopy Nominatim. Here is the code:

from geopy.geocoders import Nominatim
geolocator = Nominatim()

Locations = pd.read_csv("cap.csv", delimiter = '\t')
Locations.columns = ['CAP']
Locations = Locations.drop_duplicates()
Cities = []
for cap in Locations['CAP']:
  print(cap)
  city = geolocator.geocode(query = cap, addressdetails = True, language = 'it')

The problem is that the results I get are not in Italian, but they are:

arrondissement d'Anfa مقاطعة أنفا
성거읍
Sinak
Galatone
H/E Ward
Δήμος Κερατσινίου - Δραπετσώνας

Do you know how can I get these names in Italian?

I would also like to get a more detailed address output. At the moment this is what I get: Susegana, Treviso, Veneto, 31058, Italia

I would like something that tells me which is the city, so for example city: Susegana, etc.

Thank you, Carlotta.

asked 30 Mar '20, 08:17

Carlotta's gravatar image

Carlotta
21449
accept rate: 0%

edited 30 Mar '20, 10:42


Nominatim can only return Italian names if there are ones in the database (e.g. the name:it hstore tag has a value).

You could try to alter your geolocator.geocode call by setting it's language to 'it,en' to get more results in latin script, as the name:en hstore tag is far more often filled with a value than the name:it one.

permanent link

answered 30 Mar '20, 10:29

Spiekerooger's gravatar image

Spiekerooger
3.1k22356
accept rate: 16%

Thanks!

I will try this way and let you know if I solved my problem.

At the moment if I do city.address I get this output: Susegana, Treviso, Veneto, 31058, Italia

I assumed that the city is the first string, but I am not sure. Is there a way to get an output that tells me something like city: Susegana, etc? I tried with addressdetails = True, but it doesn't seem to return what I need.

Thanks, Carlotta.

(30 Mar '20, 10:40) Carlotta
1

I'm not familiar with geopy, but the city name should be in address.city from the addressdetails. Your city.address looks rather like the display_name returned by Nominatim. Can you get the raw output returned by the geocode function and than see if you have a ['address']['city'] in there?

(30 Mar '20, 10:56) Spiekerooger
2

You are totally right! Under city.raw['address']['town'] I found what I needed.

Thanks, Carlotta.

(30 Mar '20, 11:12) Carlotta

Many countries have 5 digit zip codes. Make sure you add the country name to the query, e.g. '12345, Italy'. It also helps to inspect the result for the country and remove any that are not in Italy.

permanent link

answered 30 Mar '20, 11:57

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

Thanks, I had in plan to add it but thank you for the advice anyway!

(30 Mar '20, 14:04) Carlotta

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×689
×133
×107
×78
×72

question asked: 30 Mar '20, 08:17

question was seen: 3,011 times

last updated: 30 Mar '20, 14:04

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