mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
410 lines
16 KiB
Python
410 lines
16 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
***************************************************************************
|
|
__init__.py
|
|
---------------------
|
|
Date : May 2014
|
|
Copyright : (C) 2014 by Nathan Woodrow
|
|
Email : woodrow dot nathan at gmail dot com
|
|
***************************************************************************
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************
|
|
"""
|
|
|
|
__author__ = 'Nathan Woodrow'
|
|
__date__ = 'May 2014'
|
|
__copyright__ = '(C) 2014, Nathan Woodrow'
|
|
|
|
from qgis.PyQt.QtCore import NULL
|
|
from qgis._core import *
|
|
|
|
@MONKEYPATCH_INJECTIONS@
|
|
|
|
from .additions.edit import edit, QgsEditError
|
|
from .additions.fromfunction import fromFunction
|
|
from .additions.metaenum import metaEnumFromType, metaEnumFromValue
|
|
from .additions.processing import processing_output_layer_repr, processing_source_repr
|
|
from .additions.projectdirtyblocker import ProjectDirtyBlocker
|
|
from .additions.providermetadata import PyProviderMetadata
|
|
from .additions.qgsfeature import mapping_feature
|
|
from .additions.qgsfunction import register_function, qgsfunction
|
|
from .additions.qgsgeometry import _geometryNonZero, mapping_geometry
|
|
from .additions.qgssettings import _qgssettings_enum_value, _qgssettings_set_enum_value, _qgssettings_flag_value
|
|
from .additions.qgssettingsentry import PyQgsSettingsEntryEnumFlag
|
|
from .additions.qgstaskwrapper import QgsTaskWrapper
|
|
from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory
|
|
from .additions.runtimeprofiler import ScopedRuntimeProfileContextManager
|
|
from .additions.validitycheck import check
|
|
from .additions.ranges import datetime_range_repr, date_range_repr
|
|
|
|
# Injections into classes
|
|
QgsFeature.__geo_interface__ = property(mapping_feature)
|
|
QgsGeometry.__bool__ = _geometryNonZero
|
|
QgsGeometry.__geo_interface__ = property(mapping_geometry)
|
|
QgsGeometry.__nonzero__ = _geometryNonZero
|
|
QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr
|
|
QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr
|
|
QgsProject.blockDirtying = ProjectDirtyBlocker
|
|
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory
|
|
QgsRuntimeProfiler.profile = ScopedRuntimeProfileContextManager
|
|
QgsSettings.enumValue = _qgssettings_enum_value
|
|
QgsSettings.setEnumValue = _qgssettings_set_enum_value
|
|
QgsSettings.flagValue = _qgssettings_flag_value
|
|
QgsTask.fromFunction = fromFunction
|
|
QgsDateTimeRange.__repr__ = datetime_range_repr
|
|
QgsDateRange.__repr__ = date_range_repr
|
|
|
|
# Classes patched
|
|
QgsSettingsEntryEnumFlag = PyQgsSettingsEntryEnumFlag
|
|
|
|
# Classes patched using a derived class
|
|
QgsProviderMetadata = PyProviderMetadata
|
|
|
|
# monkey patch deprecated enum values to maintain API
|
|
# TODO - remove for QGIS 4.0
|
|
QgsMarkerLineSymbolLayer.Interval = Qgis.MarkerLinePlacement.Interval
|
|
QgsMarkerLineSymbolLayer.Vertex = Qgis.MarkerLinePlacement.Vertex
|
|
QgsMarkerLineSymbolLayer.LastVertex = Qgis.MarkerLinePlacement.LastVertex
|
|
QgsMarkerLineSymbolLayer.FirstVertex = Qgis.MarkerLinePlacement.FirstVertex
|
|
QgsMarkerLineSymbolLayer.CentralPoint = Qgis.MarkerLinePlacement.CentralPoint
|
|
QgsMarkerLineSymbolLayer.CurvePoint = Qgis.MarkerLinePlacement.CurvePoint
|
|
|
|
QgsRasterFillSymbolLayer.FillCoordinateMode = Qgis.SymbolCoordinateReference
|
|
QgsRasterFillSymbolLayer.Feature = Qgis.SymbolCoordinateReference.Feature
|
|
QgsRasterFillSymbolLayer.Viewport = Qgis.SymbolCoordinateReference.Viewport
|
|
|
|
QgsShapeburstFillSymbolLayer.ShapeburstColorType = Qgis.GradientColorSource
|
|
QgsShapeburstFillSymbolLayer.SimpleTwoColor = Qgis.GradientColorSource.SimpleTwoColor
|
|
QgsShapeburstFillSymbolLayer.ColorRamp = Qgis.GradientColorSource.ColorRamp
|
|
|
|
QgsVectorLayer.VertexMarkerType = Qgis.VertexMarkerType
|
|
QgsVectorLayer.SemiTransparentCircle = Qgis.VertexMarkerType.SemiTransparentCircle
|
|
QgsVectorLayer.SemiTransparentCircle.is_monkey_patched = True
|
|
QgsVectorLayer.SemiTransparentCircle.__doc__ = "Semi-transparent circle marker"
|
|
QgsVectorLayer.Cross = Qgis.VertexMarkerType.Cross
|
|
QgsVectorLayer.Cross.is_monkey_patched = True
|
|
QgsVectorLayer.Cross.__doc__ = "Cross marker"
|
|
QgsVectorLayer.NoMarker = Qgis.VertexMarkerType.NoMarker
|
|
QgsVectorLayer.NoMarker.is_monkey_patched = True
|
|
QgsVectorLayer.NoMarker.__doc__ = "No marker"
|
|
|
|
# Monkey patch static const "QgsDataProvider.SUBLAYER_SEPARATOR" which was removed for QGIS 3.12
|
|
QgsDataProvider.SUBLAYER_SEPARATOR = QgsDataProvider.sublayerSeparator()
|
|
|
|
# Monkey patch Qgis vars
|
|
Qgis.QGIS_VERSION = Qgis.version()
|
|
Qgis.QGIS_VERSION_INT = Qgis.versionInt()
|
|
Qgis.QGIS_RELEASE_NAME = Qgis.releaseName()
|
|
|
|
# Monkey patch QgsMapLayerType
|
|
|
|
QgsMapLayerType = Qgis.LayerType
|
|
QgsMapLayerType.VectorLayer = Qgis.LayerType.Vector
|
|
QgsMapLayerType.VectorLayer.is_monkey_patched = True
|
|
QgsMapLayerType.VectorLayer.__doc__ = "Vector layer"
|
|
QgsMapLayerType.RasterLayer = Qgis.LayerType.Raster
|
|
QgsMapLayerType.RasterLayer.is_monkey_patched = True
|
|
QgsMapLayerType.RasterLayer.__doc__ = "Raster layer"
|
|
QgsMapLayerType.PluginLayer = Qgis.LayerType.Plugin
|
|
QgsMapLayerType.PluginLayer.is_monkey_patched = True
|
|
QgsMapLayerType.PluginLayer.__doc__ = "Plugin based layer"
|
|
QgsMapLayerType.MeshLayer = Qgis.LayerType.Mesh
|
|
QgsMapLayerType.MeshLayer.is_monkey_patched = True
|
|
QgsMapLayerType.MeshLayer.__doc__ = "Mesh layer. Added in QGIS 3.2"
|
|
QgsMapLayerType.VectorTileLayer = Qgis.LayerType.VectorTile
|
|
QgsMapLayerType.VectorTileLayer.is_monkey_patched = True
|
|
QgsMapLayerType.VectorTileLayer.__doc__ = "Vector tile layer. Added in QGIS 3.14"
|
|
QgsMapLayerType.AnnotationLayer = Qgis.LayerType.Annotation
|
|
QgsMapLayerType.AnnotationLayer.is_monkey_patched = True
|
|
QgsMapLayerType.AnnotationLayer.__doc__ = "Contains freeform, georeferenced annotations. Added in QGIS 3.16"
|
|
QgsMapLayerType.PointCloudLayer = Qgis.LayerType.PointCloud
|
|
QgsMapLayerType.PointCloudLayer.is_monkey_patched = True
|
|
QgsMapLayerType.PointCloudLayer.__doc__ = "Point cloud layer. Added in QGIS 3.18"
|
|
QgsMapLayerType.GroupLayer = Qgis.LayerType.Group
|
|
QgsMapLayerType.GroupLayer.is_monkey_patched = True
|
|
QgsMapLayerType.GroupLayer.__doc__ = "Composite group layer. Added in QGIS 3.24"
|
|
QgsMapLayerType.baseClass = Qgis
|
|
|
|
# Monkey patch unused CRS WKT aliases
|
|
QgsCoordinateReferenceSystem.WKT2_2018 = Qgis.CrsWktVariant.Wkt2_2019
|
|
Qgis.CrsWktVariant.WKT2_2018 = Qgis.CrsWktVariant.Wkt2_2019
|
|
QgsCoordinateReferenceSystem.WKT2_2018.is_monkey_patched = True
|
|
QgsCoordinateReferenceSystem.WKT2_2018.__doc__ = "Alias for WKT2_2019"
|
|
QgsCoordinateReferenceSystem.WKT2_2018_SIMPLIFIED = Qgis.CrsWktVariant.Wkt2_2019Simplified
|
|
Qgis.CrsWktVariant.WKT2_2018_SIMPLIFIED = Qgis.CrsWktVariant.Wkt2_2019Simplified
|
|
QgsCoordinateReferenceSystem.WKT2_2018_SIMPLIFIED.is_monkey_patched = True
|
|
QgsCoordinateReferenceSystem.WKT2_2018_SIMPLIFIED.__doc__ = "Alias for WKT2_2019_SIMPLIFIED"
|
|
|
|
# Monkey patch QgsDxfExport
|
|
QgsDxfExport.SymbologyExport = Qgis.FeatureSymbologyExport
|
|
QgsDxfExport.SymbologyExport.FeatureSymbology = Qgis.FeatureSymbologyExport.PerFeature
|
|
QgsDxfExport.SymbologyExport.SymbolLayerSymbology = Qgis.FeatureSymbologyExport.PerSymbolLayer
|
|
QgsDxfExport.NoSymbology = Qgis.FeatureSymbologyExport.NoSymbology
|
|
QgsDxfExport.FeatureSymbology = Qgis.FeatureSymbologyExport.PerFeature
|
|
QgsDxfExport.SymbolLayerSymbology = Qgis.FeatureSymbologyExport.PerSymbolLayer
|
|
|
|
# Maintain class name API
|
|
QgsBox3d = QgsBox3D
|
|
QgsMesh3dAveragingMethod = QgsMesh3DAveragingMethod
|
|
QgsMesh3dDataBlock = QgsMesh3DDataBlock
|
|
|
|
GEOWKT = geoWkt()
|
|
PROJECT_SCALES = Qgis.defaultProjectScales()
|
|
GEOPROJ4 = geoProj4()
|
|
GEO_EPSG_CRS_AUTHID = geoEpsgCrsAuthId()
|
|
GEO_NONE = geoNone()
|
|
|
|
# TODO QGIS 4.0 - remove, require use of explicit getter/setter
|
|
|
|
QgsAbstractMetadataBaseValidator.ValidationResult.identifier = property(QgsAbstractMetadataBaseValidator.ValidationResult._identifier)
|
|
QgsAbstractMetadataBaseValidator.ValidationResult.identifier = QgsAbstractMetadataBaseValidator.ValidationResult.identifier.setter(QgsAbstractMetadataBaseValidator.ValidationResult.setIdentifier)
|
|
|
|
|
|
# TODO QGIS 4.0 - remove, replaced by Qgis.LinePlacementFlags
|
|
class LinePlacementFlags:
|
|
OnLine = 1
|
|
AboveLine = 2
|
|
BelowLine = 4
|
|
MapOrientation = 8
|
|
|
|
QgsPalLayerSettings.LinePlacementFlags = LinePlacementFlags
|
|
QgsPalLayerSettings.OnLine = QgsPalLayerSettings.LinePlacementFlags.OnLine
|
|
QgsPalLayerSettings.AboveLine = QgsPalLayerSettings.LinePlacementFlags.AboveLine
|
|
QgsPalLayerSettings.BelowLine = QgsPalLayerSettings.LinePlacementFlags.BelowLine
|
|
QgsPalLayerSettings.MapOrientation = QgsPalLayerSettings.LinePlacementFlags.MapOrientation
|
|
|
|
|
|
def get_placement_flags(self):
|
|
return self.lineSettings().placementFlags()
|
|
|
|
|
|
def set_placement_flags(self, flags):
|
|
self.lineSettings().setPlacementFlags(Qgis.LabelLinePlacementFlags(flags))
|
|
|
|
|
|
QgsPalLayerSettings.placementFlags = property(get_placement_flags)
|
|
QgsPalLayerSettings.placementFlags = QgsPalLayerSettings.placementFlags.setter(set_placement_flags)
|
|
|
|
|
|
def get_merge_lines(self):
|
|
return self.lineSettings().mergeLines()
|
|
|
|
|
|
def set_merge_lines(self, merge):
|
|
self.lineSettings().setMergeLines(merge)
|
|
|
|
|
|
QgsPalLayerSettings.mergeLines = property(get_merge_lines)
|
|
QgsPalLayerSettings.mergeLines = QgsPalLayerSettings.mergeLines.setter(set_merge_lines)
|
|
|
|
|
|
def get_add_direction_symbol(self):
|
|
return self.lineSettings().addDirectionSymbol()
|
|
|
|
|
|
def set_add_direction_symbol(self, add):
|
|
self.lineSettings().setAddDirectionSymbol(add)
|
|
|
|
|
|
QgsPalLayerSettings.addDirectionSymbol = property(get_add_direction_symbol)
|
|
QgsPalLayerSettings.addDirectionSymbol = QgsPalLayerSettings.addDirectionSymbol.setter(set_add_direction_symbol)
|
|
|
|
|
|
def get_left_direction_symbol(self):
|
|
return self.lineSettings().leftDirectionSymbol()
|
|
|
|
|
|
def set_left_direction_symbol(self, symbol):
|
|
self.lineSettings().setLeftDirectionSymbol(symbol)
|
|
|
|
|
|
QgsPalLayerSettings.leftDirectionSymbol = property(get_left_direction_symbol)
|
|
QgsPalLayerSettings.leftDirectionSymbol = QgsPalLayerSettings.leftDirectionSymbol.setter(set_left_direction_symbol)
|
|
|
|
|
|
def get_right_direction_symbol(self):
|
|
return self.lineSettings().rightDirectionSymbol()
|
|
|
|
|
|
def set_right_direction_symbol(self, symbol):
|
|
self.lineSettings().setRightDirectionSymbol(symbol)
|
|
|
|
|
|
QgsPalLayerSettings.rightDirectionSymbol = property(get_right_direction_symbol)
|
|
QgsPalLayerSettings.rightDirectionSymbol = QgsPalLayerSettings.rightDirectionSymbol.setter(set_right_direction_symbol)
|
|
|
|
|
|
def get_reverse_direction_symbol(self):
|
|
return self.lineSettings().reverseDirectionSymbol()
|
|
|
|
|
|
def set_reverse_direction_symbol(self, reverse):
|
|
self.lineSettings().setReverseDirectionSymbol(reverse)
|
|
|
|
|
|
QgsPalLayerSettings.reverseDirectionSymbol = property(get_reverse_direction_symbol)
|
|
QgsPalLayerSettings.reverseDirectionSymbol = QgsPalLayerSettings.reverseDirectionSymbol.setter(set_reverse_direction_symbol)
|
|
|
|
|
|
# TODO QGIS 4.0 - remove, replaced by QgsLabelLineSettings.DirectionSymbolPlacement
|
|
class DirectionSymbols:
|
|
SymbolLeftRight = 0
|
|
SymbolAbove = 1
|
|
SymbolBelow = 2
|
|
|
|
QgsPalLayerSettings.DirectionSymbols = DirectionSymbols
|
|
QgsPalLayerSettings.SymbolLeftRight = QgsPalLayerSettings.DirectionSymbols.SymbolLeftRight
|
|
QgsPalLayerSettings.SymbolAbove = QgsPalLayerSettings.DirectionSymbols.SymbolAbove
|
|
QgsPalLayerSettings.SymbolBelow = QgsPalLayerSettings.DirectionSymbols.SymbolBelow
|
|
|
|
|
|
def get_direction_symbol_placement(self):
|
|
return self.lineSettings().directionSymbolPlacement()
|
|
|
|
|
|
def set_direction_symbol_placement(self, flags):
|
|
self.lineSettings().setDirectionSymbolPlacement(QgsLabelLineSettings.DirectionSymbolPlacement(flags))
|
|
|
|
|
|
QgsPalLayerSettings.placeDirectionSymbol = property(get_direction_symbol_placement)
|
|
QgsPalLayerSettings.placeDirectionSymbol = QgsPalLayerSettings.placeDirectionSymbol.setter(set_direction_symbol_placement)
|
|
|
|
|
|
def get_overrun_distance(self):
|
|
return self.lineSettings().overrunDistance()
|
|
|
|
|
|
def set_overrun_distance(self, distance):
|
|
self.lineSettings().setOverrunDistance(distance)
|
|
|
|
|
|
QgsPalLayerSettings.overrunDistance = property(get_overrun_distance)
|
|
QgsPalLayerSettings.overrunDistance = QgsPalLayerSettings.overrunDistance.setter(set_overrun_distance)
|
|
|
|
|
|
def get_overrun_distance_unit(self):
|
|
return self.lineSettings().overrunDistanceUnit()
|
|
|
|
|
|
def set_overrun_distance_unit(self, unit):
|
|
self.lineSettings().setOverrunDistanceUnit(unit)
|
|
|
|
|
|
QgsPalLayerSettings.overrunDistanceUnit = property(get_overrun_distance_unit)
|
|
QgsPalLayerSettings.overrunDistanceUnit = QgsPalLayerSettings.overrunDistanceUnit.setter(set_overrun_distance_unit)
|
|
|
|
|
|
def get_overrun_distance_scale(self):
|
|
return self.lineSettings().overrunDistanceMapUnitScale()
|
|
|
|
|
|
def set_overrun_distance_scale(self, scale):
|
|
self.lineSettings().setOverrunDistanceMapUnitScale(scale)
|
|
|
|
|
|
QgsPalLayerSettings.overrunDistanceMapUnitScale = property(get_overrun_distance_scale)
|
|
QgsPalLayerSettings.overrunDistanceMapUnitScale = QgsPalLayerSettings.overrunDistanceMapUnitScale.setter(set_overrun_distance_scale)
|
|
|
|
|
|
def get_limit_num_labels(self):
|
|
return self.thinningSettings().limitNumberOfLabelsEnabled()
|
|
|
|
|
|
def set_limit_num_labels(self, limit):
|
|
self.thinningSettings().setLimitNumberLabelsEnabled(limit)
|
|
|
|
|
|
QgsPalLayerSettings.limitNumLabels = property(get_limit_num_labels)
|
|
QgsPalLayerSettings.limitNumLabels = QgsPalLayerSettings.limitNumLabels.setter(set_limit_num_labels)
|
|
|
|
|
|
|
|
def get_max_num_labels(self):
|
|
return self.thinningSettings().maximumNumberLabels()
|
|
|
|
|
|
def set_max_num_labels(self, limit):
|
|
self.thinningSettings().setMaximumNumberLabels(limit)
|
|
|
|
|
|
QgsPalLayerSettings.maxNumLabels = property(get_max_num_labels)
|
|
QgsPalLayerSettings.maxNumLabels = QgsPalLayerSettings.maxNumLabels.setter(set_max_num_labels)
|
|
|
|
|
|
|
|
def get_min_feature_size(self):
|
|
return self.thinningSettings().minimumFeatureSize()
|
|
|
|
|
|
def set_min_feature_size(self, limit):
|
|
self.thinningSettings().setMinimumFeatureSize(limit)
|
|
|
|
|
|
QgsPalLayerSettings.minFeatureSize = property(get_min_feature_size)
|
|
QgsPalLayerSettings.minFeatureSize = QgsPalLayerSettings.minFeatureSize.setter(set_min_feature_size)
|
|
|
|
|
|
|
|
def get_is_obstacle(self):
|
|
return self.obstacleSettings().isObstacle()
|
|
|
|
|
|
def set_is_obstacle(self, enabled):
|
|
self.obstacleSettings().setIsObstacle(enabled)
|
|
|
|
|
|
QgsPalLayerSettings.obstacle = property(get_is_obstacle)
|
|
QgsPalLayerSettings.obstacle = QgsPalLayerSettings.obstacle.setter(set_is_obstacle)
|
|
|
|
|
|
def get_obstacle_factor(self):
|
|
return self.obstacleSettings().factor()
|
|
|
|
|
|
def set_obstacle_factor(self, factor):
|
|
self.obstacleSettings().setFactor(factor)
|
|
|
|
|
|
QgsPalLayerSettings.obstacleFactor = property(get_obstacle_factor)
|
|
QgsPalLayerSettings.obstacleFactor = QgsPalLayerSettings.obstacleFactor.setter(set_obstacle_factor)
|
|
|
|
|
|
|
|
# TODO QGIS 4.0 - remove, replaced by QgsLabelObstacleSettings.ObstacleType
|
|
|
|
QgsPalLayerSettings.ObstacleType = QgsLabelObstacleSettings.ObstacleType
|
|
QgsPalLayerSettings.PolygonInterior = QgsLabelObstacleSettings.ObstacleType.PolygonInterior
|
|
QgsPalLayerSettings.PolygonBoundary = QgsLabelObstacleSettings.ObstacleType.PolygonBoundary
|
|
QgsPalLayerSettings.PolygonWhole = QgsLabelObstacleSettings.ObstacleType.PolygonWhole
|
|
|
|
|
|
def get_obstacle_type(self):
|
|
return self.obstacleSettings().type()
|
|
|
|
|
|
def set_obstacle_type(self, _type):
|
|
self.obstacleSettings().setType(QgsLabelObstacleSettings.ObstacleType(_type))
|
|
|
|
|
|
QgsPalLayerSettings.obstacleType = property(get_obstacle_type)
|
|
QgsPalLayerSettings.obstacleType = QgsPalLayerSettings.obstacleType.setter(set_obstacle_type)
|
|
|
|
|
|
def get_display_all(self):
|
|
return self.placementSettings().overlapHandling() == Qgis.LabelOverlapHandling.AllowOverlapIfRequired
|
|
|
|
|
|
def set_display_all(self, enabled):
|
|
self.placementSettings().setOverlapHandling(Qgis.LabelOverlapHandling.AllowOverlapIfRequired if enabled else Qgis.LabelOverlapHandling.PreventOverlap)
|
|
self.placementSettings().setAllowDegradedPlacement(enabled)
|
|
|
|
|
|
QgsPalLayerSettings.displayAll = property(get_display_all)
|
|
QgsPalLayerSettings.displayAll = QgsPalLayerSettings.displayAll.setter(set_display_all)
|