NGSI-LD Revise GeoProperty model
Opened this issue · 0 comments
djs0109 commented
Is your feature request related to a problem? Please describe.
According to https://datatracker.ietf.org/doc/html/rfc7946, Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection are allowed. However, GeometryCollection is explicitly excluded by the NGSI-LD specification.
Right now, only "Point" is allowed
The implementation in V2 can be referred to
FiLiP/filip/models/ngsi_v2/base.py
Line 449 in 49952a6
Suggestion
import geojson_pydantic
if type_ == "GeoProperty"":
if isinstance(
value,
(
Point,
MultiPoint,
LineString,
MultiLineString,
Polygon,
MultiPolygon
),
):
return value
if isinstance(value, dict):
_geo_json_type = value.get("type", None)
if _geo_json_type == "Point":
return Point(**value)
elif _geo_json_type == "MultiPoint":
return MultiPoint(**value)
elif _geo_json_type == "LineString":
return LineString(**value)
elif _geo_json_type == "MultiLineString":
return MultiLineString(**value)
elif _geo_json_type == "Polygon":
return Polygon(**value)
elif _geo_json_type == "MultiPolygon":
return MultiPolygon(**value)
raise TypeError(f"{type(value)} does not match "
f"{DataType.GEOJSON}")