Skip to content

Commit 9065a68

Browse files
authored
Merge pull request #428 from jbouffard/bug-fix/metadata-serialization
Bounds Containing SpaceTimeKeys Can Now be Serialized
2 parents d6cf88e + f60b551 commit 9065a68

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

geopyspark/geotrellis/__init__.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This subpackage contains the code that reads, writes, and processes data using GeoTrellis."""
22
from collections import namedtuple
33
import warnings
4+
import datetime
45
import functools
56
import datetime
67
from shapely.geometry import box
@@ -9,6 +10,13 @@
910
from geopyspark.geotrellis.constants import CellType, NO_DATA_INT
1011

1112

13+
_EPOCH = datetime.datetime.utcfromtimestamp(0)
14+
15+
16+
def _convert_to_unix_time(date_time):
17+
return int((date_time - _EPOCH).total_seconds() * 1000)
18+
19+
1220
def deprecated(func):
1321
"""This is a decorator which can be used to mark functions
1422
as deprecated. It will result in a warning being emmitted
@@ -399,15 +407,12 @@ class Bounds(namedtuple("Bounds", 'minKey maxKey')):
399407
__slots__ = []
400408

401409
def _asdict(self):
402-
if isinstance(self.minKey, dict):
403-
min_key_dict = self.minKey
404-
else:
405-
min_key_dict = self.minKey._asdict()
410+
min_key_dict = self.minKey._asdict()
411+
max_key_dict = self.maxKey._asdict()
406412

407-
if isinstance(self.maxKey, dict):
408-
max_key_dict = self.maxKey
409-
else:
410-
max_key_dict = self.maxKey._asdict()
413+
if hasattr(self.minKey, 'instant'):
414+
min_key_dict['instant'] = _convert_to_unix_time(min_key_dict['instant'])
415+
max_key_dict['instant'] = _convert_to_unix_time(max_key_dict['instant'])
411416

412417
return {'minKey': min_key_dict, 'maxKey': max_key_dict}
413418

geopyspark/geotrellis/protobufcodecs.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ensure_pyspark()
77

88
from geopyspark.geotrellis import (Extent, ProjectedExtent, TemporalProjectedExtent, SpatialKey,
9-
SpaceTimeKey, Tile)
9+
SpaceTimeKey, Tile, _convert_to_unix_time)
1010

1111
from geopyspark.geotrellis.protobuf.tileMessages_pb2 import ProtoTile, ProtoMultibandTile, ProtoCellType
1212
from geopyspark.geotrellis.protobuf import keyMessages_pb2
@@ -25,12 +25,6 @@
2525
7: 'DOUBLE'
2626
}
2727

28-
_EPOCH = datetime.datetime.utcfromtimestamp(0)
29-
30-
31-
def _convert_to_unix_time(date_time):
32-
return int((date_time - _EPOCH).total_seconds() * 1000)
33-
3428

3529
# DECODERS
3630

0 commit comments

Comments
 (0)