Skip to content

Instantly share code, notes, and snippets.

/rotate.py Secret

Created September 21, 2011 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/dfdb507f3a32002ffc18 to your computer and use it in GitHub Desktop.
Save anonymous/dfdb507f3a32002ffc18 to your computer and use it in GitHub Desktop.
Крутилка .osm файлов
#!/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']))
def rotate(e):
point = complex(float(e.attrib['lon']), float(e.attrib['lat']))
r = center + (point - center) * turn
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