Skip to content

Commit 1fe248f

Browse files
committed
PR #233 improve default CRS (and base/height) handling in filter_bbox
1 parent 77efa85 commit 1fe248f

12 files changed

+75
-46
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

2121
### Changed
2222

23+
- Improve default handling of `crs` (and `base`/`height`) in `filter_bbox`: avoid explicitly sending `null` unnecessarily
24+
([#233](https://github.com/Open-EO/openeo-python-client/pull/233)).
25+
- Update documentation/examples/tests: EPSG CRS in `filter_bbox` should be integer code, not string
26+
([#233](https://github.com/Open-EO/openeo-python-client/pull/233)).
27+
28+
2329
### Removed
2430

2531
### Fixed

openeo/imagecollection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from openeo.rest.job import RESTJob
1111
from openeo.rest.service import Service
12-
from openeo.util import get_temporal_extent, first_not_none
12+
from openeo.util import get_temporal_extent, first_not_none, dict_no_none
1313

1414

1515
if hasattr(typing, 'TYPE_CHECKING') and typing.TYPE_CHECKING:
@@ -92,9 +92,8 @@ def filter_bbox(self, west, east, north, south, crs=None, base=None, height=None
9292
# Subclasses are expected to implement this method, but for bit of backwards compatibility
9393
# with old style subclasses we forward to `bbox_filter`
9494
# TODO: replace this with raise NotImplementedError() or decorate with @abstractmethod
95-
kwargs = dict(west=west, east=east, north=north, south=south, crs=crs)
96-
if base or height:
97-
kwargs.update(base=base, height=height)
95+
kwargs = dict(west=west, east=east, north=north, south=south)
96+
kwargs.update(dict_no_none(crs=crs, base=base, height=height))
9897
return self.bbox_filter(**kwargs)
9998

10099
@deprecated(reason="Use `filter_bbox()` instead.")

openeo/rest/datacube.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def filter_bbox(
295295
296296
>>> cube.filter_bbox(west=3, south=51, east=4, north=52, crs=4326)
297297
298-
- With a (west, south, east, north) list or tuple::
298+
- With a (west, south, east, north) list or tuple
299+
(note that EPSG:4326 is the default CRS, so it's not nececarry to specify it explicitly)::
299300
300301
>>> cube.filter_bbox([3, 51, 4, 52])
301302
>>> cube.filter_bbox(bbox=[3, 51, 4, 52])
@@ -365,10 +366,7 @@ def filter_bbox(
365366
raise ValueError(bbox)
366367

367368
extent = {'west': west, 'east': east, 'north': north, 'south': south}
368-
if crs is not None:
369-
extent["crs"] = crs
370-
if base is not None or height is not None:
371-
extent.update(base=base, height=height)
369+
extent.update(dict_no_none(crs=crs, base=base, height=height))
372370

373371
return self.process(
374372
process_id='filter_bbox',

openeo/rest/imagecollectionclient.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from openeo.rest import BandMathException
1414
from openeo.rest.job import RESTJob
1515
from openeo.rest.service import Service
16-
from openeo.util import get_temporal_extent, legacy_alias
16+
from openeo.util import get_temporal_extent, legacy_alias, dict_no_none
1717

1818
if hasattr(typing, 'TYPE_CHECKING') and typing.TYPE_CHECKING:
1919
# Imports for type checking only (circular import issue at runtime). `hasattr` is Python 3.5 workaround #210
@@ -121,12 +121,8 @@ def _filter_temporal(self, start: str, end: str) -> 'ImageCollection':
121121
)
122122

123123
def filter_bbox(self, west, east, north, south, crs=None, base=None, height=None) -> 'ImageCollection':
124-
extent = {
125-
'west': west, 'east': east, 'north': north, 'south': south,
126-
'crs': crs,
127-
}
128-
if base is not None or height is not None:
129-
extent.update(base=base, height=height)
124+
extent = {'west': west, 'east': east, 'north': north, 'south': south}
125+
extent.update(dict_no_none(crs=crs, base=base, height=height))
130126
return self.graph_add_process(
131127
process_id='filter_bbox',
132128
args={

openeo/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def date_to_rfc3339(d: Any) -> str:
179179
return rfc3339.normalize(d)
180180

181181

182-
def dict_no_none(*args, **kwargs):
182+
def dict_no_none(*args, **kwargs) -> dict:
183183
"""
184184
Helper to build a dict containing given key-value pairs where the value is not None.
185185
"""

tests/data/0.4.0/aggregate_zonal_path.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"west": 3,
1010
"east": 6,
1111
"north": 52,
12-
"south": 50,
13-
"crs": "EPSG:4326"
12+
"south": 50
1413
}
1514
},
1615
"result": false

tests/data/0.4.0/aggregate_zonal_polygon.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"west": 3,
1010
"east": 6,
1111
"north": 52,
12-
"south": 50,
13-
"crs": "EPSG:4326"
12+
"south": 50
1413
}
1514
},
1615
"result": false

tests/data/1.0.0/aggregate_zonal_parameter.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"west": 3,
1818
"east": 6,
1919
"north": 52,
20-
"south": 50,
21-
"crs": "EPSG:4326"
20+
"south": 50
2221
}
2322
}
2423
},

tests/data/1.0.0/aggregate_zonal_path.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"west": 3,
1818
"east": 6,
1919
"north": 52,
20-
"south": 50,
21-
"crs": "EPSG:4326"
20+
"south": 50
2221
}
2322
}
2423
},

tests/data/1.0.0/aggregate_zonal_polygon.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"west": 3,
1818
"east": 6,
1919
"north": 52,
20-
"south": 50,
21-
"crs": "EPSG:4326"
20+
"south": 50
2221
}
2322
}
2423
},

0 commit comments

Comments
 (0)