Commit 3c7aa3f0 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

fixed default stretch of raster images


MapTextFormat is saved in settings based on project settings
Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow <benjamin.jakimow@geo.hu-berlin.de>
parent 288c9c02
Pipeline #12484 failed
......@@ -21,15 +21,15 @@ import pathlib
import sys
from qgis.gui import QgisInterface
def run():
# add site-packages to sys.path
pluginDir = pathlib.Path(__file__).parents[1]
sys.path.append(pluginDir.as_posix())
print(pluginDir)
from eotimeseriesviewer.tests import start_app
import qgis.utils
from qgis.gui import QgisInterface
qgisIface = isinstance(qgis.utils.iface, QgisInterface)
if not qgisIface:
......
......@@ -1382,9 +1382,6 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
def onTimeSeriesChanged(self, *args):
if not self.mSpatialMapExtentInitialized:
if len(self.mTimeSeries) > 0:
if len(self.ui.dockMapViews) == 0:
self.ui.dockMapViews.createMapView()
extent = self.timeSeries().maxSpatialExtent()
if isinstance(extent, SpatialExtent):
self.mapWidget().setCrs(extent.crs())
......@@ -1401,6 +1398,9 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
tsd = self.timeSeries()[0]
self.setCurrentDate(tsd)
if len(self.ui.dockMapViews) == 0:
self.ui.dockMapViews.createMapView()
if len(self.mTimeSeries) == 0:
self.mSpatialMapExtentInitialized = False
......
......@@ -520,7 +520,7 @@ class MapCanvas(QgsMapCanvas):
self.mMapView = mapView
self.mInfoItem.setTextFormat(mapView.mapTextFormat())
self.addToRefreshPipeLine(mapView.mapBackgroundColor())
#self.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
# self.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
def setTSD(self, tsd: TimeSeriesDate):
"""
......@@ -711,24 +711,18 @@ class MapCanvas(QgsMapCanvas):
sourceLayer = existing[existingSources.index(source)]
else:
# add new layer
loadDefaultStyle = not mapView.mLayerStyleInitialized.get(sensor, False)
loadDefaultStyle = mapView.mLayerStyleInitialized.get(sensor, False) == False
master: SensorProxyLayer = mapView.sensorProxyLayer(sensor)
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
sourceLayer.setMapLayerStyle(master.mapLayerStyle())
sourceLayer.styleChanged.connect(lambda *args, l=sourceLayer: self.onSetMasterLayerStyle(l))
if loadDefaultStyle:
mapView.mLayerStyleInitialized[sensor] = True
mapView.sensorProxyLayer(sensor).setMapLayerStyle(sourceLayer.mapLayerStyle())
assert isinstance(sourceLayer, QgsRasterLayer)
expected.append(sourceLayer)
else:
......@@ -742,8 +736,6 @@ class MapCanvas(QgsMapCanvas):
return
else:
lyrs = self.layers()
if lyrs != expected:
self.setLayers(expected)
if True:
# set sources first
......@@ -761,32 +753,35 @@ class MapCanvas(QgsMapCanvas):
if QColor in keys:
self.setCanvasColor(self.mTimedRefreshPipeLine.pop(QColor))
if lyrs != expected:
self.setLayers(expected)
if MapCanvas.Command in keys:
commands = self.mTimedRefreshPipeLine.pop(MapCanvas.Command)
#print(commands)
# print(commands)
for command in commands:
assert isinstance(command, MapCanvas.Command)
if command == MapCanvas.Command.RefreshRenderer:
sensor = self.tsd().sensor()
#master = self.mapView().sensorProxyLayer(sensor)
#masterStyle = QgsMapLayerStyle()
#masterStyle.readFromLayer(master)
#masterStyleXML = masterStyle.xmlData()
# master = self.mapView().sensorProxyLayer(sensor)
# masterStyle = QgsMapLayerStyle()
# masterStyle.readFromLayer(master)
# masterStyleXML = masterStyle.xmlData()
for l in self.layers():
if isinstance(l, SensorProxyLayer) and l.sensor() == sensor:
l.triggerRepaint()
#style = QgsMapLayerStyle()
#style.readFromLayer(l)
#if style.xmlData() == masterStyleXML:
# style = QgsMapLayerStyle()
# style.readFromLayer(l)
# if style.xmlData() == masterStyleXML:
# print(style.xmlData())
# s = ""
#else:
# else:
# style.writeToLayer(l)
self.mTimedRefreshPipeLine.clear()
#self.freeze(False)
# self.freeze(False)
self.refresh()
# is this really required?
......@@ -1177,16 +1172,15 @@ class MapCanvas(QgsMapCanvas):
def onSetLayerProperties(self, lyr: QgsRasterLayer):
showLayerPropertiesDialog(lyr, self, useQGISDialog=True)
#if isinstance(lyr, SensorProxyLayer):
# if isinstance(lyr, SensorProxyLayer):
# #print('# MAPCANVAS :onsetLayerProperties: SET')
# r = lyr.renderer().clone()
# proxyLayer = self.mMapView.sensorProxyLayer(lyr.sensor())
# r.setInput(proxyLayer.dataProvider())
# proxyLayer.setRenderer(r)
#else:
# else:
# #print('# MAPCANVAS :onsetLayerProperties: not a SensorProxyLayer')
def onOpenLayersInQGIS(self, mapLayers: typing.List[QgsMapLayer]):
layers = []
......@@ -1347,6 +1341,9 @@ class MapCanvas(QgsMapCanvas):
if isinstance(layer, QgsRasterLayer):
layer.setRenderer(newRenderer)
return True
return False
def saveMapImageDialog(self, fileType):
"""
......
......@@ -92,8 +92,8 @@ class MapView(QFrame):
loadUi(DIR_UI / 'mapview.ui', self)
# self.setupUi(self)
from eotimeseriesviewer.settings import defaultValues, Keys
DEFAULT_VALUES = defaultValues()
from eotimeseriesviewer.settings import values, Keys
DEFAULT_VALUES = values()
self.mMapBackgroundColor = DEFAULT_VALUES[Keys.MapBackgroundColor]
self.mMapTextFormat = DEFAULT_VALUES[Keys.MapTextFormat]
self.mMapWidget = None
......@@ -231,11 +231,6 @@ class MapView(QFrame):
nodeMapView.setAttribute('showSensorName', str(self.optionShowSensorName.isChecked()))
nodeMapView.setAttribute('showMapViewName', str(self.optionShowMapViewName.isChecked()))
"""
m.addAction(self.optionShowDate)
m.addAction(self.optionShowSensorName)
m.addAction(self.optionShowMapViewName)
"""
context = QgsReadWriteContext()
nodeTextStyle = self.mapTextFormat().writeXml(doc, context)
nodeMapView.appendChild(nodeTextStyle)
......@@ -1046,7 +1041,7 @@ class MapWidget(QFrame):
self.mSpatialExtent: SpatialExtent = SpatialExtent.world()
self.mCrs: QgsCoordinateReferenceSystem = self.mSpatialExtent.crs()
self.mCrsInitialized = False
self.mCrsInitialized: bool = False
self.mCurrentDate: TimeSeriesDate = None
self.mCrosshairPosition: SpatialPoint = None
......@@ -1222,7 +1217,7 @@ class MapWidget(QFrame):
for mapView in self.mapViews():
# test for initial raster stretches
for sensor in self.timeSeries().sensors():
if not mapView.mLayerStyleInitialized.get(sensor):
if mapView.mLayerStyleInitialized.get(sensor, False) == False:
for c in self.mapViewCanvases(mapView):
# find the first map canvas that contains layer data of this sensor
# in its extent
......@@ -1274,6 +1269,7 @@ class MapWidget(QFrame):
:param doc:
:return:
"""
context = QgsReadWriteContext()
mwNode = doc.createElement('EOTSV_MAPWIDGET')
mapSize = self.mapSize()
mwNode.setAttribute('mapsPerMapView', f'{self.mapsPerMapView()}')
......@@ -1290,7 +1286,7 @@ class MapWidget(QFrame):
return True
def readXml(self, node: QDomNode):
from .settings import setValue, Keys
if not node.nodeName() == 'EOTSV_MAPWIDGET':
node = node.firstChildElement('EOTSV_MAPWIDGET')
if node.isNull():
......@@ -1303,7 +1299,9 @@ class MapWidget(QFrame):
int(node.attribute('mapWidth')),
int(node.attribute('mapHeight'))
)
self.setMapSize(mapSize)
setValue(Keys.MapSize, mapSize)
nodeExtent = node.firstChildElement('MapExtent')
if nodeExtent.nodeName() == 'MapExtent':
......@@ -1313,13 +1311,18 @@ class MapWidget(QFrame):
self.setSpatialExtent(extent)
mvNode = node.firstChildElement('MapView').toElement()
while mvNode.nodeName() == 'MapView':
mapView = MapView.readXml(mvNode)
if isinstance(mapView, MapView):
setValue(Keys.MapTextFormat, mapView.mapTextFormat())
setValue(Keys.MapBackgroundColor, mapView.mapBackgroundColor())
for s in mapView.sensors():
self.timeSeries().addSensor(s)
self.addMapView(mapView)
mvNode = mvNode.nextSibling().toElement()
def usedLayers(self) -> typing.List[QgsMapLayer]:
......@@ -1583,6 +1586,8 @@ class MapWidget(QFrame):
self.sigMapViewsChanged.emit()
self.sigMapViewAdded.emit(mapView)
s = ""
if not isinstance(self.mCurrentMapView, MapView):
self.mCurrentMapView = mapView
......
......@@ -57,6 +57,7 @@ def defaultValues() -> dict:
d[Keys.SensorMatching] = SensorMatching.PX_DIMS
import eotimeseriesviewer
d[Keys.Debug] = eotimeseriesviewer.DEBUG
# map visualization
d[Keys.MapUpdateInterval] = 500 # milliseconds
d[Keys.MapSize] = QSize(150, 150)
......
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