Użyj OpenStreetMap, dostępu do Internetu, narzędzia wget i filtru XPath, takiego jak XML :: XPath . Żądanie powinno być podzielone na BBoxy 2x2 stopnia. Oto przykład 12 stopni na zachód do 14 stopni na wschód i 52 stopni na południe i 54 stopni na północ. Berlin jest w środku ... z wieloma informacjami. W przypadku mniejszych jednostek użyj miejsca = miasto. Format przychodzący to XML.
wget -O osm-city-12-52-14-54.xml "http://open.mapquestapi.com/xapi/api/0.6/node[place=city][bbox=12,52,14,54]"
wget -O osm-town-12-52-14-54.xml "http://open.mapquestapi.com/xapi/api/0.6/node[place=town][bbox=12,52,14,54]"
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="Osmosis SNAPSHOT-r26564">
<node id="21484051" version="7" timestamp="2010-07-13T20:11:08Z" uid="15720" user="J budissin" changeset="5211741" lat="52.2994511" lon="13.6244389">
<tag k="openGeoDB:auto_update" v="population,is_in"/>
<tag k="openGeoDB:loc_id" v="19549"/>
<tag k="openGeoDB:is_in_loc_id" v="294"/>
<tag k="openGeoDB:name" v="Königs Wusterhausen"/>
<tag k="openGeoDB:is_in" v="Dahme-Spreewald,Brandenburg,Bundesrepublik Deutschland,Europe"/>
<tag k="openGeoDB:layer" v="6"/>
<tag k="openGeoDB:version" v="0.2.6.11 / 2007-12-04 / http://fa-technik.adfc.de/code/opengeodb/dump/"/>
<tag k="openGeoDB:telephone_area_code" v="03375"/>
<tag k="openGeoDB:population" v="32785"/>
<tag k="is_in" v="Dahme-Spreewald,Brandenburg,Bundesrepublik Deutschland,Europe"/>
<tag k="openGeoDB:community_identification_number" v="12061260"/>
<tag k="openGeoDB:license_plate_code" v="LDS"/>
<tag k="openGeoDB:sort_name" v="KOENIGS WUSTERHAUSEN"/>
<tag k="openGeoDB:type" v="Stadt"/>
<tag k="openGeoDB:postal_codes" v="15711,15831"/>
<tag k="name:hsb" v="Parsk (Königs Wusterhausen)"/>
<tag k="name" v="Königs Wusterhausen"/>
<tag k="opengeodb:lat" v="52.296999"/>
<tag k="opengeodb:lon" v="13.6297229"/>
<tag k="place" v="town"/>
<tag k="population" v="33370"/>
</node>
...
Prosty skrypt harlarza perla:
#!/usr/bin/perl -w
# --------------------------------------------------------
# Simple OSM Harvester
# --------------------------------------------------------
use strict;
use XML::XPath;
use XML::XPath::XMLParser;
# Use UFT 8
binmode(STDOUT, ":utf8");
# --------------------------------------------------------
# Parameter @todo put params into commandline arguments
# --------------------------------------------------------
# while ($cmd = shift) {
# $level = shift if $cmd =~ /level/;
# $east = shift if $cmd =~ /east/;
# ....
# }
# --------------------------------------------------------
my $level="town";
my $east=14;
my $west=12;
my $north=54;
my $south=52;
# --------------------------------------------------------
# OS Call wget
# --------------------------------------------------------
my @call =`wget -O osm-town-$west-$south-$east-$north.xml "http://open.mapquestapi.com/xapi/api/0.6/node[place=$level][bbox=$west,$south,$east,$north]"`;
# --------------------------------------------------------
# Parse the stuff
# --------------------------------------------------------
my $xp = XML::XPath->new(filename => "osm-town-$west-$south-$east-$north.xml");
my $nodes = $xp->find('/osm/node'); # find all paragraphs
for my $node ($nodes->get_nodelist) {
# print $n, "\n";
my $lat = $xp->find('./@lat', $node);
my $lon = $xp->find('./@lon', $node);
my $name = $xp->find('./tag[@k=\'name\']/@v', $node);
my $pop = $xp->find('./tag[@k=\'population\']/@v', $node);
print "name=$name\tlogitude=$lon\tlatitude=$lat\tpopulation=$pop\n";
}
# --------------------------------------------------------
# EOF
# --------------------------------------------------------
Wygenerowano wyjście (przepraszam niemiecki LANG z wget)
./osm.pl
Warnung: Joker-Zeichen werden bei HTTP nicht unterstützt.
--2014-02-04 01:13:23-- http://open.mapquestapi.com/xapi/api/0.6/node[place=town][bbox=12,52,14,54]
Auflösen des Hostnamen »open.mapquestapi.com (open.mapquestapi.com)«... 205.188.201.176
Verbindungsaufbau zu open.mapquestapi.com (open.mapquestapi.com)|205.188.201.176|:80... verbunden.
HTTP-Anforderung gesendet, warte auf Antwort... 200 OK
Länge: nicht spezifiziert [text/xml]
In »»osm-town-12-52-14-54.xml«« speichern.
[ <=> ] 128.148 242K/s in 0,5s
2014-02-04 01:13:30 (242 KB/s) - »»osm-town-12-52-14-54.xml«« gespeichert [128148]
name=Königs Wusterhausen logitude=13.6244389 latitude=52.2994511 population=q33370
name=Teterow logitude=12.5753569 latitude=53.7709505 population=9647
name=Neukalen logitude=12.7905515 latitude=53.822817 population=2304
name=Premnitz logitude=12.3384178 latitude=52.5310487 population=9671
name=Havelberg logitude=12.0733335 latitude=52.8234367 population=7400
name=Teltow logitude=13.2644532 latitude=52.4016457 population=19541