pyrosm/pyrosm

Running the example from the docs, receiving TypeError regarding geometry objects

Closed this issue · 7 comments

Hey there,

so when I try to run the following example, I'm getting the mentioned error which I will also attach. I've tried out multiple ways and multiple kinds of data (buildings, pois, network with specific flags) to no avail.

This is what I'm trying after installing pyrosm with conda install -c conda-forge pyrosm:

from pyrosm import OSM
from pyrosm import get_data

# Pyrosm comes with a couple of test datasets 
# that can be used straight away without
# downloading anything
fp = get_data("test_pbf")

# Initialize the OSM parser object
osm = OSM(fp)

# Read all drivable roads
# =======================
drive_net = osm.get_network(network_type="driving")
drive_net.plot()

which results in:

TypeError                                 Traceback (most recent call last)
Input In [32], in <cell line: 14>()
     10 osm = OSM(fp)
     12 # Read all drivable roads
     13 # =======================
---> 14 drive_net = osm.get_network(network_type="driving")
     15 drive_net.plot()

File ~\anaconda3\envs\dataex\lib\site-packages\pyrosm\pyrosm.py:205, in OSM.get_network(self, network_type, extra_attributes, nodes)
    202     self._read_pbf()
    204 # Filter network data with given filter
--> 205 edges, node_gdf = get_network_data(
    206     self._node_coordinates,
    207     self._way_records,
    208     tags_as_columns,
    209     network_filter,
    210     self.bounding_box,
    211     slice_to_segments=nodes,
    212 )
    214 if edges is not None:
    215     # Add metadata
    216     edges._metadata.append(network_type)

File ~\anaconda3\envs\dataex\lib\site-packages\pyrosm\networks.py:37, in get_network_data(node_coordinates, way_records, tags_as_columns, network_filter, bounding_box, slice_to_segments)
     34     return None, None
     36 # Prepare GeoDataFrame
---> 37 edges, nodes = prepare_geodataframe(
     38     nodes,
     39     node_coordinates,
     40     ways,
     41     relations,
     42     relation_ways,
     43     tags_as_columns,
     44     bounding_box,
     45     parse_network=True,
     46     calculate_seg_lengths=slice_to_segments,
     47 )
     49 return edges, nodes

File ~\anaconda3\envs\dataex\lib\site-packages\pyrosm\frames.pyx:134, in pyrosm.frames.prepare_geodataframe()

File ~\anaconda3\envs\dataex\lib\site-packages\pyrosm\frames.pyx:141, in pyrosm.frames.prepare_geodataframe()

File ~\anaconda3\envs\dataex\lib\site-packages\pyrosm\frames.pyx:71, in pyrosm.frames.prepare_way_gdf()

File ~\anaconda3\envs\dataex\lib\site-packages\geopandas\geodataframe.py:184, in GeoDataFrame.__init__(self, data, geometry, crs, *args, **kwargs)
    182         _crs_mismatch_warning()
    183         # TODO: raise error in 0.9 or 0.10.
--> 184     self.set_geometry(geometry, inplace=True)
    186 if geometry is None and crs:
    187     warnings.warn(
    188         "Assigning CRS to a GeoDataFrame without a geometry column is now "
    189         "deprecated and will not be supported in the future.",
    190         FutureWarning,
    191         stacklevel=2,
    192     )

File ~\anaconda3\envs\dataex\lib\site-packages\geopandas\geodataframe.py:318, in GeoDataFrame.set_geometry(self, col, drop, inplace, crs)
    315     level.crs = crs
    317 # Check that we are using a listlike of geometries
--> 318 level = _ensure_geometry(level, crs=crs)
    319 index = frame.index
    320 frame[geo_column_name] = level

File ~\anaconda3\envs\dataex\lib\site-packages\geopandas\geodataframe.py:43, in _ensure_geometry(data, crs)
     41 else:
     42     if isinstance(data, Series):
---> 43         out = from_shapely(np.asarray(data), crs=crs)
     44         return GeoSeries(out, index=data.index, name=data.name)
     45     else:

File ~\anaconda3\envs\dataex\lib\site-packages\geopandas\array.py:151, in from_shapely(data, crs)
    135 def from_shapely(data, crs=None):
    136     """
    137     Convert a list or array of shapely objects to a GeometryArray.
    138 
   (...)
    149 
    150     """
--> 151     return GeometryArray(vectorized.from_shapely(data), crs=crs)

File ~\anaconda3\envs\dataex\lib\site-packages\geopandas\_vectorized.py:136, in from_shapely(data)
    134         out.append(None)
    135     else:
--> 136         raise TypeError("Input must be valid geometry objects: {0}".format(geom))
    138 if compat.USE_PYGEOS:
    139     return np.array(out, dtype=object)

TypeError: Input must be valid geometry objects: MULTILINESTRING ((26.943 60.526, 26.943 60.526), (26.943 60.526, 26.943 60.526), (26.943 60.526, 26.941 60.528), (26.941 60.528, 26.941 60.528), (26.941 60.528, 26.94 60.53), (26.94 60.53, 26.938 60.532), (26.938 60.532, 26.937 60.533), (26.937 60.533, 26.936 60.534), (26.936 60.534, 26.934 60.536), (26.934 60.536, 26.932 60.538))

@grndng : Hi thanks for raising this issue! This is most likely due to an updated version of pygeos/shapely, and these changes have not yet been accounted for in pyrosm. I will look into this (plus various other issues) in the coming weeks, as I finally should have time to make progress again with this project.

I'm experiencing same error
TypeError: Input must be valid geometry objects: LINESTRING (-2.61 51.366, -2.61 51.366)

Also getting the same error with shapely = "1.8.2"; no errors with shapely = "1.8.1"

Thanks guys for reporting. Will take a look at this after first getting more urgent maintenance related issues fixed.

Same error using Shapely 1.8.0. Any update on the horizon? Thanks

Having the same issue with get_pois(), any updates or workarounds found? Thanks!!

This should be now fixed in the new release pyrosm v0.6.2 which uses by default Shapely 2.0. See #214 .Try updating pyrosm with pip (installing from conda-forge is soon available as well).