girs.rastfeat.rasterize.rasterize_layers_by_field

rasterize_layers_by_field(layers, field_names, **kwargs)

Rasterize a layer containing lines or polygons.

Raster values are set according to field values found in field_name. If field_name is a list of field names, its length must coincide with the number of layers given in layer_in.

The spatial reference system will be the same as from layer_in.

If layer_in contains more than one layer and layer_number is not given, generate a raster with as many bands as layers.

if no raster_out was defined, the raster will be created in the memory.It is possible to define a label for raster_out in the memory by explicitly setting the driver to ‘MEM’, e.g., raster_out=’mylabel’, driver=’MEM’

The parameters defining the raster properties are (in priority order):
  • raster_parameters: a raster will be created, transformed to the the coordinate system of layer_in and clipped according to layer_in. The raster parameters are retrieved from the new raster. Driver from raster parameters is not used
  • layer_in: raster parameters are obtained from envelope of layer_in; pixel_size = 1/100 of the narrowest layer extent (width or height) if pixel_size: (nx, ny) or n is not given
Parameters:
  • layers – Layers filename, Layers object or a layer, If a Layers object was given, use the layer specified in layer_number
  • field_names (str) – the field name of the layer used to rasterize. The burn value will be unique for each unique value found in the field name
  • kwargs
    key layer_number:
     only used if layer_in is a Layers object. If layer_in is a Layers object and layer_number is unset, use all layers and create the corresponding number of bands
    key raster_out:an existing rasters or filename of the new rasters
    key driver:None
    key raster_parameters:
     
    key clip:
    key pixel_size:None
Returns:

a Raster object if raster_out is a file name, otherwise the same object as in raster_out but with the burned layer

Return type:

RasterWriter