Commit 5d64c12e authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

refactored package imports

parent 03b2e0b3
......@@ -19,7 +19,10 @@
***************************************************************************/
"""
# noinspection PyPep8Naming
import os
import pathlib
from qgis.core import QgsApplication, Qgis
from qgis.PyQt.QtGui import QIcon
__version__ = '1.13' # sub-subversion number is added automatically
LICENSE = 'GNU GPL-3'
......@@ -37,16 +40,6 @@ CREATE_ISSUE = 'https://bitbucket.org/jakimowb/eo-time-series-viewer/issues/new'
DEPENDENCIES = ['numpy', 'gdal']
URL_TESTDATA = r''
import os
import sys
import fnmatch
import site
import re
import pathlib
from qgis.core import QgsApplication, Qgis
from qgis.PyQt.QtGui import QIcon
DEBUG: bool = bool(os.environ.get('EOTSV_DEBUG', False))
DIR = pathlib.Path(__file__).parent
......
import os, re, logging, datetime
from osgeo import gdal
import datetime
import re
import os
import numpy as np
from qgis import *
from qgis.PyQt.QtCore import QDate
from osgeo import gdal
from qgis.core import QgsMapLayer, QgsRasterLayer
from qgis.PyQt.QtCore import QDate
# regular expression. compile them only once
# thanks to user "funkwurm" in
# http://stackoverflow.com/questions/28020805/regex-validate-correct-iso8601-date-string-with-time
regISODate1 = re.compile(r'(?:[1-9]\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:Z|[+-][01]\d:[0-5]\d)')
regISODate3 = re.compile(r'([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?')
regISODate2 = re.compile(r'(19|20|21\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?')
#regISODate2 = re.compile(r'([12]\d{3}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?')
#https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
regYYYYMMDD = re.compile(r'(?P<year>(19|20)\d\d)(?P<hyphen>-?)(?P<month>1[0-2]|0[1-9])(?P=hyphen)(?P<day>3[01]|0[1-9]|[12][0-9])')
regISODate1 = re.compile(
r'(?:[1-9]\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:Z|[+-][01]\d:[0-5]\d)')
regISODate3 = re.compile(
r'([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?')
regISODate2 = re.compile(
r'(19|20|21\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?')
# regISODate2 = re.compile(r'([12]\d{3}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?')
# https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
regYYYYMMDD = re.compile(
r'(?P<year>(19|20)\d\d)(?P<hyphen>-?)(?P<month>1[0-2]|0[1-9])(?P=hyphen)(?P<day>3[01]|0[1-9]|[12][0-9])')
regYYYY = re.compile(r'(?P<year>(19|20)\d\d)')
regMissingHypen = re.compile(r'^\d{8}')
regYYYYMM = re.compile(r'([0-9]{4})-(1[0-2]|0[1-9])')
......@@ -24,6 +29,7 @@ regYYYYMM = re.compile(r'([0-9]{4})-(1[0-2]|0[1-9])')
regYYYYDOY = re.compile(r'(?P<year>(19|20)\d\d)-?(?P<day>36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9])')
regDecimalYear = re.compile(r'(?P<year>(19|20)\d\d)\.(?P<datefraction>\d\d\d)')
def matchOrNone(regex, text):
match = regex.search(text)
if match:
......@@ -31,7 +37,8 @@ def matchOrNone(regex, text):
else:
return None
def dateDOY(date:datetime.date) -> int:
def dateDOY(date: datetime.date) -> int:
"""
Returns the DOY
:param date:
......@@ -43,6 +50,7 @@ def dateDOY(date:datetime.date) -> int:
date = date.astype(datetime.date)
return date.timetuple().tm_yday
def daysPerYear(year) -> int:
"""Returns the days per year"""
if isinstance(year, np.datetime64):
......@@ -52,6 +60,7 @@ def daysPerYear(year) -> int:
return dateDOY(datetime.date(year=year, month=12, day=31))
def num2date(n, dt64=True, qDate=False):
"""
Converts a decimal-year number into a date
......@@ -69,12 +78,11 @@ def num2date(n, dt64=True, qDate=False):
yearDuration = daysPerYear(year)
yearElapsed = fraction * yearDuration
import math
doy = round(yearElapsed)
if doy < 1:
doy = 1
try:
date = datetime.date(year, 1, 1) + datetime.timedelta(days=doy-1)
date = datetime.date(year, 1, 1) + datetime.timedelta(days=doy - 1)
except:
s = ""
if qDate:
......@@ -85,7 +93,7 @@ def num2date(n, dt64=True, qDate=False):
return date
def extractDateTimeGroup(text:str) -> np.datetime64:
def extractDateTimeGroup(text: str) -> np.datetime64:
"""
Extracts a date-time-group from a text string
:param text: a string
......@@ -95,7 +103,7 @@ def extractDateTimeGroup(text:str) -> np.datetime64:
if match:
matchedText = match.group()
if regMissingHypen.search(matchedText):
matchedText = '{}-{}-{}'.format(matchedText[0:4],matchedText[4:6],matchedText[6:])
matchedText = '{}-{}-{}'.format(matchedText[0:4], matchedText[4:6], matchedText[6:])
return np.datetime64(matchedText)
match = regYYYYMMDD.search(text)
......@@ -122,29 +130,32 @@ def extractDateTimeGroup(text:str) -> np.datetime64:
return np.datetime64(match.group('year'))
return None
def datetime64FromYYYYMMDD(yyyymmdd):
if re.search(r'^\d{8}$', yyyymmdd):
#insert hyphens
yyyymmdd = '{}-{}-{}'.format(yyyymmdd[0:4],yyyymmdd[4:6],yyyymmdd[6:8])
# insert hyphens
yyyymmdd = '{}-{}-{}'.format(yyyymmdd[0:4], yyyymmdd[4:6], yyyymmdd[6:8])
return np.datetime64(yyyymmdd)
def datetime64FromYYYYDOY(yyyydoy):
return datetime64FromDOY(yyyydoy[0:4], yyyydoy[4:7])
def DOYfromDatetime64(dt):
doy = dt.astype('datetime64[D]') - dt.astype('datetime64[Y]') + 1
doy = doy.astype(np.int16)
return doy
return (dt.astype('datetime64[D]') - dt.astype('datetime64[Y]')).astype(int)+1
return (dt.astype('datetime64[D]') - dt.astype('datetime64[Y]')).astype(int) + 1
def datetime64FromDOY(year, doy):
if type(year) is str:
year = int(year)
if type(doy) is str:
doy = int(doy)
return np.datetime64('{:04d}-01-01'.format(year)) + np.timedelta64(doy-1, 'D')
def datetime64FromDOY(year, doy):
if type(year) is str:
year = int(year)
if type(doy) is str:
doy = int(doy)
return np.datetime64('{:04d}-01-01'.format(year)) + np.timedelta64(doy - 1, 'D')
class ImageDateReader(object):
......@@ -166,6 +177,7 @@ class ImageDateReader(object):
raise NotImplementedError()
return None
class ImageReaderOWS(ImageDateReader):
"""Date reader for OGC web services"""
......@@ -189,6 +201,7 @@ class ImageDateReaderDefault(ImageDateReader):
"""
Default reader for dates in gdal.Datasets
"""
def __init__(self, dataSet):
super(ImageDateReaderDefault, self).__init__(dataSet)
self.regDateKeys = re.compile('(acquisition[ _]*(time|date|datetime))', re.IGNORECASE)
......@@ -218,10 +231,12 @@ class ImageDateReaderDefault(ImageDateReader):
return dtg
return None
class ImageDateReaderPLEIADES(ImageDateReader):
"""
Date reader for PLEIADES images
"""
def __init__(self, dataSet):
super(ImageDateReaderPLEIADES, self).__init__(dataSet)
......@@ -254,20 +269,22 @@ class ImageDateReaderSentinel2(ImageDateReader):
return np.datetime64(timeStamp)
return None
class ImageDateParserLandsat(ImageDateReader):
"""
Reader for date in LANDSAT images
#see https://landsat.usgs.gov/what-are-naming-conventions-landsat-scene-identifiers
"""
regLandsatSceneID = re.compile(r'L[COTEM][4578]\d{3}\d{3}\d{4}\d{3}[A-Z]{2}[A-Z1]\d{2}')
regLandsatProductID = re.compile(r'L[COTEM]0[78]_(L1TP|L1GT|L1GS)_\d{3}\d{3}_\d{4}\d{2}\d{2}_\d{4}\d{2}\d{2}_0\d{1}_(RT|T1|T2)')
regLandsatSceneID = re.compile(r'L[COTEM][4578]\d{3}\d{3}\d{4}\d{3}[A-Z]{2}[A-Z1]\d{2}')
regLandsatProductID = re.compile(
r'L[COTEM]0[78]_(L1TP|L1GT|L1GS)_\d{3}\d{3}_\d{4}\d{2}\d{2}_\d{4}\d{2}\d{2}_0\d{1}_(RT|T1|T2)')
def __init__(self, dataSet):
super(ImageDateParserLandsat, self).__init__(dataSet)
def readDTG(self):
#search for LandsatSceneID (old) and Landsat Product IDs (new)
# search for LandsatSceneID (old) and Landsat Product IDs (new)
sceneID = matchOrNone(ImageDateParserLandsat.regLandsatSceneID, self.baseName)
if sceneID:
return datetime64FromYYYYDOY(sceneID[9:16])
......@@ -278,15 +295,14 @@ class ImageDateParserLandsat(ImageDateReader):
return None
dateParserList = [c for c in ImageDateReader.__subclasses__()]
dateParserList.insert(0, dateParserList.pop(dateParserList.index(ImageDateReaderDefault))) # set to first position
dateParserList.insert(0, dateParserList.pop(dateParserList.index(ImageDateReaderDefault))) # set to first position
def parseDateFromDataSet(dataSet:gdal.Dataset) -> np.datetime64:
def parseDateFromDataSet(dataSet: gdal.Dataset) -> np.datetime64:
assert isinstance(dataSet, gdal.Dataset)
for parser in dateParserList:
dtg = parser(dataSet).readDTG()
if dtg:
return dtg
return None
import enum
from qgis.core import *
from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsField, QgsFields, \
QgsEditorWidgetSetup, QgsFeature, QgsVectorLayerTools, \
QgsRendererCategory, QgsCategorizedSymbolRenderer, QgsProject, QgsMapLayerStore, QgsSymbol
from qgis.gui import *
from qgis.gui import QgsDockWidget, QgsSpinBox, QgsDoubleSpinBox, \
QgsEditorConfigWidget, QgsEditorWidgetFactory, QgsEditorWidgetWrapper, \
QgsGui, QgsEditorWidgetRegistry, QgsDateTimeEdit, QgsDateEdit, QgsTimeEdit
......
......@@ -43,7 +43,7 @@ from qgis.core import *
from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsMessageOutput, QgsCoordinateReferenceSystem, \
Qgis, QgsWkbTypes, QgsTask, QgsProviderRegistry, QgsMapLayerStore, QgsFeature, QgsField, \
QgsTextFormat, QgsProject, QgsSingleSymbolRenderer, QgsGeometry, QgsApplication, QgsFillSymbol, \
QgsProjectArchive, QgsZipUtils
QgsProjectArchive, QgsZipUtils, QgsPointXY
from qgis.gui import *
from qgis.gui import QgsMapCanvas, QgsStatusBar, QgsFileWidget, \
......@@ -410,8 +410,8 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
"""
return EOTimeSeriesViewer._instance
sigCurrentLocationChanged = pyqtSignal([SpatialPoint],
[SpatialPoint, QgsMapCanvas])
sigCurrentLocationChanged = pyqtSignal([QgsCoordinateReferenceSystem, QgsPointXY],
[QgsCoordinateReferenceSystem, QgsPointXY, QgsMapCanvas])
sigCurrentSpectralProfilesChanged = pyqtSignal(list)
sigCurrentTemporalProfilesChanged = pyqtSignal(list)
......@@ -456,15 +456,19 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
self.mTaskManagerButton.setFont(statusBarFont)
self.mStatusBar.addPermanentWidget(self.mTaskManagerButton, 10, QgsStatusBar.AnchorLeft)
self.mTaskManagerButton.clicked.connect(lambda *args: self.ui.dockTaskManager.raise_())
mvd = self.ui.dockMapViews
dts = self.ui.dockTimeSeries
mw = self.ui.mMapWidget
self.mMapLayerStore = self.mapWidget().mMapLayerStore
import eotimeseriesviewer.utils
eotimeseriesviewer.utils.MAP_LAYER_STORES.insert(0, self.mapLayerStore())
from eotimeseriesviewer.timeseries import TimeSeriesDock
from eotimeseriesviewer.mapvisualization import MapViewDock, MapWidget
mvd: MapViewDock = self.ui.dockMapViews
dts = self.ui.dockTimeSeries
mw: MapWidget = self.ui.mMapWidget
assert isinstance(mvd, MapViewDock)
assert isinstance(mw, MapWidget)
assert isinstance(dts, TimeSeriesDock)
......@@ -515,7 +519,9 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
mw.sigSpatialExtentChanged.connect(self.timeSeries().setCurrentSpatialExtent)
mw.sigVisibleDatesChanged.connect(self.timeSeries().setVisibleDates)
mw.sigMapViewAdded.connect(self.onMapViewAdded)
mw.sigCurrentLocationChanged.connect(self.setCurrentLocation)
mw.sigCurrentLocationChanged.connect(
lambda crs, pt, canvas=mw: self.setCurrentLocation(SpatialPoint(crs, pt),
mapCanvas=mw.currentMapCanvas()))
mw.sigCurrentLayerChanged.connect(self.updateCurrentLayerActions)
self.ui.optionSyncMapCenter.toggled.connect(self.mapWidget().setSyncWithQGISMapCanvas)
......@@ -631,14 +637,15 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
from eotimeseriesviewer import DOCUMENTATION, SpectralLibrary, SpectralLibraryPanel, SpectralLibraryWidget
self.ui.actionShowOnlineHelp.triggered.connect(lambda: webbrowser.open(DOCUMENTATION))
SLW = self.ui.dockSpectralLibrary.spectralLibraryWidget()
SLW: SpectralLibraryWidget = self.ui.dockSpectralLibrary.spectralLibraryWidget()
assert isinstance(SLW, SpectralLibraryWidget)
SLW.setMapInteraction(True)
SLW.setCurrentProfilesMode(SpectralLibraryWidget.CurrentProfilesMode.automatically)
SLW.sigMapExtentRequested.connect(self.setSpatialExtent)
SLW.sigMapCenterRequested.connect(self.setSpatialCenter)
SLW.actionSelectProfilesFromMap.setVisible(True)
SLW.sigLoadFromMapRequest.connect(lambda *args: self.setMapTool(MapTools.SpectralProfile))
#SLW.setMapInteraction(True)
#SLW.setCurrentProfilesMode(SpectralLibraryWidget.CurrentProfilesMode.automatically)
#SLW.sigMapExtentRequested.connect(self.setSpatialExtent)
#SLW.sigMapCenterRequested.connect(self.setSpatialCenter)
SLW.setVectorLayerTools(self.mVectorLayerTools)
# add time-specific fields
sl = self.spectralLibrary()
......@@ -1202,7 +1209,8 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
self.mCurrentMapLocation = spatialPoint
if isinstance(mapCanvas, QgsMapCanvas):
self.sigCurrentLocationChanged[SpatialPoint, QgsMapCanvas].emit(self.mCurrentMapLocation, mapCanvas)
self.sigCurrentLocationChanged[QgsCoordinateReferenceSystem, QgsPointXY, QgsMapCanvas].emit(
self.mCurrentMapLocation.crs(), self.mCurrentMapLocation, mapCanvas)
if bCLV:
self.loadCursorLocationValueInfo(spatialPoint, mapCanvas)
......@@ -1216,7 +1224,9 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
if bTP:
self.loadCurrentTemporalProfile(spatialPoint)
self.sigCurrentLocationChanged[SpatialPoint].emit(self.mCurrentMapLocation)
self.sigCurrentLocationChanged[QgsCoordinateReferenceSystem, QgsPointXY].emit(
self.mCurrentMapLocation.crs(),
self.mCurrentMapLocation)
@pyqtSlot(SpatialPoint, QgsMapCanvas)
def loadCursorLocationValueInfo(self, spatialPoint: SpatialPoint, mapCanvas: QgsMapCanvas):
......
......@@ -19,27 +19,18 @@
***************************************************************************/
"""
# noinspection PyPep8Naming
KEY_LAST_CLICKED = 'LAST_CLICKED'
import time
import eotimeseriesviewer.settings
import sys
import typing
import os
import re
import enum
import qgis.utils
from .externals.qps.classification.classificationscheme import ClassificationScheme, ClassInfo
from .externals.qps.crosshair.crosshair import CrosshairDialog, CrosshairStyle, CrosshairMapCanvasItem
from .externals.qps.layerproperties import showLayerPropertiesDialog
from .externals.qps.maptools import *
from .externals.qps.utils import *
from .labeling import quickLabelLayers, setQuickTSDLabelsForRegisteredLayers
from .timeseries import TimeSeriesDate, TimeSeriesSource, SensorProxyLayer
from qgis.PyQt.QtGui import QIcon, QContextMenuEvent, QMouseEvent, QPainter, QFont, QColor
from qgis.PyQt.QtWidgets import QApplication, QDialog, QMenu, QFileDialog, QSizePolicy, QStyle, QStyleOptionProgressBar
from qgis.PyQt.QtCore import QSize, QDate, QDateTime, QDir, QFile, QMimeData, pyqtSignal, Qt, \
QPoint, QObject, QRectF, QPointF, QRect, QTimer
from qgis.core import *
from qgis.gui import *
from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsContrastEnhancement, \
QgsDateTimeRange, QgsProject, QgsTextRenderer, QgsApplication, QgsCoordinateReferenceSystem, \
QgsMapToPixel, QgsRenderContext, QgsMapSettings, QgsRasterRenderer, \
......@@ -47,7 +38,7 @@ from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsContrastEn
QgsSingleBandPseudoColorRenderer, QgsWkbTypes, QgsRasterLayerTemporalProperties, QgsRasterDataProvider, \
QgsTextFormat, QgsMapLayerStore, QgsMultiBandColorRenderer, QgsSingleBandGrayRenderer, QgsField, \
QgsRectangle, QgsPolygon, QgsMultiBandColorRenderer, QgsRectangle, QgsSingleBandGrayRenderer, \
QgsLayerTreeGroup, QgsUnitTypes
QgsLayerTreeGroup, QgsUnitTypes, QgsMimeDataUtils
from qgis.gui import QgsMapCanvas, QgisInterface, QgsFloatingWidget, QgsUserInputWidget, \
QgsAdvancedDigitizingDockWidget, QgsMapCanvasItem, \
......@@ -55,6 +46,20 @@ from qgis.gui import QgsMapCanvas, QgisInterface, QgsFloatingWidget, QgsUserInpu
QgsGeometryRubberBand
from .externals.qps.classification.classificationscheme import ClassificationScheme, ClassInfo
from .externals.qps.crosshair.crosshair import CrosshairDialog, CrosshairStyle, CrosshairMapCanvasItem
from .externals.qps.layerproperties import showLayerPropertiesDialog
from .externals.qps.maptools import QgsMapToolSelectionHandler, \
CursorLocationMapTool, QgsMapToolAddFeature, \
SpectralProfileMapTool, TemporalProfileMapTool, MapToolCenter, PixelScaleExtentMapTool, FullExtentMapTool, QgsMapToolSelect
from .externals.qps.utils import SpatialExtent, SpatialPoint
from .labeling import quickLabelLayers, setQuickTSDLabelsForRegisteredLayers
from .timeseries import TimeSeriesDate, TimeSeriesSource, SensorProxyLayer
import eotimeseriesviewer.settings
KEY_LAST_CLICKED = 'LAST_CLICKED'
def toQgsMimeDataUtilsUri(mapLayer: QgsMapLayer):
uri = QgsMimeDataUtils.Uri()
uri.name = mapLayer.name()
......@@ -1360,7 +1365,7 @@ class MapCanvas(QgsMapCanvas):
path = filenameFromString('{}.{}'.format(self.mTSD.date(), self.mMapView.title()))
else:
path = 'mapcanvas'
path = jp(lastDir, '{}.{}'.format(path, fileType.lower()))
path = os.path.join(lastDir, '{}.{}'.format(path, fileType.lower()))
path, _ = QFileDialog.getSaveFileName(self, 'Save map as {}'.format(fileType), path)
if len(path) > 0:
self.saveAsImage(path, None, fileType)
......
......@@ -19,35 +19,22 @@
# noinspection PyPep8Naming
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
class MapViewScrollArea(QScrollArea):
#sigResized = pyqtSignal()
def __init__(self, *args, **kwds):
super(MapViewScrollArea, self).__init__(*args, **kwds)
self.horizontalScrollBar().setTracking(False)
self.verticalScrollBar().setTracking(False)
#def resizeEvent(self, event):
#super(MapViewScrollArea, self).resizeEvent(event)
#self.sigResized.emit()
def distanceToCenter(self, widget:QWidget) -> int:
def distanceToCenter(self, widget: QWidget) -> int:
# self.visibleRegion().boundingRect().isValid()
halfSize = widget.size() * 0.5
centerInParent = widget.mapToParent(QPoint(halfSize.width(), halfSize.height()))
r = self.viewport().rect()
centerViewPort = QPoint(int(r.x() + r.width() *0.5 ), int(r.y()+r.height()*0.5))
centerViewPort = QPoint(int(r.x() + r.width() * 0.5), int(r.y() + r.height() * 0.5))
diff = centerInParent - centerViewPort
return diff.manhattanLength()
#def sizeHint(self):
# parent = self.parent()
# hint = super(MapViewScrollArea, self).sizeHint()
# return hint
......@@ -20,43 +20,34 @@
***************************************************************************/
"""
import os
import enum
import sys
import re
import fnmatch
import collections
import copy
import traceback
import bisect
import json
from eotimeseriesviewer import DIR_UI
from qgis.core import *
from qgis.core import QgsContrastEnhancement, QgsRasterShader, QgsColorRampShader, QgsProject, \
QgsCoordinateReferenceSystem, QgsVector, QgsTextFormat, \
import typing
import numpy as np
import qgis.utils
from qgis.PyQt.QtCore import Qt, QSize, pyqtSignal, QModelIndex, QTimer, QAbstractListModel
from qgis.PyQt.QtGui import QColor, QIcon, QGuiApplication, QMouseEvent
from qgis.PyQt.QtWidgets import QWidget, QLayoutItem, QFrame, QLabel, QGridLayout, QSlider, QMenu, QToolBox, QDialog
from qgis.PyQt.QtXml import QDomDocument, QDomNode, QDomElement
from qgis.core import QgsCoordinateReferenceSystem, QgsVector, QgsTextFormat, \
QgsRectangle, QgsRasterRenderer, QgsMapLayerStore, QgsMapLayerStyle, \
QgsLayerTreeModel, QgsLayerTreeGroup, \
QgsLayerTree, QgsLayerTreeLayer, \
QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsMapLayerProxyModel, QgsColorRamp, QgsSingleBandPseudoColorRenderer
from qgis.gui import *
from qgis.gui import QgsDockWidget, QgsMapCanvas, QgsMapTool, QgsCollapsibleGroupBox, QgsLayerTreeView, \
QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsMapLayerProxyModel, QgsPointXY, QgsReadWriteContext
from qgis.gui import QgsDockWidget, QgsMapCanvas, QgsLayerTreeView, \
QgisInterface, QgsLayerTreeViewMenuProvider, QgsLayerTreeMapCanvasBridge, \
QgsProjectionSelectionWidget, QgsMessageBar
from qgis.PyQt.QtXml import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
import numpy as np
from .utils import *
from . import Option, OptionListModel
from .timeseries import SensorInstrument, TimeSeriesDate, TimeSeries, SensorProxyLayer
from .utils import loadUi
from .mapviewscrollarea import MapViewScrollArea
from .mapcanvas import MapCanvas, MapTools, MapCanvasInfoItem, MapCanvasMapTools, KEY_LAST_CLICKED
from eotimeseriesviewer import debugLog
from .externals.qps.crosshair.crosshair import getCrosshairStyle, CrosshairStyle, CrosshairMapCanvasItem
from .externals.qps.layerproperties import showLayerPropertiesDialog
from .externals.qps.maptools import *
from .externals.qps.layerproperties import VectorLayerTools
from .externals.qps.maptools import MapTools
from .mapcanvas import MapCanvas, MapCanvasInfoItem, KEY_LAST_CLICKED
from .timeseries import SensorInstrument, TimeSeriesDate, TimeSeries, SensorProxyLayer
from .utils import loadUi, SpatialPoint, SpatialExtent, datetime64
from eotimeseriesviewer import DIR_UI
from eotimeseriesviewer.main import fixMenuButtons
KEY_LOCKED_LAYER = 'eotsv/locked'
KEY_SENSOR_GROUP = 'eotsv/sensorgroup'
KEY_SENSOR_LAYER = 'eotsv/sensorlayer'
......@@ -999,7 +990,7 @@ class MapWidget(QFrame):
sigCurrentCanvasChanged = pyqtSignal(MapCanvas)
sigCurrentMapViewChanged = pyqtSignal(MapView)
sigCurrentDateChanged = pyqtSignal(TimeSeriesDate)
sigCurrentLocationChanged = pyqtSignal(SpatialPoint, MapCanvas)
sigCurrentLocationChanged = pyqtSignal(QgsCoordinateReferenceSystem, QgsPointXY)
sigVisibleDatesChanged = pyqtSignal(list)
sigViewModeChanged = pyqtSignal(ViewMode)
......@@ -1350,7 +1341,6 @@ class MapWidget(QFrame):
self.mTimeSeries.sigTimeSeriesDatesAdded.disconnect(self._updateSliderRange)
self.mTimeSeries.sigTimeSeriesDatesRemoved.disconnect(self._updateSliderRange)
self.mTimeSeries = ts
if isinstance(self.mTimeSeries, TimeSeries):
self.mTimeSeries.sigVisibilityChanged.connect(self._updateCanvasDates)
......@@ -1728,7 +1718,7 @@ class MapWidget(QFrame):
# mapCanvas.sigDestinationCrsChanged.connect(self.setCrs)
mapCanvas.sigCrosshairPositionChanged.connect(self.onCrosshairPositionChanged)
mapCanvas.sigCanvasClicked.connect(self.onCanvasClicked)
mapCanvas.mapTools().mtCursorLocation.sigLocationRequest[SpatialPoint, QgsMapCanvas].connect(
mapCanvas.mapTools().mtCursorLocation.sigLocationRequest[QgsCoordinateReferenceSystem, QgsPointXY].connect(
self.sigCurrentLocationChanged)
def _disconnectCanvasSignals(self, mapCanvas: MapCanvas):
......@@ -2209,8 +2199,6 @@ class MapViewDock(QgsDockWidget):
return QSize(self.spinBoxMapSizeX.value(),
self.spinBoxMapSizeY.value())
def dummySlot(self):
s = ""
def onMapViewsRemoved(self, mapViews):
......
from qgis.core import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtXml import *
from qgis.core import QgsReadWriteContext, QgsProject, QgsMapLayer, QgsRasterLayer, QgsVectorLayer
from qgis.gui import QgsLayerTreeLayer, QgsLayerTreeGroup, QgsLayerTree
import re
from qgis.gui import *
......@@ -60,8 +59,6 @@ def fromLayerList(mapLayers):
return mimeData
def toLayerList(mimeData):
"""
Extracts a layer-tree-group from a QMimeData
......@@ -77,14 +74,13 @@ def toLayerList(mimeData):
xml = doc.toString()
node = doc.firstChildElement(MDF_LAYERTREEMODELDATA_XML)
context = QgsReadWriteContext()
#context.setPathResolver(QgsProject.instance().pathResolver())
# context.setPathResolver(QgsProject.instance().pathResolver())
layerTree = QgsLayerTree.readXml(node, context)
lt = QgsLayerTreeGroup.readXml(node, context)
#layerTree.resolveReferences(QgsProject.instance(), True)
# layerTree.resolveReferences(QgsProject.instance(), True)
registeredLayers = QgsProject.instance().mapLayers()
attributesLUT= {}
attributesLUT = {}
childs = node.childNodes()
for i in range(childs.count()):
......@@ -118,7 +114,7 @@ def toLayerList(mimeData):
if isinstance(mapLayer, QgsMapLayer):
newMapLayers.append(mapLayer)
elif MDF_URILIST in mimeData.formats():
pass
pass
else:
s = ""