Skip to content

Styles

qgis_project.Style(opacity=1.0) dataclass

Base class for layer styling.

Parameters:

Name Type Description Default
opacity float

The layer opacity in the interval [0, 1]

1.0

set_style(layer)

Apply the style to the low-level QGIS objects for layer styling.

Source code in qgis_project/style.py
def set_style(self, layer: Layer):
    """Apply the style to the low-level QGIS objects for layer styling."""
    if self.opacity is not None:
        layer.qgis_layer.setOpacity(self.opacity)

qgis_project.RasterStyle(opacity=1.0, vmin=None, vmax=None) dataclass

Bases: Style

Base class for raster layer styling.

Parameters:

Name Type Description Default
vmin float | list[float] | None

The minimum value used for the colorbar/contrast stretch. If None, will be automatically determined from the layer data. For styles with multiple bands (e.g. RasterStyleMultiBandColor), a list applies one value per band; a single value applies to all bands.

None
vmax float | list[float] | None

The maximum value used for the colorbar/contrast stretch. If None, will be automatically determined from the layer data. For styles with multiple bands (e.g. RasterStyleMultiBandColor), a list applies one value per band; a single value applies to all bands.

None

qgis_project.RasterStyleBW(opacity=1.0, vmin=None, vmax=None) dataclass

Bases: RasterStyle

A black-and-white style for raster layers.

qgis_project.RasterStyleSinglePseudocolor(opacity=1.0, vmin=None, vmax=None, colormap='viridis') dataclass

Bases: RasterStyle

A single-band pseudocolor style for raster layers.

Parameters:

Name Type Description Default
colormap str

Name of a QGIS built-in color ramp (case-insensitive), e.g. "Viridis", "Spectral", "RdYlBu". Run `QgsStyle.defaultStyle().colorRampNames()`` to see all available names.

'viridis'

qgis_project.RasterStyleMultiBandColor(opacity=1.0, vmin=None, vmax=None) dataclass

Bases: RasterStyle

A multi-band color (RGB) style for raster layers.

Maps three raster bands to the red, green, and blue channels, each with an independent contrast stretch — e.g. true-color or false-color composites. Requires layer.band_idx to be a list of three band numbers, e.g. [1, 2, 3] for (R, G, B).

qgis_project.RasterStylePaletted(opacity=1.0, vmin=None, vmax=None, colors=None, labels=None, colormap='Spectral') dataclass

Bases: RasterStyle

A paletted / unique-value style for single-band rasters — one fixed color per discrete band value.

Suited to categorical rasters (land cover, classification masks, segmentation output) where each pixel value is a class label rather than a continuous measurement. Unlike RasterStyleSinglePseudocolor, no interpolation is applied between values; vmin/vmax are ignored.

Parameters:

Name Type Description Default
colors dict[int, str] | None

Explicit mapping of band value to color, e.g. {1: "#1b9e77", 2: "red", 3: "0,0,255"}. If None, the distinct values present in the band are detected automatically and assigned colors from colormap.

None
labels dict[int, str] | None

Optional mapping of band value to legend label. Values without an entry fall back to the numeric value as their label.

None
colormap str

Name of a QGIS built-in color ramp (case-insensitive) used to assign colors when colors is not given, e.g. "Spectral", "Turbo", "Random colors". Run QgsStyle.defaultStyle().colorRampNames() to see all available names.

'Spectral'

qgis_project.VectorStyle(opacity=1.0) dataclass

Bases: Style

Base class for vector layer styling.

qgis_project.VectorStyleSingleSymbol(opacity=1.0, color=None, outline_color=None, outline_width=None, size=None, marker_shape=None) dataclass

Bases: VectorStyle

A single-symbol style for vector layers — every feature rendered identically.

Parameters:

Name Type Description Default
color str | None

Fill (polygon), line, or marker color, e.g. "red", "#ff0000", or "255,0,0,255". If None, the QGIS default symbol color is kept.

None
outline_color str | None

Outline/stroke color for polygon and marker symbols.

None
outline_width float | None

Outline/stroke width in millimeters for polygon, line, and marker symbols.

None
size float | None

Marker size in millimeters. Only applies to point layers.

None
marker_shape str | None

Marker shape for point layers, e.g. "circle", "square", "triangle", "star". See QgsSimpleMarkerSymbolLayerBase.decodeShape() for all accepted names.

None

qgis_project.VectorStyleCategorized(opacity=1.0, field='', colormap='Spectral') dataclass

Bases: VectorStyle

A categorized style for vector layers — one color per unique attribute value.

Parameters:

Name Type Description Default
field str

Name of the attribute field to categorize by.

''
colormap str

Name of a QGIS built-in color ramp (case-insensitive), e.g. "Spectral", "RdYlBu", "Turbo". Run QgsStyle.defaultStyle().colorRampNames() to see all available names.

'Spectral'

qgis_project.VectorStyleGraduated(opacity=1.0, field='', num_classes=5, vmin=None, vmax=None, colormap='Viridis') dataclass

Bases: VectorStyle

A graduated (choropleth) style for vector layers — equal-interval color classes based on a numeric attribute.

Parameters:

Name Type Description Default
field str

Name of the numeric attribute field to classify.

''
num_classes int

Number of equal-width classes.

5
vmin float | None

Lower bound of the classification range. If None, uses the field's minimum value.

None
vmax float | None

Upper bound of the classification range. If None, uses the field's maximum value.

None
colormap str

Name of a QGIS built-in color ramp (case-insensitive), e.g. "Viridis", "Spectral", "RdYlBu". Run QgsStyle.defaultStyle().colorRampNames() to see all available names.

'Viridis'

qgis_project.VectorLabels(field='', size=10.0, color='black', is_expression=False) dataclass

Attribute-based labels for vector layers.

Labeling is independent of the layer's renderer/style and can be combined with any VectorStyle.

Parameters:

Name Type Description Default
field str

Name of the attribute field to use as label text, or a QGIS expression if is_expression is True.

''
size float

Font size in points.

10.0
color str

Text color, e.g. "black", "#000000".

'black'
is_expression bool

If True, field is evaluated as a QGIS expression rather than a plain field name, e.g. "name || ' (' || value || ')'".

False