Skip to content

Commit f7fc5f3

Browse files
committed
feat: add size restriction for too many images
1 parent 4ab528d commit f7fc5f3

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

mapswipe_workers/mapswipe_workers/utils/process_mapillary.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def filter_results(
208208
return None
209209
df = filter_by_timerange(df, start_time, end_time)
210210

211-
212211
return df
213212

214213

@@ -235,10 +234,15 @@ def get_image_metadata(
235234
)
236235
if sampling_threshold is not None:
237236
downloaded_metadata = spatial_sampling(downloaded_metadata, sampling_threshold)
238-
if downloaded_metadata.isna().all().all() == False:
239-
return {
240-
"ids": downloaded_metadata["id"].tolist(),
241-
"geometries": downloaded_metadata["geometry"].tolist(),
242-
}
237+
if downloaded_metadata.isna().all().all() == False or downloaded_metadata.empty == False:
238+
if len(downloaded_metadata) > 100000:
239+
err = (f"Too many Images with selected filter "
240+
f"options for the AoI: {len(downloaded_metadata)}")
241+
raise ValueError(err)
242+
else:
243+
return {
244+
"ids": downloaded_metadata["id"].tolist(),
245+
"geometries": downloaded_metadata["geometry"].tolist(),
246+
}
243247
else:
244248
raise ValueError("No Mapillary Features in the AoI match the filter criteria.")

mapswipe_workers/tests/unittests/test_process_mapillary.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,30 @@ def test_get_image_metadata_no_rows(self, mock_coordinate_download):
328328
with self.assertRaises(ValueError):
329329
get_image_metadata(self.fixture_data, **params)
330330

331+
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
332+
def test_get_image_metadata_empty_response(self, mock_coordinate_download):
333+
df = self.fixture_df.copy()
334+
df = df.drop(df.index)
335+
mock_coordinate_download.return_value = (
336+
df,
337+
None
338+
)
339+
340+
with self.assertRaises(ValueError):
341+
get_image_metadata(self.fixture_data)
342+
343+
@patch("mapswipe_workers.utils.process_mapillary.filter_results")
344+
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
345+
def test_get_image_metadata_size_restriction(self, mock_coordinate_download, mock_filter_results):
346+
mock_filter_results.return_value = pd.DataFrame({'ID': range(1, 100002)})
347+
mock_coordinate_download.return_value = (
348+
self.fixture_df,
349+
None,
350+
)
351+
352+
with self.assertRaises(ValueError):
353+
get_image_metadata(self.fixture_data)
354+
331355

332356
if __name__ == "__main__":
333357
unittest.main()

0 commit comments

Comments
 (0)