Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geopy: retrieving country names in English

I am trying to reverse geocode coordinates and retrieve corresponding country codes using geopy. However, Geopy does not seem to provide a method for fetching country codes. So, I am trying to retrieve country names first, and then convert them to codes. Unfortunately, my code gives me country names in non-English languages.

How can I fetch country names in English ?

My code:

geolocator = Nominatim()
....
with open('coordinates.txt' , 'r') as readfile:
for line in readfile:
    fields = line.split("\t")
    address, (latitude, longitude) = geolocator.reverse(fields[1]+","+fields[2])
    if address:
        address = address.split(",")
        print "%s" % (address[-1])

The output I am getting:

Ελλάδα
Україна
Türkiye
Shqipëria
Tanzania
ኢትዮጵያ Ethiopia
Bosna i Hercegovina
Türkiye
Shqipëria
România
السودان - Sudan
like image 994
ApplePi Avatar asked Mar 31 '15 05:03

ApplePi


People also ask

What is Nominatim GeoPy?

Nominatim is the Latin for ('by name'). It is also a tool to search OpenStreetMap data by address or location (geocoding). Nominatim is included in the GeoPy in the GeoPy Python library.

What is GeoPy distance?

Geopy is a Python library that simplifies the calculation of geographic distances between two points. It makes it easier for developers to retrieve coordinates of various locations using third-party geocoders, as well as other data sources.


1 Answers

Pass in the language parameter to the reverse() request, e.g.:

geolocator.reverse(','.join(fields[1:3]), language='en')
like image 133
AChampion Avatar answered Oct 14 '22 17:10

AChampion