Thursday, January 11, 2018

GPS coordinates of all Slovak villages

While I could get more or less complete GPS coordinates for Czech villages, I had little luck finding the same for Slovakia. In the end I downloaded OpenStreetMap data for Slovakia, cloned imposm.parser, and wrote a simple script to get comma separated values:

hajma@debian:~/bin/osm$ cat
from imposm.parser import OSMParser
import codecs
import locale
import sys

# simple class that handles the parsed OSM data.
class HighwayCounter(object):

    def coords_callback(tags, coords):
        for x in coords:
            if 'place' in x[1].keys():
                if x[1]['place'] == 'village':
                    if 'is_in' in x[1].keys():
                        print("\"%s, %s\", %s, %s" % (x[1]['name'], x[1]['is_in'], x[2][0], x[2][1]))
                        print("\"%s, Slovensko\", %s, %s" % (x[1]['name'], x[2][0], x[2][1]))
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
# instantiate counter and parser and start parsing
counter = HighwayCounter()
p = OSMParser(concurrency=1, nodes_callback=counter.coords_callback)


No comments:

Post a Comment