Skip to content

Commit

Permalink
🥅 Catch specific ValueError on conversion to spatialpandas
Browse files Browse the repository at this point in the history
On converting a vector geometry in a geopandas.GeoDataFrame (which could be wrapped in StreamWrapper) to a spatialpandas.GeoDataFrame, there could be several different types of `ValueError`s raised. This modifies the exception raising to target only the one specific ValueError caused by invalid geometry type. See logic at https://github.com/holoviz/spatialpandas/blame/v0.4.8/spatialpandas/geometry/base.py#L805-L849 for how the original ValueError is raised. Also clarified that MultiPoint, MultiLineString and MultiPolygon geometry types are supported.
  • Loading branch information
weiji14 committed May 29, 2023
1 parent 377992b commit e4e4d04
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions zen3geo/datapipes/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ def __iter__(self) -> Iterator[xr.DataArray]:
columns = ["geometry"] if not hasattr(vector, "columns") else None
_vector = spatialpandas.GeoDataFrame(data=vector, columns=columns)
except ValueError as e:
raise NotImplementedError(
f"Unsupported geometry type(s) {set(vector.geom_type)} detected, "
"only point, line or polygon vector geometry types are supported."
) from e
if str(e) == "Unable to convert data argument to a GeometryList array":
raise NotImplementedError(
f"Unsupported geometry type(s) {set(vector.geom_type)} detected, "
"only point, line or polygon vector geometry types "
"(or their multi- equivalents) are supported."
) from e
else:
raise e

# Determine geometry type to know which rasterization method to use
vector_dtype: spatialpandas.geometry.GeometryDtype = _vector.geometry.dtype
Expand Down

0 comments on commit e4e4d04

Please sign in to comment.