-
Notifications
You must be signed in to change notification settings - Fork 84
/
createfinalosm.py
68 lines (51 loc) · 2.25 KB
/
createfinalosm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import sys
import imagestoosm.config as osmcfg
import xml.etree.ElementTree as ET
import shapely.geometry as geometry
def makeOsmFileName( fileNumber):
return os.path.join( "anomaly","reviewed_{:02d}.osm".format(fileNumber))
# clean out the old OSM files.
fileCount = 1
while (os.path.exists(makeOsmFileName(fileCount))):
os.remove( makeOsmFileName(fileCount))
fileCount += 1
fileCount = 1
# besides sticking the single accepted OSM files together, this script
# also need to fix up the negative/placeholder ids to be unique in the
# file.
startId = 0
anomalyStatusFile = os.path.join( "anomaly","status.csv")
osmTreeRoot = ET.Element('osm')
osmTreeRoot.attrib['version'] = "0.6"
if ( os.path.exists(anomalyStatusFile)):
with open(anomalyStatusFile,"rt",encoding="ascii") as f:
for line in f:
(status,osmFileName) = line.split(',')
osmFileName = osmFileName.strip()
if ( status == "accepted") :
tree = ET.parse(osmFileName)
root = tree.getroot()
wayCount = 0
for node in root.iter('node'):
node.attrib['id'] = "{0:d}".format(int(node.attrib['id'])-startId)
wayCount += 1
osmTreeRoot.append(node)
for node in root.findall('./way/nd'):
node.attrib['ref'] = "{0:d}".format(int(node.attrib['ref'])-startId)
for node in root.iter('way'):
node.attrib['id'] = "{0:d}".format(int(node.attrib['id'])-startId)
wayCount += 1
osmTreeRoot.append(node)
startId += wayCount
# only only allows 10,000 elements in a single change set upload, make different osm file
# so they can be uploaded without blowing up.
if ( startId > 9500) :
tree = ET.ElementTree(osmTreeRoot)
tree.write( makeOsmFileName(fileCount))
fileCount += 1
osmTreeRoot = ET.Element('osm')
osmTreeRoot.attrib['version'] = "0.6"
startId = 0
tree = ET.ElementTree(osmTreeRoot)
tree.write( makeOsmFileName(fileCount))