UDST / pandana

Pandas Network Analysis by UrbanSim: fast accessibility metrics and shortest paths, using contraction hierarchies :world_map:
http://udst.github.io/pandana
GNU Affero General Public License v3.0
385 stars 84 forks source link

osm.pdna_network_from_bbox error #181

Closed SHITIANYU-hue closed 1 year ago

SHITIANYU-hue commented 1 year ago

in the demo, when i run :

network = osm.pdna_network_from_bbox(37.698, -122.517, 37.819, -122.354) # San Francisco, CA

There will be error: ValueError: Assigning CRS to a GeoDataFrame without a geometry column is not supported. Use GeoDataFrame.set_geometry to set the active geometry column.

image

sablanchard commented 1 year ago

Hi @SHITIANYU-hue it looks like you do not have the optional package OSMnet installed in order to use that OSM network download function and thats why you have a geodataframe with no geometry column, see the error: modulenotfounderror in the traceback. try installing that package and trying it again. Ill close this issue for now.

eric-gengzhou commented 1 year ago

I encountered the same error but I do have the OSMnet package installed.

larsschwarz commented 1 year ago

Same here.

pandana 0.6.1 osmnet 0.1.6 geopandas 0.11.0

knaaptime commented 1 year ago

the error originates from osmnet, which pandana uses under the hood. The issue has been fixed upstream, so you can install the dev version of osmnet to get this working until a new release is made over there.

until then you could use osmnx to get the tables you need to input into pandana. Something like this should work

def pdna_network_from_gdf(gdf, network_type='walk'):

    graph = ox.graph_from_polygon(gdf.unary_union, network_type=network_type)
    n,e= ox.utils_graph.graph_to_gdfs(graph, geometry=False)
    e = e.reset_index()

    return pdna.Network(edge_from=e['u'], edge_to=e['v'], edge_weights=e[['length']], node_x=n['x'], node_y=n['y'])
larsschwarz commented 1 year ago

Thanks @knaaptime, I tried the pdna_network_from_gdf fix together the Pandana example. Removed geometry=False, because it triggers another error (TypeError: graph_to_gdfs() got an unexpected keyword argument 'geometry') which seems due to the Osmnx version I use.

However the lcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance') from the example then triggers a

line 395, in _imp_name_to_num assert imp_name in self.impedance_names, "An impedance with that name" \AssertionError: An impedance with that namewas not found

error. Guess I'll try the dev version of osmnet instead now.

knaaptime commented 1 year ago

in the func i gave above the impedance column is "length", so maybe try imp_name='length'

(or you could rename the column from the edge table e=e.rename(columns={'length':'distance'}))