def output(): l.debug("Outputting XML") # First, set up a few data structures for optimization purposes global geometries, features nodes = [geometry for geometry in geometries if type(geometry) == Point] ways = [geometry for geometry in geometries if type(geometry) == Way] relations = [ geometry for geometry in geometries if type(geometry) == Relation ] featuresmap = {feature.geometry: feature for feature in features} w = XMLWriter(open(options.outputFile, 'w')) w.start("osm", version='0.6', generator='myogr2osm') for node in nodes: w.start("node", version="1", timestamp="2012-01-01T00:00:00.0+11:00", changeset="0", visible="true", id=str(node.id), lat=str(node.y), lon=str(node.x)) if node in featuresmap: for (key, value) in featuresmap[node].tags.items(): w.element("tag", k=key, v=value) w.end("node") for way in ways: w.start("way", version="1", timestamp="2012-01-01T00:00:00.0+11:00", changeset="0", visible="true", id=str(way.id)) for node in way.points: w.element("nd", ref=str(node.id)) if way in featuresmap: for (key, value) in featuresmap[way].tags.items(): w.element("tag", k=key, v=value) w.end("way") for relation in relations: w.start("relation", version="1", timestamp="2012-01-01T00:00:00.0+11:00", changeset="0", visible="true", id=str(relation.id)) for (member, role) in relation.members: w.element("member", type="way", ref=str(member.id), role=role) if relation in featuresmap: for (key, value) in featuresmap[relation].tags.items(): w.element("tag", k=key, v=value) w.end("relation") w.end("osm")
print "Segment join operations: " + str(segmentJoinCount) print "Lines: " + str(lineCount) print "Areas: " + str(areaCount) #print nodeRefs #print segmentNodes #print lineSegments #print areaRings #print segmentRefs print print "Generating OSM XML..." print "Generating nodes." #w = XMLWriter(sys.stdout) w = XMLWriter(open(outputFile, 'w')) w.start("osm", version='0.6', generator='ogr2osm') # First, the nodes for (nodeID, (x, y)) in nodeCoords.items(): w.start("node", visible="true", id=str(nodeID), lat=str(y), lon=str(x)) for (tagKey, tagValue) in nodeTags[nodeID].items(): if tagValue: w.element("tag", k=tagKey, v=tagValue) w.end("node") if showProgress: sys.stdout.write('.') #print "Generated nodes. On to shared segments." # Now, the segments used by more than one line/area, as untagged ways
print "Segment join operations: " + str(segmentJoinCount) print "Lines: " + str(lineCount) print "Areas: " + str(areaCount) #print nodeRefs #print segmentNodes #print lineSegments #print areaRings #print segmentRefs print print "Generating OSM XML..." print "Generating nodes." #w = XMLWriter(sys.stdout) w = XMLWriter(open(options.outputFile, 'w'),encoding='UTF-8') w.declaration() w.start("osm", version='0.6', generator='ogr2osm') # First, the nodes for (nodeID, (x, y)) in nodeCoords.items(): w.start("node", visible="true", id=str(nodeID), lat=str(y), lon=str(x)) for (tagKey, tagValue) in nodeTags[nodeID].items(): if tagValue: w.element("tag", k=escape(tagKey), v=escape(tagValue)) w.end("node") if showProgress: sys.stdout.write('.') #print "Generated nodes. On to shared segments."