corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
517 stars 82 forks source link

reproject does not handle scalar coordinates #15

Closed snowman2 closed 5 years ago

snowman2 commented 5 years ago
~/scripts/rioxarray/rioxarray/rioxarray.py in reproject_match(self, match_data_array, resampling)
    648             dst_crs,
    649             dst_affine_width_height=(dst_affine, dst_width, dst_height),
--> 650             resampling=resampling,
    651         )
    652 

~/scripts/rioxarray/rioxarray/rioxarray.py in reproject(self, dst_crs, resolution, dst_affine_width_height, resampling)
    607             name=self._obj.name,
    608             data=dst_data,
--> 609             coords=_make_coords(self._obj, dst_affine, dst_width, dst_height, dst_crs),
    610             dims=tuple(dst_dims),
    611             attrs=new_attrs,

~/scripts/rioxarray/rioxarray/rioxarray.py in _make_coords(src_data_array, dst_affine, dst_width, dst_height, dst_crs)
    175             src_data_array[coord].dims,
    176             src_data_array[coord].values,
--> 177             src_data_array[coord].attrs,
    178         )
    179     new_coords = _warp_spatial_coords(src_data_array, dst_affine, dst_width, dst_height)

~/scripts/terrain-compute/.venv/lib/python3.6/site-packages/xarray/core/variable.py in __init__(self, dims, data, attrs, encoding, fastpath)
   1622         if self.ndim != 1:
   1623             raise ValueError('%s objects must be 1-dimensional' %
-> 1624                              type(self).__name__)
   1625 
   1626         # Unlike in Variable, always eagerly load values into memory

ValueError: IndexVariable objects must be 1-dimensional

This can happen when not dropping the band coordinate after open_rasterio and using squeeze for a single band raster:

import xarray
xds = xarray.open_rasterio("file.tif").squeeze()
snowman2 commented 5 years ago

Current workaround:

xds = xarray.open_rasterio("file.tif").squeeze().drop("band")