-
I am trying to create a valid in memory raster from a numpy array. I'm running into a problem where operations on my from-numpy raster involving other rasters read in using Example code: import numpy as np
import xarray as xr
import rioxarray as rxr
from affine import Affine
cs = np.array(
[
[
[1, 2, 2, 1, 3, 4],
[4, 7, 5, -1, 2, 6],
[1, 4, 5, -1, 5, 1],
[5, 8, 7, 5, 6, 6],
[7, 3, 2, 6, 4, 6],
[1, 3, 4, 4, 3, 2],
]
]
)
coords = [list(range(d)) for d in cs.shape]
dims = ["band", "y", "x"]
xcs = (
xr.DataArray(cs, coords=coords, dims=dims)
.astype("int32")
.rio.write_nodata(-1)
.rio.write_transform(Affine(1.0, 0.0, -0.5, 0.0, 1.0, -0.5))
)
print(f"xcs:\n{xcs}\n")
print(f"xcs transform:\n{xcs.rio.transform()}")
# ESRI output raster that has identical data
ecs = rxr.open_rasterio("costs.tif")
print(f"ecs:\n{ecs}\n")
print(f"ecs transform:\n{ecs.rio.transform()}")
print(f"xcs == ecs:\n{xcs == ecs}:\n")
xcs.rio.to_raster("test.tif")
rxcs = rxr.open_rasterio("test.tif")
print(f"rxcs:\n{rxcs}\n")
print(f"rxcs == ecs:\n{rxcs == ecs}") Output:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
The main difference I see is that the coordinate order is different in the Update: the band is different |
Beta Was this translation helpful? Give feedback.
The main difference I see is that the coordinate order is different in the
y
axis. I would recommend sorting it.Also, this may help: https://corteva.github.io/rioxarray/stable/examples/reproject_match.html
Update: the band is different