Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2014 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0e3e726397591b16cbcf to your computer and use it in GitHub Desktop.
Save anonymous/0e3e726397591b16cbcf to your computer and use it in GitHub Desktop.
JOSM Command Line plugin "Ellipse" by OverQuantum bugfix (support commas in parameters)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# ellipse.py {Center} {Radius1} {Radius2} {Angle} {Sides}
#
# Made from circle.py ( Copyright 2010-2011 Hind <foxhind@gmail.com> )
# by OverQuantum, 2014-10-30
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import sys
import math
import projections
from OsmData import OsmData, LON, LAT, TAG, REF, NODES
def main():
if len(sys.argv) != 6:
return 0
sides = int(sys.argv[5])
if sides < 3:
return 0
coords = (sys.argv[1].split(','))
lon = float(coords[0].replace(',', '.'))
lat = float(coords[1].replace(',', '.'))
radius1 = float(sys.argv[2].replace(',', '.'))/math.cos(math.radians(lat))
radius2 = float(sys.argv[3].replace(',', '.'))/math.cos(math.radians(lat))
rot_angle = math.radians(float(sys.argv[4].replace(',', '.')))
if radius1 <= 0:
return 0
if radius2 <= 0:
return 0
startangle = 0
coords_m = projections.from4326((lon,lat), "EPSG:3857")
tData = OsmData()
wayid = tData.addway()
for i in range(sides):
angle = startangle + 2*math.pi*i/sides
x = coords_m[0] + radius1 * math.cos(angle) * math.cos(rot_angle) - radius2 * math.sin(angle) * math.sin(rot_angle)
y = coords_m[1] + radius1 * math.cos(angle) * math.sin(rot_angle) + radius2 * math.sin(angle) * math.cos(rot_angle)
node = projections.to4326((x, y), "EPSG:3857")
nodeid = tData.addnode()
tData.nodes[nodeid][LON] = node[0]
tData.nodes[nodeid][LAT] = node[1]
tData.ways[wayid][REF].append(nodeid)
tData.ways[wayid][REF].append(tData.ways[wayid][REF][0])
tData.addcomment("Done.")
tData.write(sys.stdout)
return 0
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment