I am converting vector features to raster using Rasterio rasterize(). I am trying to find a way to specify the output spatial resolution. The current approach specifies the number of pixels (shape = 100, 100) in the XY dimensions.
import geopandas as gpd from rasterio.features import rasterize gdf = gpd.read_file('/path/to/polylines.shp') shape = 100, 100 transform = rasterio.transform.from_bounds(*gdf['geometry'].total_bounds, *shape) raster = rasterize( [(shape, 1) for shape in gdf['geometry']], out_shape=shape, transform=transform, fill=0, all_touched=True, dtype=rasterio.uint8) The following GDAL approach does what I am after, although I need to stay within the Rasterio package:
import gdal import ogr # https://stackoverflow.com/a/59892342 lines = '/path/to/poly_lines.shp' input_shp = ogr.Open(lines) output_raster = '/path/to/out_raster.tif' shp_layer = input_shp.GetLayer() pixel_size = 30 xmin, xmax, ymin, ymax = shp_layer.GetExtent() ds = gdal.Rasterize(output_raster, lines, xRes=pixel_size, yRes=pixel_size, burnValues=1, outputBounds=[xmin, ymin, xmax, ymax], allTouched=True, outputType=gdal.GDT_Byte) ds = None How can I specify the spatial resolution when using Rasterio rasterize()?