in src/mapillary/models/geojson.py [0:0]
def __init__(self, geojson: dict) -> None:
"""Initializing GeoJSON constructor"""
# Validate that the geojson passed is indeed a dictionary
if isinstance(geojson, dict):
# The GeoJSON should only contain the keys of `type`, `features`, if not empty,
# raise exception
if [key for key in geojson.keys() if key not in ["type", "features"]]:
# Raise InvalidOptionError
InvalidOptionError(
# The parameter that caused the exception
param="GeoJSON.__init__.geojson",
# The invalid value passed
value=geojson,
# The keys that should be passed instead
options=["type", "features"],
)
# If the GeoJSON is not of type dictionary
else:
# Raise InvalidOptionError
InvalidOptionError(
# The parameter that caused the exception
param="GeoJSON.__init__.geojson",
# The invalid value passed
value=geojson,
# The keys that should be passed instead
options=["type", "features"],
)
# Validate that the geojson passed is indeed a dictionary
if not isinstance(geojson["features"], list):
# If not, raise InvalidOptionError
InvalidOptionError(
# The parameter that caused the exception
param="FeatureList.__init__.geojson['features']",
# The invalid value passed
value=geojson["features"],
# The type of the value that should be passed
options=["list"],
)
# Setting the type parameter
self.type: str = geojson["type"]
# Setting the list of features
self.features: list = (
[Feature(feature=feature) for feature in geojson["features"]]
if (geojson["features"] != []) or (geojson["features"] is not None)
else []
)