Skip to content

Commit

Permalink
EP-3251 fix DataCube.mask
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Mar 10, 2020
1 parent a6d0908 commit 91205c2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion openeo/rest/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ def mask(self, polygon: Union[Polygon, MultiPolygon, str] = None, srs="EPSG:4326
No data values will be left untouched by the masking operation.
# TODO: just provide a single `mask` argument and detect the type: polygon or process graph
# TODO: mask process has been split in mask/mask_polygon
# TODO: also see `mask` vs `mask_polygon` processes in https://github.com/Open-EO/openeo-processes/pull/110
:param polygon: A polygon, provided as a :class:`shapely.geometry.Polygon` or :class:`shapely.geometry.MultiPolygon`, or a filename pointing to a valid vector file
Expand All @@ -781,7 +782,7 @@ def mask(self, polygon: Union[Polygon, MultiPolygon, str] = None, srs="EPSG:4326
})

mask = {
'from_node': new_collection.node_id
'from_node': new_collection.builder.result_node
}
else:
if polygon.area == 0:
Expand Down
41 changes: 39 additions & 2 deletions tests/rest/test_datacube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import openeo
import pytest
from openeo.internal.graphbuilder import GraphBuilder
import shapely.geometry

import openeo
from openeo.rest.connection import Connection

API_URL = "https://oeo.net"
Expand Down Expand Up @@ -28,6 +29,42 @@ def con100(requests_mock) -> Connection:
return openeo.connect(API_URL)


def test_mask_polygon(con100: Connection):
img = con100.load_collection("S2")
polygon = shapely.geometry.box(0, 0, 1, 1)
masked = img.mask(polygon=polygon)
assert sorted(masked.graph.keys()) == ["loadcollection1", "mask1"]
assert masked.graph["mask1"] == {
"process_id": "mask",
"arguments": {
"data": {"from_node": "loadcollection1"},
'mask': {
'coordinates': (((1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)),),
'crs': {'properties': {'name': 'EPSG:4326'}, 'type': 'name'},
'type': 'Polygon'}
},
"result": True
}


def test_mask_polygon_path(con100: Connection):
img = con100.load_collection("S2")
masked = img.mask(polygon="path/to/polygon.json")
assert sorted(masked.graph.keys()) == ["loadcollection1", "mask1", "readvector1"]
assert masked.graph["mask1"] == {
"process_id": "mask",
"arguments": {
"data": {"from_node": "loadcollection1"},
"mask": {"from_node": "readvector1"},
},
"result": True
}
assert masked.graph["readvector1"] == {
"process_id": "read_vector",
"arguments": {"filename": "path/to/polygon.json"},
}


def test_mask_raster(con100: Connection):
img = con100.load_collection("S2")
mask = con100.load_collection("MASK")
Expand Down

0 comments on commit 91205c2

Please sign in to comment.