Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse Geocoding Without Web Access

I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.

I have a couple ideas so far but wondered if anyone had any ideas on either of the following:

  • What is the best approach for tackling this problem in an efficient manner?
  • Where is a good place to find and what is the appropriate format for North American state/province boundaries

As a starter, here are the two main ideas I have:

  1. Break North America into a grid with each rectangle in the grid mapping to a particular state province. Do a lookup on this table (which grows quickly the more precise you would like to be) based on the latitude and then the longitude (or vice versa).
  2. Define polygons for each of the states and do some sort of calculation to determine in which polygon a lat/lon pair lies. I am not sure exactly how to go about this. HTML image maps come to mind as one way of defining the bounds for a state/province.

I am working in python for the interested or those that might have a nice library they would like to suggest.

To be clear... I do not have web access available to me, so using an existing reverse geocoding service is not an option at runtime

like image 709
Paul Osborne Avatar asked Sep 15 '09 04:09

Paul Osborne


People also ask

How can I reverse geocode for free?

Reverse Geocoding and Geolocation Service by Noggle is a free API that allows developers to embed the functionality to locate the largest city or nearest one to the latitude to longitude location. Another free reverse geocoding API is Opencage Geocoder by Opencage.

Can you reverse geocode in Excel?

You can use the OpenCage Geocoding API inside Microsoft Excel to convert a list of coordinates to placenames (reverse geocoding) or placenames/addresses to coordinates (forward geocoding).

Is Google Maps reverse geocoding free?

It's free as long as you credit them and you need fewer than 15000 lookups per day. You can pay if you need more.

Is there any free geocoding API?

While most geocoding services come with a hefty price tag or credit fee, QGIS offers several geocoding plugins for free. And the best part about QGIS is that it's completely open-source licensed under the GNU General Public License. In QGIS 3, geocoding is all in open source using the OSM Place Search plugin.


2 Answers

I created an offline reverse geocoding module for countries: https://bitbucket.org/richardpenman/reverse_geocode

>>> import reverse_geocode 
>>> coordinates = (-37.81, 144.96), (31.76, 35.21)
>>> reverse_geocode.search(coordinates)
[{'city': 'Melbourne', 'code': 'AU', 'country': 'Australia'},
 {'city': 'Jerusalem', 'code': 'IL', 'country': 'Israel'}]

I will see if I can add data for states.

like image 84
hoju Avatar answered Oct 14 '22 00:10

hoju


I suggest using a variant of your first idea: Use a spatial index. A spatial index is a data structure built from rectangles, mapping lat/long to the payload. In this case you will probably map rectangles to state-province pairs. An R-tree may be a good option. Here's an R-tree python package. You could detect roaming by comparing the results of consecutive searches.

like image 37
Yuval F Avatar answered Oct 14 '22 00:10

Yuval F