def populate_profile_db(osmdb_name, profiledb_name, dem_basenames, resolution): ddb = OSMDB(osmdb_name) elevs = ElevationPile() for dem_basename in dem_basenames: elevs.add(dem_basename) pdb = ProfileDB(profiledb_name, overwrite=True) n = ddb.count_edges() print "Profiling %d way segments" % n for i, (id, parent_id, node1, node2, dist, geom, tags) in enumerate(ddb.edges()): if i % 1000 == 0: print "%d/%d" % (i, n) raw_profile = elevs.profile(geom, resolution) profile = [] tunnel = tags.get('tunnel') bridge = tags.get('bridge') if tunnel == 'yes' or tunnel == 'true' or bridge == 'yes' or bridge == 'true': if len(raw_profile) > 0: ss, ee = raw_profile[0] if ee is not None: profile.append((ss, ee)) if len(raw_profile) > 1: ss, ee = raw_profile[-1] if ee is not None: profile.append((ss, ee)) else: for ss, ee in raw_profile: if ee is not None: profile.append((ss, ee)) pdb.store(id, profile) pdb.conn.commit()
def populate_profile_db( osmdb_name, profiledb_name, dem_basenames, resolution ): ddb = OSMDB( osmdb_name ) elevs = ElevationPile() for dem_basename in dem_basenames: elevs.add( dem_basename ) pdb = ProfileDB( profiledb_name, overwrite=True ) n = ddb.count_edges() print "Profiling %d way segments"%n for i, (id, parent_id, node1, node2, dist, geom, tags) in enumerate( ddb.edges() ): if i%1000==0: print "%d/%d"%(i,n) raw_profile = elevs.profile( geom, resolution ) profile = [] tunnel = tags.get('tunnel') bridge = tags.get('bridge') if tunnel == 'yes' or tunnel == 'true' or bridge == 'yes' or bridge == 'true': if len(raw_profile) > 0: ss, ee = raw_profile[0] if ee is not None: profile.append( (ss,ee) ) if len(raw_profile) > 1: ss, ee = raw_profile[-1] if ee is not None: profile.append( (ss,ee) ) else: for ss, ee in raw_profile: if ee is not None: profile.append( (ss,ee) ) pdb.store( id, profile ) pdb.conn.commit()
def main(): usage = """usage: python gdb_import_osm.py <graphdb_filename> <osmdb_filename>""" parser = OptionParser(usage=usage) parser.add_option( "-n", "--namespace", dest="namespace", default="osm", help="prefix all imported vertices with namespace string") parser.add_option( "-s", "--slog", action="append", dest="slog_strings", default=[], help= "specify slog for highway type, in highway_type:slog form. For example, 'motorway:10.5'" ) parser.add_option( "-p", "--profiledb", dest="profiledb_filename", default=None, help="specify profiledb to annotate streets with rise/fall data") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() exit(-1) slogs = {} for slog_string in options.slog_strings: highway_type, slog_penalty = slog_string.split(":") slogs[highway_type] = float(slog_penalty) print "slog values: %s" % slogs graphdb_filename = args[0] osmdb_filename = args[1] print "importing osmdb '%s' into graphdb '%s'" % (osmdb_filename, graphdb_filename) profiledb = ProfileDB( options.profiledb_filename) if options.profiledb_filename else None osmdb = OSMDB(osmdb_filename) gdb = GraphDatabase(graphdb_filename, overwrite=False) gdb_import_osm(gdb, osmdb, options.namespace, slogs, profiledb) print "done"
def main(): if len(argv) < 2: print "usage: python import_ned.py graphdb_filename profiledb_filename" return graphdb_filename = argv[1] profiledb_filename = argv[2] gdb = GraphDatabase( graphdb_filename ) profiledb = ProfileDB( profiledb_filename ) n = gdb.num_edges() for i, (oid, vertex1, vertex2, edge) in enumerate( list(gdb.all_edges(include_oid=True)) ): if i%500==0: print "%s/%s"%(i,n) if isinstance( edge, Street ): rise, fall = get_rise_and_fall( profiledb.get( edge.name ) ) edge.rise = rise edge.fall = fall gdb.remove_edge( oid ) gdb.add_edge( vertex1, vertex2, edge )
def main(): if len(argv) < 2: print "usage: python import_ned.py graphdb_filename profiledb_filename" return graphdb_filename = argv[1] profiledb_filename = argv[2] gdb = GraphDatabase(graphdb_filename) profiledb = ProfileDB(profiledb_filename) n = gdb.num_edges() for i, (oid, vertex1, vertex2, edge) in enumerate(list(gdb.all_edges(include_oid=True))): if i % 500 == 0: print "%s/%s" % (i, n) if isinstance(edge, Street): rise, fall = get_rise_and_fall(profiledb.get(edge.name)) edge.rise = rise edge.fall = fall gdb.remove_edge(oid) gdb.add_edge(vertex1, vertex2, edge)
def get( self, external_id ): packed_geom, packed_profile = list(self.execute( "SELECT geom, profile FROM ep_geoms WHERE id=?", (external_id,) ))[0] return unpack_coords( packed_geom ), unpack_coords( packed_profile ) import sys def selftest(): assert description_from_north( (0,0), (0,1) ) == "north" assert description_from_north( (0,0), (1,1) ) == "northeast" assert description_from_north( (0,0), (1,0) ) == "east" assert description_from_north( (0,0), (1,-1) ) == "southeast" assert description_from_north( (0,0), (0,-1) ) == "south" assert description_from_north( (0,0), (-1,-1) ) == "southwest" assert description_from_north( (0,0), (-1,0) ) == "west" assert description_from_north( (0,0), (-1,1) ) == "northwest" if __name__=='__main__': #selftest() print "usage: python shortcut_cache.py basename" basename = sys.argv[1] ch = reincarnate_ch( basename ) osmdb = OSMDB( basename+".osmdb" ) profiledb = ProfileDB( basename+".profiledb" ) scc = ShortcutCache( basename+".scc", overwrite=True ) scc.ingest( osmdb, profiledb, ch.upgraph ) scc.ingest( osmdb, profiledb, ch.downgraph )
def __init__(self, ch_basename, osmdb_filename, profiledb_filename): graphdb = GraphDatabase(graphdb_filename) self.osmdb = OSMDB(osmdb_filename) self.profiledb = ProfileDB(profiledb_filename) self.ch = reincarnate_ch(ch_basename) self.shortcut_cache = ShortcutCache(ch_basename + ".scc")
def main(): usage = """usage: python gdb_import_osm.py <graphdb_filename> <osmdb_filename>""" parser = OptionParser(usage=usage) parser.add_option( "-n", "--namespace", dest="namespace", default="osm", help="prefix all imported vertices with namespace string") parser.add_option( "-s", "--slog", action="append", dest="slog_strings", default=[], help= "specify slog for highway type, in highway_type:slog form. For example, 'motorway:10.5'" ) parser.add_option( "-p", "--profiledb", dest="profiledb_filename", default=None, help="specify profiledb to annotate streets with rise/fall data") parser.add_option( "-c", "--slog_config", dest="slog_config", default=None, metavar="CONFIG.yaml", help="file containing slog parameters for highways, cycleways, etc") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() exit(-1) slogs = {} slog_config = {} if options.slog_config: slog_config = yaml.load(open(options.slog_config).read()) for highway_type, slog_penalty in slog_config.get('slogs', {}).items(): slogs[highway_type] = float(slog_penalty) for slog_string in options.slog_strings: highway_type, slog_penalty = slog_string.split(":") slogs[highway_type] = float(slog_penalty) print "slog values: %s" % slogs slog_config['slogs'] = slogs if slog_config.get('slog_function'): slog_config['slog_function'] = import_object( slog_config['slog_function']) graphdb_filename = args[0] osmdb_filename = args[1] print "importing osmdb '%s' into graphdb '%s'" % (osmdb_filename, graphdb_filename) profiledb = ProfileDB( options.profiledb_filename) if options.profiledb_filename else None osmdb = OSMDB(osmdb_filename) gdb = GraphDatabase(graphdb_filename, overwrite=False) gdb_import_osm(gdb, osmdb, options.namespace, slog_config, profiledb) print "done"