wildman: (Default)
[personal profile] wildman
использую жж как файло помойку :)


#!/usr/bin/python

import sys
import re

filename = sys.argv[1]
type = sys.argv[2]
print "process [%s]" % filename

tags = {
    'cil': {'natural':'coastline'},
    'bdy': {'boundary':'administrative','admin_level':'8'},
    'riv': {'waterway':'river'},
    }[type]

reSeg = re.compile( 'segment +([0-9]+) +rank +([0-9]+) +points +([0-9]+)' )
reCrd = re.compile( '[ \t]*([0-9]+\.[0-9]+)[ \t]+([0-9]+\.[0-9]+)' )

file = open(filename)
out = open("%s.osm" % filename, 'w')
line = 0
id = {'cil':-1000000, 'bdy':-2000000, 'riv':-3000000}[type]
ids = []
out.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
out.write( "<osm version=\"0.5\" generator=\"wdb2osm.py\">\n" )

while True:
    src = file.readline()
    if src == '':
        break
    src = src.strip()
    matchResult = reSeg.match( src )
    if matchResult:
        print "new seg [%s]" % src
        if ids:
            id -= 1
            out.write( "<way id=\"%d\" user=\"\" timestamp=\"\">\n" % ( id ) )
            for ref in ids:
                out.write( "<nd ref=\"%d\" />\n" % ( ref ) )
            for k in tags.keys():
                out.write( "<tag k=\"%s\" v=\"%s\" />\n" % ( k, tags[k] ) )
            out.write( "</way>\n" )
        ids = []
    else:
        matchResult = reCrd.match( src )
        if matchResult:
            id -= 1
            ids.append( id )
            lat = float( matchResult.group(1) )
            lon = float( matchResult.group(2) )
            out.write( "<node id=\"%d\" lat=\"%f\" lon=\"%f\" user=\"\" timestamp=\"\" />\n" % ( id, lat, lon ) )
    line += 1

out.write( "</osm>\n" )
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

wildman: (Default)
wildman

July 2016

S M T W T F S
     12
3456789
10111213141516
17181920212223
2425 2627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 19th, 2025 05:59 pm
Powered by Dreamwidth Studios