Class: QgsMapBoxGlStyleConverter¶
- class qgis.core.QgsMapBoxGlStyleConverter¶
Bases:
sip.wrapper
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 callingrenderer()
orlabeling()
respectively.New in version 3.16.
QgsMapBoxGlStyleConverter() Constructor for QgsMapBoxGlStyleConverter.
Methods
Takes a QColor object and returns HSLA components in required format for QGIS
color_hsla()
expression function.Converts a JSON
style
map, and returns the resultant status of the conversion.Returns a descriptive error message if an error was encountered during the style conversion, or an empty string if no error was encountered.
Generates an interpolation for values between
valueMin
andvalueMax
, scaled between the rangeszoomMin
tozoomMax
.Returns a new instance of a vector tile labeling representing the converted style, or
None
if the style could not be converted successfully.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
scale_linear()
orscale_exp()
(depending on base value).Interpolates a point/offset with either
scale_linear()
orscale_exp()
(depending on base value).Interpolates a string by zoom.
Converts a value to Qt.PenJoinStyle enum from JSON value.
Parse list of
layers
from JSON.Parses a line layer.
Parses and converts a match function value list.
Takes values from stops and uses either
scale_linear()
orscale_exp()
functions to interpolate alpha component of color.Takes values from stops and uses either
scale_linear()
orscale_exp()
functions to interpolate point/offset values.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.
Returns a new instance of a vector tile renderer representing the converted style, or
None
if the style could not be converted successfully.Retrieves the sprite image with the specified
name
, taken from the specifiedcontext
.Retrieves the sprite image with the specified
name
, taken from the specifiedcontext
as a base64 encoded valueReturns a list of user-friendly warnings generated during the conversion, e.g.
Attributes
- Color = 0¶
- NoLayerList = 1¶
- Numeric = 1¶
- Opacity = 2¶
- Point = 3¶
- class PropertyType¶
Bases:
int
- class Result¶
Bases:
int
- Success = 0¶
- colorAsHslaComponents(color: Union[QColor, Qt.GlobalColor]) Tuple[int, int, int, int] ¶
Takes a QColor object and returns HSLA components in required format for QGIS
color_hsla()
expression function.- Parameters
color (Union[QColor) – 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
- Return type
Tuple[int, int, int, int]
- convert(self, style: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext = None) QgsMapBoxGlStyleConverter.Result ¶
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.convert(self, style: str, context:
QgsMapBoxGlStyleConversionContext
= None) -> QgsMapBoxGlStyleConverter.Result Converts a JSONstyle
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 (Dict[str) –
context (
QgsMapBoxGlStyleConversionContext
= None) –
- Return type
- errorMessage(self) str ¶
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
- interpolateExpression(zoomMin: float, zoomMax: float, valueMin: Any, valueMax: Any, base: float, multiplier: float = 1, contextPtr: QgsMapBoxGlStyleConversionContext = None) str ¶
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 (
QgsMapBoxGlStyleConversionContext
= None) –
- Return type
str
- labeling(self) QgsVectorTileLabeling ¶
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
- parseArrayStops(stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1) str ¶
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
- parseCapStyle(style: str) Qt.PenCapStyle ¶
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 (str) –
- Return type
Qt.PenCapStyle
- parseCircleLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext) Tuple[bool, QgsVectorTileBasicRendererStyle] ¶
Parses a circle layer.
Warning
This is private API only, and may change in future QGIS versions
- Parameters
jsonLayer (Dict[str) – circle layer to parse
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type
Tuple[bool, QgsVectorTileBasicRendererStyle]
- Returns
True
if the layer was successfully parsed.style: generated QGIS vector tile style
- parseColor(color: Any, context: QgsMapBoxGlStyleConversionContext) QColor ¶
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
- parseColorExpression(colorExpression: Any, context: QgsMapBoxGlStyleConversionContext) str ¶
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 since QGIS 3.22
- parseExpression(expression: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, colorExpected: bool = False) str ¶
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
- parseFillLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, isBackgroundStyle: bool = False) Tuple[bool, QgsVectorTileBasicRendererStyle] ¶
Parses a fill layer.
Warning
This is private API only, and may change in future QGIS versions
- Parameters
jsonLayer (Dict[str) – fill layer to parse
context (QgsMapBoxGlStyleConversionContext) – conversion context
isBackgroundStyle (bool = False) – set to
True
if the layer should be parsed as background layer
- Return type
Tuple[bool, QgsVectorTileBasicRendererStyle]
- Returns
True
if the layer was successfully parsed.style: generated QGIS vector tile style
- parseInterpolateByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1) Tuple[QgsProperty, float] ¶
Parses a numeric value which is interpolated by zoom range.
- Parameters
json (Dict[str) – definition of interpolation
context (QgsMapBoxGlStyleConversionContext) – conversion context
multiplier (float = 1) – optional multiplication factor
- Return type
Tuple[
QgsProperty
, float]- Returns
QgsProperty
representing interpolation settingsdefaultNumber: storage for a reasonable “default” number representing the overall property.
- parseInterpolateColorByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext) Tuple[QgsProperty, QColor] ¶
Parses a color value which is interpolated by zoom range.
- Parameters
json (Dict[str) – definition of color interpolation
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type
Tuple[
QgsProperty
, QColor]- Returns
QgsProperty
representing interpolation settingsdefaultColor: storage for a reasonable “default” color representing the overall property.
- parseInterpolateListByZoom(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255) Tuple[QgsProperty, QColor, float] ¶
Interpolates a list which starts with the interpolate function.
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) –
- Return type
Tuple[
QgsProperty
, QColor, float]
- parseInterpolateOpacityByZoom(json: Dict[str, Any], maxOpacity: int, contextPtr: QgsMapBoxGlStyleConversionContext = None) QgsProperty ¶
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) –
maxOpacity (int) –
contextPtr (
QgsMapBoxGlStyleConversionContext
= None) –
- Return type
- parseInterpolatePointByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1) Tuple[QgsProperty, QPointF] ¶
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) –
context (QgsMapBoxGlStyleConversionContext) –
multiplier (float = 1) –
- Return type
Tuple[
QgsProperty
, QPointF]
- parseInterpolateStringByZoom(json: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, conversionMap: Dict[str, Any]) Tuple[QgsProperty, str] ¶
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) –
context (QgsMapBoxGlStyleConversionContext) –
conversionMap (Dict[str) –
- Return type
Tuple[
QgsProperty
, str]
- parseJoinStyle(style: str) Qt.PenJoinStyle ¶
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 (str) –
- Return type
Qt.PenJoinStyle
- parseLayers(self, layers: Iterable[Any], context: QgsMapBoxGlStyleConversionContext = None)¶
Parse list of
layers
from JSON.Warning
This is private API only, and may change in future QGIS versions
- Parameters
layers (Iterable[Any]) –
context (
QgsMapBoxGlStyleConversionContext
= None) –
- parseLineLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext) Tuple[bool, QgsVectorTileBasicRendererStyle] ¶
Parses a line layer.
Warning
This is private API only, and may change in future QGIS versions
- Parameters
jsonLayer (Dict[str) – line layer to parse
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type
Tuple[bool, QgsVectorTileBasicRendererStyle]
- Returns
True
if the layer was successfully parsed.style: generated QGIS vector tile style
- parseMatchList(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255) Tuple[QgsProperty, QColor, float] ¶
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) –
- Return type
Tuple[
QgsProperty
, QColor, float]
- parseOpacityStops(base: float, stops: Iterable[Any], maxOpacity: int, context: QgsMapBoxGlStyleConversionContext) str ¶
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
- parsePointStops(base: float, stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1) str ¶
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
- parseStops(base: float, stops: Iterable[Any], multiplier: float, context: QgsMapBoxGlStyleConversionContext) str ¶
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
- parseStringStops(stops: Iterable[Any], context: QgsMapBoxGlStyleConversionContext, conversionMap: Dict[str, Any]) Tuple[str, str] ¶
Parses a list of interpolation stops containing string values.
- Parameters
stops (Iterable[Any]) – definition of interpolation stops
context (QgsMapBoxGlStyleConversionContext) – conversion context
conversionMap (Dict[str) – map of input string to output expression value
- Return type
Tuple[str, str]
- Returns
converted expression
defaultString: reasonable default value taken from stops
- parseSymbolLayer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext) Tuple[QgsVectorTileBasicRendererStyle, bool, QgsVectorTileBasicLabelingStyle, bool] ¶
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) – symbol layer to parse
rendererStyle – generated QGIS vector tile style
hasRenderer – will be set to
True
if symbol layer generated a renderer stylelabelingStyle – generated QGIS vector tile labeling
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type
Tuple[
QgsVectorTileBasicRendererStyle
, bool,QgsVectorTileBasicLabelingStyle
, bool]
- parseSymbolLayerAsRenderer(jsonLayer: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext) Tuple[bool, QgsVectorTileBasicRendererStyle] ¶
Parses a symbol layer as a renderer
Warning
This is private API only, and may change in future QGIS versions
- Parameters
jsonLayer (Dict[str) – fill layer to parse
context (QgsMapBoxGlStyleConversionContext) – conversion context
- Return type
Tuple[bool, QgsVectorTileBasicRendererStyle]
- Returns
True
if symbol layer was converted to rendererrendererStyle: generated QGIS vector tile style
- parseValueList(json: Iterable[Any], type: QgsMapBoxGlStyleConverter.PropertyType, context: QgsMapBoxGlStyleConversionContext, multiplier: float = 1, maxOpacity: int = 255) Tuple[QgsProperty, QColor, float] ¶
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) –
- Return type
Tuple[
QgsProperty
, QColor, float]
- renderer(self) QgsVectorTileRenderer ¶
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
- retrieveSprite(name: str, context: QgsMapBoxGlStyleConversionContext, spriteSize: QSize) QImage ¶
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 (str) –
context (QgsMapBoxGlStyleConversionContext) –
spriteSize (QSize) –
- Return type
QImage
- retrieveSpriteAsBase64(value: Any, context: QgsMapBoxGlStyleConversionContext, spriteSize: QSize, spriteProperty: str, spriteSizeProperty: str) str ¶
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) –
spriteSize (QSize) –
spriteProperty (str) –
spriteSizeProperty (str) –
- Return type
str
- warnings(self) List[str] ¶
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.
See also
- Return type
List[str]