Skip to content

Commit

Permalink
additional bounding box methods to DriverVectorCube (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Oct 12, 2022
1 parent 2ec255e commit 8e3b58a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openeo_driver/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.21.0a1"
__version__ = "0.21.1a1"
6 changes: 6 additions & 0 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ def to_legacy_save_result(self) -> Union["AggregatePolygonResult", "JSONResult"]
def get_bounding_box(self) -> Tuple[float, float, float, float]:
return tuple(self._geometries.total_bounds)

def get_bounding_box_geometry(self) -> shapely.geometry.Polygon:
return shapely.geometry.Polygon.from_bounds(*self.get_bounding_box())

def get_bounding_box_geojson(self) -> dict:
return shapely.geometry.mapping(self.get_bounding_box_geometry())

def get_geometries(self) -> Sequence[shapely.geometry.base.BaseGeometry]:
return self._geometries.geometry

Expand Down
11 changes: 11 additions & 0 deletions tests/test_vectorcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,14 @@ def test_from_geojson(self, geojson, expected):
"type": "FeatureCollection",
"features": expected,
})

def test_get_bounding_box(self, gdf):
vc = DriverVectorCube(gdf)
assert vc.get_bounding_box() == (1, 1, 5, 4)
assert vc.get_bounding_box_geometry() == Polygon.from_bounds(1, 1, 5, 4)
assert vc.get_bounding_box_geojson() == {
"type": "Polygon",
"coordinates": (
((1.0, 1.0), (1.0, 4.0), (5.0, 4.0), (5.0, 1.0), (1.0, 1.0)),
),
}

0 comments on commit 8e3b58a

Please sign in to comment.