UDST / urbanaccess

A tool for GTFS transit and OSM pedestrian network accessibility analysis by UrbanSim
https://udst.github.io/urbanaccess/index.html
GNU Affero General Public License v3.0
241 stars 57 forks source link

OSM download function broken #93

Closed dagvogeltje closed 1 year ago

dagvogeltje commented 1 year ago

Description of the bug

Hello everyone,

I am trying to follow the urbanaccess example code, but it returns an error at the OSM data download part, something related to geopandas...

GTFS feed or OSM data (optional)

GTFS data is for Belgian transit agency De Lijn. OSM bounding box is 4.6109,50.5534,6.1737,51.5273 (Basically Belgian Limburg and Dutch Limburg, with Eindhoven, Aachen, and Liege included.)

Environment

Paste the code that reproduces the issue here:

nodes, edges = urbanaccess.osm.load.ua_network_from_bbox(bbox=bbox,
                                                remove_lcn=True)

Everything else is exactly same as the example code, except:

  1. Loading GTFS instead of downloading first. Downloading GTFS instead of loading from PC did not change anything with the error.

    validation = True
    verbose = True
    remove_stops_outsidebbox = True
    append_definitions = True
    # bbox for Euregio
    bbox = (4.6109,50.5534,6.1737,51.5273)
    # Change directory to change scenarios
    loaded_feeds = ua.gtfs.load.gtfsfeed_to_df(gtfsfeed_path="D:\Data\GTFS",
                                           validation=validation,
                                           verbose=verbose,
                                           bbox=bbox,
                                           remove_stops_outsidebbox=remove_stops_outsidebbox,
                                           append_definitions=append_definitions)
  2. Converted date column from int64 to object. Removing this didn't change anything with the error.

    
    loaded_feeds.calendar_dates=loaded_feeds.calendar_dates.astype({'date':'object'})
    loaded_feeds.calendar_dates['date']=loaded_feeds.calendar_dates['date'].apply(lambda x: str(x))
    print (loaded_feeds.calendar_dates.dtypes)

loaded_feeds.calendar_dates.head()

ua.gtfs.network.create_transit_net(gtfsfeeds_dfs=loaded_feeds, day='thursday', timerange=['07:30:00', '09:30:00'], calendar_dates_lookup={'date':'20211007'})


#### Paste the error message (if applicable):
```python
C:\Anaconda\lib\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)
C:\Anaconda\lib\site-packages\geopandas\geodataframe.py in crs(self)
    430         try:
--> 431             return self.geometry.crs
    432         except AttributeError:

C:\Anaconda\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5574             return self[name]
-> 5575         return object.__getattribute__(self, name)
   5576 

C:\Anaconda\lib\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)
C:\Anaconda\lib\site-packages\pandas\core\generic.py in __setattr__(self, name, value)
   5599             try:
-> 5600                 existing = getattr(self, name)
   5601                 if isinstance(existing, Index):

C:\Anaconda\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5574             return self[name]
-> 5575         return object.__getattribute__(self, name)
   5576 

C:\Anaconda\lib\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)
~\AppData\Local\Temp\ipykernel_19732\129358322.py in <module>
----> 1 nodes, edges = ua.osm.load.ua_network_from_bbox(bbox=bbox,
      2                                                 remove_lcn=True)

C:\Anaconda\lib\site-packages\urbanaccess\osm\load.py in ua_network_from_bbox(lat_min, lng_min, lat_max, lng_max, bbox, network_type, timeout, memory, max_query_area_size, remove_lcn)
     74     two_way = False
     75 
---> 76     nodes, edges = network_from_bbox(lat_min=lat_min, lng_min=lng_min,
     77                                      lat_max=lat_max, lng_max=lng_max,
     78                                      bbox=bbox, network_type=network_type,

C:\Anaconda\lib\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,

C:\Anaconda\lib\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,

C:\Anaconda\lib\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 

C:\Anaconda\lib\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

C:\Anaconda\lib\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):

C:\Anaconda\lib\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

C:\Anaconda\lib\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.
sablanchard commented 1 year ago

Thanks @dagvogeltje, this is related to the dependency package OSMnet here: https://github.com/UDST/osmnet and is not an issue with UrbanAccess. This issue for OSMnet has been fixed on the dev branch of the OSMnet package but has not yet been released on conda or pip so Id suggest installing the latest version of OSMnet from the dev branch manually by:

closing this issue since its related to OSMnet