Skip to content

Commit

Permalink
fix: requesting the same tile multiple times for multipolygon
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigaszi committed Jan 28, 2025
1 parent 508edf8 commit 7ff2688
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mapswipe_workers/mapswipe_workers/utils/process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def create_tiles(polygon, level):
if isinstance(polygon, Polygon):
polygon = MultiPolygon([polygon])

tiles = []
tiles = set()
for i, poly in enumerate(polygon.geoms):
tiles.extend(list(mercantile.tiles(*poly.bounds, level)))
tiles.update(list(mercantile.tiles(*poly.bounds, level)))

bbox_list = [mercantile.bounds(tile.x, tile.y, tile.z) for tile in tiles]
bbox_polygons = [box(*bbox) for bbox in bbox_list]
Expand Down
15 changes: 11 additions & 4 deletions mapswipe_workers/tests/unittests/test_process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def setUpClass(cls):
def setUp(self):
self.level = 14
self.test_polygon = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
self.test_multipolygon = MultiPolygon(
[self.test_polygon, Polygon([(2, 2), (3, 2), (3, 3), (2, 3)])]
)
self.empty_polygon = Polygon()
self.empty_geometry = GeometryCollection()

Expand All @@ -60,9 +57,19 @@ def test_create_tiles_with_valid_polygon(self):
self.assertFalse(tiles.empty)

def test_create_tiles_with_multipolygon(self):
tiles = create_tiles(self.test_multipolygon, self.level)
polygon = Polygon(
[
(0.00000000, 0.00000000),
(0.000000001, 0.00000000),
(0.00000000, 0.000000001),
(0.00000000, 0.000000001),
]
)
multipolygon = MultiPolygon([polygon, polygon])
tiles = create_tiles(multipolygon, self.level)
self.assertIsInstance(tiles, pd.DataFrame)
self.assertFalse(tiles.empty)
self.assertEqual(len(tiles), 1)

def test_create_tiles_with_empty_polygon(self):
tiles = create_tiles(self.empty_polygon, self.level)
Expand Down

0 comments on commit 7ff2688

Please sign in to comment.