mapillary / mapillary-python-sdk

A Python 3 library built on the Mapillary API v4 to facilitate retrieving and working with Mapillary data.
MIT License
37 stars 14 forks source link

[Utils] Added decoding for image pixel geometry #108

Closed Rubix982 closed 2 years ago

Rubix982 commented 2 years ago

Pixel Geometry

:trophy: Added main utility decode_pixel_geometry_in_geojson for decoding all the pixel geometries from the GeoJSON.

This should close #32.

Test Run

import mapillary as mly
from utils.format import decode_pixel_geometry_in_geojson
mly.set_access_token('MLY|XXX')
data = mly.get_detections_with_image_id(image_id=1933525276802129).to_dict()
data = decode_pixel_geometry_in_geojson(geojson=data, normalized=True).to_dict() # for normalized coordinates
data = decode_pixel_geometry_in_geojson(geojson=data).to_dict() # for un-normalized coordinates

Normalized output

'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222,
30.270651388889]}, 'properties': {'created_at': '2021-05-20T17:49:01+0000', 'id': '1942105415944115', 'image_id': None,
'pixel_geometry': {'coordinates': [[[0.610107421875, 0.37060546875], [0.615234375, 0.37060546875], [0.615234375,
0.361572265625], [0.610107421875, 0.361572265625], [0.610107421875, 0.37060546875]]]}, 'value': 'regulatory--no-
parking--g2'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties':
{'created_at': '2021-05-20T18:40:21+0000', 'id': '1942144785940178', 'image_id': None, 'pixel_geometry': {'coordinates':
[[[0.88818359375, 0.502685546875], [0.898681640625, 0.502685546875], [0.898681640625, 0.47509765625],
[0.88818359375, 0.47509765625], [0.88818359375, 0.502685546875]]]},

Un-normalized output

{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222,
30.270651388889]}, 'properties': {'created_at': '2021-05-20T17:49:01+0000', 'id': '1942105415944115', 'image_id': None,
'pixel_geometry': {'coordinates': [[[2499, 1518], [2520, 1518], [2520, 1481], [2499, 1481], [2499, 1518]]]}, 'value': 'regulatory 
--no-parking--g2'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]},
'properties': {'created_at': '2021-05-20T18:40:21+0000', 'id': '1942144785940178', 'image_id': None, 'pixel_geometry':
{'coordinates': [[[3638, 2059], [3681, 2059], [3681, 1946], [3638, 1946], [3638, 2059]]]}, 'value': 'information--parking--g1'}},
{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]},
Rubix982 commented 2 years ago

Thanks, @OmarMuhammedAli. :smile: