Skip to content

Commit 14f0a32

Browse files
committed
grid, implode; some comments
20141210 grid2m and implode (wipe) scripts from Xmypblu 20141210 describing comments for ellipse, replace2 and tagcalc (two latest renamed for menu)
1 parent 026f394 commit 14f0a32

11 files changed

+247
-11
lines changed

ellipse.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# -*- coding: utf-8 -*-
33
#
44
# ellipse.py {Center} {Radius1} {Radius2} {Angle} {Sides}
5-
#
5+
#
6+
# Script creates ellipse, specified by center, semi-major and semi-minor axises and rotation angle
7+
# Hint: ellipse with 4 sides allows to draw rotated axises
8+
#
69
# Made from circle.py ( Copyright 2010-2011 Hind <foxhind@gmail.com> )
710
# by OverQuantum, 2014-10-30
811
# bugfix by Vitalts (comma support+spaces), 2014-10-31

grid2m.png

320 Bytes
Loading

grid2m.py

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# grid2m.py {Cell}
5+
#
6+
# Script creates square grid escribing selected object(s)
7+
# (members of selected relations is not counted)
8+
# Will not create grid for 1 node or so
9+
#
10+
# Made from grid2m script by Xmypblu (2014-01-18, https://github.com/Xmypblu)
11+
# by OverQuantum 2014
12+
# 2014-12-10 updated for counting several objects, including nodes (+minor modification)
13+
#
14+
# This program is free software; you can redistribute it and/or modify
15+
# it under the terms of the GNU General Public License as published by
16+
# the Free Software Foundation; either version 2 of the License, or
17+
# (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27+
# MA 02110-1301, USA.
28+
29+
import sys
30+
import math
31+
import projections
32+
from OsmData import OsmData, LON, LAT, REF, ACTION, DELETE
33+
34+
if sys.version_info[0] < 3:
35+
reload(sys)
36+
sys.setdefaultencoding("utf-8") # a hack to support UTF-8
37+
38+
def main():
39+
nData = OsmData() # Nodes
40+
rData = OsmData() # Escribing way
41+
nData.read(sys.stdin)
42+
rData.read(sys.stdin)
43+
cell = float(sys.argv[1].replace(',', '.')) # cell size, meters
44+
45+
rbbox = getbbox(rData, nData) # bbox of escribing objects
46+
if rbbox[0]>rbbox[2]: #degenerate bbox, nothing was selected or only relations
47+
return 0
48+
rcenter = getbboxcenter(rbbox) # bbox center
49+
50+
b_cells = bbox_cell(rbbox, rcenter, cell)
51+
createcell(b_cells, rData, nData)
52+
53+
def bbox_cell (rbbox, rcenter, cell):
54+
nbbox_lon = []
55+
nbbox_lat = []
56+
nbbox = []
57+
58+
a1 = projections.from4326((rbbox[0],rbbox[1]), "EPSG:3857")
59+
b1 = projections.from4326((rbbox[2],rbbox[3]), "EPSG:3857")
60+
cell = float(cell)/math.cos(math.radians(rcenter[1]))
61+
62+
a = a1[0] # base coordinates
63+
b = a1[1]
64+
65+
while a < b1[0]:
66+
nbbox_lon.append(a)
67+
a += cell
68+
69+
while b < b1[1]:
70+
nbbox_lat.append(b)
71+
b += cell
72+
73+
for z in nbbox_lon:
74+
for x in nbbox_lat:
75+
z2 = z + cell
76+
x2 = x + cell
77+
nbbox.append([[z, x2], [z2, x2], [z2, x], [z, x]])
78+
return nbbox
79+
80+
def createcell(b_cells, rData, nData):
81+
n=0
82+
for i in b_cells:
83+
wayid = rData.addway()
84+
for y in i:
85+
node = projections.to4326((y[0], y[1]), "EPSG:3857")
86+
nodeid = rData.addnode()
87+
rData.nodes[nodeid][LON] = node[0]
88+
rData.nodes[nodeid][LAT] = node[1]
89+
rData.ways[wayid][REF].append(nodeid)
90+
rData.ways[wayid][REF].append(rData.ways[wayid][REF][0])
91+
n+=1
92+
rData.addcomment("Created " + str(n) + " squares.")
93+
rData.write(sys.stdout)
94+
return 0
95+
96+
def getbbox(data, nodedata):
97+
bbox = [1000, 1000, -1000, -1000] #degenerate bbox for lat/lon
98+
for wayid in data.ways.keys():
99+
for nodeid in data.ways[wayid][REF]:
100+
node = nodedata.nodes[nodeid]
101+
if node[LON] < bbox[0]:
102+
bbox[0] = node[LON]
103+
if node[LON] > bbox[2]:
104+
bbox[2] = node[LON]
105+
if node[LAT] < bbox[1]:
106+
bbox[1] = node[LAT]
107+
if node[LAT] > bbox[3]:
108+
bbox[3] = node[LAT]
109+
for nodeid in data.nodes.keys():
110+
node = data.nodes[nodeid]
111+
if node[LON] < bbox[0]:
112+
bbox[0] = node[LON]
113+
if node[LON] > bbox[2]:
114+
bbox[2] = node[LON]
115+
if node[LAT] < bbox[1]:
116+
bbox[1] = node[LAT]
117+
if node[LAT] > bbox[3]:
118+
bbox[3] = node[LAT]
119+
return bbox
120+
121+
def getbboxcenter(bbox):
122+
return ((bbox[0] + bbox[2]) * 0.5, (bbox[1] + bbox[3]) * 0.5)
123+
124+
if __name__ == '__main__':
125+
main()

grid2m.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<command version="3" name="Grid" icon="grid2m.png" run="python grid2m.py {Cell}">
3+
<parameter required="true" type="any" maxinstances="0">
4+
<name>Escribing</name>
5+
<description>Object(s) to cover with grid</description>
6+
</parameter>
7+
<parameter required="true" type="length" minvalue="0.1" maxvalue="10000">
8+
<name>Cell</name>
9+
<description>Cell size(m)</description>
10+
<value>100</value>
11+
</parameter>
12+
</command>

implode.png

1.27 KB
Loading

implode.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# implode.py
5+
#
6+
# Script implodes each selected way to a single node (bbox center) which inherits all way's tags
7+
#
8+
# Made from wipe script by Xmypblu (2014-01-18, https://github.com/Xmypblu)
9+
# by OverQuantum, 2014-12-10
10+
#
11+
# This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU General Public License as published by
13+
# the Free Software Foundation; either version 2 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; if not, write to the Free Software
23+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24+
# MA 02110-1301, USA.
25+
26+
import sys
27+
import math
28+
29+
from OsmData import OsmData, Map, LON, LAT, ACTION, MODIFY, TAG, CREATE, REF, NODES, WAYS, RELATIONS, DELETE
30+
31+
if sys.version_info[0] < 3:
32+
reload(sys)
33+
sys.setdefaultencoding("utf-8") # a hack to support UTF-8
34+
35+
def main():
36+
nData = OsmData() # Nodes
37+
rData = OsmData() # Reference way
38+
nData.read(sys.stdin)
39+
rData.read(sys.stdin)
40+
idn = list(rData.ways.keys())
41+
createnode(rData, nData, idn)
42+
43+
def createnode(rData, nData, idn):
44+
for a in idn:
45+
rbbox = getbbox(rData, nData, a)
46+
rcenter = getbboxcenter(rbbox)
47+
nid = rData.addnode()
48+
rData.nodes[nid][LON] = rcenter[0]
49+
rData.nodes[nid][LAT] = rcenter[1]
50+
rData.nodes[nid][TAG] = rData.ways[a][TAG].copy()
51+
way = rData.ways[a]
52+
way[ACTION] = DELETE
53+
ispolygon = way[REF][0] == way[REF][len(way[REF]) - 1]
54+
to = len(way[REF])
55+
if ispolygon: to -= 1
56+
for i in range(to):
57+
nodeid = way[REF][i]
58+
nData.nodes[nodeid][ACTION] = DELETE
59+
rData.nodes.update(nData.nodes)
60+
rData.ways.update(rData.ways)
61+
rData.write(sys.stdout)
62+
return 0
63+
64+
def getbbox(data, nodedata, wayid):
65+
anynode = nodedata.nodes[data.ways[wayid][REF][0]]
66+
bbox = [anynode[LON], anynode[LAT], anynode[LON], anynode[LAT]]
67+
for nodeid in data.ways[wayid][REF]:
68+
node = nodedata.nodes[nodeid]
69+
if node[LON] < bbox[0]:
70+
bbox[0] = node[LON]
71+
elif node[LON] > bbox[2]:
72+
bbox[2] = node[LON]
73+
if node[LAT] < bbox[1]:
74+
bbox[1] = node[LAT]
75+
elif node[LAT] > bbox[3]:
76+
bbox[3] = node[LAT]
77+
return bbox
78+
79+
def getbboxcenter(bbox):
80+
return (bbox[0] + (bbox[2] - bbox[0]) / 2.0, bbox[1] + (bbox[3] - bbox[1]) / 2.0)
81+
82+
if __name__ == '__main__':
83+
main()

implode.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<command version="3" name="Implode" icon="implode.png" run="python implode.py">
3+
<parameter required="true" type="way" maxinstances="0">
4+
<name>Objects</name>
5+
<description>Objects to implode</description>
6+
</parameter>
7+
</command>

replace2.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
#
4-
# replace2.py - without rotation
4+
# replace2.py
5+
#
6+
# Script performs replacing geometry of target objects by reference object with care of existing nodes and tags
7+
# This script does not perform rotation of objects, unlike original replace.py
58
#
69
# Copyright 2011 Hind <foxhind@gmail.com>
7-
# modified by OverQuantum, 2012-08-05
8-
# updated 2012-08-18
9-
# fix to 4 spaces indentation 2014-12-06
10+
# 2012-08-05 modified by OverQuantum for no rotation
11+
# 2012-08-18 updated from new replace.py
12+
# 2014-12-06 fix to 4 spaces indentation
1013
#
1114
# This program is free software; you can redistribute it and/or modify
1215
# it under the terms of the GNU General Public License as published by

replace2.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<command version="3" name="Replace2" icon="replace2.png" run="python replace2.py">
2+
<command version="3" name="Replace2 (no rotation)" icon="replace2.png" run="python replace2.py">
33
<parameter required="true" type="way">
44
<name>Ref</name>
55
<description>Reference way</description>

tagcalc.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
#
44
# regexp.py {NewTag} {Formula}
55
#
6-
# Made from regexp.py ( Copyright 2011 Hind <foxhind@gmail.com> )
7-
# by OverQuantum, 2014-12-06 - 2014-12-09
6+
# Script creates new tag on each selected object, tag is calculated by formula,
7+
# allowing to concatenate object's tags and some parameters
88
#
99
# Formula = [ <fix string> ] [ #tag=<tag># ] [ <fix string> ] [ #p=<param># ] [ <fix string> ]
1010
# <tag> - tag name (key) of this object
1111
# <param> = lat / lon / uid / ver / user / chg / nodes / ways / rels
1212
# uid - user id; nodes - valid for ways and relations; lat and lon works only for nodes
13-
# note: <fix string> should contain "" to have " in result (due to command line interface)
13+
# note: <fix string> should contain "" to have " in result (due to interface of CommandLine)
14+
#
15+
# Example: regexp.py "name" "Height #tag=ele#"
1416
#
15-
# example: regexp.py "name" "Height #tag=ele#"
17+
# Made from regexp.py ( Copyright 2011 Hind <foxhind@gmail.com> )
18+
# by OverQuantum, 2014-12-06 - 2014-12-09
1619
#
1720
# This program is free software; you can redistribute it and/or modify
1821
# it under the terms of the GNU General Public License as published by

tagcalc.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<command version="3" name="TagCalc" icon="tagcalc.png" run='python tagcalc.py "{NewTag}" "{Formula}"'>
2+
<command version="3" name="TagCalc (experimental)" icon="tagcalc.png" run='python tagcalc.py "{NewTag}" "{Formula}"'>
33
<parameter required="true" type="any" maxinstances="0">
44
<name>Objects</name>
55
<description>Any objects to processing</description>

0 commit comments

Comments
 (0)