gdal icon indicating copy to clipboard operation
gdal copied to clipboard

gdal vector rasterize - clip to requested geometry, not source dataset

Open PostholerCom opened this issue 2 weeks ago • 4 comments

Feature description

This would be similar to gdalwarp -crop_to_cutline.

When rasterizing a vector data set you can 'clip' the source with --sql or --where, but the resulting raster has the spatial dimension of the source dataset.

Yes, you can use --extent, but you're kinda guessing at it.

Consider the following image. It would 'be nice' if it was cropped to the resulting image:

gdal vector rasterize \ -i /vsizip/vsicurl/https://www2.census.gov/geo/tiger/TIGER2025/STATE/tl_2025_us_state.zip \ --where "stusps = 'CA'" -l tl_2025_us_state --burn 1 --size 1500,1500 -o tmp.tif --overwrite \ && gdal raster convert -i tmp.tif -o tmp.png --overwrite \ && eog tmp.png

Thanks! Scott

Additional context

No response

PostholerCom avatar Dec 06 '25 21:12 PostholerCom

I've make that possible in https://github.com/OSGeo/gdal/pull/13520 by extending gdal vector clip, and thus your problem can be fixed with

gdal pipeline read /vsizip/vsicurl/https://www2.census.gov/geo/tiger/TIGER2025/STATE/tl_2025_us_state.zip ! \
                        filter --where  "stusps = 'CA'" ! \
                        clip ! \
                        rasterize  --burn 1 --size 1500,1500 --datatype Byte ! \
                        write out.png --overwrite

rouault avatar Dec 07 '25 17:12 rouault

I just did a pull/build and tested:

gdal pipeline read /vsizip/vsicurl/https://www2.census.gov/geo/tiger/TIGER2025/STATE/tl_2025_us_state.zip !
filter --where "stusps = 'CA'" !
clip !
rasterize --burn 1 --size 1500,1500 --datatype Byte !
write out.png --overwrite ERROR 1: clip: --bbox, --geometry or --like must be specified 0...10...20...30...40...50...60...70...80...90...100 - done.

gdal --version GDAL 3.13.0dev-511c64b030, released 2025/12/07

PostholerCom avatar Dec 07 '25 20:12 PostholerCom

GDAL 3.13.0dev-511c64b030, released 2025/12/07

511c64b030 is a master commit, not the branch of this PR which hasn't yet been merged

rouault avatar Dec 07 '25 20:12 rouault

Got it. I'll be patient. ;)

PostholerCom avatar Dec 07 '25 20:12 PostholerCom