Commit ec52d115 authored by Benjamin Jakimow's avatar Benjamin Jakimow

fixed MapCanvas.stretchToExtent for none-SensorProxyLayers

mapvisualization.py: added type hints
timeseries.py: added type hints, SensorInstrument mockup dataset copies wavelength information, optimized findMatchingSensor(), added tooltips to settings panel

pulled qps update on reading "μm"
update README.md
Signed-off-by: Benjamin Jakimow's avatarbenjamin.jakimow <benjamin.jakimow@geo.hu-berlin.de>
parent d945332f
......@@ -3,7 +3,7 @@
The EO Time Series Viewer is a [http://www.qgis.org](QGIS) plugin to visualize time series of remote sensing images.
Its major purpose is to ease the visualization and labeling of images from multiple sensors.
Please visit [Wiki](https://bitbucket.org/jakimowb/eo-time-series-viewer) for more information.
Please visit http://eo-time-series-viewer.readthedocs.io/en/latest/ for more information.
## Licence and Use ##
......
......@@ -1018,7 +1018,7 @@ def parseWavelength(dataset):
.format(key, len(tmp), dataset.RasterCount), file=sys.stderr)
if re.search(r'wavelength.units?', key):
if re.search(r'(Micrometers?|um)', values, re.I):
if re.search(r'(Micrometers?|um|μm)', values, re.I):
wlu = 'um' # fix with python 3 UTF
elif re.search(r'(Nanometers?|nm)', values, re.I):
wlu = 'nm'
......
......@@ -48,6 +48,7 @@ from eotimeseriesviewer.mapcanvas import MapCanvas
from eotimeseriesviewer.profilevisualization import SpectralTemporalVisualization
from eotimeseriesviewer.temporalprofiles import TemporalProfileLayer
from eotimeseriesviewer.mapvisualization import MapView, MapWidget
import eotimeseriesviewer.settings as eotsvSettings
from eotimeseriesviewer import SpectralProfile, SpectralLibrary, SpectralLibraryPanel
from eotimeseriesviewer.externals.qps.maptools import MapTools, CursorLocationMapTool, QgsMapToolSelect, QgsMapToolSelectionHandler
from eotimeseriesviewer.externals.qps.cursorlocationvalue import CursorLocationInfoModel, CursorLocationInfoDock
......@@ -341,9 +342,7 @@ class TimeSeriesViewer(QgisInterface, QObject):
QgisInterface.__init__(self)
QApplication.processEvents()
self.mMapLayerStore = QgsMapLayerStore()
import eotimeseriesviewer.utils
eotimeseriesviewer.utils.MAP_LAYER_STORES.insert(0, self.mapLayerStore())
TimeSeriesViewer._instance = self
self.ui = TimeSeriesViewerUI()
......@@ -351,6 +350,12 @@ class TimeSeriesViewer(QgisInterface, QObject):
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
assert isinstance(mvd, MapViewDock)
......@@ -374,6 +379,7 @@ class TimeSeriesViewer(QgisInterface, QObject):
self.mSpatialMapExtentInitialized = False
self.mTimeSeries.sigTimeSeriesDatesAdded.connect(self.onTimeSeriesChanged)
self.mTimeSeries.sigTimeSeriesDatesRemoved.connect(self.onTimeSeriesChanged)
self.mTimeSeries.sigSensorAdded.connect(self.onSensorAdded)
dts.setTimeSeries(self.mTimeSeries)
self.ui.dockSensors.setTimeSeries(self.mTimeSeries)
......@@ -1041,14 +1047,14 @@ class TimeSeriesViewer(QgisInterface, QObject):
self.mTimeSeries.loadFromFile(path, n_max=n_max, progressDialog=progressDialog, runAsync=runAsync)
def createMapView(self, name:str=None):
def createMapView(self, name:str=None)->MapView:
"""
Creates a new MapView.
:return: MapView
"""
return self.ui.dockMapViews.createMapView(name=name)
def mapViews(self)->list:
def mapViews(self)->typing.List[MapView]:
"""
Returns all MapViews
:return: [list-of-MapViews]
......@@ -1079,6 +1085,13 @@ class TimeSeriesViewer(QgisInterface, QObject):
self.messageBar().pushMessage(tag, message, level)
def onSensorAdded(self, sensor:SensorInstrument):
sensorNames = eotsvSettings.value(eotsvSettings.Keys.SensorNames, default=dict())
assert isinstance(sensorNames, dict)
if sensor.id() in sensorNames.keys():
sensor.setName(sensorNames[sensor.id()])
def onTimeSeriesChanged(self, *args):
if not self.mSpatialMapExtentInitialized:
......
......@@ -1209,6 +1209,9 @@ class MapCanvas(QgsMapCanvas):
if not isinstance(layer, QgsRasterLayer):
return
if not isinstance(spatialExtent, SpatialExtent):
spatialExtent = SpatialExtent.fromLayer(layer)
r = layer.renderer()
dp = layer.dataProvider()
newRenderer = None
......@@ -1276,7 +1279,7 @@ class MapCanvas(QgsMapCanvas):
if isinstance(layer, SensorProxyLayer):
self.mMapView.sensorProxyLayer(layer.sensor()).setRenderer(newRenderer)
elif isinstance(layer, QgsRasterLayer):
layer.setRenderer(layer)
layer.setRenderer(newRenderer)
def saveMapImageDialog(self, fileType):
......
......@@ -1136,14 +1136,14 @@ class MapWidget(QFrame, loadUIFormClass(jp(DIR_UI, 'mapwidget.ui'))):
"""
return self.mMapSize
def mapCanvases(self)->list:
def mapCanvases(self)->typing.List[MapCanvas]:
"""
Returns all MapCanvases
:return: [list-of-MapCanvases]
"""
return self.findChildren(MapCanvas)
def mapViewCanvases(self, mapView:MapView)->list:
def mapViewCanvases(self, mapView:MapView)->typing.List[MapCanvas]:
"""
Returns the MapCanvases related to a MapView
:param mapView: MapView
......
......@@ -206,8 +206,8 @@ class SensorInstrument(QObject):
if self.mNameOriginal in [None, '']:
from eotimeseriesviewer.settings import value, Keys
sensorNames = value(Keys.SensorNames, default={})
import eotimeseriesviewer.settings as settings
sensorNames = settings.value(settings.Keys.SensorNames, default={})
sensor_name = sensorNames.get(sid, '{}bands@{}m'.format(self.nb, self.px_size_x))
self.setName(sensor_name)
else:
......@@ -220,6 +220,11 @@ class SensorInstrument(QObject):
import uuid
path = '/vsimem/mockupImage.{}.bsq'.format(uuid.uuid4())
self.mMockupDS = TestObjects.inMemoryImage(path=path, nb=self.nb, eType=self.dataType, ns=2, nl=2)
if self.wl is not None:
self.mMockupDS.SetMetadataItem('wavelength', '{{{}}}'.format(','.join(str(wl) for wl in self.wl)))
if self.wlu is not None:
self.mMockupDS.SetMetadataItem('wavelength units', self.wlu)
self.mMockupDS.FlushCache()
s = ""
......@@ -572,6 +577,8 @@ class TimeSeriesSource(object):
uri.layerType = 'raster'
return uri
def asRasterLayer(self)->QgsRasterLayer:
return QgsRasterLayer(self.uri(), self.name(), 'gdal')
def pixelCoordinate(self, geometry)->QPoint:
"""
......@@ -1042,10 +1049,10 @@ class SensorMatching(enum.Enum):
"""
Describes when two different sources should be considered to be from the same sensor
"""
DIMS = 'Image Dimensions'
DIMS_WL = 'Img. Dims. + Wavelength'
DIMS_Name = 'Img. Dims. + Name'
DIMS_WL_Name = 'Img. Dims. + Wavelength + Name'
DIMS = 'Image Dimensions only'
DIMS_WL = 'Image Dimensions + Wavelength'
DIMS_Name = 'Image Dimensions + Name'
DIMS_WL_Name = 'Image Dimensions + Wavelength + Name'
def doLoadTimeSeriesSourcesTask(qgsTask:QgsTask, dump):
......@@ -1175,27 +1182,34 @@ class TimeSeries(QAbstractItemModel):
def findMatchingSensor(self, sensorID:str)->SensorInstrument:
if isinstance(sensorID, str):
nb, px_size_x, px_size_y, dt, wl, wlu, name = sensorIDtoProperties(sensorID)
else:
assert isinstance(sensorID, tuple) and len(sensorID) == 7
nb, px_size_x, px_size_y, dt, wl, wlu, name = sensorID
if self.mProductSimilarity == SensorMatching.DIMS:
for sensor in self.sensors():
if (sensor.nb, sensor.px_size_y, sensor.px_size_x, sensor.dataType) == (nb, px_size_y, px_size_x, dt):
return sensor
elif self.mProductSimilarity == SensorMatching.DIMS_Name:
for sensor in self.sensors():
if (sensor.nb, sensor.px_size_y, sensor.px_size_x, sensor.dataType, sensor.mNameOriginal) == (nb, px_size_y, px_size_x, dt, name):
return sensor
elif self.mProductSimilarity == SensorMatching.DIMS_WL:
for sensor in self.sensors():
if (sensor.nb, sensor.px_size_y, sensor.px_size_x, sensor.dataType, sensor.wl, sensor.wlu) == (nb, px_size_y, px_size_x, dt, wl, wlu):
return sensor
elif self.mProductSimilarity == SensorMatching.DIMS_WL_Name:
for sensor in self.sensors():
if (sensor.nb, sensor.px_size_y, sensor.px_size_x, sensor.dataType, sensor.wl, sensor.wlu, sensor.mNameOriginal) == (
nb, px_size_y, px_size_x, dt, wl, wlu, name):
return sensor
DIMS = (nb, px_size_y, px_size_x, dt)
for sensor in self.sensors():
DIMS2 = (sensor.nb, sensor.px_size_y, sensor.px_size_x, sensor.dataType)
bName = sensor.mNameOriginal == name
bWL = wlu == sensor.wlu and np.array_equal(wl, sensor.wl)
if DIMS != DIMS2:
# self.mProductSimilarity == SensorMatching.DIMS:
continue
if self.mProductSimilarity == SensorMatching.DIMS:
return sensor
elif self.mProductSimilarity == SensorMatching.DIMS_Name and bName:
return sensor
elif self.mProductSimilarity == SensorMatching.DIMS_WL and bWL:
return sensor
elif self.mProductSimilarity == SensorMatching.DIMS_WL_Name and bName and bWL:
return sensor
return None
def sensor(self, sensorID:str)->SensorInstrument:
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<width>592</width>
<height>326</height>
</rect>
</property>
......@@ -51,7 +51,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="pageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
......@@ -113,6 +113,9 @@
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbDateTimePrecission">
<property name="toolTip">
<string>Defines the accuracy with which source images of same sensor but different time stamps are combined into the same image group.</string>
</property>
<property name="whatsThis">
<string>Selects the precission used to extract time stamps from raster meta data.</string>
</property>
......@@ -127,6 +130,9 @@
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbSensorMatching">
<property name="toolTip">
<string>Specifies when source images should be considered to be from the same sensor/image product.</string>
</property>
<property name="whatsThis">
<string>Selects the precission used to extract time stamps from raster meta data.</string>
</property>
......@@ -219,6 +225,19 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
......@@ -267,6 +286,9 @@
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Intervall to check if updates are available for map canvases, e.g. to render new layers or apply renderer changes.</string>
</property>
<property name="suffix">
<string>msec</string>
</property>
......@@ -303,17 +325,17 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
<customwidget>
<class>QgsFontButton</class>
<extends>QToolButton</extends>
......
......@@ -101,7 +101,7 @@ class TestInit(TestCase):
TSV.show()
TSV.createMapView('True Color')
TSV.createMapView('Near Infrared')
#TSV.loadExampleTimeSeries()
TSV.loadExampleTimeSeries()
while QgsApplication.taskManager().countActiveTasks() > 0 or len(TSV.timeSeries().mTasks) > 0:
QCoreApplication.processEvents()
......
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