Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clip image locations to aoi #984

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions mapswipe_workers/mapswipe_workers/utils/process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,15 @@ def coordinate_download(
for col in target_columns:
if col not in downloaded_metadata.columns:
downloaded_metadata[col] = None

if (
downloaded_metadata.isna().all().all() is False
or downloaded_metadata.empty is True
or downloaded_metadata.empty is False
):
downloaded_metadata = downloaded_metadata[
downloaded_metadata["geometry"].apply(
lambda point: point.within(polygon)
)
]

return downloaded_metadata


Expand Down
24 changes: 22 additions & 2 deletions mapswipe_workers/tests/unittests/test_process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pandas as pd
from shapely import wkt
from shapely.geometry import GeometryCollection, MultiPolygon, Polygon
from shapely.geometry import GeometryCollection, MultiPolygon, Point, Polygon

from mapswipe_workers.utils.process_mapillary import (
coordinate_download,
Expand Down Expand Up @@ -191,10 +191,30 @@ def test_download_and_process_tile_failure(self, mock_get):

@patch("mapswipe_workers.utils.process_mapillary.download_and_process_tile")
def test_coordinate_download(self, mock_download_and_process_tile):
mock_download_and_process_tile.return_value = pd.DataFrame([{"geometry": None}])
inside_points = [
(0.2, 0.2),
(0.5, 0.5),
]
outside_points = [
(1.5, 0.5),
(0.5, 1.5),
(-0.5, 0.5),
]
points = inside_points + outside_points
data = [
{
"geometry": Point(x, y),
}
for x, y in points
]

mock_download_and_process_tile.return_value = pd.DataFrame(data)

metadata = coordinate_download(self.test_polygon, self.level)

metadata = metadata.drop_duplicates()
self.assertEqual(len(metadata), len(inside_points))

self.assertIsInstance(metadata, pd.DataFrame)

@patch("mapswipe_workers.utils.process_mapillary.download_and_process_tile")
Expand Down
Loading