Skip to content

Commit 31bfded

Browse files
author
Xee authors
committed
Merge pull request #144 from google:geometry_bounds
PiperOrigin-RevId: 619939651
2 parents 5fe4395 + 7beabcf commit 31bfded

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

xee/ext.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,16 @@ def get_info(self) -> Dict[str, Any]:
278278
rpcs.append(('projection', self.projection))
279279

280280
if isinstance(self.geometry, ee.Geometry):
281-
rpcs.append(('bounds', self.geometry.bounds()))
281+
rpcs.append(('bounds', self.geometry.bounds(1, proj=self.projection)))
282282
else:
283-
rpcs.append(('bounds', self.image_collection.first().geometry().bounds()))
283+
rpcs.append(
284+
(
285+
'bounds',
286+
self.image_collection.first()
287+
.geometry()
288+
.bounds(1, proj=self.projection),
289+
)
290+
)
284291

285292
# TODO(#29, #30): This RPC call takes the longest time to compute. This
286293
# requires a full scan of the images in the collection, which happens on the
@@ -293,14 +300,16 @@ def get_info(self) -> Dict[str, Any]:
293300
# client-side. Ideally, this would live behind a xarray-backend-specific
294301
# feature flag, since it's not guaranteed that data is this consistent.
295302
columns = ['system:id', self.primary_dim_property]
296-
rpcs.append((
297-
'properties',
303+
rpcs.append(
298304
(
299-
self.image_collection.reduceColumns(
300-
ee.Reducer.toList().repeat(len(columns)), columns
301-
).get('list')
302-
),
303-
))
305+
'properties',
306+
(
307+
self.image_collection.reduceColumns(
308+
ee.Reducer.toList().repeat(len(columns)), columns
309+
).get('list')
310+
),
311+
)
312+
)
304313

305314
info = ee.List([rpc for _, rpc in rpcs]).getInfo()
306315

xee/ext_integration_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,32 @@ def __getitem__(self, params):
269269

270270
self.assertEqual(getter.count, 3)
271271

272+
def test_geometry_bounds_with_and_without_projection(self):
273+
image = (
274+
ee.ImageCollection('LANDSAT/LC08/C01/T1')
275+
.filterDate('2017-01-01', '2017-01-03')
276+
.first()
277+
)
278+
point = ee.Geometry.Point(-40.2414893624401, 105.48790177216375)
279+
distance = 311.5
280+
scale = 5000
281+
projection = ee.Projection('EPSG:4326', [1, 0, 0, 0, -1, 0]).atScale(scale)
282+
image = image.reproject(projection)
283+
284+
geometry = point.buffer(distance, proj=projection).bounds(proj=projection)
285+
286+
data_store = xee.EarthEngineStore(
287+
ee.ImageCollection(image),
288+
projection=image.projection(),
289+
geometry=geometry,
290+
)
291+
data_store_bounds = data_store.get_info['bounds']
292+
293+
self.assertNotEqual(geometry.bounds().getInfo(), data_store_bounds)
294+
self.assertEqual(
295+
geometry.bounds(1, proj=projection).getInfo(), data_store_bounds
296+
)
297+
272298
def test_getitem_kwargs(self):
273299
arr = xee.EarthEngineBackendArray('B4', self.store)
274300
self.assertEqual(arr.store.getitem_kwargs['initial_delay'], 1500)

0 commit comments

Comments
 (0)