sg

Cuma, Aralık 09, 2005

Re: Get Country Name


I just remembered I do something similar to this for my site
www.nearby.org.uk

this is done with a list of bounding boxes for each country, then the
smallest rectangle that contains the point of interest is then found.

the datafile I used to import into my database is available here
http://www.nearby.org.uk/coords/countries.csv
and the perl code I used to prototype this data:

$bestarea = 999999999999999999;
open (EXP,"countries.csv");
foreach (<EXP>) {
@parts = split(/,/,$_,5);
if ($x > $parts[0] && $x < $parts[2] &&
$y > $parts[1] && $y < $parts[3]) {
$area = ($parts[2] - $parts[0]) * ($parts[3] && $parts[1]);
if ($area < $bestarea) {
$parts[4] =~ tr/\n\r//d;
$bestcountry = $parts[4];
$bestarea = $area;
}
}
}
close (EXP);

this could easily be implemented in PHP or even javascript, or better
in SQL. Or even better alogirthms are probably possible.

This of course wont be too accurate for iregular shaped landlocked
countries, esp around borders. Also will of course return the country
for around the sea... but by and by is quite acurate...

make what use of the data you can, but it comes with no garentees!

0 Comments:

Yorum Gönder

<< Home


Komik Videolar   islam  şarkı sözleri  yemek tarifleri  gelibolu  huzur   sağlık