Skip to content

Reverse Geocoding: Find city names from latitude and longitude coordinates

– cross reference and apply shapefile polygons on coordinates in data – Python/GIS | Geopandas & shapley

Use-case:

Applying reverse-geocoding free of charge using an appropriate shapefile (including polygons data) in Python. Let’s say you have some geographical coordinates in your data (latitudes and longitudes). The questions is how to identify the city name, province name or other geographical levels depending on which country or regions we are looking at. This creates a nice consistent location identification in your data. In this tutorial, I use the shapefile polygons from Statistics Canada – Census boundary files. You can find the shapefiles here for download: source: https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-eng.cfm

In the case of Canada and this shapefile, there are geographical information related to Census Division, Census SubDivision, Census Metropolitan Area, Economic Region, Province, among some other levels. We are going to identify all these information using coordinates data.

Video Tutorial for this blog is available here:


Step1: package

Step2: data input

Data sample for coordinate to reverse geocode:

One more thing here is to separate latitude and longitude from comma separated coordinates column:

Step3: Polygon data in shapefiles

We use geopandas package to read the shapefile data.

An important note here is to have mind your coordinate type should be same and consistent between data and shapefile or polygon. Here my data is in normal coordinate type that would normally see using google maps, but not my shapefile coordinate. Hence, I use to_crs function to fix it. More context on that can be found here https://gis.stackexchange.com/questions/276940/re-projecting-lat-and-long-in-python-geopandas-but-geometry-unchanged

Here is the previous of shapefile data:

Step4: test the reverse geocoding method: Point function from shapley package

you get a true or false value from this.

Step5: the main step, scaled application of reverse geocoding on all data

Final data review:

As you can see rows are missing such as first one. This means their coordinates are not matched to any polygons. You may interpret them as invalid or outside scope coordinates.

Related Links

1 thought on “Reverse Geocoding: Find city names from latitude and longitude coordinates”

Leave a Reply

Your email address will not be published. Required fields are marked *