Skip to content

Commit 67e44c7

Browse files
committed
DriverVectorCube.from_geojson: add support for Point/MultiPoint/GeometryCollection
related to #71/#114/#141
1 parent 56b8e7b commit 67e44c7

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

openeo_driver/datacube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ def from_fiona(cls, paths: List[str], driver: str, options: dict) -> "DriverVect
195195
def from_geojson(cls, geojson: dict) -> "DriverVectorCube":
196196
"""Construct vector cube from GeoJson dict structure"""
197197
# TODO support more geojson types?
198-
if geojson["type"] in {"Polygon", "MultiPolygon"}:
198+
if geojson["type"] in {"Polygon", "MultiPolygon", "Point", "MultiPoint"}:
199199
features = [{"type": "Feature", "geometry": geojson, "properties": {}}]
200200
elif geojson["type"] in {"Feature"}:
201201
features = [geojson]
202202
elif geojson["type"] in {"GeometryCollection"}:
203-
#TODO GeometryCollection is offically unsupported
203+
# TODO #71 #114 Deprecate/avoid usage of GeometryCollection
204204
log.error("Input GeoJSON of deprecated type 'GeometryCollection', please use a FeatureCollection or another type of Multi geometry.")
205205
features = [{"type": "Feature", "geometry": g, "properties": {}} for g in geojson["geometries"]]
206206
elif geojson["type"] in {"FeatureCollection"}:

tests/test_vectorcube.py

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,33 @@ def test_with_cube_to_geojson(self, gdf):
131131
],
132132
),
133133
(
134+
{"type": "Point", "coordinates": [1, 1]},
135+
[
136+
DictSubSet(
137+
{
138+
"type": "Feature",
139+
"geometry": {"type": "Point", "coordinates": (1, 1)},
140+
"properties": {},
141+
}
142+
),
143+
],
144+
),
145+
(
146+
{"type": "MultiPoint", "coordinates": [[1, 1], [2, 3]]},
147+
[
148+
DictSubSet(
149+
{
150+
"type": "Feature",
151+
"geometry": {
152+
"type": "MultiPoint",
153+
"coordinates": ((1, 1), (2, 3)),
154+
},
155+
"properties": {},
156+
}
157+
),
158+
],
159+
),
160+
(
134161
{
135162
"type": "Feature",
136163
"geometry": {"type": "MultiPolygon", "coordinates": [[[(1, 1), (3, 1), (2, 3), (1, 1)]]]},
@@ -172,8 +199,44 @@ def test_with_cube_to_geojson(self, gdf):
172199
"properties": {"id": 2},
173200
}),
174201
],
175-
),
176-
])
202+
),
203+
(
204+
{
205+
"type": "GeometryCollection",
206+
"geometries": [
207+
{
208+
"type": "Polygon",
209+
"coordinates": [[(1, 1), (3, 1), (2, 3), (1, 1)]],
210+
},
211+
{
212+
"type": "MultiPolygon",
213+
"coordinates": [[[(1, 1), (3, 1), (2, 3), (1, 1)]]],
214+
},
215+
],
216+
},
217+
[
218+
DictSubSet(
219+
{
220+
"type": "Feature",
221+
"geometry": {
222+
"type": "Polygon",
223+
"coordinates": (((1, 1), (3, 1), (2, 3), (1, 1)),),
224+
},
225+
}
226+
),
227+
DictSubSet(
228+
{
229+
"type": "Feature",
230+
"geometry": {
231+
"type": "MultiPolygon",
232+
"coordinates": [(((1, 1), (3, 1), (2, 3), (1, 1)),)],
233+
},
234+
}
235+
),
236+
],
237+
),
238+
],
239+
)
177240
def test_from_geojson(self, geojson, expected):
178241
vc = DriverVectorCube.from_geojson(geojson)
179242
assert vc.to_geojson() == DictSubSet({

0 commit comments

Comments
 (0)