View Single Post
  #2  
Old February 13th 06, 08:21 PM posted to rec.aviation.simulators
external usenet poster
 
Posts: n/a
Default Lat/Lon to country codes/political boundaries

You'd need a fairly large database of coordinates to determine that.
Basically what I'd do is generate a fairly dense grid of cells overlaid on a
world map which lists the countries for each cell and store that in a
database.
Then have a system to determine in which cell a particular spacial
coordinate is located.
If you store 2 coordinates of each grid cell (upper left and lower right for
example) you should be able to do that easily.

If there's only one country linked to the gridcell, you have your answer.
If there's more than one you can either subdivide the cell until you get a
clean answer (within restrictions of course, you'll have to break off
somewhere if the coordinates are almost on top of a border), or divide the
border into line segments and determine on which side of the line segment
your coordinate is located which will tell you the country code.
The latter is probably faster to do on the fly, but harder to implement.
The former could be done in advance by enabling the database to store cells
of different sizes.

For example you have a cell with coordinates N0W0-N3W3 which is in the UK.
Now you're looking for N1W1, which lies between N0 and N3 so that gives you
a range of cells.
W1 lies between W0 and W3 which gives you the exact cell and the answer.

Sounds like an interesting project come to think...

"rutledge" wrote in message
oups.com...
Can anybody help me out with taking an arbitrary (lat,lng) pair and
outputting a country code or name?. Ideally, I am looking for source
code that I can wrap into my own flight planner, but anything that
nudges me along in the right direction will be greatly appreciated.

Cheers.