Skip to content

Remove non-standard srs argument from mask_polygon #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- Remove non-standard `srs` argument from `DataCube.mask_polygon` hmethod (EP-3747 related)

### Fixed

- `Connection`: don't send default auth headers to non-backend domains ([#201](https://github.com/Open-EO/openeo-python-client/issues/201))
Expand Down
12 changes: 5 additions & 7 deletions openeo/rest/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ def mask(self, mask: 'DataCube' = None, replacement=None) -> 'DataCube':

def mask_polygon(
self, mask: Union[Polygon, MultiPolygon, str, pathlib.Path] = None,
srs="EPSG:4326", replacement=None, inside: bool = None
replacement=None, inside: bool = None
) -> 'DataCube':
"""
Applies a polygon mask to a raster data cube. To apply a raster mask use `mask`.
Expand All @@ -1124,9 +1124,11 @@ def mask_polygon(
The pixel values are replaced with the value specified for `replacement`,
which defaults to `no data`.

:param mask: A polygon, provided as a :class:`shapely.geometry.Polygon` or :class:`shapely.geometry.MultiPolygon`, or a filename pointing to a valid vector file
:param srs: The reference system of the provided polygon, by default this is Lat Lon (EPSG:4326).
:param mask: A polygon, provided as a :class:`shapely.geometry.Polygon`
or :class:`shapely.geometry.MultiPolygon`, or a filename pointing to a valid vector file
:param replacement: the value to replace the masked pixels with
:param inside: If set to true all pixels for which the point at the pixel center
does intersect with any polygon are replaced.
"""
if isinstance(mask, (str, pathlib.Path)):
# TODO: default to loading file client side?
Expand All @@ -1140,10 +1142,6 @@ def mask_polygon(
if mask.area == 0:
raise ValueError("Mask {m!s} has an area of {a!r}".format(m=mask, a=mask.area))
mask = shapely.geometry.mapping(mask)
mask['crs'] = {
'type': 'name',
'properties': {'name': srs}
}
elif isinstance(mask, Parameter):
pass
else:
Expand Down
9 changes: 1 addition & 8 deletions openeo/rest/imagecollectionclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def linear_scale_range(self, input_min, input_max, output_min, output_max) -> 'I
}
return self.graph_add_process(process_id, args)

def mask(self, polygon: Union[Polygon, MultiPolygon,str]=None, srs="EPSG:4326", rastermask: 'ImageCollection'=None,
def mask(self, polygon: Union[Polygon, MultiPolygon,str]=None, rastermask: 'ImageCollection'=None,
replacement=None) -> 'ImageCollection':
"""
Mask the image collection using either a polygon or a raster mask.
Expand All @@ -781,7 +781,6 @@ def mask(self, polygon: Union[Polygon, MultiPolygon,str]=None, srs="EPSG:4326",
# 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
:param srs: The reference system of the provided polygon, by default this is Lat Lon (EPSG:4326).
:param rastermask: the raster mask
:param replacement: the value to replace the masked pixels with
:raise: :class:`ValueError` if a polygon is supplied and its area is 0.
Expand All @@ -805,12 +804,6 @@ def mask(self, polygon: Union[Polygon, MultiPolygon,str]=None, srs="EPSG:4326",
raise ValueError("Mask {m!s} has an area of {a!r}".format(m=polygon, a=polygon.area))

geojson = mapping(polygon)
geojson['crs'] = {
'type': 'name',
'properties': {
'name': srs
}
}
mask = geojson
new_collection = self
elif rastermask is not None:
Expand Down
3 changes: 1 addition & 2 deletions tests/rest/datacube/test_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ def test_mask_polygon(s2cube, api_version):
assert graph["arguments"] == {
"data": {'from_node': 'loadcollection1'},
"mask": {
'type': 'Polygon',
'coordinates': (((0.0, 0.0), (1.9, 0.0), (1.9, 1.9), (0.0, 1.9), (0.0, 0.0)),),
'crs': {'properties': {'name': 'EPSG:4326'}, 'type': 'name'},
'type': 'Polygon'
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/rest/datacube/test_datacube100.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def test_mask_polygon(con100: Connection):
"arguments": {
"data": {"from_node": "loadcollection1"},
'mask': {
'type': 'Polygon',
'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
}
Expand Down