jetzt habe ich nocheinmal ein kleines Python Problem, das ich nicht in den Griff bekomme.
Vielleicht habt Ihr mir auch einen Tipp ?
Ich habe jetzt ein 2. Script, welches dieses Script verwendet: http://www.python-forum.de/topic-12337.html
Der Code ist folgender:
Code: Alles auswählen
import libosm
osmfilename = 'Freiburg_17102007.osm'
print "Opening and parsing OSM file...",
osmfile = libosm.OSMFile( osmfilename )
print "done"
print "Splitting ways...",
osmfile = osmfile.split_ways()
print "done"
print "Outputting to SQL file..."
output = [] # to become list of [edge_id, from_id, to_id, cost, reverse_cost]
i=0
for id, (nodes, tags) in osmfile.ways.iteritems():
cost = osmfile.way_length(id)
if 'oneway' not in tags or (tags['oneway'] != 'true' and tags['oneway'] != 'yes'):
reverse_cost = cost
else:
reverse_cost = 20000000
output.append( ( i, nodes[0], nodes[-1], cost, reverse_cost ) )
i += 1
ret = []
# There's a bug in pgrouting where the server crashes if two node_ids are too far apart.
# So we rename the nodes to values near zero as they go into the SQL file
i=0
osm_to_pgroute = {}
for way_id, from_id, to_id, length, backlength in output:
#=======COPING WITH PGROUTING BUG=============
if from_id in osm_to_pgroute:
from_id = osm_to_pgroute[from_id]
else:
osm_to_pgroute[from_id] = from_id = i
i += 1
if to_id in osm_to_pgroute:
to_id = osm_to_pgroute[to_id]
else:
osm_to_pgroute[to_id] = to_id = i
i += 1
#=======DONE COPING============================
ret.append( "INSERT INTO edges VALUES (%d, %d, %d, %f, %f);"%(way_id, from_id, to_id, length, backlength) )
fp = open( 'routing_table.sql', 'w' )
fp.write( "\n".join(ret) )
fp.close()
Code: Alles auswählen
for id, (nodes, tags) in osmfile.ways.iteritems():
Also habe ich wohl keine Sequenz,...Traceback (most recent call last):
File "osm_to_pgrouting.py", line 17, in <module>
for id, (nodes, tags) in osmfile.ways.iteritems():
TypeError: iteration over non-sequence
Wie kann ich die Schleife umschreiben oder fixen ?
Hat hier jemand eine Idee ?