-
-
Save shurshur/fa83e3182c71c4fff386 to your computer and use it in GitHub Desktop.
Крутилка .osm файлов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: sts=4 sw=4 et | |
import sys, math, lxml.etree | |
if len(sys.argv) != 3 : | |
print "Usage: %s file angle" % sys.argv[0] | |
sys.exit(0) | |
fn, angle = sys.argv[1:] | |
angle = math.radians(float(angle)) | |
turn = complex(math.cos(angle), math.sin(angle)) | |
xml = lxml.etree.parse(fn != "-" and open(fn) or sys.stdin) | |
nodes = xml.xpath('/osm/node') | |
center = complex(float(nodes[0].attrib['lon']), float(nodes[0].attrib['lat'])) | |
sc = math.cos(center.imag) | |
def rotate(e): | |
point = complex(float(e.attrib['lon']), float(e.attrib['lat'])) | |
diff = point - center | |
diff = complex(diff.real*sc, diff.imag) | |
r = diff * turn | |
r = complex(r.real/sc, r.imag) | |
r = center + r | |
e.attrib['lon'], e.attrib['lat'] = str(r.real), str(r.imag) | |
map(rotate, nodes) | |
print lxml.etree.tostring(xml, encoding='utf-8', xml_declaration=True, pretty_print=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment