Skip to content

Commit

Permalink
Save coordinates as lists of lists instead of tuples
Browse files Browse the repository at this point in the history
- I'm not sure why we aren't using `safe_dumper`
  • Loading branch information
omad committed May 26, 2016
1 parent 4bd9d35 commit 5cb4fd8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
15 changes: 14 additions & 1 deletion eodatasets/metadata/valid_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ def valid_region(images, mask_value=None):
# transform from pixel space into CRS space
geom = shapely.affinity.affine_transform(geom, (transform.a, transform.b, transform.d,
transform.e, transform.xoff, transform.yoff))
return shapely.geometry.mapping(geom)

output = shapely.geometry.mapping(geom)
output['coordinates'] = _to_lists(output['coordinates'])
return output


def _to_lists(x):
"""
Returns lists of lists when given tuples of tuples
"""
if isinstance(x, tuple):
return [_to_lists(el) for el in x]

return x
10 changes: 5 additions & 5 deletions eodatasets/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ def path_representer(dumper, data):
return RelativeDumper


def write_yaml_metadata(d, metadata_path, target_directory=None):
def write_yaml_metadata(dataset_metadata, metadata_path, target_directory=None):
"""
Write the given dataset to yaml.
All 'Path' values are converted to relative paths: relative to the given
target directory.
:type d: DatasetMetadata
:type dataset_metadata: DatasetMetadata
:type target_directory: str or Path
:type metadata_path: str or Path
"""
Expand All @@ -153,10 +153,10 @@ def write_yaml_metadata(d, metadata_path, target_directory=None):
target_directory = os.path.dirname(os.path.abspath(metadata_file))

_LOG.info('Writing metadata file %r', metadata_file)
with open(str(metadata_file), 'w') as f:
with open(str(metadata_file), 'w') as output_file:
yaml.dump(
d,
f,
dataset_metadata,
output_file,
default_flow_style=False,
indent=4,
Dumper=_create_relative_dumper(str(target_directory)),
Expand Down
1 change: 1 addition & 0 deletions eodatasets/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ def __init__(self, type_=None, coordinates=None):
#: :type:
self.coordinates = coordinates


def rebase_path(from_root_path, to_root_path, path):
"""
Rebase the path to a new root path.
Expand Down
9 changes: 6 additions & 3 deletions tests/integration/test_ls8_nbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ def test_package():
'datum': 'GDA94',
'ellipsoid': 'GRS80',
'valid_data': {'type': 'Polygon',
'coordinates': (((644100.0, 6282925.0), (644075.0, 6282800.0),
(644200.0, 6282775.0), (644225.0, 6282900.0),
(644100.0, 6282925.0)),)}
'coordinates': [[[644100.0, 6282925.0],
[644075.0, 6282800.0],
[644200.0, 6282775.0],
[644225.0, 6282900.0],
[644100.0, 6282925.0]]]
}
}
},
'image': {
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/test_ls8_pqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ def test_package():
'ellipsoid': 'GRS80',
'orientation': 'NORTH_UP',
'zone': -56,
'valid_data': {'coordinates': (((319250.0, 6636775.0), (319225.0, 6636500.0),
(319500.0, 6636475.0), (319525.0, 6636750.0),
(319250.0, 6636775.0)),),
'valid_data': {'coordinates': [[[319250.0, 6636775.0],
[319225.0, 6636500.0],
[319500.0, 6636475.0],
[319525.0, 6636750.0],
[319250.0, 6636775.0]]],
'type': 'Polygon'}
}
},
Expand Down

0 comments on commit 5cb4fd8

Please sign in to comment.