Commit 404c3a1d authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

added debuglog messages


refactoring
mapvisualization.py: refresh and times
Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow benjamin.jakimow@geo.hu-berlin.de <benjamin.jakimow@geo.hu-berlin.de>
parent 8005ed61
......@@ -20,6 +20,7 @@
"""
# noinspection PyPep8Naming
import os
import inspect
import pathlib
from qgis.core import QgsApplication, Qgis
from qgis.PyQt.QtGui import QIcon
......@@ -40,7 +41,7 @@ CREATE_ISSUE = 'https://bitbucket.org/jakimowb/eo-time-series-viewer/issues/new'
DEPENDENCIES = ['numpy', 'osgeo.gdal']
URL_TESTDATA = r''
DEBUG: bool = bool(os.environ.get('EOTSV_DEBUG', False))
DEBUG: bool = str(os.environ.get('DEBUG', '1')).lower() in ['true', '1', 'yes']
DIR = pathlib.Path(__file__).parent
DIR_REPO = DIR.parent
......@@ -55,10 +56,24 @@ DIR_QGIS_RESOURCES = DIR_REPO / 'qgisresources'
URL_QGIS_RESOURCES = r'https://bitbucket.org/jakimowb/qgispluginsupport/downloads/qgisresources.zip'
def debugLog(msg: str):
def debugLog(msg: str= '', skip_prefix: bool=False):
if DEBUG:
print('DEBUG:' + msg, flush=True)
if skip_prefix:
prefix = ''
else:
curFrame = inspect.currentframe()
outerFrames = inspect.getouterframes(curFrame)
FOI = outerFrames[1]
stack = inspect.stack()
if "self" in stack[1][0].f_locals.keys():
stack_class = stack[1][0].f_locals["self"].__class__.__name__
elif '__file__' in stack[1][0].f_locals.keys():
stack_class = stack[1][0].f_locals['__file__']
else:
stack_class = ''
stack_method = stack[1][0].f_code.co_name
prefix = f'{stack_class}.{FOI.function}: {os.path.basename(FOI.filename)}:{FOI.lineno}:'
print(f'DEBUG:{prefix}{msg}', flush=True)
# import QPS modules
# skip imports when on RTD, as we can not install the full QGIS environment as required
......
......@@ -475,10 +475,8 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
assert isinstance(mw, MapWidget)
assert isinstance(tswidget, TimeSeriesWidget)
def onClosed():
EOTimeSeriesViewer._instance = None
self.ui.sigAboutToBeClosed.connect(self.onClosing)
self.ui.sigAboutToBeClosed.connect(onClosed)
import qgis.utils
assert isinstance(qgis.utils.iface, QgisInterface)
QgsProject.instance().layersWillBeRemoved.connect(self.onLayersWillBeRemoved)
......@@ -518,7 +516,7 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
assert isinstance(self, EOTimeSeriesViewer)
self.profileDock.sigMoveToDate.connect(self.setCurrentDate)
mw.sigSpatialExtentChanged.connect(self.timeSeries().setCurrentSpatialExtent)
# mw.sigSpatialExtentChanged.connect(self.timeSeries().setCurrentSpatialExtent)
mw.sigVisibleDatesChanged.connect(self.timeSeries().setVisibleDates)
mw.sigMapViewAdded.connect(self.onMapViewAdded)
mw.sigCurrentLocationChanged[QgsCoordinateReferenceSystem, QgsPointXY].connect(
......@@ -672,6 +670,14 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
if eotsvSettings.value(SettingKeys.StartupRestoreProjectSettings, False):
self.onReloadProject()
def onClosing(self):
debugLog(f'Close EOTSV')
EOTimeSeriesViewer._instance = None
while len(self.mapViews()) > 0:
mv = self.mapViews()[0]
debugLog(f'Remove map view {mv}')
self.mapWidget().removeMapView()
def onWriteProject(self, dom: QDomDocument):
node = dom.createElement('EOTSV')
......@@ -974,6 +980,7 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
"""
Moves the map view to a TimeSeriesSource
"""
debugLog('EOTImeSeriesViewersetCurrentSource')
tss = self.timeSeries().findSource(tss)
if isinstance(tss, TimeSeriesSource):
self.ui.mMapWidget.setCurrentDate(tss.timeSeriesDate())
......@@ -1219,6 +1226,7 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
Sets the map canvas extent
:param spatialExtent: SpatialExtent
"""
debugLog()
self.mapWidget().setSpatialExtent(spatialExtent)
def setSpatialCenter(self, spatialPoint: SpatialPoint):
......@@ -1478,6 +1486,7 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
if len(self.mTimeSeries) > 0:
extent = self.timeSeries().maxSpatialExtent()
if isinstance(extent, SpatialExtent):
debugLog('Extent changed')
self.mapWidget().setCrs(extent.crs())
self.mapWidget().setSpatialExtent(extent)
self.mSpatialMapExtentInitialized = True
......
......@@ -45,13 +45,13 @@ from qgis.gui import QgsMapCanvas, QgisInterface, QgsFloatingWidget, QgsUserInpu
QgsMapTool, QgsMapToolPan, QgsMapToolZoom, QgsMapToolCapture, QgsMapToolIdentify, \
QgsGeometryRubberBand, QgsMapMouseEvent
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
SpectralProfileMapTool, TemporalProfileMapTool, MapToolCenter, PixelScaleExtentMapTool, FullExtentMapTool, \
QgsMapToolSelect
from .externals.qps.utils import SpatialExtent, SpatialPoint
from .labeling import quickLabelLayers, setQuickTSDLabelsForRegisteredLayers, quickLayerFieldSetup
from .timeseries import TimeSeriesDate, TimeSeriesSource, SensorProxyLayer
......@@ -514,7 +514,7 @@ class MapCanvas(QgsMapCanvas):
self.mInfoItem.setTextFormat(mapView.mapTextFormat())
self.addToRefreshPipeLine(mapView.mapBackgroundColor())
self.setCrosshairStyle(mapView.crosshairStyle())
#self.setCrosshairVisibility(mapView.crosshairStyle())
# self.setCrosshairVisibility(mapView.crosshairStyle())
# self.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
......@@ -712,7 +712,7 @@ class MapCanvas(QgsMapCanvas):
sourceLayer = SensorProxyLayer(source,
sensor=sensor,
options=QgsRasterLayer.LayerOptions(
loadDefaultStyle=loadDefaultStyle))
loadDefaultStyle=loadDefaultStyle))
sourceLayer.setName(f'{lyr.name()} {source}')
sourceLayer.setCustomProperty('eotsv/sensorid', sensor.id())
sourceLayer.mTSS = tss
......@@ -812,7 +812,7 @@ class MapCanvas(QgsMapCanvas):
if emitSignal:
s = ""
#self.sigCrosshairStyleChanged.emit(self.mCrosshairItem.crosshairStyle())
# self.sigCrosshairStyleChanged.emit(self.mCrosshairItem.crosshairStyle())
else:
s = ""
......@@ -932,7 +932,8 @@ class MapCanvas(QgsMapCanvas):
reg = QgsGui.editorWidgetRegistry()
factory = reg.factory(EDITOR_WIDGET_REGISTRY_KEY)
observation_indices = []
from .labeling import layerClassSchemes, setQuickClassInfo, LabelShortcutType, LabelConfigurationKey, quickLayerGroups
from .labeling import layerClassSchemes, setQuickClassInfo, LabelShortcutType, LabelConfigurationKey, \
quickLayerGroups
if len(lyrWithSelectedFeatures) == 0:
a = m.addAction('No features selected.')
......@@ -1191,9 +1192,8 @@ class MapCanvas(QgsMapCanvas):
action = menu.addAction('Update source visibility')
action.setToolTip('Updates observation source visibility according their spatial intersection '
'with this map extent.')
action.triggered.connect(lambda *args,
ext=self.spatialExtent():
ts.focusVisibility(ext=ext,
action.triggered.connect(lambda *args, ext=self.spatialExtent():
ts.focusVisibility(ext,
date_of_interest=date,
max_after=n_max,
max_before=n_max
......@@ -1204,10 +1204,8 @@ class MapCanvas(QgsMapCanvas):
'with this map extent.<br/>'
'<span style="color:red">This can take some time for long time series</span>')
action.triggered.connect(lambda *args,
ext=self.spatialExtent():
ts.focusVisibility(ext=ext, date_of_interest=date))
action.triggered.connect(lambda *args, ext=self.spatialExtent():
ts.focusVisibility(ext, date_of_interest=date))
menu.addSeparator()
action = menu.addAction('Hide Date')
......@@ -1274,7 +1272,7 @@ class MapCanvas(QgsMapCanvas):
if Qgis.QGIS_VERSION >= '3.16':
super(MapCanvas, self).mousePressEvent(event)
if bRight and \
isinstance(mt, (QgsMapToolAddFeature, )) \
isinstance(mt, (QgsMapToolAddFeature,)) \
and not bool(mt.flags() & QgsMapTool.ShowContextMenu) \
and bool(modifiers & Qt.ControlModifier):
menu = QMenu()
......@@ -1295,7 +1293,7 @@ class MapCanvas(QgsMapCanvas):
super().mousePressEvent(event)
if bLeft and not isinstance(mt, (QgsMapToolAddFeature, )):
if bLeft and not isinstance(mt, (QgsMapToolAddFeature,)):
ms = self.mapSettings()
pointXY = ms.mapToPixel().toMapCoordinates(event.x(), event.y())
spatialPoint = SpatialPoint(ms.destinationCrs(), pointXY)
......
......@@ -1488,7 +1488,6 @@ class TimeSeries(QAbstractItemModel):
self.mLUT_Path2TSD = {}
self.mVisibleDates: typing.Set[TimeSeriesDate] = set()
self.mCurrentSpatialExtent = None
self.cnDate = 'Date'
self.cnSensor = 'Sensor'
......@@ -1506,16 +1505,8 @@ class TimeSeries(QAbstractItemModel):
if imageFiles is not None:
self.addSources(imageFiles)
def setCurrentSpatialExtent(self, spatialExtent: SpatialExtent):
"""
Sets the spatial extent currently shown
:param spatialExtent:
"""
if isinstance(spatialExtent, SpatialExtent) and self.mCurrentSpatialExtent != spatialExtent:
self.mCurrentSpatialExtent = spatialExtent
def focusVisibility(self,
ext: SpatialExtent = None,
ext: SpatialExtent,
runAsync: bool = None,
date_of_interest: np.datetime64 = None,
max_before: int = -1,
......@@ -1531,8 +1522,8 @@ class TimeSeries(QAbstractItemModel):
:param runAsync: if True (default), the visibility check is run in a parallel task
:param ext: SpatialExtent
"""
if ext is None:
ext = self.currentSpatialExtent()
assert isinstance(ext, SpatialExtent)
if runAsync is None:
from eotimeseriesviewer.settings import value, Keys
runAsync = value(Keys.QgsTaskAsync, True)
......@@ -1609,13 +1600,6 @@ class TimeSeries(QAbstractItemModel):
idx1 = self.index(rowMax, 0)
self.dataChanged.emit(idx0, idx1, [Qt.CheckStateRole])
def currentSpatialExtent(self) -> SpatialExtent:
"""
Returns the current spatial extent
:return: SpatialExtent
"""
return self.mCurrentSpatialExtent
def setVisibleDates(self, tsds: list):
"""
Sets the TimeSeriesDates currently shown
......
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