From 855d690a0c205d71e5411b5bdce6fa3b351deff9 Mon Sep 17 00:00:00 2001 From: "benjamin.jakimow" <benjamin.jakimow@geo.hu-berlin.de> Date: Thu, 4 Jul 2019 10:18:18 +0200 Subject: [PATCH] implemented LabelShortcutType.SourceImage to label path of source image under cursor --- CHANGELOG | 4 +++- eotimeseriesviewer/labeling.py | 15 +++++++++------ eotimeseriesviewer/main.py | 7 ++++--- eotimeseriesviewer/mapcanvas.py | 16 +++++++++++----- tests/test_labeling.py | 2 +- tests/test_timeseries.py | 3 --- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fd3d1614..f51250bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,9 @@ Changelog ============== 2019-07-04 (version 1.5): - * + * fixed missing updates of time series tree view when adding / removing source images + * map canvas context menu lists layers with spatial extent intersecting the cursor position only + * fixes feature selection error 2019-07-02 (version 1.4): * adding vector layers with sublayers will add all sublayers diff --git a/eotimeseriesviewer/labeling.py b/eotimeseriesviewer/labeling.py index af046d37..6ee943f6 100644 --- a/eotimeseriesviewer/labeling.py +++ b/eotimeseriesviewer/labeling.py @@ -12,7 +12,7 @@ from eotimeseriesviewer.utils import loadUI, qgisInstance from eotimeseriesviewer.externals.qps.classification.classificationscheme \ import ClassificationSchemeWidget, ClassificationScheme, ClassInfo, ClassificationSchemeComboBox -from eotimeseriesviewer.timeseries import TimeSeriesDate +from eotimeseriesviewer.timeseries import TimeSeriesDate, TimeSeriesSource #the QgsProject(s) and QgsMapLayerStore(s) to search for QgsVectorLayers MAP_LAYER_STORES = [QgsProject.instance()] @@ -28,6 +28,7 @@ class LabelShortcutType(enum.Enum): Year = 'Year' DecimalYear = 'Decimal Year' Sensor = 'Sensor Name' + SourceImage = 'Source Image' #Classification = 'Classification' def shortcuts(field:QgsField): @@ -38,7 +39,7 @@ def shortcuts(field:QgsField): """ assert isinstance(field, QgsField) - shortCutsString = [LabelShortcutType.Sensor, LabelShortcutType.Date] + shortCutsString = [LabelShortcutType.Sensor, LabelShortcutType.Date, LabelShortcutType.SourceImage] shortCutsInt = [LabelShortcutType.Year, LabelShortcutType.DOY] shortCutsFloat = [LabelShortcutType.Year, LabelShortcutType.DOY, LabelShortcutType.DecimalYear] @@ -136,14 +137,14 @@ def quickLabelLayers()->list: break return layers -def setQuickTSDLabelsForRegisteredLayers(tsd:TimeSeriesDate): +def setQuickTSDLabelsForRegisteredLayers(tsd:TimeSeriesDate, tss:TimeSeriesSource): """ :param tsd: TimeSeriesDate :param classInfos: """ for layer in quickLabelLayers(): assert isinstance(layer, QgsVectorLayer) - setQuickTSDLabels(layer, tsd) + setQuickTSDLabels(layer, tsd, tss) def setQuickClassInfo(vectorLayer:QgsVectorLayer, field, classInfo:ClassInfo): """ @@ -177,10 +178,10 @@ def setQuickClassInfo(vectorLayer:QgsVectorLayer, field, classInfo:ClassInfo): vectorLayer.changeAttributeValue(feature.id(), idx, value, oldValue) vectorLayer.endEditCommand() -def setQuickTSDLabels(vectorLayer:QgsVectorLayer, tsd:TimeSeriesDate): +def setQuickTSDLabels(vectorLayer:QgsVectorLayer, tsd:TimeSeriesDate, tss:TimeSeriesSource): """ Labels selected features with information related to TimeSeriesDate tsd, according to - the settings specified in this model. + the settings specified in this model. Note: this will not the any ClassInfo or the source image values :param tsd: TimeSeriesDate :param classInfos: """ @@ -209,6 +210,8 @@ def setQuickTSDLabels(vectorLayer:QgsVectorLayer, tsd:TimeSeriesDate): value = str(tsd.date()) elif labelType == LabelShortcutType.DecimalYear: value = tsd.decimalYear() + elif labelType == LabelShortcutType.SourceImage and isinstance(tss, TimeSeriesSource): + value = tss.uri() #elif labelType == LabelShortcutType.Classification: # pass diff --git a/eotimeseriesviewer/main.py b/eotimeseriesviewer/main.py index 74433728..d8b54861 100644 --- a/eotimeseriesviewer/main.py +++ b/eotimeseriesviewer/main.py @@ -923,7 +923,7 @@ class TimeSeriesViewer(QgisInterface, QObject): self.clearTimeSeries() progressDialog = QProgressDialog(self.ui) progressDialog.setWindowTitle('Image Loading') - progressDialog.setMinimumDuration(2000) + progressDialog.setMinimumDuration(1000) self.mTimeSeries.loadFromFile(path, n_max=n_max, progressDialog=progressDialog) @@ -1168,9 +1168,10 @@ class TimeSeriesViewer(QgisInterface, QObject): s.setValue('dir_datasources', dn) if files: - progressDialog = QProgressDialog('Images Loading', 'Cancel', 0, len(files), parent=self.ui) + progressDialog = QProgressDialog('Image Loading', 'Cancel', 0, len(files), parent=self.ui) progressDialog.setLabelText('Start loading {} images....'.format(len(files))) - progressDialog.setMinimumDuration(2000) + progressDialog.setWindowTitle('Image Loading') + progressDialog.setMinimumDuration(1000) progressDialog.setValue(0) if loadAsync: diff --git a/eotimeseriesviewer/mapcanvas.py b/eotimeseriesviewer/mapcanvas.py index aba98887..751beec2 100644 --- a/eotimeseriesviewer/mapcanvas.py +++ b/eotimeseriesviewer/mapcanvas.py @@ -599,11 +599,11 @@ class MapCanvas(QgsMapCanvas): from .main import TimeSeriesViewer eotsv = TimeSeriesViewer.instance() - viewPortRasterLayers = [l for l in self.layers() if isinstance(l, QgsRasterLayer) - and SpatialExtent.fromLayer(l).toCrs(self.crs()).contains(pointGeo)] - viewPortSensorLayers = [l for l in viewPortRasterLayers if isinstance(l, SensorProxyLayer)] + viewPortMapLayers = [l for l in self.layers() if isinstance(l, QgsMapLayer)] - viewPortVectorLayers = [l for l in self.layers() if isinstance(l, QgsVectorLayer)] + viewPortRasterLayers = [l for l in viewPortMapLayers if isinstance(l, QgsRasterLayer) and SpatialExtent.fromLayer(l).toCrs(self.crs()).contains(pointGeo)] + viewPortSensorLayers = [l for l in viewPortRasterLayers if isinstance(l, SensorProxyLayer)] + viewPortVectorLayers = [l for l in viewPortMapLayers if isinstance(l, QgsVectorLayer)] refSensorLayer = None refRasterLayer = None @@ -616,6 +616,12 @@ class MapCanvas(QgsMapCanvas): menu = QMenu() if isinstance(self.tsd(), TimeSeriesDate): + tss = None + sourceUris = self.tsd().sourceUris() + for sl in viewPortSensorLayers: + if sl.source() in sourceUris: + tss = self.tsd()[sourceUris.index(sl.source())] + break lyrWithSelectedFeatures = [l for l in quickLabelLayers() if l.isEditable() and l.selectedFeatureCount() > 0] @@ -627,7 +633,7 @@ class MapCanvas(QgsMapCanvas): a = m.addAction('Set Date/Sensor attributes') a.setToolTip('Writes the date ate and sensor quick labels of selected features in {}.'.format(layerNames)) - a.triggered.connect(lambda *args, tsd = self.tsd(): setQuickTSDLabelsForRegisteredLayers(tsd)) + a.triggered.connect(lambda *args, tsd = self.tsd(), tss=tss: setQuickTSDLabelsForRegisteredLayers(tsd, tss)) from .labeling import EDITOR_WIDGET_REGISTRY_KEY as QUICK_LABEL_KEY from .labeling import CONFKEY_CLASSIFICATIONSCHEME, layerClassSchemes, setQuickClassInfo diff --git a/tests/test_labeling.py b/tests/test_labeling.py index f1553bdb..838cd475 100644 --- a/tests/test_labeling.py +++ b/tests/test_labeling.py @@ -348,7 +348,7 @@ class testclassLabelingTest(unittest.TestCase): - setQuickTSDLabels(lyr, tsd) + setQuickTSDLabels(lyr, tsd, None) fields = lyr.fields() setQuickClassInfo(lyr, fields.lookupField('class1l'), classInfo1) setQuickClassInfo(lyr, fields.lookupField('class1n'), classInfo1) diff --git a/tests/test_timeseries.py b/tests/test_timeseries.py index 68b96af6..130afb11 100644 --- a/tests/test_timeseries.py +++ b/tests/test_timeseries.py @@ -279,9 +279,6 @@ class TestInit(unittest.TestCase): while QgsApplication.taskManager().countActiveTasks() > 0 or len(TS.mTasks) > 0: QCoreApplication.processEvents() - #self.assertTrue(len(TS) > 0) - #self.assertTrue(len(TS) == len(files)) - if SHOW_GUI: QAPP.exec_() -- GitLab