Running the example from the docs, receiving TypeError regarding geometry objects
See original GitHub issueHey 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))
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeError: Input geometry column must contain valid ...
TypeError: Input geometry column must contain valid geometry objects. I've tried this script which I found for a similar question:
Read more >Converting a column of Polygons from string to GeoPandas ...
TypeError: Input geometry column must contain valid geometry objects. python · polygon · geopandas · Share.
Read more >Issues · HTenkanen/pyrosm - GitHub
Add a progress bar while executing a request ... Running the example from the docs, receiving TypeError regarding geometry objects bug Something isn't...
Read more >Debugging guide | Google Earth Engine
The first error informs you that the bandNames variable is not defined in the scope in which it's referenced. As a solution, set...
Read more >Casper van der Wel - PyGEOS
The Geometry object keeps track of the underlying GEOSGeometry and lets the python ... For other keyword-only arguments, see the NumPy ufunc docs....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
Also getting the same error with shapely = “1.8.2”; no errors with shapely = “1.8.1”