Closed phlamirande closed 2 years ago
I looked at your data, and it appears that your points don't properly represent the grid.
If I do:
numpy.unique(xr.y.diff(dim="y"))
I get:
array([ 10., 710.])
To solve your problem, I believe you need to rasterize your points to a grid. geocube
can help: https://corteva.github.io/geocube/stable/getting_started.html
For example:
gdf = geopandas.GeoDataFrame(
df[columns],
geometry=geopandas.points_from_xy(
df.x, df.y, crs="epsg:26911"
)
)
xr = make_geocube(
gdf,
resolution=10,
fill=-9999,
)
for col in columns:
print("Column : " + col)
output_path = os.path.join(output_directory, col + ".tif")
xr[col].rio.to_raster(raster_path=output_path, dtype="int16")
Thanks @snowman2,
My group and I usually work with contiguous blocks of data, but it happens that sometimes we have to deal with non-contiguous data such as what I am showing here.
When applying the make_geocube() command, the output geotiffs are correct. So I understand that rioxarray requires that the x-y points are evenly spaced ? Is that right?
However, it seems that the execution time increases by lot (from 2-3s to 90s). Is there a workaround solution that would take less computation time ?
So I understand that rioxarray requires that the x-y points are evenly spaced ? Is that right?
That is correct.
Is there a workaround solution that would take less computation time ?
You would need to add in the missing rows filled in with nodata.
I am closing as I believe this has been resolved. If you have further questions, feel free to ask them.
Problem description
Attached data : clusters.csv I have a geospatial dataset, a single csv containing x, y and clusters data (about 147 000 cells). The cell size is 10m and the CRS is epsg:26911. The dataset comprises two distinct yet nearby areas : I want to convert this csv data to geotiff by using rioxarray.to_raster function.
Expected Output
I would expect the raster to look like this
I rather get a raster where the cells are slightly offset from where they should be. The cell size is now 10.48xxxxx m when I was expecting a 10 m. See below on the image, the black transparent layer is the problematic one created with rioxarray while the ''correct'' colored one is the output created with geocube.
I found that this behavior happens only when you have two or more distrinct / non-contiguous spatial blocks in your data. Otherwise, if the data is in a single block (cell that touches), the output is fine.
Code
Environment Information
I use QGIS for visualisation of the geotiffs.
Installation method
conda
Conda environment information (if you installed with conda):
Environment (
conda list
):Details about
conda
and system (conda info
):Thanks a lot, P-H