Class: QgsMapBoxGlStyleConverter¶
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings.
Conversions are performed by calling convert()
with either a
JSON map or JSON string value, and then retrieving the results by
calling renderer()
or labeling()
respectively.
Added in version 3.16.
Enums
Property types, for interpolated value conversion |
Methods
Converts a JSON style map, and returns the resultant status of the conversion. |
|
Returns a list of new map layers corresponding to sublayers of the style, e.g. raster layers. |
|
Returns a descriptive error message if an error was encountered during the style conversion, or an empty string if no error was encountered. |
|
Returns a new instance of a vector tile labeling representing the converted style, or |
|
Parse list of layers from JSON. |
|
Parse a raster source from JSON. |
|
Parse list of sources from JSON. |
|
Returns a list of raster sub layers contained in the style. |
|
Returns a new instance of a vector tile renderer representing the converted style, or |
|
Returns the list of converted sources. |
|
Returns a list of user-friendly warnings generated during the conversion, e.g. as a result of MapBox GL style settings which cannot be translated to QGIS styles. |
Static Methods
Takes a QColor object and returns HSLA components in required format for QGIS |
|
Generates an interpolation for values between valueMin and valueMax, scaled between the ranges zoomMin to zoomMax. |
|
Takes numerical arrays from stops. |
|
Converts a value to Qt.PenCapStyle enum from JSON value. |
|
Parses a circle layer. |
|
Parses a color in one of these supported formats: |
|
Converts an expression representing a color to a string (can be color string or an expression where a color is expected) |
|
Converts a MapBox GL expression to a QGIS expression. |
|
Parses a fill layer. |
|
Parses a numeric value which is interpolated by zoom range. |
|
Parses a color value which is interpolated by zoom range. |
|
Interpolates a list which starts with the interpolate function. |
|
Interpolates opacity with either |
|
Interpolates a point/offset with either |
|
Interpolates a string by zoom. |
|
Converts a value to Qt.PenJoinStyle enum from JSON value. |
|
Parses a list of interpolation stops containing label values. |
|
Parses a line layer. |
|
Parses and converts a match function value list. |
|
Takes values from stops and uses either |
|
Takes values from stops and uses either |
|
Parses and converts a match function value list. |
|
Parses a list of interpolation stops |
|
Parses a list of interpolation stops containing string values. |
|
Parses a symbol layer as renderer or labeling. |
|
Parses a symbol layer as a renderer |
|
Parses and converts a value list (e.g. an interpolate list). |
|
Retrieves the sprite image with the specified name, taken from the specified context. |
|
Retrieves the sprite image with the specified name, taken from the specified context as a base64 encoded value |
|
Retrieves the sprite image with the specified name, taken from the specified context as a base64 encoded value |
Attributes
- class qgis.core.QgsMapBoxGlStyleConverter[source]¶
Bases:
object
- __init__()
Constructor for QgsMapBoxGlStyleConverter.
- NoLayerList = 1¶
- class PropertyType(*values)¶
Bases:
IntEnum
Property types, for interpolated value conversion
Warning
This is private API only, and may change in future QGIS versions
Color
: Color propertyNumeric
: Numeric property (e.g. line width, text size)Opacity
: Opacity propertyPoint
: Point/offset propertyNumericArray
: Numeric array for dash arrays or such
- Color = 0¶
- Numeric = 1¶
- NumericArray = 4¶
- Opacity = 2¶
- Point = 3¶
- class Result¶
Bases:
int
- Success = 0¶
- static colorAsHslaComponents(color: QColor | Qt.GlobalColor)[source]¶
Takes a QColor object and returns HSLA components in required format for QGIS
color_hsla()
expression function.- Parameters:
color (Union[QColor, Qt.GlobalColor]) -> (int) – input color
hue – an integer value from 0 to 360
saturation – an integer value from 0 to 100
lightness – an integer value from 0 to 100
alpha – an integer value from 0 (completely transparent) to 255 (opaque).
Warning
This is private API only, and may change in future QGIS versions
- convert(self, style: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext | None = None) QgsMapBoxGlStyleConverter.Result [source]¶
Converts a JSON
style
map, and returns the resultant status of the conversion.If an error occurs during conversion then a descriptive error message can be retrieved by calling
errorMessage()
.After conversion, the resultant labeling and style rules can be retrieved by calling
renderer()
orlabeling()
respectively.The optional
context
argument can be set to use a specific context during the conversion.- Parameters:
style (Dict[str, Any])
context (Optional[QgsMapBoxGlStyleConversionContext] = None)
- Return type:
- convert(self, style: str | None, context: QgsMapBoxGlStyleConversionContext | None = None) QgsMapBoxGlStyleConverter.Result [source]
Converts a JSON
style
string, and returns the resultant status of the conversion.If an error occurs during conversion then a descriptive error message can be retrieved by calling
errorMessage()
.After conversion, the resultant labeling and style rules can be retrieved by calling
renderer()
orlabeling()
respectively.The optional
context
argument can be set to use a specific context during the conversion.- Parameters:
style (Optional[str])
context (Optional[QgsMapBoxGlStyleConversionContext] = None)
- Return type:
- createSubLayers(self) List[QgsMapLayer] ¶
Returns a list of new map layers corresponding to sublayers of the style, e.g. raster layers.
The caller takes ownership of the returned layers.
Added in version 3.28.
- Return type:
List[QgsMapLayer]
- errorMessage(self) str [source]¶
Returns a descriptive error message if an error was encountered during the style conversion, or an empty string if no error was encountered.
See also
- Return type:
str
- static interpolateExpression(zoomMin: float, zoomMax: float, valueMin: Any, valueMax: Any, base: float, multiplier: float = 1, contextPtr: QgsMapBoxGlStyleConversionContext | None = None) str [source]¶
Generates an interpolation for values between
valueMin
andvalueMax
, scaled between the rangeszoomMin
tozoomMax
.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
zoomMin (float)
zoomMax (float)
valueMin (Any)
valueMax (Any)
base (float)
multiplier (float = 1)
contextPtr (Optional[QgsMapBoxGlStyleConversionContext] = None)
- Return type:
str
- labeling(self) QgsVectorTileLabeling | None [source]¶
Returns a new instance of a vector tile labeling representing the converted style, or
None
if the style could not be converted successfully.- Return type:
Optional[QgsVectorTileLabeling]
- static parseArrayStops(stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1) str [source]¶
Takes numerical arrays from stops.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
stops (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1)
- Return type:
str
- static parseCapStyle(style: str | None) Qt.PenCapStyle [source]¶
Converts a value to Qt.PenCapStyle enum from JSON value.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
style (Optional[str])
- Return type:
Qt.PenCapStyle
- static parseCircleLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext)[source]¶
Parses a circle layer.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
jsonLayer (Dict[str, Any]) – circle layer to parse
context (
QgsMapBoxGlStyleConversionContext
) -> (bool) – conversion context
- Returns:
True
if the layer was successfully parsed.style: generated QGIS vector tile style
- static parseColor(color: Any, context: QgsMapBoxGlStyleConversionContext) QColor [source]¶
Parses a
color
in one of these supported formats:c #fff or c #ffffff
hsl(30, 19%, 90%)
orhsla(30, 19%, 90%, 0.4)
rgb(10, 20, 30)
orrgba(10, 20, 30, 0.5)
Returns an invalid color if the color could not be parsed.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
color (Any)
context (QgsMapBoxGlStyleConversionContext)
- Return type:
QColor
- static parseColorExpression(colorExpression: Any, context: QgsMapBoxGlStyleConversionContext) str [source]¶
Converts an expression representing a color to a string (can be color string or an expression where a color is expected)
- Parameters:
colorExpression (Any) – the color expression
context (QgsMapBoxGlStyleConversionContext) – the style conversion context
- Return type:
str
- Returns:
the QGIS expression string
Added in version 3.22.
- static parseExpression(expression: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, colorExpected: bool = False) str [source]¶
Converts a MapBox GL expression to a QGIS expression.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
expression (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
colorExpected (bool = False)
- Return type:
str
- static parseFillLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, isBackgroundStyle: bool = False)[source]¶
Parses a fill layer.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
jsonLayer (Dict[str, Any]) – fill layer to parse
context (QgsMapBoxGlStyleConversionContext) – conversion context
isBackgroundStyle (bool = False) -> (bool) – set to
True
if the layer should be parsed as background layer
- Returns:
True
if the layer was successfully parsed.style: generated QGIS vector tile style
- static parseInterpolateByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1)[source]¶
Parses a numeric value which is interpolated by zoom range.
- Parameters:
json (Dict[str, Any]) – definition of interpolation
context (QgsMapBoxGlStyleConversionContext) – conversion context
multiplier (float = 1) -> (QgsProperty) – optional multiplication factor
- Returns:
QgsProperty
representing interpolation settingsdefaultNumber: a reasonable “default” number representing the overall property.
- static parseInterpolateColorByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext)[source]¶
Parses a color value which is interpolated by zoom range.
- Parameters:
json (Dict[str, Any]) – definition of color interpolation
context (
QgsMapBoxGlStyleConversionContext
) -> (QgsProperty) – conversion context
- Returns:
QgsProperty
representing interpolation settingsdefaultColor: a reasonable “default” color representing the overall property.
- static parseInterpolateListByZoom(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255)[source]¶
Interpolates a list which starts with the interpolate function.
Warning
This is private API only, and may change in future QGIS versions
Added in version 3.40.
- Parameters:
json (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1)
maxOpacity (int = 255) -> (QgsProperty)
- static parseInterpolateOpacityByZoom(json: Dict[str, Any], maxOpacity: int, contextPtr: QgsMapBoxGlStyleConversionContext | None = None) QgsProperty [source]¶
Interpolates opacity with either
scale_linear()
orscale_exp()
(depending on base value). Forjson
with intermediate stops it usesparseOpacityStops()
function. It uses QGISset_color_part()
function to set alpha component of color.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
json (Dict[str, Any])
maxOpacity (int)
contextPtr (Optional[QgsMapBoxGlStyleConversionContext] = None)
- Return type:
- static parseInterpolatePointByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1)[source]¶
Interpolates a point/offset with either
scale_linear()
orscale_exp()
(depending on base value). Forjson
with intermediate stops it usesparsePointStops()
function.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
json (Dict[str, Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1) -> (QgsProperty)
- static parseInterpolateStringByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, conversionMap: Dict[str, Any])[source]¶
Interpolates a string by zoom. For
json
with intermediate stops it usesparseStringStops()
function.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
json (Dict[str, Any])
context (QgsMapBoxGlStyleConversionContext)
conversionMap (Dict[str, Any]) -> (QgsProperty)
- static parseJoinStyle(style: str | None) Qt.PenJoinStyle [source]¶
Converts a value to Qt.PenJoinStyle enum from JSON value.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
style (Optional[str])
- Return type:
Qt.PenJoinStyle
- static parseLabelStops(stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext) str [source]¶
Parses a list of interpolation stops containing label values.
- Parameters:
stops (Iterable[Any]) – definition of interpolation stops
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type:
str
- Returns:
converted expression
- parseLayers(self, layers: Iterable[Any], context: QgsMapBoxGlStyleConversionContext | None = None)[source]¶
Parse list of
layers
from JSON.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
layers (Iterable[Any])
context (Optional[QgsMapBoxGlStyleConversionContext] = None)
- static parseLineLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext)[source]¶
Parses a line layer.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
jsonLayer (Dict[str, Any]) – line layer to parse
context (
QgsMapBoxGlStyleConversionContext
) -> (bool) – conversion context
- Returns:
True
if the layer was successfully parsed.style: generated QGIS vector tile style
- static parseMatchList(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255)[source]¶
Parses and converts a match function value list.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
json (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1)
maxOpacity (int = 255) -> (QgsProperty)
- static parseOpacityStops(base: float, stops: Iterable[Any], maxOpacity: int, context: QgsMapBoxGlStyleConversionContext) str [source]¶
Takes values from stops and uses either
scale_linear()
orscale_exp()
functions to interpolate alpha component of color.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
base (float)
stops (Iterable[Any])
maxOpacity (int)
context (QgsMapBoxGlStyleConversionContext)
- Return type:
str
- static parsePointStops(base: float, stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1) str [source]¶
Takes values from stops and uses either
scale_linear()
orscale_exp()
functions to interpolate point/offset values.Warning
This is private API only, and may change in future QGIS versions
- Parameters:
base (float)
stops (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1)
- Return type:
str
- parseRasterSource(self, source: Dict[str, Any], name: str | None, context: QgsMapBoxGlStyleConversionContext | None = None)[source]¶
Parse a raster
source
from JSON.Warning
This is private API only, and may change in future QGIS versions
Added in version 3.28.
- Parameters:
source (Dict[str, Any])
name (Optional[str])
context (Optional[QgsMapBoxGlStyleConversionContext] = None)
- parseSources(self, sources: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext | None = None)[source]¶
Parse list of
sources
from JSON.Warning
This is private API only, and may change in future QGIS versions
Added in version 3.28.
- Parameters:
sources (Dict[str, Any])
context (Optional[QgsMapBoxGlStyleConversionContext] = None)
- static parseStepList(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255)[source]¶
Parses and converts a match function value list.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
json (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1)
maxOpacity (int = 255) -> (QgsProperty)
- static parseStops(base: float, stops: Iterable[Any], multiplier: float, context: QgsMapBoxGlStyleConversionContext) str [source]¶
Parses a list of interpolation stops
- Parameters:
base (float) – interpolation exponent base
stops (Iterable[Any]) – definition of interpolation stops
multiplier (float) – optional multiplication factor
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type:
str
- static parseStringStops(stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, conversionMap: Dict[str, Any])[source]¶
Parses a list of interpolation stops containing string values.
- Parameters:
stops (Iterable[Any]) – definition of interpolation stops
context (QgsMapBoxGlStyleConversionContext) – conversion context
conversionMap (Dict[str, Any]) -> (str) – map of input string to output expression value
- Returns:
converted expression
defaultString: reasonable default value taken from stops
- static parseSymbolLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext)[source]¶
Parses a symbol layer as renderer or labeling.
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
jsonLayer (Dict[str, Any]) – symbol layer to parse
context (
QgsMapBoxGlStyleConversionContext
) -> (QgsVectorTileBasicRendererStyle) – conversion context
- Returns:
rendererStyle: generated QGIS vector tile style
hasRenderer:
True
if symbol layer generated a renderer stylelabelingStyle: generated QGIS vector tile labeling
hasLabeling:
True
if symbol layer generated a labeling style
- static parseSymbolLayerAsRenderer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext)[source]¶
Parses a symbol layer as a renderer
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
jsonLayer (Dict[str, Any]) – fill layer to parse
context (
QgsMapBoxGlStyleConversionContext
) -> (bool) – conversion context
- Returns:
True
if symbol layer was converted to rendererrendererStyle: generated QGIS vector tile style
- static parseValueList(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255)[source]¶
Parses and converts a value list (e.g. an interpolate list).
Warning
This is private API only, and may change in future QGIS versions
- Parameters:
json (Iterable[Any])
context (QgsMapBoxGlStyleConversionContext)
multiplier (float = 1)
maxOpacity (int = 255) -> (QgsProperty)
- rasterSubLayers(self) List[QgsMapBoxGlStyleRasterSubLayer] ¶
Returns a list of raster sub layers contained in the style.
Added in version 3.28.
- Return type:
- renderer(self) QgsVectorTileRenderer | None [source]¶
Returns a new instance of a vector tile renderer representing the converted style, or
None
if the style could not be converted successfully.- Return type:
Optional[QgsVectorTileRenderer]
- static retrieveSprite(name: str | None, context: QgsMapBoxGlStyleConversionContext, spriteSize: QSize) QImage [source]¶
Retrieves the sprite image with the specified
name
, taken from the specifiedcontext
.The
context
must have valid sprite definitions and images set viaQgsMapBoxGlStyleConversionContext.setSprites()
prior to conversion.- Parameters:
name (Optional[str])
context (QgsMapBoxGlStyleConversionContext)
spriteSize (QSize)
- Return type:
QImage
- static retrieveSpriteAsBase64(value: Any, context: QgsMapBoxGlStyleConversionContext) str [source]¶
Retrieves the sprite image with the specified
name
, taken from the specifiedcontext
as a base64 encoded valueThe
context
must have valid sprite definitions and images set viaQgsMapBoxGlStyleConversionContext.setSprites()
prior to conversion.- Parameters:
value (Any)
context (QgsMapBoxGlStyleConversionContext)
- Return type:
str
- static retrieveSpriteAsBase64WithProperties(value: Any, context: QgsMapBoxGlStyleConversionContext)[source]¶
Retrieves the sprite image with the specified
name
, taken from the specifiedcontext
as a base64 encoded valueThe
context
must have valid sprite definitions and images set viaQgsMapBoxGlStyleConversionContext.setSprites()
prior to conversion.Added in version 3.40.
- Parameters:
value (Any)
context (
QgsMapBoxGlStyleConversionContext
) -> (str)
- sources(self) List[QgsMapBoxGlStyleAbstractSource] ¶
Returns the list of converted sources.
Added in version 3.28.
- Return type: