Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions map2loop/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def sample(
Returns:
pandas.DataFrame: the sampled data points
"""
valid_geometry = (
shapely.geometry.point.Point,
shapely.geometry.multipoint.MultiPoint
)

all_valid_geometries = all(isinstance(geom, valid_geometry) for geom in spatial_data.geometry)
if not all_valid_geometries:
raise ValueError("Invalid geometry types found in spatial_data")

data = spatial_data.copy()
data["X"] = data.geometry.x
data["Y"] = data.geometry.y
Expand Down Expand Up @@ -149,6 +158,16 @@ def sample(
Returns:
pandas.DataFrame: the sampled data points
"""
valid_geometry = (
shapely.geometry.multipolygon.MultiPolygon,
shapely.geometry.polygon.Polygon,
shapely.geometry.multilinestring.MultiLineString,
shapely.geometry.linestring.LineString
)
all_valid_geometries = all(isinstance(geom, valid_geometry) for geom in spatial_data.geometry)
if not all_valid_geometries:
raise ValueError("Invalid geometry types found in spatial_data")

schema = {"ID": str, "X": float, "Y": float, "featureId": str}
df = pandas.DataFrame(columns=schema.keys()).astype(schema)
for _, row in spatial_data.iterrows():
Expand Down