Describe the bug
generate_terrain() throws away the caller's spatial reference. When the input
DataArray already has coordinates and geo-attributes (crs, res, units), the
output drops them and builds a synthetic grid from x_range/y_range (default
(0, 500)) instead.
It's easiest to hit through the .xrs accessor, where you pass your own
georeferenced raster:
my_attrs = {'res': (30, 30), 'crs': 'EPSG:5070', 'units': 'meters'}
xarr = xr.DataArray(arr, coords={'y': ys, 'x': xs}, dims=('y', 'x'),
name='study_area', attrs=my_attrs)
terrain = xarr.xrs.generate_terrain()
xarr has y/x coords on a 30 m grid, res=(30, 30), and crs='EPSG:5070'. The
result comes back as:
Coordinates:
* y (y) float64 0.625 1.875 3.125 ... 498.1 499.4
* x (x) float64 0.8333 2.5 4.167 ... 497.5 499.2
Attributes:
res: (1.6666666666666667, 1.25)
The coords are rescaled to the (0, 500) default, res is overwritten, and
crs/units are gone.
Expected behavior
When the caller's array carries its own coords and geo-attrs, the output should
keep them: matching coords, chunks (dask), attrs['res'], and attrs['crs'].
A bare template with no coords/attrs should keep today's behavior of synthesizing
coords from x_range/y_range.
Additional context
In xrspatial/terrain.py, generate_terrain() builds fresh coords from
x_range/y_range and sets attrs={'res': (dx, dy)}, ignoring the caller's
coords and attrs. The accessor in xrspatial/accessor.py just forwards
self._obj, so the fix belongs in generate_terrain. The dask data chunks
already survive through map_blocks — coords and attrs are the gap.
Describe the bug
generate_terrain()throws away the caller's spatial reference. When the inputDataArray already has coordinates and geo-attributes (
crs,res,units), theoutput drops them and builds a synthetic grid from
x_range/y_range(default(0, 500)) instead.It's easiest to hit through the
.xrsaccessor, where you pass your owngeoreferenced raster:
xarrhas y/x coords on a 30 m grid,res=(30, 30), andcrs='EPSG:5070'. Theresult comes back as:
The coords are rescaled to the
(0, 500)default,resis overwritten, andcrs/unitsare gone.Expected behavior
When the caller's array carries its own coords and geo-attrs, the output should
keep them: matching
coords,chunks(dask),attrs['res'], andattrs['crs'].A bare template with no coords/attrs should keep today's behavior of synthesizing
coords from
x_range/y_range.Additional context
In
xrspatial/terrain.py,generate_terrain()builds fresh coords fromx_range/y_rangeand setsattrs={'res': (dx, dy)}, ignoring the caller'scoords and attrs. The accessor in
xrspatial/accessor.pyjust forwardsself._obj, so the fix belongs ingenerate_terrain. The dask data chunksalready survive through
map_blocks— coords and attrs are the gap.