As I mentioned here, when I add a raster inside a geocube are produced a lot of nodata.
After a test @snowman2 has indicates that this is a possible bug of xarray libraries.
I was able to reproduce the issue you demonstrated. I think it has to do with decimal precision of the coordinates when adding the DataArray to the Dataset. That being said, I checked that the x coordinate and y coordinates were the exact same for raster_in and out_grid. This is likely an issue with xarray and not geocube.
For a workaround, this got it working without the gaps for me:
import geopandas
import rioxarray
from geocube.api.core import make_geocube
vector_in = geopandas.read_file("vector_data.shp")
raster_in = rioxarray.open_rasterio("raster_data.tif", masked=True).sel(band=1).drop("band")
out_grid = make_geocube(
vector_data=vector_in,
measurements=["id"],
like=raster_in,
)
out_grid["process_value"] = (raster_in.dims, raster_in.values, raster_in.attrs, raster_in.encoding)
As I mentioned here, when I add a raster inside a geocube are produced a lot of nodata.
After a test @snowman2 has indicates that this is a possible bug of xarray libraries.