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 Network Loader Error #190

Closed milanjanosov closed 4 months ago

milanjanosov commented 4 months ago

Description of the bug

I have been using Pandana for a few years now, and all of a sudden, I bumped into an error also replicated by this short sample code. I first experienced it with Pandana 0.6 - now updated to 0.7, but the issue remains. Any suggestions?

Environment

Paste the code that reproduces the issue here:

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

Paste the error message (if applicable):

AttributeError                            Traceback (most recent call last)
/opt/anaconda3/envs/ox/lib/python3.8/site-packages/geopandas/geodataframe.py in crs(self)
    435         try:
--> 436             return self.geometry.crs
    437         except AttributeError:

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5574             return self[name]
-> 5575         return object.__getattribute__(self, name)
   5576 

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/geopandas/geodataframe.py in _get_geometry(self)
    234 
--> 235             raise AttributeError(msg)
    236         return self[self._geometry_column_name]

AttributeError: You are calling a geospatial method on the GeoDataFrame, but the active geometry column to use has not been set. 
There are no existing columns with geometry data type. You can add a geometry column as the active geometry column with df.set_geometry. 

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
/opt/anaconda3/envs/ox/lib/python3.8/site-packages/pandas/core/generic.py in __setattr__(self, name, value)
   5599             try:
-> 5600                 existing = getattr(self, name)
   5601                 if isinstance(existing, Index):

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5574             return self[name]
-> 5575         return object.__getattribute__(self, name)
   5576 

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/geopandas/geodataframe.py in crs(self)
    437         except AttributeError:
--> 438             raise AttributeError(
    439                 "The CRS attribute of a GeoDataFrame without an active "

AttributeError: The CRS attribute of a GeoDataFrame without an active geometry column is not defined. Use GeoDataFrame.set_geometry to set the active geometry column.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-5-45ce39b05739> in <module>
      1 from pandana.loaders import osm
      2 
----> 3 network = osm.pdna_network_from_bbox(37.698, -122.517, 37.819, -122.354)  # San Francisco, CA

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/pandana/loaders/osm.py in pdna_network_from_bbox(lat_min, lng_min, lat_max, lng_max, bbox, network_type, two_way, timeout, memory, max_query_area_size)
     58                                   "https://udst.github.io/osmnet/")
     59 
---> 60     nodes, edges = network_from_bbox(lat_min=lat_min, lng_min=lng_min,
     61                                      lat_max=lat_max, lng_max=lng_max,
     62                                      bbox=bbox, network_type=network_type,

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/osmnet/load.py in network_from_bbox(lat_min, lng_min, lat_max, lng_max, bbox, network_type, two_way, timeout, memory, max_query_area_size, custom_osm_filter)
    844         'lat_min, lng_min, lat_max, and lng_max must be floats'
    845 
--> 846     nodes, ways, waynodes = ways_in_bbox(
    847         lat_min=lat_min, lng_min=lng_min, lat_max=lat_max, lng_max=lng_max,
    848         network_type=network_type, timeout=timeout,

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/osmnet/load.py in ways_in_bbox(lat_min, lng_min, lat_max, lng_max, network_type, timeout, memory, max_query_area_size, custom_osm_filter)
    648     """
    649     return parse_network_osm_query(
--> 650         osm_net_download(lat_max=lat_max, lat_min=lat_min, lng_min=lng_min,
    651                          lng_max=lng_max, network_type=network_type,
    652                          timeout=timeout, memory=memory,

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/osmnet/load.py in osm_net_download(lat_min, lng_min, lat_max, lng_max, network_type, timeout, memory, max_query_area_size, custom_osm_filter)
    135     polygon = Polygon([(lng_max, lat_min), (lng_min, lat_min),
    136                        (lng_min, lat_max), (lng_max, lat_max)])
--> 137     geometry_proj, crs_proj = project_geometry(polygon,
    138                                                crs={'init': 'epsg:4326'})
    139 

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/osmnet/load.py in project_geometry(geometry, crs, to_latlong)
    443     """
    444     gdf = gpd.GeoDataFrame()
--> 445     gdf.crs = crs
    446     gdf.name = 'geometry to project'
    447     gdf['geometry'] = None

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/geopandas/geodataframe.py in __setattr__(self, attr, val)
    203             object.__setattr__(self, attr, val)
    204         else:
--> 205             super().__setattr__(attr, val)
    206 
    207     def _get_geometry(self):

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/pandas/core/generic.py in __setattr__(self, name, value)
   5614                         stacklevel=find_stack_level(),
   5615                     )
-> 5616                 object.__setattr__(self, name, value)
   5617 
   5618     @final

/opt/anaconda3/envs/ox/lib/python3.8/site-packages/geopandas/geodataframe.py in crs(self, value)
    446         """Sets the value of the crs"""
    447         if self._geometry_column_name is None:
--> 448             raise ValueError(
    449                 "Assigning CRS to a GeoDataFrame without a geometry column is not "
    450                 "supported. Use GeoDataFrame.set_geometry to set the active "

ValueError: Assigning CRS to a GeoDataFrame without a geometry column is not supported. Use GeoDataFrame.set_geometry to set the active geometry column.
sablanchard commented 4 months ago

Hi @milanjanosov , this issue should be fixed with the latest version of Pandana's dependency OSMnet see here for more information: https://github.com/UDST/pandana/issues/182#issuecomment-1662492623 and was fixed here: https://github.com/UDST/osmnet/pull/30 will close this issue for now since its related to OSMnet.