import math import time import string from OSMReader import OSMReader inFile = str(sys.argv[1]) start = time.clock() # # Step 1: Scan input file, build lists # try: # Input is maybe a very big file inputfile = OSMReader(inFile) except: print "Failed to initialize OSMReader with file " + inFile exit(-1) # These are consts. Don't change them ;) cUnknown = -1 cNodes = 1 cWays = 2 cRelations = 3 cChangesets = 4 (root, ext) = os.path.splitext(string.lower(inFile)) outFilename = root+"-junk.osm"
## gp.addfield(nodetagtab,fieldname,"TEXT","#","#","255") except Exception, ErrorDesc: AddMsgAndPrint("Step 1 Failed" + str(ErrorDesc), 1) print gp.GetMessages() del gp sys.exit(-1) # # Step 2: Load nodes and tags # try: AddMsgAndPrint("Step 2/5: Load the nodes and tags") # Input can be an uncompressed OSM XML file or bzip2 or gzip compressed osmFile = OSMReader(inFile) if compress_temp_files: unbuiltsegments = bz2.BZ2File(scratchSpace + '/unbuiltsegments.dat', 'w') unbuiltways = bz2.BZ2File(scratchSpace + '/unbuiltways.dat', 'w') else: unbuiltsegments = open(scratchSpace + '/unbuiltsegments.dat', 'w') unbuiltways = open(scratchSpace + '/unbuiltways.dat', 'w') node = ('ID', 'x', 'y', 'ver', 'ts', 'uid', 'user', 'changeset') way = ('ID', 'ver', 'ts', 'uid', 'user', 'changeset') segment = ('id', 'start', 'end') tag = ('key', 'value') ##------------------------------------------------------------------------------