Skip to content

Commit 2540773

Browse files
committed
feat: enable panoramax for street project
1 parent e32dcb3 commit 2540773

File tree

5 files changed

+53
-48
lines changed

5 files changed

+53
-48
lines changed

mapswipe_workers/mapswipe_workers/definitions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
OSMCHA_API_LINK = "https://osmcha.org/api/v1/"
1818
OSMCHA_API_KEY = os.environ["OSMCHA_API_KEY"]
1919
MAPILLARY_API_LINK = "https://tiles.mapillary.com/maps/vtp/mly1_computed_public/2/"
20+
PANORAMAX_API_LINK = "https://api.panoramax.xyz/api/map"
2021
MAPILLARY_API_KEY = os.environ["MAPILLARY_API_KEY"]
2122

2223
# number of geometries for project geometries

mapswipe_workers/mapswipe_workers/project_types/street/project.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self, project_draft):
4343

4444
self.geometry = project_draft["geometry"]
4545

46+
self.tileServer = project_draft["tileServer"]
47+
4648
# TODO: validate inputs
4749
ImageMetadata = get_image_metadata(
4850
self.geometry,
@@ -53,6 +55,7 @@ def __init__(self, project_draft):
5355
organization_id=project_draft.get("organizationId", None),
5456
randomize_order=project_draft.get("randomizeOrder", None),
5557
sampling_threshold=project_draft.get("samplingThreshold", None),
58+
provider=self.tileServer.get("name", None),
5659
)
5760

5861
self.imageIds = ImageMetadata["ids"]

mapswipe_workers/mapswipe_workers/utils/process_mapillary.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mapswipe_workers.definitions import (
1313
MAPILLARY_API_KEY,
1414
MAPILLARY_API_LINK,
15+
PANORAMAX_API_LINK,
1516
CustomError,
1617
logger,
1718
)
@@ -42,18 +43,31 @@ def create_tiles(polygon, level):
4243
return tiles
4344

4445

45-
def download_and_process_tile(row, polygon, kwargs, attempt_limit=3):
46+
def download_and_process_tile(row, polygon, provider, kwargs, attempt_limit=3):
4647
z = row["z"]
4748
x = row["x"]
4849
y = row["y"]
49-
url = f"{MAPILLARY_API_LINK}{z}/{x}/{y}?access_token={MAPILLARY_API_KEY}"
50+
if provider == "mapillary":
51+
url = f"{MAPILLARY_API_LINK}{z}/{x}/{y}?access_token={MAPILLARY_API_KEY}"
52+
elif provider == "panoramax":
53+
url = f"{PANORAMAX_API_LINK}/{z}/{x}/{y}.mvt"
54+
else:
55+
raise Exception(f"Unknown provider {provider}")
5056

5157
attempt = 0
5258
while attempt < attempt_limit:
5359
try:
5460
data = get_mapillary_data(url, x, y, z)
5561
if data.isna().all().all() is False or data.empty is False:
5662
data = data[data["geometry"].apply(lambda point: point.within(polygon))]
63+
if provider == "panoramax":
64+
data = data.rename(
65+
columns={
66+
"account_id": "creator_id",
67+
"ts": "captured_at",
68+
"type": "is_pano",
69+
}
70+
)
5771
target_columns = [
5872
"id",
5973
"geometry",
@@ -99,7 +113,12 @@ def get_mapillary_data(url, x, y, z):
99113

100114

101115
def coordinate_download(
102-
polygon, level, kwargs: dict, use_concurrency=True, workers=os.cpu_count() * 4
116+
polygon,
117+
level,
118+
provider,
119+
kwargs: dict,
120+
use_concurrency=True,
121+
workers=os.cpu_count() * 4,
103122
):
104123
tiles = create_tiles(polygon, level)
105124

@@ -110,7 +129,7 @@ def coordinate_download(
110129
workers = 1
111130

112131
downloaded_metadata = parallelized_processing(
113-
downloaded_metadata, kwargs, polygon, tiles, workers
132+
downloaded_metadata, kwargs, polygon, tiles, workers, provider
114133
)
115134
if len(downloaded_metadata):
116135
downloaded_metadata = pd.concat(downloaded_metadata, ignore_index=True)
@@ -120,9 +139,9 @@ def coordinate_download(
120139
return downloaded_metadata
121140

122141

123-
def parallelized_processing(data, kwargs, polygon, tiles, workers):
142+
def parallelized_processing(data, kwargs, polygon, tiles, workers, provider):
124143
process_tile_with_args = partial(
125-
download_and_process_tile, polygon=polygon, kwargs=kwargs
144+
download_and_process_tile, polygon=polygon, provider=provider, kwargs=kwargs
126145
)
127146
with ProcessPoolExecutor(max_workers=workers) as executor:
128147
futures = list(
@@ -215,7 +234,13 @@ def get_image_metadata(
215234
end_time: str = None,
216235
randomize_order=False,
217236
sampling_threshold=None,
237+
provider=None,
218238
):
239+
if provider is None:
240+
raise ValueError("Provider cannot be None.")
241+
elif provider == "panoramax":
242+
level = 15
243+
219244
kwargs = {
220245
"is_pano": is_pano,
221246
"creator_id": creator_id,
@@ -224,7 +249,7 @@ def get_image_metadata(
224249
"end_time": end_time,
225250
}
226251
aoi_polygon = geojson_to_polygon(aoi_geojson)
227-
downloaded_metadata = coordinate_download(aoi_polygon, level, kwargs)
252+
downloaded_metadata = coordinate_download(aoi_polygon, level, provider, kwargs)
228253
if downloaded_metadata.empty or downloaded_metadata.isna().all().all():
229254
raise CustomError(
230255
"No Mapillary Features in the AoI or no Features match the filter criteria."

mapswipe_workers/tests/fixtures/projectDrafts/street.json

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,11 @@
1010
"type": "Polygon",
1111
"coordinates": [
1212
[
13-
[
14-
39.27186980415655,
15-
-6.818313681620424
16-
],
17-
[
18-
39.27186980415655,
19-
-6.824056026803248
20-
],
21-
[
22-
39.27489288297136,
23-
-6.823996705403303
24-
],
25-
[
26-
39.27483313833096,
27-
-6.817969613314901
28-
],
29-
[
30-
39.27186980415655,
31-
-6.818313681620424
32-
]
13+
[4.824, 45.755],
14+
[4.854, 45.755],
15+
[4.854, 45.77],
16+
[4.824, 45.77],
17+
[4.824, 45.755]
3318
]
3419
]
3520
}
@@ -46,5 +31,8 @@
4631
"requestingOrganisation": "test",
4732
"verificationNumber": 3,
4833
"groupSize": 25,
49-
"samplingThreshold": 0.1
34+
"samplingThreshold": 0.1,
35+
"tileServer": {
36+
"name": "panoramax"
37+
}
5038
}

mapswipe_workers/tests/integration/fixtures/street/projectDrafts/street.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,11 @@
1010
"type": "Polygon",
1111
"coordinates": [
1212
[
13-
[
14-
39.27186980415655,
15-
-6.818313681620424
16-
],
17-
[
18-
39.27186980415655,
19-
-6.824056026803248
20-
],
21-
[
22-
39.27489288297136,
23-
-6.823996705403303
24-
],
25-
[
26-
39.27483313833096,
27-
-6.817969613314901
28-
],
29-
[
30-
39.27186980415655,
31-
-6.818313681620424
32-
]
13+
[4.824, 45.755],
14+
[4.854, 45.755],
15+
[4.854, 45.77],
16+
[4.824, 45.77],
17+
[4.824, 45.755]
3318
]
3419
]
3520
}
@@ -46,5 +31,8 @@
4631
"requestingOrganisation": "test",
4732
"verificationNumber": 3,
4833
"groupSize": 25,
34+
"tileServer": {
35+
"name": "panoramax"
36+
},
4937
"customOptions": [{ "color": "", "label": "", "value": -999 }, { "color": "#008000", "label": "yes", "value": 1 }, { "color": "#FF0000", "label": "no", "value": 2 }, { "color": "#FFA500", "label": "maybe", "value": 3 }]
5038
}

0 commit comments

Comments
 (0)