Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for rasterio geotiff tags #3249

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions xarray/backends/rasterio_.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,14 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc
attrs["units"] = riods.units

# Parse extra metadata from tags, if supported
parsers = {"ENVI": _parse_envi}
parsers = {"ENVI": _parse_envi, "GTiff": lambda m: m}

driver = riods.driver
if driver in parsers:
meta = parsers[driver](riods.tags(ns=driver))
if driver == "GTiff":
dcherian marked this conversation as resolved.
Show resolved Hide resolved
meta = parsers[driver](riods.tags())
else:
meta = parsers[driver](riods.tags(ns=driver))

for k, v in meta.items():
# Add values as coordinates if they match the band count,
Expand Down
6 changes: 6 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3923,6 +3923,12 @@ def test_ENVI_tags(self):
assert isinstance(rioda.attrs["map_info"], str)
assert isinstance(rioda.attrs["samples"], str)

def test_geotiff_tags(self):
# Create a geotiff file with some tags
with create_tmp_geotiff() as (tmp_file, _):
with xr.open_rasterio(tmp_file) as rioda:
assert isinstance(rioda.attrs["AREA_OR_POINT"], str)
dcherian marked this conversation as resolved.
Show resolved Hide resolved

def test_no_mftime(self):
# rasterio can accept "filename" urguments that are actually urls,
# including paths to remote files.
Expand Down