Domanda

I have devices moving across the entire country that report their GPS positions back to me. What i would like to do is to have a system that maps these coordinates to a named area.

I see two approaches to this:

  • Have a database that defines areas as polygons stretching between various GPS coords.
  • Use some form of webservice that can provide the info for me.

Either will be fine. It doesn't have to be very accurate at all, as i only need to know the region involved so that i know which regional office to call if something wrong happens with the device.

In the first approach, how would you build an SQL table that contained the data? And what would be your approach for matching a GPS coordinate to one of the defined areas? There wouldn't be many areas to define, and they'd be quite large, so manually inputting the values defining the areas wouldn't be a problem.

In the case of the second approach, does anyone know a way of programatically pulling this info off the web on demand? (I'd probably go for Perl WWW::Mechanize in this case). "close to Somecity" would be enough.

-

PS: This is not a "do the work for me" kind of question, but more of a brainstorming request. pseudo-code is fine. General theorizing on the subject is also fine.

È stato utile?

Soluzione

In the first approach, how would you build an SQL table that contained the data? And what would be your approach for matching a GPS coordinate to one of the defined areas?

Asume: An area is defined as an closed polygon.
You match the GPS coordinate by simply calling a point inside polygon method, like

boolean isInside =  polygon.contains(latitude, longitude);

If you have few polygons you can do a brute force search through all existing polygons. If you have many of them and each (ten-) thousands of points, the you want to use a spatial grid, like a quadtree or k-d tree, to reduce the search to the relevant polygons.

method.

Altri suggerimenti

this process is called reverse geocoding, many services providers such as google, yahoo, and esri provide services that will allow to do this thing

they will return the closest point of interest or address, but you can keep the administrative level you are interested in

check terms of use to see which service is compatible with your intended usage

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top