Closed DahnJ closed 2 years ago
I recommend looking here if you are rasterizing points: https://corteva.github.io/geocube/stable/examples/rasterize_point_data.html
I recommend looking here if you are rasterizing points: https://corteva.github.io/geocube/stable/examples/rasterize_point_data.html
Thanks for the pointer. This makes sense — a regular grid in one projection won't stay a regular grid in another, and thus it makes more sense to resample/interpolate.
For completeness, here's an example of how geocube
could be used here, using the variables from the original example
import geopandas as gpd
from geocube.api.core import make_geocube
from geocube.rasterize import rasterize_points_griddata
gdf = gpd.GeoDataFrame(
data['z'],
geometry=gpd.points_from_xy(
x=data.index.get_level_values('x'),
y=data.index.get_level_values('y'),
crs='epsg:5514'
))
output = make_geocube(
vector_data=gdf,
measurements=['z'],
output_crs="epsg:4326",
resolution=(-0.01, 0.003),
rasterize_function=rasterize_points_griddata,
)
> output
<xarray.Dataset>
Dimensions: (y: 3, x: 2)
Coordinates:
* y (y) float64 49.81 49.8 49.79
* x (x) float64 16.1 16.1
spatial_ref int64 0
Data variables:
z (y, x) float64 507.8 530.9 539.6 544.0 539.9 539.9
However, I'm still curious about the behaviour of reproject
. In what sense is the output "correct", or how am I using it wrong?
The results seem to match GDAL:
xdata.rio.to_raster("test.tif")
gdalwarp test.tif test_4326.tif -t_srs "EPSG:4326"
rds = rioxarray.open_rasterio("test_4326.tif")
The main difference is the nodata value is 0
with GDAL:
<xarray.DataArray (band: 1, y: 4, x: 1)>
array([[[0.],
[0.],
[0.],
[0.]]])
Coordinates:
* band (band) int64 1
* x (x) float64 16.1
* y (y) float64 49.82 49.81 49.8 49.79
spatial_ref int64 0
Attributes:
scale_factor: 1.0
add_offset: 0.0
long_name:
I think it the small grid size in the X dimension is likely causing the troubles:
>>> xdata.rio.resolution()
(0.15999999991618097, 965.5)
You may get better information on the mailing list or issue tracker here: https://github.com/OSGeo/gdal
I see. Thank you for the help, I'm closing this issue.
Code Sample
Problem description
Using
xdata.rio.reproject()
does not seem to correctly reproject the dataExpected Output
I expected a
xarray.Dataset
with re-projected coordinates and same values as the input dataset.Environment Information
Installation method
conda
Conda environment information (if you installed with conda):
Environment (
conda list
):Details about
conda
and system (conda info
):