In what country are the coordinates 41.44241, 21.31530 ?

A manual Google Maps search tells me it is in Macedonia.

Is there a program (or library) that would tell me this programmatically?


  • If the coordinates are not in a country, it should say sea or something appropriate
  • For contested areas like Kashmir, anything is fine, I am not picky
  • Free
  • Works on Linux
  • If no library/program is available, a web API can be OK too but it must accept at least 50,000 requests daily
  • Did you see stackoverflow.com/questions/10567539/… ? – KGo Mar 20 '15 at 19:36
  • @KaranGoel: That JavaScript question is about some guy's buggy source code that calls Google Maps API, and how to fix that code. Full-address geocoding sounds overkill, but it is certainly much better than nothing, so feel free to add an answer here about Google Maps API :-) – Nicolas Raoul Mar 23 '15 at 3:31
  • Something fundamentally wrong about your request is that you want 50k daily requests for free. If you really have than much quota, you should be expecting to pay. – KGo Mar 24 '15 at 19:19
  • @KaranGoel: If I had a week of vacations right now, I would develop a library that does this, and give it away for free (as open source). It is not rocket science, just get a borders map from OpenStreetMap and calculate in which country each point falls. – Nicolas Raoul Mar 25 '15 at 2:02
  • It honestly doesn't feel like something that would take a week. But at 1.5 million monthly requests it will definitely won't be free. You'll still have to get your own server instances or whatever. – KGo Mar 25 '15 at 6:22

A simple method to match a set of latitudes and longitudes is to use QGIS and the Point Sampling Tool

  1. Firstly, download and install QGIS
  2. Download and install a spatial dataset of political boundary polygons (for example from naturalearthdata.com
  3. Create a CSV containing your points and whatever other attributes you're interested in
  4. Open QGIS and install the Point Sampling Tool plugin (instructions in the QGIS documentation)
  5. Add the political boundaries to the project (instructions in the QGIS docs)
  6. Add the CSV of the points of interest (instructions in the QGIS docs)
  7. Use the Point Sampling Tool by clicking the icon Point Sampling Tool icon in the toolbar
  8. Select the attributes from both layers you want to keep in the new file, and create a new shapefile as output
  9. Check the Add created layer to the TOC button to re-add the data to the map
  10. Right click on the newly created layer in the Table of Contents and select Save Layer As
  11. Select CSV and hit OK and you get a CSV with country points joined to the CSV
  • That works perfectly! 50k points takes about half an hour, which is reasonable. Most importantly, it works offline, which is ideal for time/network costs/privacy. First time using QGIS, it is quite intuitive so the steps above are easily performed. – Nicolas Raoul Mar 30 '15 at 3:40

You're looking at Reverse Geocoding. If you're familiar with Python I'd recommend the geopy library which includes geocoders for a number of services including Yahoo, Google, and OpenStreetMap Nominatum.

Your issue will be the quantity of requests, which will depend on the license of the geocoding service that you use, so you'll have to examine those carefully. For 50 000 addresses per day you may end up having to pay for a service.

For example to use the Google geocoder assuming your points are a latitude/longitude coordinate pair:

from geopy.geocoders import GoogleV3

geolocator = GoogleV3()
location = geolocator.reverse((41.44241, 21.31530), exactly_one=True)

If handling the larger volumes of data as @Nicolas Raoul suggests above you should really be downloading a dataset containing political boundaries (for example from naturalearthdata.com) and using a GIS system such as QGIS to intersect the data with your points.

  • Full address reverse geocoding is overkill for what I am trying to achieve. An offline country-level geocoding library would be perfect. It could be as simple as: IF -32<latitude<-53 AND 164<longitude<180 THEN "New Zealand"-type code (slightly more complex for some countries). Your QGIS idea sounds exactly like what I need, would you mind detailing it a bit as another answer? Thanks a lot! – Nicolas Raoul Mar 26 '15 at 2:23
  • You could also take a look at using the political boundary data from soest.hawaii.edu/pwessel/gshhg or the CIA data evl.uic.edu/pape/data/WDB – Steve Barnes Mar 27 '15 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.