Skip to content

Commit

Permalink
Merge pull request #986 from mapswipe/street-project-exception-handling
Browse files Browse the repository at this point in the history
fix: exception handling when no elements are matched with filter
  • Loading branch information
ofr1tz authored Dec 17, 2024
2 parents c3b58aa + 0f54062 commit 2a25bd8
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions mapswipe_workers/mapswipe_workers/utils/process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,35 @@ def get_image_metadata(
):
aoi_polygon = geojson_to_polygon(aoi_geojson)
downloaded_metadata = coordinate_download(aoi_polygon, level, attempt_limit)
if downloaded_metadata.isna().all().all() or downloaded_metadata.empty:

if downloaded_metadata.empty or downloaded_metadata.isna().all().all():
raise ValueError("No Mapillary Features in the AoI.")

downloaded_metadata = downloaded_metadata[
downloaded_metadata["geometry"].apply(lambda geom: isinstance(geom, Point))
]

downloaded_metadata = filter_results(
filtered_metadata = filter_results(
downloaded_metadata, creator_id, is_pano, organization_id, start_time, end_time
)
if sampling_threshold is not None:
downloaded_metadata = spatial_sampling(downloaded_metadata, sampling_threshold)

if (
downloaded_metadata.isna().all().all() is False
or downloaded_metadata.empty is False
filtered_metadata is None
or filtered_metadata.empty
or filtered_metadata.isna().all().all()
):
if len(downloaded_metadata) > 100000:
err = (
f"Too many Images with selected filter "
f"options for the AoI: {len(downloaded_metadata)}"
)
raise ValueError(err)
else:
return {
"ids": downloaded_metadata["id"].tolist(),
"geometries": downloaded_metadata["geometry"].tolist(),
}
else:
raise ValueError("No Mapillary Features in the AoI match the filter criteria.")

if sampling_threshold is not None:
filtered_metadata = spatial_sampling(filtered_metadata, sampling_threshold)

total_images = len(filtered_metadata)
if total_images > 100000:
raise ValueError(
f"Too many Images with selected filter options for the AoI: {total_images}"
)

return {
"ids": filtered_metadata["id"].tolist(),
"geometries": filtered_metadata["geometry"].tolist(),
}

0 comments on commit 2a25bd8

Please sign in to comment.