2

Here is my problem.

I have a csv file, with latitude and longitude coordinates. I would need to know the name of the French towns and the relevant postal codes that match these coordinates.

My initial coordinates seem to be quite precise as I'm using Maxmind Geolite city. I'm trying to match the coordinates with the data set from this website.

http://public.opendatasoft.com/explore/dataset/correspondance-code-insee-code-postal/?tab=export&location=3,18.54017,-3.01253&basemap=mapquest

However, the coordinates when doing the matching does not work properly.

Question is the following: Is there a online tool where I can load a csv file with the coordinates and whave in return, the postal codes and the names of town?

I'm insisting for French towns as I'm in France.

2

Yes, you may use this site for batch processing:

Batch Conversions of Latitude/Longitude to Address (Reverse Geocoding)

46.7270,2.5059 = Rue des Varennes, Saint-Amand-Montrond, Cher, Centre, Metropolitan France, 18200, France

This site uses MapQuest reverse geocode service. You will have to apply some additional logic to parse out the city/town name and zip info.

1

What you need to do is a spatial join on the lat/long coordinates and the french postal zones

Here is the tutorial http://www.qgistutorials.com/en/docs/performing_spatial_joins.html

The GIS DATA... postal zones can be found on this website

https://www.data.gouv.fr/en/datasets/correspondances-code-insee-code-postal-idf/

Hope this helps!!

  • Hi, I've just tried. Have you try this solution yourself...? – Andy K Nov 6 '14 at 13:11
  • Your answer gave me new thoughts. Thank you for that. – Andy K Nov 6 '14 at 13:37
  • I have done similar spatial joins in the past but have not downloaded the postal zones of france. – jonathanw Nov 7 '14 at 14:32
  • I've tried several attempts but QGIS does not work well with the projections. – Andy K Nov 7 '14 at 14:49
1

After many attempts and even contacting the man, Denis Carrière , who created the geocoder module on Python, please find the solution below.

I feel a bit drained after providing this first foray into developement , although my script was different initially, but I feel happy with the results and the helps. :)

All done in Python, of course.

import geocoder
import unicodecsv
import logging
import time
import csv

pcode=[]

with open('locs2.csv', 'rb') as f:
    reader = csv.DictReader(f)
    for line in reader:            
        lat = float(line['lat'])
        lon = float(line['lon'])
        g = geocoder.mapquest([lat,lon], method='reverse')
        attempts = 1  # number of lookups
        while not(g.ok) and attempts < 4:
            logging.warning('Geocoding ERROR: {}'.format(g.debug()))
            time.sleep(2)  # 2 seconds are specified in the API. If you still get errors, it's because you've reached the daily quota.
            g = geocoder.mapquest([lat,lon], method='reverse')
            attempts += 1
        if attempts > 3:
            logging.warning('Daily quota of google lookups exceeded.')
            break
        pcode.extend(g.postal)
        logging.info('Geocoding SUCCESS: ({},{},{})'.format(lat,lon,pcode))

Link here : https://stackoverflow.com/questions/26914900/reverse-geocoding-with-python-geocoder

  • 1
    Rather than just posting a link, you should include at least a summary of the answer given at the other site, if not the entire answer and just linking there as 'source'. Links can become broken or deprecated, eliminating any usefulness of the answer here. – Chris W Nov 13 '14 at 18:19
  • Hi Chris, indeed. Done. Please have a look. – Andy K Nov 24 '14 at 9:52

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.