min_node_id = 100000000 max_node_id = 0 min_way_node_id = 100000000 max_way_node_id = 0 obj_count = 0 from OSMReader import OSMReader # # Step 1: Scan input file, build lists # try: # Input is maybe a very big file inputfile = OSMReader(inFile) except: print "Failed to initialize OSMReader" exit(-1) if show_stats: print "Step 1: List nodes in BBOX" try: #for uline in inputfile: while True: # Read one OSM XML object without depending on line breaks # (so this works with history files) inputfile.getNextObject()
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"
from collections import Counter from OSMReader import OSMReader from matplotlib import pyplot as plt from methods import methods infile = '/home/sofiane/projects/data/overpass_doha_roads.geojson' rn, line_points, line_properties = OSMReader.build_road_network_from_overpass_output(infile) methods.draw_roadnet_with_edge_features(rn, discriminating_feature='maxspeed') way_lanes = [] way_speeds = [] way_oneway = [] for k, v in line_properties.iteritems(): way_lanes.append(v.get('lanes', None)) way_speeds.append(v.get('maxspeed', None)) way_oneway.append(v.get('oneway', None)) cnt = Counter(way_lanes) cnt = cnt.most_common() plt.figure(figsize=(12,6)) plt.bar(range(len(cnt)), [v[1] for v in cnt], width=1/1, color="blue", align='center') plt.xticks(range(len(cnt)), [v[0] for v in cnt], fontsize=12) plt.ylabel('Number of OSM ways') plt.xlabel('OSM Lanes Label') #plt.savefig('/home/sofiane/papers/1.in_preparation/mapMetadata/figs/osm_nb_lanes.pdf', format='PDF') cnt = Counter(way_speeds)
## 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') ##------------------------------------------------------------------------------
## 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') ##------------------------------------------------------------------------------
for ii in range(3): seeds, seedweight = splitclusters(datapointwts, seeds) print('cluster split: ', time.time() - start) gedges = coocurematrix(datapointwts, seeds) print('coocurence matrix computed: ', time.time() - start) gedges = prunegraph(gedges, seeds) print('graph pruning. number of edges = ', len(gedges), time.time() - start) getgeojson(gedges, seeds) printedges(gedges, seeds, datapointwts) printclusters(seeds) # 2. Run the map fusion code. start = time.time() # Work on the static map: OSM, etc. G = OSMReader.build_road_network_from_osm_shapefile(basemap_path) print('Generated OSM graph from shapefiles in:', time.time() - start) seedsosm, neighborsosm = getosmmap(base_map=G) seedsosm, neighborsosm = densifymap(seedsosm, neighborsosm, 20) print ('osm map read/densified: ', time.time()-start, len(seedsosm), \ sum([len(neighborsosm[xx]) for xx in neighborsosm])) clusters, clusterneighbour = getclusters(seedsosm, neighborsosm) deadclusters = detectdeadclusters(densified_data, clusters, clusterneighbour) print('dead clusters found: ', time.time() - start, len(deadclusters)) clusters1, clusterneighbour1 = deletenodesfromgraph( clusters, clusterneighbour, deadclusters) # Work on Kharita seedskha, neighborskha = getourmap() seedskha, neighborskha = stitchtwomaps(seedskha, neighborskha, clusters1, clusterneighbour1)