Newer
Older
DV.ui.parent().layout().removeWidget(DV.ui)
DV.ui.hide()
DV.ui.close()
removedDates.append(DV.TSD)
del DV

Benjamin Jakimow
committed
if len(removedDates) > 0:
self.sigResizeRequired.emit()

Benjamin Jakimow
committed

Benjamin Jakimow
committed

Benjamin Jakimow
committed
def __getitem__(self, slice):
return self.mViews[slice]
def __delitem__(self, slice):
self.removeDates(self.mViews[slice])

benjamin.jakimow@geo.hu-berlin.de
committed
class MapViewListModel(QAbstractListModel):
"""
A model to store a list of map views.

benjamin.jakimow@geo.hu-berlin.de
committed
"""
sigMapViewsAdded = pyqtSignal(list)
sigMapViewsRemoved = pyqtSignal(list)

benjamin.jakimow@geo.hu-berlin.de
committed
def __init__(self, parent=None):
super(MapViewListModel, self).__init__(parent)
self.mMapViewList = []

benjamin.jakimow@geo.hu-berlin.de
committed
def addMapView(self, mapView):
i = len(self.mMapViewList)
self.insertMapView(i, mapView)
def insertMapView(self, i, mapView):
self.insertMapViews(i, [mapView])
def insertMapViews(self, i, mapViews):
assert isinstance(mapViews, list)
assert i >= 0 and i <= len(self.mMapViewList)
self.beginInsertRows(QModelIndex(), i, i + len(mapViews) - 1)

benjamin.jakimow@geo.hu-berlin.de
committed
for j in range(len(mapViews)):
mapView = mapViews[j]
assert isinstance(mapView, MapView)
mapView.sigTitleChanged.connect(
lambda : self.doRefresh([mapView])
)
self.mMapViewList.insert(i + j, mapView)
self.endInsertRows()
self.sigMapViewsAdded.emit(mapViews)

benjamin.jakimow@geo.hu-berlin.de
committed
def doRefresh(self, mapViews):
for mapView in mapViews:
idx = self.mapView2idx(mapView)
self.dataChanged.emit(idx, idx)

benjamin.jakimow@geo.hu-berlin.de
committed
def removeMapView(self, mapView):
self.removeMapViews([mapView])

benjamin.jakimow@geo.hu-berlin.de
committed
def removeMapViews(self, mapViews):
assert isinstance(mapViews, list)
for mv in mapViews:
assert mv in self.mMapViewList
idx = self.mapView2idx(mv)
self.beginRemoveRows(idx.parent(), idx.row(), idx.row())
self.mMapViewList.remove(mv)
self.endRemoveRows()
self.sigMapViewsRemoved.emit(mapViews)

benjamin.jakimow@geo.hu-berlin.de
committed
def rowCount(self, parent=None, *args, **kwargs):
return len(self.mMapViewList)

benjamin.jakimow@geo.hu-berlin.de
committed
def columnCount(self, QModelIndex_parent=None, *args, **kwargs):
return 1
def idx2MapView(self, index):
if isinstance(index, QModelIndex):
if index.isValid():
index = index.row()
else:
return None
assert index >= 0 and index < len(self.mMapViewList)
return self.mMapViewList[index]
def mapView2idx(self, mapView):
assert isinstance(mapView, MapView)
row = self.mMapViewList.index(mapView)
return self.createIndex(row, 0, mapView)

benjamin.jakimow@geo.hu-berlin.de
committed
def __getitem__(self, slice):
return self.mMapViewList[slice]
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return None
if (index.row() >= len(self.mMapViewList)) or (index.row() < 0):
return None
mapView = self.idx2MapView(index)
assert isinstance(mapView, MapView)
if role == Qt.DisplayRole:
value = '{} {}'.format(index.row() +1 , mapView.title())
#if role == Qt.DecorationRole:
#value = classInfo.icon(QSize(20,20))
if role == Qt.UserRole:
value = mapView
return value
class MapViewDock(QgsDockWidget, loadUI('mapviewdock.ui')):
sigMapViewAdded = pyqtSignal(MapView)
sigMapViewRemoved = pyqtSignal(MapView)
sigShowProfiles = pyqtSignal(SpatialPoint, MapCanvas, str)
sigMapCanvasColorChanged = pyqtSignal(QColor)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
sigCrsChanged = pyqtSignal(QgsCoordinateReferenceSystem)
sigMapSizeChanged = pyqtSignal(QSize)
def setTimeSeries(self, timeSeries:TimeSeries):
assert isinstance(timeSeries, TimeSeries)
self.mTimeSeries = timeSeries
self.mTimeSeries.sigSensorAdded.connect(self.addSensor)
self.mTimeSeries.sigSensorRemoved.connect(self.removeSensor)
def __init__(self, parent=None):
super(MapViewDock, self).__init__(parent)
self.setupUi(self)
self.btnAddMapView.setDefaultAction(self.actionAddMapView)
self.btnRemoveMapView.setDefaultAction(self.actionRemoveMapView)
self.btnCrs.crsChanged.connect(self.sigCrsChanged)
self.btnMapCanvasColor.colorChanged.connect(self.onMapCanvasBackgroundColorChanged)
self.btnApplySizeChanges.clicked.connect(lambda : self.sigMapSizeChanged.emit(QSize(self.spinBoxMapSizeX.value(),self.spinBoxMapSizeY.value())))
self.actionAddMapView.triggered.connect(self.createMapView)
self.actionRemoveMapView.triggered.connect(lambda : self.removeMapView(self.currentMapView()) if self.currentMapView() else None)
self.actionApplyStyles.triggered.connect(self.refreshCurrentMapView)
self.toolBox.currentChanged.connect(self.onToolboxIndexChanged)
self.spinBoxMapSizeX.valueChanged.connect(lambda: self.onMapSizeChanged('X'))
self.spinBoxMapSizeY.valueChanged.connect(lambda: self.onMapSizeChanged('Y'))
self.mLastMapSize = self.mapSize()

benjamin.jakimow@geo.hu-berlin.de
committed
"""
Returns the defined MapViews
:return: [list-of-MapViews]
"""
assert isinstance(self.toolBox, QToolBox)
mapViews = []
for i in range(self.toolBox.count()):
item = self.toolBox.widget(i)
if isinstance(item, MapView):
mapViews.append(item)
return mapViews

Benjamin Jakimow
committed
"""
Returns all MapCanvases from all MapViews
:return: [list-of-MapCanvases]

Benjamin Jakimow
committed
"""
maps = []
for mapView in self.mapViews():
assert isinstance(mapView, MapView)
maps.extend(mapView.mapCanvases())
return maps

Benjamin Jakimow
committed
if isinstance(crs, QgsCoordinateReferenceSystem):
old = self.btnCrs.crs()
if old != crs:
self.btnCrs.setCrs(crs)
self.btnCrs.setLayerCrs(crs)
def setMapSize(self, size):
assert isinstance(size, QSize)
ws = [self.spinBoxMapSizeX, self.spinBoxMapSizeY]
oldSize = self.mapSize()
b = oldSize != size
for w in ws:
w.blockSignals(True)
self.spinBoxMapSizeX.setValue(size.width()),
self.spinBoxMapSizeY.setValue(size.height())
self.mLastMapSize = QSize(size)
for w in ws:
w.blockSignals(False)
self.mLastMapSize = QSize(size)
if b:
self.sigMapSizeChanged.emit(size)
def onMapSizeChanged(self, dim):
newSize = self.mapSize()
#1. set size of other dimension accordingly
if dim is not None:
if self.checkBoxKeepSubsetAspectRatio.isChecked():
if dim == 'X':
vOld = self.mLastMapSize.width()
vNew = newSize.width()
targetSpinBox = self.spinBoxMapSizeY
elif dim == 'Y':
vOld = self.mLastMapSize.height()
vNew = newSize.height()
targetSpinBox = self.spinBoxMapSizeX

benjamin.jakimow@geo.hu-berlin.de
committed
oldState = targetSpinBox.blockSignals(True)
targetSpinBox.setValue(int(round(float(vNew) / vOld * targetSpinBox.value())))
targetSpinBox.blockSignals(oldState)
newSize = self.mapSize()
if newSize != self.mLastMapSize:
self.btnApplySizeChanges.setEnabled(True)
else:
self.sigMapSizeChanged.emit(self.mapSize())
self.btnApplySizeChanges.setEnabled(False)
self.setMapSize(newSize)

benjamin.jakimow@geo.hu-berlin.de
committed
def mapSize(self):
return QSize(self.spinBoxMapSizeX.value(),
self.spinBoxMapSizeY.value())

benjamin.jakimow@geo.hu-berlin.de
committed
def refreshCurrentMapView(self, *args):
mv = self.currentMapView()
if isinstance(mv, MapView):
mv.refreshMapView()
else:
s =""

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
for mapView in mapViews:
idx = self.stackedWidget.indexOf(mapView.ui)
if idx >= 0:
self.stackedWidget.removeWidget(mapView.ui)
mapView.ui.close()
else:
s = ""

benjamin.jakimow@geo.hu-berlin.de
committed
self.actionRemoveMapView.setEnabled(len(self.mMapViews) > 0)

benjamin.jakimow@geo.hu-berlin.de
committed
def mapBackgroundColor(self)->QColor:
"""
Returns the map canvas background color
:return: QColor
"""
return self.btnMapCanvasColor.color()

benjamin.jakimow@geo.hu-berlin.de
committed
def setMapBackgroundColor(self, color:QColor):
"""
Sets the MapCanvas background color
:param color: QColor
"""
if color != self.mapBackgroundColor():
self.btnMapCanvasColor.setColor(color)

benjamin.jakimow@geo.hu-berlin.de
committed
def onMapCanvasBackgroundColorChanged(self, color:QColor):
"""
Reacts on a changes map color
:param color: QColor
"""
assert isinstance(color, QColor)
self.mColor = color
for mapCanvas in self.mapCanvases():
assert isinstance(mapCanvas, MapCanvas)
mapCanvas.addToRefreshPipeLine(color)

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
def onMapViewsAdded(self, mapViews):
nextShown = None
for mapView in mapViews:
mapView.sigTitleChanged.connect(self.updateTitle)
self.stackedWidget.addWidget(mapView.ui)
if nextShown is None:
nextShown = mapView

benjamin.jakimow@geo.hu-berlin.de
committed
contents = mapView.ui.scrollAreaWidgetContents
size = contents.size()
hint = contents.sizeHint()
#mapView.ui.scrollArea.update()
s = ""
#setMinimumSize(mapView.ui.scrollAreaWidgetContents.sizeHint())
#hint = contents.sizeHint()
#contents.setMinimumSize(hint)
if isinstance(nextShown, MapView):
self.setCurrentMapView(nextShown)

benjamin.jakimow@geo.hu-berlin.de
committed
for mapView in mapViews:
self.sigMapViewAdded.emit(mapView)

benjamin.jakimow@geo.hu-berlin.de
committed
def updateButtons(self, *args):
b = len(self.mMapViews) > 0
self.actionRemoveMapView.setEnabled(b)
self.actionApplyStyles.setEnabled(b)
self.actionHighlightMapView.setEnabled(b)

benjamin.jakimow@geo.hu-berlin.de
committed
def createMapView(self)->MapView:
"""
Create a new MapView
:return: MapView
"""

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
n = len(self.mapViews()) + 1
title = 'Map View {}'.format(n)
while title in [m.title() for m in self.mapViews()]:
n += 1
title = 'Map View {}'.format(n)
mapView.setTitle(title)
mapView.sigShowProfiles.connect(self.sigShowProfiles)

benjamin.jakimow@geo.hu-berlin.de
committed
mapView.setTimeSeries(self.mTimeSeries)
self.addMapView(mapView)
return mapView

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
"""

benjamin.jakimow@geo.hu-berlin.de
committed
"""
assert isinstance(mapView, MapView)
mapView.sigTitleChanged.connect(lambda *args, mv=mapView : self.onMapViewUpdated(mv))
mapView.sigMapViewVisibility.connect(lambda *args, mv=mapView : self.onMapViewUpdated(mv))
i = self.toolBox.addItem(mapView, mapView.windowIcon(), mapView.title())
self.toolBox.setCurrentIndex(i)
self.onMapViewUpdated(mapView)
self.sigMapViewAdded.emit(mapView)

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
b = isinstance(self.toolBox.currentWidget(), MapView)
self.actionRemoveMapView.setEnabled(b)

benjamin.jakimow@geo.hu-berlin.de
committed
def onMapViewUpdated(self, mapView:MapView):
"""
Handles updates that react on MapView changes
:param mapView: MapView to make the update for
"""
numMV = 0
for i in range(self.toolBox.count()):
item = self.toolBox.widget(i)
if mapView.isVisible():
icon = QIcon(":/timeseriesviewer/icons/mapview.svg")
else:
icon = QIcon(":/timeseriesviewer/icons/mapviewHidden.svg")

benjamin.jakimow@geo.hu-berlin.de
committed
self.toolBox.setItemIcon(i, icon)
self.toolBox.setItemText(i, 'Map View {} "{}"'.format(numMV, mapView.title()))
break

benjamin.jakimow@geo.hu-berlin.de
committed
def removeMapView(self, mapView:MapView)->MapView:
"""
Removes a MapView
:param mapView: MapView
:return: MapView
"""
assert mapView in self.mapViews()
for i in range(self.toolBox.count()):
w = self.toolBox.widget(i)
if isinstance(w, MapView) and w == mapView:
self.toolBox.removeItem(i)
mapView.close()
if self.toolBox.count() >= i:
self.toolBox.setCurrentIndex(min(i, self.toolBox.count()-1))

benjamin.jakimow@geo.hu-berlin.de
committed
self.sigMapViewRemoved.emit(mapView)
return mapView

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
def __len__(self)->int:
"""
Returns the number of MapViews
:return: int
"""
return len(self.mapViews())

benjamin.jakimow@geo.hu-berlin.de
committed
def __iter__(self):
"""
Provides an iterator over all MapViews
:return:
"""
return iter(self.mapViews())

benjamin.jakimow@geo.hu-berlin.de
committed
def __getitem__(self, slice):

benjamin.jakimow@geo.hu-berlin.de
committed
def __contains__(self, mapView):
return mapView in self.mapViews()

benjamin.jakimow@geo.hu-berlin.de
committed
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mapViews().index(mapView)
def addSensor(self, sensor:SensorInstrument):
"""
Adds a new SensorInstrument
:param sensor: SensorInstrument
"""
for mapView in self.mapViews():
mapView.addSensor(sensor)
def removeSensor(self, sensor:SensorInstrument):
"""
Removes a Sensor
:param sensor: SensorInstrument
"""
for mapView in self.mMapViews:
mapView.removeSensor(sensor)
def applyStyles(self):
for mapView in self.mMapViews:
mapView.applyStyles()
def setCrosshairStyle(self, crosshairStyle):
for mapView in self.mMapViews:
mapView.setCrosshairStyle(crosshairStyle)
def setShowCrosshair(self, b):
for mapView in self.mMapViews:
mapView.setCrosshairVisibility(b)
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mapViewsDefinitions.index(mapView)
assert isinstance(mapView, MapView) and mapView in self.mapViews()
self.toolBox.setCurrentWidget(mapView)
def updateTitle(self, *args):
# self.btnToggleMapViewVisibility.setChecked(mapView)
mapView = self.currentMapView()
if isinstance(mapView, MapView):
title = '{} | {}'.format(self.baseTitle, mapView.title())
else:
title = self.baseTitle
self.setWindowTitle(title)
def currentMapView(self):
w = self.toolBox.currentWidget()
if isinstance(w, MapView):
return w
return None
"""
sigLoadingStarted = pyqtSignal(DatumView, MapView)
sigLoadingFinished = pyqtSignal(DatumView, MapView)
sigShowProfiles = pyqtSignal(SpatialPoint, MapCanvas, str)
sigShowMapLayerInfo = pyqtSignal(dict)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
sigMapSizeChanged = pyqtSignal(QSize)
sigCRSChanged = pyqtSignal(QgsCoordinateReferenceSystem)
sigActivateMapTool = pyqtSignal(str)
sigMapViewAdded = pyqtSignal(MapView)
sigMapViewRemoved = pyqtSignal(MapView)
sigVisibleDatesChanged = pyqtSignal(list)
def __init__(self, timeSeriesViewer):
super(SpatialTemporalVisualization, self).__init__()
# assert isinstance(timeSeriesViewer, TimeSeriesViewer), timeSeriesViewer
# default map settings
self.mSpatialExtent = SpatialExtent.world()
self.mCRS = self.mSpatialExtent.crs()
self.mSize = QSize(200, 200)
self.mColor = Qt.black
self.mMapCanvases = []
self.ui = timeSeriesViewer.ui
self.mVisibleDates = set()
self.mMapToolKey = MapTools.Pan
self.mMapToolMode = None
self.scrollArea = self.ui.scrollAreaSubsets
assert isinstance(self.scrollArea, MapViewScrollArea)
self.scrollArea.horizontalScrollBar().valueChanged.connect(self.onVisibleMapsChanged)
self.scrollArea.horizontalScrollBar().rangeChanged.connect(self.onVisibleMapsChanged)
# self.scrollArea.sigResized.connect(self.onVisibleMapsChanged)
# self.scrollArea.sigResized.connect(self.refresh())
# self.scrollArea.horizontalScrollBar().valueChanged.connect(self.mRefreshTimer.start)
self.TSV = timeSeriesViewer
self.TS = timeSeriesViewer.timeSeries()
self.ui.dockMapViews.setTimeSeries(self.TS)
self.targetLayout = self.ui.scrollAreaSubsetContent.layout()
self.MVC = self.ui.dockMapViews
assert isinstance(self.MVC, MapViewDock)
self.MVC.sigShowProfiles.connect(self.sigShowProfiles.emit)
self.MVC.sigMapViewAdded.connect(self.onMapViewAdded)
self.MVC.sigMapViewAdded.connect(self.sigMapViewAdded.emit)
self.MVC.sigMapViewRemoved.connect(self.sigMapViewRemoved.emit)
self.vectorOverlay = None
self.DVC = DateViewCollection(self)
self.DVC.sigResizeRequired.connect(self.adjustScrollArea)
self.TS.sigTimeSeriesDatesAdded.connect(self.DVC.addDates)
self.TS.sigTimeSeriesDatesRemoved.connect(self.DVC.removeDates)
self.DVC.addDates(self.TS[:])
if len(self.TS) > 0:
self.setSpatialExtent(self.TS.maxSpatialExtent())
#self.setSubsetSize(QSize(100,50))
self.mMapRefreshTimer = QTimer(self)
self.mMapRefreshTimer.timeout.connect(self.timedCanvasRefresh)
self.mMapRefreshTimer.setInterval(500)
self.mMapRefreshTimer.start()
self.mNumberOfHiddenMapsToRefresh = 2
self.mCurrentLayer = None
self.mSyncLock = False
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
def setMapTool(self, mapToolKey):
mode = None
if mapToolKey == MapTools.SelectFeature:
if self.ui.optionSelectFeaturesRectangle.isChecked():
mode = QgsMapToolSelectionHandler.SelectionMode.SelectSimple
elif self.ui.optionSelectFeaturesPolygon.isChecked():
mode = QgsMapToolSelectionHandler.SelectionMode.SelectPolygon
elif self.ui.optionSelectFeaturesFreehand.isChecked():
mode = QgsMapToolSelectionHandler.SelectionMode.SelectFreehand
elif self.ui.optionSelectFeaturesRadius.isChecked():
mode = QgsMapToolSelectionHandler.SelectionMode.SelectRadius
else:
mode = QgsMapToolSelectionHandler.SelectionMode.SelectSimple
self.mMapToolKey = mapToolKey
self.mMapToolMode = mode
from .mapcanvas import MapCanvas, MapCanvasMapTools
for canvas in self.mapCanvases():
if isinstance(canvas, MapCanvas):
mapTools = canvas.mapTools()
mapTools.activate(mapToolKey)
mt = canvas.mapTool()
if isinstance(mt, QgsMapToolSelect):
mt.setSelectionMode(mode)
def setCurrentLayer(self, layer):
assert layer is None or isinstance(layer, QgsMapLayer)
self.mCurrentLayer = layer
for canvas in self.mapCanvases():
assert isinstance(canvas, QgsMapCanvas)
canvas.setCurrentLayer(layer)
def syncQGISCanvasCenter(self, qgisChanged:bool):
if self.mSyncLock:
return
iface = qgis.utils.iface
assert isinstance(iface, QgisInterface)
c = iface.mapCanvas()
if not isinstance(c, QgsMapCanvas):
return
tsvCenter = self.spatialExtent().spatialCenter()
qgsCenter = SpatialExtent.fromMapCanvas(c).spatialCenter()
if qgisChanged:
# change EOTSV
if tsvCenter.crs().isValid():
self.mSyncLock = True
qgsCenter = qgsCenter.toCrs(tsvCenter.crs())
if isinstance(qgsCenter, SpatialPoint):
self.setSpatialCenter(qgsCenter)
else:
# change QGIS
if qgsCenter.crs().isValid():
self.mSyncLock = True
tsvCenter = tsvCenter.toCrs(qgsCenter.crs())
if isinstance(tsvCenter, SpatialPoint):
c.setCenter(tsvCenter)
else:
pass

benjamin.jakimow@geo.hu-berlin.de
committed
def visibleMaps(self)->list:
"""
Returns a list of mapcanvas visible to the user
:return: [list-of-MapCanvases
"""
return [m for m in self.mapCanvases() if m.isVisibleToViewport()]
def onVisibleMapsChanged(self, *args):
visibleDates = set([m.tsd() for m in self.visibleMaps()])
if visibleDates != self.mVisibleDates:
self.mVisibleDates.clear()
self.mVisibleDates.update(visibleDates)
self.sigVisibleDatesChanged.emit(list(self.mVisibleDates))
self.mSyncLock = False
# do refresh maps
visibleMaps = self.visibleMaps()
hiddenMaps = sorted([m for m in self.mapCanvases() if not m.isVisibleToViewport()],
key = lambda c : self.scrollArea.distanceToCenter(c) )
n = 0
# redraw all visible maps
for c in visibleMaps:
assert isinstance(c, MapCanvas)
c.timedRefresh()
n += 1
if n < 10:
# refresh up to mNumberOfHiddenMapsToRefresh maps which are not visible to the user
i = 0
for c in hiddenMaps:
assert isinstance(c, MapCanvas)
c.timedRefresh()
i += 1
if i >= self.mNumberOfHiddenMapsToRefresh and not force:
break
def mapViewFromCanvas(self, mapCanvas:MapCanvas)->MapView:
"""
Returns the MapView a mapCanvas belongs to
:param mapCanvas: MapCanvas
:return: MapView
"""
for mapView in self.MVC:
assert isinstance(mapView, MapView)
if mapCanvas in mapView.mapCanvases():
return mapView
return None
def onMapViewAdded(self, *args):
self.adjustScrollArea()
s = ""
def createMapView(self)->MapView:

Benjamin Jakimow
committed
def registerMapCanvas(self, mapCanvas:MapCanvas):
"""
Connects a MapCanvas and its signals
:param mapCanvas: MapCanvas
"""
from eotimeseriesviewer.mapcanvas import MapCanvas
assert isinstance(mapCanvas, MapCanvas)
mapCanvas.setMapLayerStore(self.TSV.mMapLayerStore)
mapCanvas.sigCrosshairPositionChanged.connect(lambda point, canvas=mapCanvas: self.TSV.setCurrentLocation(point, canvas))

Benjamin Jakimow
committed
# set general canvas properties
mapCanvas.setFixedSize(self.mSize)
mapCanvas.setDestinationCrs(self.mCRS)
mapCanvas.setSpatialExtent(self.mSpatialExtent)

Benjamin Jakimow
committed
mapCanvas.sigSpatialExtentChanged.connect(self.setSpatialExtent)
mapCanvas.sigCrosshairPositionChanged.connect(self.onCrosshairChanged)
# activate the current map tool
mapTools = mapCanvas.mapTools()
mapTools.activate(self.mMapToolKey)
mt = mapCanvas.mapTool()
if isinstance(mt, QgsMapToolSelect):
mt.setSelectionMode(self.mMapToolMode)
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
def onCrosshairChanged(self, spatialPoint:SpatialPoint):
"""
Synchronizes all crosshair positions. Takes care of CRS differences.
:param spatialPoint: SpatialPoint of new Crosshair position
"""
from eotimeseriesviewer import CrosshairStyle
srcCanvas = self.sender()
if isinstance(srcCanvas, MapCanvas):
dstCanvases = [c for c in self.mapCanvases() if c != srcCanvas]
else:
dstCanvases = [c for c in self.mapCanvases()]
if isinstance(spatialPoint, SpatialPoint):
for mapCanvas in dstCanvases:
mapCanvas.setCrosshairPosition(spatialPoint, emitSignal=False)
def setCrosshairStyle(self, crosshairStyle:CrosshairStyle):
"""
Sets a crosshair style to all map canvas
:param crosshairStyle: CrosshairStyle
"""
for mapView in self.mapViews():
assert isinstance(mapView, MapView)
mapView.setCrosshairStyle(crosshairStyle)
def setCrosshairVisibility(self, b:bool):
"""
Sets the Crosshair visiblity
:param b: bool
"""
assert isinstance(b, bool)
self.onCrosshairChanged(b)
def setVectorLayer(self, lyr:QgsVectorLayer):
"""
Sets a QgsVectorLaye to be shown on top of raster images
:param lyr: QgsVectorLayer
"""
self.MVC.setVectorLayer(lyr)

Benjamin Jakimow
committed
def setMapSize(self, size):
assert isinstance(size, QSize)
self.mSize = size
from eotimeseriesviewer.mapcanvas import MapCanvas
for mapCanvas in self.mMapCanvases:
assert isinstance(mapCanvas, MapCanvas)
mapCanvas.setFixedSize(size)
self.sigMapSizeChanged.emit(self.mSize)
self.adjustScrollArea()

Benjamin Jakimow
committed
def mapSize(self)->QSize:
"""
Returns the MapCanvas size
:return: QSize
"""
return QSize(self.mSize)

Benjamin Jakimow
committed
def refresh(self):
"""
Refreshes all visible MapCanvases
"""
for c in self.mapCanvases():
assert isinstance(c, MapCanvas)
c.refresh()

Benjamin Jakimow
committed

Benjamin Jakimow
committed
def adjustScrollArea(self):
"""
Adjusts the scroll area widget to fit all visible widgets
"""
m = self.targetLayout.contentsMargins()
nX = len(self.DVC)
w = h = 0
s = QSize()
r = None
tsdViews = [v for v in self.DVC if v.ui.isVisible()]
mapViews = [v for v in self.MVC if v.isVisible()]
nX = len(tsdViews)
nY = len(mapViews)
spacing = self.targetLayout.spacing()
margins = self.targetLayout.contentsMargins()
sizeX = 1
sizeY = 50
if nX > 0:
s = tsdViews[0].ui.sizeHint().width()
s = nX * (s + spacing) + margins.left() + margins.right()
sizeX = s
if nY > 0 and nX > 0:
s = tsdViews[0].ui.sizeHint().height()
s = s + margins.top() + margins.bottom()
sizeY = s
#s = tsdViews[0].ui.sizeHint()
#s = QSize(nX * (s.width() + spacing) + margins.left() + margins.right(),
# s.height() + margins.top() + margins.bottom())
#print(sizeX, sizeY)
self.targetLayout.parentWidget().resize(QSize(sizeX, sizeY))
def onLocationRequest(self, pt:SpatialPoint, canvas:QgsMapCanvas):
def setSpatialCenter(self, center:SpatialPoint, mapCanvas0=None):
Sets the spatial center of all MapCanvases
:param center: SpatialPoint
:param mapCanvas0:
extent = self.spatialExtent()
if isinstance(extent, SpatialExtent):
centerOld = extent.center()
center = center.toCrs(extent.crs())
if center != centerOld:
extent = extent.__copy__()
extent.setCenter(center)
self.setSpatialExtent(extent)
def spatialCenter(self)->SpatialPoint:
return self.spatialExtent().spatialCenter()
Sets the spatial extent of all MapCanvases
:param extent: SpatialExtent
:param mapCanvas0:
:return:
lastExtent = self.spatialExtent()
extent = extent.toCrs(self.crs())
if not isinstance(extent, SpatialExtent) \
or extent.isEmpty() or not extent.isFinite() \
or extent.width() <= 0 \
or extent.height() <= 0 \
or extent == self.mSpatialExtent:
return
if self.mSpatialExtent == extent:
return
self.mSpatialExtent = extent
for mapCanvas in self.mapCanvases():
assert isinstance(mapCanvas, MapCanvas)

Benjamin Jakimow
committed
mapCanvas.addToRefreshPipeLine(extent)
if lastExtent != extent:
self.sigSpatialExtentChanged.emit(extent)
Returns the MapViewDock that controls all MapViews
:return: MapViewDock
Sets the MapCanvas background color
:param color: QColor
assert isinstance(self.MVC, MapViewDock)
self.MVC.setMapBackgroundColor(color)
Returns MapCanvases
:param mapView: a MapView to return MapCanvases from only, defaults to None
:return: [list-of-MapCanvas]
if isinstance(mapView, MapView):
s = ""
return self.mMapCanvases[:]
Returns a list of all mapviews
:return [list-of-MapViews]:
def setCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
if self.mCRS != crs:
transform = QgsCoordinateTransform()
transform.setSourceCrs(self.mCRS)
transform.setDestinationCrs(crs)
if transform.isValid() and not transform.isShortCircuited():
self.mCRS = crs
for mapCanvas in self.mapCanvases():
# print(('STV set CRS {} {}', str(mapCanvas), self.mCRS.description()))
mapCanvas.setDestinationCrs(QgsCoordinateReferenceSystem(crs))
"""
from timeseriesviewer.utils import saveTransform
if saveTransform(self.mSpatialExtent, self.mCRS, crs):
self.mCRS = crs
else:
pass
"""
self.sigCRSChanged.emit(self.crs())
def crs(self)->QgsCoordinateReferenceSystem:
"""
Returns the QgsCoordinateReferenceSystem
:return: QgsCoordinateReferenceSystem
"""
return self.mCRS
def spatialExtent(self)->SpatialExtent:
"""
Returns the SpatialExtent
:return: SpatialExtent
"""
return self.mSpatialExtent
def navigateToTSD(self, TSD:TimeSeriesDatum):
"""
Changes the viewport of the scroll window to show the requested TimeSeriesDatum
:param TSD: TimeSeriesDatum
"""
assert isinstance(TSD, TimeSeriesDatum)
#get widget related to TSD
tsdv = self.DVC.tsdView(TSD)
assert isinstance(self.scrollArea, QScrollArea)
self.scrollArea.ensureWidgetVisible(tsdv.ui)