Skip to content

add ability to burn feature field values to raster#84

Draft
solomon-negusse wants to merge 1 commit intoxarray-contrib:mainfrom
wri:burn-feature-field
Draft

add ability to burn feature field values to raster#84
solomon-negusse wants to merge 1 commit intoxarray-contrib:mainfrom
wri:burn-feature-field

Conversation

@solomon-negusse
Copy link

@solomon-negusse solomon-negusse commented Feb 10, 2026

Hi @dcherian, we often need to burn some numeric field values when rasterizing vectors. This is a draft implementing that for rasterio engine if there is interest to adopt it. It works now but need to do some cleaning up. I see rusterize supports this as well and can take a stab at adding that too.

@solomon-negusse solomon-negusse marked this pull request as draft February 10, 2026 08:59
@dcherian
Copy link
Contributor

I'm inclined to treat this as an application of indexing or xr.where.

The default choice of using len(geometries) as a fill value bites us though. Maybe we should change that.

import xarray as xr
import xproj  # noqa
import geodatasets
import geopandas as gpd

ds = xr.tutorial.open_dataset("eraint_uvz")
ds = ds.proj.assign_crs(spatial_ref="epsg:4326")

world = gpd.read_file(geodatasets.get_path("naturalearth land"))


from rasterix.rasterize import rasterize

n = rasterize(ds, world[["geometry"]], xdim="longitude", ydim="latitude", engine="rasterio")
n.plot()

Use where to create the right indexer, and then index the dataframe

n = xr.where(n != len(world), n.astype(int), -1)
world["featurecla"].to_xarray()[n]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants