Skip to content

Commit 48c680f

Browse files
normanbdcherian
authored andcommitted
added support for rasterio geotiff tags (#3249)
1 parent 5f55d41 commit 48c680f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

xarray/backends/rasterio_.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,14 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc
322322
attrs["units"] = riods.units
323323

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

327327
driver = riods.driver
328328
if driver in parsers:
329-
meta = parsers[driver](riods.tags(ns=driver))
329+
if driver == "GTiff":
330+
meta = parsers[driver](riods.tags())
331+
else:
332+
meta = parsers[driver](riods.tags(ns=driver))
330333

331334
for k, v in meta.items():
332335
# Add values as coordinates if they match the band count,

xarray/tests/test_backends.py

+6
Original file line numberDiff line numberDiff line change
@@ -3923,6 +3923,12 @@ def test_ENVI_tags(self):
39233923
assert isinstance(rioda.attrs["map_info"], str)
39243924
assert isinstance(rioda.attrs["samples"], str)
39253925

3926+
def test_geotiff_tags(self):
3927+
# Create a geotiff file with some tags
3928+
with create_tmp_geotiff() as (tmp_file, _):
3929+
with xr.open_rasterio(tmp_file) as rioda:
3930+
assert isinstance(rioda.attrs["AREA_OR_POINT"], str)
3931+
39263932
def test_no_mftime(self):
39273933
# rasterio can accept "filename" urguments that are actually urls,
39283934
# including paths to remote files.

0 commit comments

Comments
 (0)