Commit c332cf1c authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files
parent ddbc7e80
Pipeline #12563 failed
......@@ -21,11 +21,30 @@
***************************************************************************/
"""
import enum, math
import enum
import math
from qgis import *
from qgis.core import *
from qgis.gui import *
from qgis.core import QgsField, QgsVectorLayer, QgsRasterLayer, QgsRasterDataProvider, QgsMapLayer, QgsMapLayerStore, \
QgsVectorDataProvider, QgsApplication, Qgis, \
QgsLineString, QgsMultiPoint, QgsCurvePolygon, QgsRectangle, QgsPolygon, \
QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsRectangle, QgsPointXY, QgsProject, \
QgsMapLayerProxyModel, QgsRasterRenderer, QgsMessageOutput, QgsFeature, QgsTask, Qgis, QgsGeometry, \
QgsSettings, QgsPoint, QgsFeatureRequest, \
QgsWkbTypes, QgsCsException, QgsDistanceArea, QgsAction, \
QgsExpressionContextUtils, QgsRenderContext, QgsFeatureIterator, QgsVectorLayerTools, \
QgsEditFormConfig, QgsVectorLayerUtils, QgsExpressionContextScope, QgsPointLocator
from qgis.gui import QgisInterface, QgsDialog, QgsMessageViewer, QgsMapLayerComboBox, QgsAttributeEditorContext, \
QgsMapTool, QgsMapToolZoom, QgsMapToolPan, QgsMapToolCapture, QgsMapToolIdentify, QgsMapToolEmitPoint, \
QgsAttributeDialog, QgsIdentifyMenu, QgsSnapIndicator, QgsMapCanvas, QgsRubberBand, QgsMapMouseEvent, \
QgsAttributeForm, \
QgsUserInputWidget, QgsFloatingWidget, QgsAdvancedDigitizingDockWidget, \
QgsDoubleSpinBox, \
QgsVertexMarker, QgsHighlight
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtXml import *
from qgis.PyQt.QtGui import *
......@@ -35,6 +54,7 @@ import numpy as np
from .utils import *
from .vectorlayertools import VectorLayerTools
def tr(t: str) -> str:
return t
......@@ -72,11 +92,12 @@ def createQgsMapCanvasUserInputWidget(canvas: QgsMapCanvas) -> QgsUserInputWidge
mUserInputWidget.setAnchorPoint(QgsFloatingWidget.TopRight)
return mUserInputWidget
class MapTools(enum.Enum):
"""
Static class to support the creation of QgsMapTools.
"""
#def __init__(self):
# def __init__(self):
# raise Exception('This class is not for any instantiation')
ZoomIn = 'ZOOM_IN'
ZoomOut = 'ZOOM_OUT'
......@@ -182,11 +203,12 @@ class MapTools(enum.Enum):
def mapToolEnums() -> list:
return list(MapTools.__members__.values())
class CursorLocationMapTool(QgsMapToolEmitPoint):
"""
A QgsMapTool to collect SpatialPoints
"""
sigLocationRequest = pyqtSignal([SpatialPoint], [SpatialPoint, QgsMapCanvas])
sigLocationRequest = pyqtSignal(QgsCoordinateReferenceSystem, QgsPointXY)
def __init__(self, canvas: QgsMapCanvas, showCrosshair: bool = True):
"""
......@@ -249,7 +271,7 @@ class CursorLocationMapTool(QgsMapToolEmitPoint):
pixelPoint = e.pixelPoint()
crs = self.canvas().mapSettings().destinationCrs()
self.marker.hide()
geoPoint = self.toMapCoordinates(pixelPoint)
geoPoint: QgsPointXY = self.toMapCoordinates(pixelPoint)
if self.mShowCrosshair:
# show a temporary crosshair
ext = SpatialExtent.fromMapCanvas(self.canvas())
......@@ -268,9 +290,7 @@ class CursorLocationMapTool(QgsMapToolEmitPoint):
# remove crosshair after a short while
QTimer.singleShot(self.mCrosshairTime, self.hideRubberband)
pt = SpatialPoint(crs, geoPoint)
self.sigLocationRequest[SpatialPoint].emit(pt)
self.sigLocationRequest[SpatialPoint, QgsMapCanvas].emit(pt, self.canvas())
self.sigLocationRequest[QgsCoordinateReferenceSystem, QgsPointXY].emit(crs, geoPoint)
def hideRubberband(self):
"""
......@@ -354,6 +374,7 @@ class FullExtentMapTool(QgsMapTool):
"""
A QgsMapTool to scale a QgsMapCanvas to the full extent of all available QgsMapLayers.
"""
def __init__(self, canvas):
super(FullExtentMapTool, self).__init__(canvas)
self.mCursor = createCursor(':/qps/ui/icons/cursor_zoom_fullextent.svg')
......@@ -366,6 +387,7 @@ class FullExtentMapTool(QgsMapTool):
def flags(self):
return QgsMapTool.Transient
class PointLayersMapTool(CursorLocationMapTool):
def __init__(self, canvas):
......@@ -374,11 +396,12 @@ class PointLayersMapTool(CursorLocationMapTool):
self.identifyMode = QgsMapToolIdentify.LayerSelection
QgsMapToolIdentify.__init__(self, canvas)
class SpatialExtentMapTool(QgsMapToolEmitPoint):
"""
A QgsMapTool to select a SpatialExtent
"""
sigSpatialExtentSelected = pyqtSignal(SpatialExtent)
sigSpatialExtentSelected = pyqtSignal(QgsCoordinateReferenceSystem, QgsRectangle)
def __init__(self, canvas: QgsMapCanvas):
super(SpatialExtentMapTool, self).__init__(canvas)
......@@ -419,8 +442,7 @@ class SpatialExtentMapTool(QgsMapToolEmitPoint):
self.reset()
if crs is not None and rect is not None:
extent = SpatialExtent(crs, rect)
self.sigSpatialExtentSelected.emit(extent)
self.sigSpatialExtentSelected[QgsCoordinateReferenceSystem, QgsRectangle].emit(crs, rect)
def canvasMoveEvent(self, e):
if not self.isEmittingPoint:
......@@ -454,7 +476,7 @@ class SpatialExtentMapTool(QgsMapToolEmitPoint):
class RectangleMapTool(QgsMapToolEmitPoint):
rectangleDrawed = pyqtSignal(QgsRectangle, object)
rectangleDrawed = pyqtSignal(QgsRectangle, str)
def __init__(self, canvas):
......@@ -1030,7 +1052,7 @@ class QgsMapToolDigitizeFeature(QgsMapToolCapture):
self.messageEmitted.emit(tr(
"The feature cannot be added because it's geometry collapsed due to intersection avoidance"),
Qgis.Critical)
Qgis.Critical)
self.stopCapturing()
return
......@@ -1741,6 +1763,3 @@ class QgsMapToolSelect(QgsMapTool):
else:
QgsMapToolSelectUtils.selectMultipleFeatures(self.canvas(), self.mSelectionHandler.selectedGeometry(),
modifiers)
......@@ -86,7 +86,7 @@ def initQgisApplication(*args, qgisResourceDir: str = None,
:return: QgsApplication instance of local QGIS installation
"""
warnings.warn('Use qps.testing.start_app instead', DeprecationWarning)
return start_app(cleanup=True, options=StartOptions.All())
return start_app(cleanup=True, options=StartOptions.All)
@enum.unique
......@@ -816,8 +816,6 @@ class TestObjects():
@staticmethod
def processingAlgorithm():
from qgis.core import QgsProcessingAlgorithm
class TestProcessingAlgorithm(QgsProcessingAlgorithm):
def __init__(self):
......
......@@ -46,7 +46,7 @@ import datetime
from qgis.core import *
from qgis.core import QgsField, QgsVectorLayer, QgsRasterLayer, QgsRasterDataProvider, QgsMapLayer, QgsMapLayerStore, \
QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsRectangle, QgsPointXY, QgsProject, \
QgsMapLayerProxyModel, QgsRasterRenderer, QgsMessageOutput, QgsFeature, QgsTask, Qgis
QgsMapLayerProxyModel, QgsRasterRenderer, QgsMessageOutput, QgsFeature, QgsTask, Qgis, QgsGeometry
from qgis.gui import *
from qgis.gui import QgisInterface, QgsDialog, QgsMessageViewer, QgsMapLayerComboBox, QgsMapCanvas
......@@ -873,10 +873,14 @@ def qgsVectorLayer(source) -> QgsVectorLayer:
"""
if isinstance(source, QgsVectorLayer):
return source
if isinstance(source, pathlib.Path):
return QgsRasterLayer(source.as_posix())
if isinstance(source, str):
return QgsVectorLayer(source)
if isinstance(source, ogr.DataSource):
return QgsVectorLayer(source.GetDescription())
if isinstance(source, QUrl):
return qgsVectorLayer(pathlib.Path(source.toString(QUrl.PreferLocalFile | QUrl.RemoveQuery)).resolve())
raise Exception('Unable to transform {} into QgsVectorLayer'.format(source))
......@@ -890,14 +894,42 @@ def qgsRasterLayer(source) -> QgsRasterLayer:
"""
if isinstance(source, QgsRasterLayer):
return source
if isinstance(source, pathlib.Path):
return QgsRasterLayer(source.as_posix())
if isinstance(source, str):
return QgsRasterLayer(source)
if isinstance(source, gdal.Dataset):
return QgsRasterLayer(source.GetDescription())
if isinstance(source, QUrl):
return qgsRasterLayer(pathlib.Path(source.toString(QUrl.PreferLocalFile | QUrl.RemoveQuery)).resolve())
raise Exception('Unable to transform {} into QgsRasterLayer'.format(source))
def qgsMapLayer(value: typing.Any) -> QgsMapLayer:
"""
Tries to convert the input into a QgsMapLayer
:param value: any
:return: QgsMapLayer or None
"""
if isinstance(value, QgsMapLayer):
return value
try:
lyr = qgsRasterLayer(value)
if isinstance(lyr, QgsRasterLayer):
return lyr
except:
pass
try:
lyr = qgsVectorLayer(value)
if isinstance(lyr, QgsVectorLayer):
return lyr
except:
pass
return None
def loadUi(uifile, baseinstance=None, package='', resource_suffix='_rc', remove_resource_references=True,
loadUiType=False):
"""
......@@ -2026,7 +2058,7 @@ class SpatialExtent(QgsRectangle):
return SpatialExtent(crs, rectangle)
@staticmethod
def fromMapCanvas(mapCanvas, fullExtent=False):
def fromMapCanvas(mapCanvas, fullExtent:bool=False):
assert isinstance(mapCanvas, QgsMapCanvas)
if fullExtent:
......@@ -2214,11 +2246,27 @@ class SpatialExtent(QgsRectangle):
def __copy__(self):
return SpatialExtent(self.crs(), QgsRectangle(self))
def __reduce_ex__(self, protocol):
return self.__class__, (self.crs().toWkt(),
self.xMinimum(), self.yMinimum(),
self.xMaximum(), self.yMaximum()
), {}
def __reduce__(self):
return self.__class__, ('',), self.__getstate__()
def __getstate__(self):
state = self.__dict__.copy()
state.pop('mCrs')
state['_crs_'] = self.crs().toWkt()
state['_xmin_'] = self.xMinimum()
state['_xmax_'] = self.xMaximum()
state['_ymin_'] = self.yMinimum()
state['_ymax_'] = self.yMaximum()
return state
def __setstate__(self, state):
self.setCrs(QgsCoordinateReferenceSystem(state.pop('_crs_')))
self.setXMinimum(state.pop('_xmin_'))
self.setXMaximum(state.pop('_xmax_'))
self.setYMinimum(state.pop('_ymin_'))
self.setYMaximum(state.pop('_ymax_'))
self.__dict__.update(state)
def __hash__(self):
return hash(str(self))
......
......@@ -28,6 +28,7 @@ import re
import shutil
import typing
import site
site.addsitedir(pathlib.Path(__file__).parents[1])
import docutils.core
from xml.dom import minidom
......@@ -39,7 +40,6 @@ from eotimeseriesviewer.externals.qps.make.deploy import QGISMetadataFileWriter
print('DIR_REPO={}'.format(DIR_REPO))
CHECK_COMMITS = False
########## Config Section
MD = QGISMetadataFileWriter()
......@@ -56,6 +56,7 @@ MD.mRepository = eotimeseriesviewer.REPOSITORY
MD.mQgisMinimumVersion = '3.14'
MD.mEmail = eotimeseriesviewer.MAIL
########## End of config section
def aboutText() -> str:
......@@ -66,8 +67,10 @@ def aboutText() -> str:
aboutText = ''.join(aboutText)
return aboutText
MD.mAbout = aboutText()
def scantree(path, pattern=re.compile(r'.$')) -> typing.Iterator[pathlib.Path]:
"""
Recursively returns file paths in directory
......@@ -86,7 +89,6 @@ def create_plugin(include_testdata: bool = False,
include_qgisresources: bool = False,
zipfilename: str = None,
latest: bool = False) -> str:
assert (DIR_REPO / '.git').is_dir()
DIR_DEPLOY = DIR_REPO / 'deploy'
......@@ -256,7 +258,7 @@ def createHTMLDocuments(dirPlugin: pathlib.Path):
pathMD = DIR_REPO / 'CHANGELOG.rst'
pathHTML = dirPlugin / 'CHANGELOG'
#pathCL2 = DIR_REPO / 'CHANGELOG'
# pathCL2 = DIR_REPO / 'CHANGELOG'
os.makedirs(pathHTML.parent, exist_ok=True)
# make html compact
......@@ -299,4 +301,3 @@ if __name__ == "__main__":
latest=args.latest)
print('EOTSV_ZIP={}'.format(path))
exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment