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

Hi everyone!

I am trying to retrieve cities from zipcode_state. Here is the code:

Locations = pd.read_csv("geoloc1.csv", delimiter = ';')
Locations = Locations.drop_duplicates()
Locations['GEOLOC1'] = Locations['GEOLOC1'].str.rstrip() # Removing spaces at the right ot the nation name
Locations['CAP NAZIONE'] = Locations['GEOLOC1'].str.split('-').str[-1].str.strip() # Remove everything before -
Locations['CAP NAZIONE'] = Locations['CAP NAZIONE'].str.replace('_',' ') # Substitutes - with space 
Output = pd.DataFrame()

for index, row in Locations.iterrows():
time.sleep(1)
cap = row['CAP NAZIONE'].split(" ",1)[0]
nazione = row['CAP NAZIONE'].split(" ",1)[1]
loca = geocode(query = row['CAP NAZIONE'], addressdetails = True, language = 'it,en')
try:
    row['LOCATION'] = loca.raw['address']['city']
except:
    try:
        row['LOCATION'] = loca.raw['address']['hamlet']
    except:
        try:
            row['LOCATION'] = loca.raw['address']['county']
        except:
            row['LOCATION'] = '_'

if nazione == 'ITALIA':
    try:
        row['REGIONE'] = loca.raw['address']['state']
    except:
        '_'
Output = Output.append(row)

The problem is that fro certain zipcode_nazione it doesn't return the right city. For example: 23841_ITALIA it returns Avellaneda that is in Buenos Aires not in Italy.

How can I get the correct city? Is there something I am doing wrong or some more accurate method, package, library I can use?

Thanks, Carlotta.

asked 31 Mar '20, 17:10

Carlotta's gravatar image

Carlotta
21449
accept rate: 0%


Nobody has added an address in Italy with that postcode to the OpenStreetMap data yet.

Right now https://nominatim.openstreetmap.org/search.php?q=23841+ITALIA returning a residential road in Argentia.

You already set language = 'it,en'. Try if it supports countrycodes = 'it' as well as filter and remove the "Italia" from the main query if possible. That will return no results, but it's slightly better than having the geocoder search in all countries.

OpenStreetMap has no central reporting tool for missing data. We often rely on people living the area to add data. I hope setting the countrycodes filter will return more results for your other postcodes.

permanent link

answered 31 Mar '20, 19:53

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

1

Update: I found the address of a local golf course with the postcode in their website and added it to OpenStreetMap. The Nominatim database updates its postcode database once per night (London time).

(31 Mar '20, 19:57) mtmail

Thank you a lot, I will try with countrycodes and see how it goes.

Thank you for adding this postecode to the OpenStreetMap website. How can I do it if I find other postecodes that are not in the OpenStreetMap data yet?

(01 Apr '20, 08:13) 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
×78
×26
×23
×5

question asked: 31 Mar '20, 17:10

question was seen: 2,528 times

last updated: 01 Apr '20, 08:13

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