Skip to content

Commit ef527bd

Browse files
committed
SpatialKeys will now display correctly when they're in Metadata
1 parent 5f7d15b commit ef527bd

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

geopyspark/geotrellis/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,14 @@ def from_dict(cls, metadata_dict):
505505
min_key = SpatialKey(**bounds_dict['minKey'])
506506
max_key = SpatialKey(**bounds_dict['maxKey'])
507507
else:
508-
min_key = SpaceTimeKey(**bounds_dict['minKey'])
509-
max_key = SpaceTimeKey(**bounds_dict['maxKey'])
508+
scala_min_key = bounds_dict['minKey']
509+
scala_max_key = bounds_dict['maxKey']
510+
511+
scala_min_key['instant'] = datetime.datetime.utcfromtimestamp(scala_min_key['instant'] / 1000)
512+
scala_max_key['instant'] = datetime.datetime.utcfromtimestamp(scala_max_key['instant'] / 1000)
513+
514+
min_key = SpaceTimeKey(**scala_min_key)
515+
max_key = SpaceTimeKey(**scala_max_key)
510516

511517
bounds = Bounds(min_key, max_key)
512518
extent = Extent(**metadata_dict['extent'])

geopyspark/tests/to_spatial_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def tearDown(self):
6363
yield
6464
BaseTestClass.pysc._gateway.close()
6565

66+
# This test should be moved to a more appropriate file once more spatial-temporal
67+
# tests are made.
68+
def test_spatial_metadata(self):
69+
metadata = self.raster_rdd.collect_metadata()
70+
min_key = metadata.bounds.minKey
71+
max_key = metadata.bounds.maxKey
72+
73+
self.assertEqual(min_key.instant, self.time)
74+
self.assertEqual(max_key.instant, self.time)
75+
6676
def test_to_spatial_raster_layer(self):
6777
actual = [k for k, v in self.raster_rdd.to_spatial_layer().to_numpy_rdd().collect()]
6878

0 commit comments

Comments
 (0)