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

Pulling network object from OSM bugged #182

Closed eric-gengzhou closed 1 year ago

eric-gengzhou commented 1 year ago

Description of the bug

Trying to pull network object from OSM using the coordinate box but retuned an error indicating no geometry was defined in dataframe.

Environment

Paste the code that reproduces the issue here:

from pandana.loaders import osm
network = osm.pdna_network_from_bbox(37.859, -122.282, 37.881, -122.252)

Paste the error message (if applicable):

/Users/opt/anaconda3/lib/python3.9/site-packages/geopandas/geodataframe.py:202: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  super().__setattr__(attr, val)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/geopandas/geodataframe.py in crs(self)
    430         try:
--> 431             return self.geometry.crs
    432         except AttributeError:

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

~/opt/anaconda3/lib/python3.9/site-packages/geopandas/geodataframe.py in _get_geometry(self)
    231 
--> 232             raise AttributeError(msg)
    233         return self[self._geometry_column_name]

AttributeError: You are calling a geospatial method on the GeoDataFrame, but the active geometry column ('geometry') is not present. 
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/lib/python3.9/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/lib/python3.9/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5574             return self[name]
-> 5575         return object.__getattribute__(self, name)
   5576 

~/opt/anaconda3/lib/python3.9/site-packages/geopandas/geodataframe.py in crs(self)
    432         except AttributeError:
--> 433             raise AttributeError(
    434                 "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)
/var/folders/8n/1m1r9lls5xd94qn848tmnf9h0000gn/T/ipykernel_1495/228294648.py in <module>
      1 from pandana.loaders import osm
----> 2 network = osm.pdna_network_from_bbox(37.859, -122.282, 37.881, -122.252)

~/opt/anaconda3/lib/python3.9/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/lib/python3.9/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/lib/python3.9/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/lib/python3.9/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/lib/python3.9/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/lib/python3.9/site-packages/geopandas/geodataframe.py in __setattr__(self, attr, val)
    200             object.__setattr__(self, attr, val)
    201         else:
--> 202             super().__setattr__(attr, val)
    203 
    204     def _get_geometry(self):

~/opt/anaconda3/lib/python3.9/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/lib/python3.9/site-packages/geopandas/geodataframe.py in crs(self, value)
    441         """Sets the value of the crs"""
    442         if self._geometry_column_name not in self:
--> 443             raise ValueError(
    444                 "Assigning CRS to a GeoDataFrame without a geometry column is not "
    445                 "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.
syedahmarabbas commented 1 year ago

I have the same issue. Built details:

geopandas                 0.12.2             pyhd8ed1ab_0    conda-forge
hdf5                      1.12.2          nompi_ha7af310_101    conda-forge
pandana                   0.6.1            py39h9d68c2a_1    conda-forge
osmnet                    0.1.6                      py_0    conda-forge
python                    3.9.16          hea58f1e_0_cpython    conda-forge
sablanchard commented 1 year ago

Issue is the same as this one: https://github.com/UDST/pandana/issues/181 and has a work around here: https://github.com/UDST/pandana/issues/181#issuecomment-1402839437 its an issue with a Pandana dependency, not Pandana itself.