diff --git a/README.md b/README.md index 10674533e9b896cb7ffeedcb760d99f412afeeab..f8c80ec61d4b98d259fd2a4fed7528b1faf899fc 100644 --- a/README.md +++ b/README.md @@ -10,58 +10,7 @@ Its major aims are: (iii) to avoid a complicated installation process -The viewer works with the python packages that are part of the most recent [Quantum GIS (QGIS)](www.qgis.org) -installation. - - - - -## Features ## -+ Uses the [Geospatial Data Abstraction Library (GDAL)](www.gdal.org), which supports up to 142 raster image [formats](http://www.gdal.org/formats_list.html) -+ Recognizes the temporal order of input images implicitly. Date-time information is extracted automatically: -by evaluating each images meta data, the image filename or the entire file path to find a date-time stamp. -+ Supports different spatial projections: There is no need to warp the image data into one projection. -+ Supports different sensors: images similar in its spectral and spatial configuration are assumed to be taken by the same "sensor". -+ Visualizes multiple band combinations, separated by sensor -+ Spatial extends of image chips can be specified in QGIS by selection of single coodinate or rectangle -+ Color scaling is applied to the entire time series, e.g. to visualize and compare surface reflectance data - - - -## Missing Features / ToDo's ## - -Several. It try to keep an updates list in the [issue section](https://bitbucket.org/jakimowb/sensecarbontsviewer/issues). -Some of them: - -+ on-the-fly calculation of (simple) spectral indices -+ colorbar/gradient visualization of single bands -+ support of mask information -+ temporal & spectral profiles -+ drag 'n drop interactivity -+ python2 and python 3 interoperability - -Your feedback (wishes, comments, bugs, ...) is always welcome: [benjamin.jakimow@geo.hu-berlin.de](benjamin.jakimow@geo.hu-berlin.de). - - -## Installation ## -You really want to use [git](https://en.wikipedia.org/wiki/Git_%28software%29) to install and update the viewer. - -If git is not available in your shell, you can download it from [https://git-scm.com/downloads](https://git-scm.com/downloads). You can install git without admin rights. - - -### Windows ### - -1. Open your command line and clone this repository to your local QGIS Python Plugin Folder - - cd %USERPROFILE%\.qgis2\python\plugins - git clone https://jakimowb@bitbucket.org/jakimowb/sensecarbontsviewer.git - -2. Start QGIS, go to Plugins -> Manage and Install and enable the "SenseCarbon TSV" Plugin -3. Download updates if available - - cd %USERPROFILE%\.qgis2\python\plugins\sensecarbontsviewer - git pull - +Please check the [Wiki](https://bitbucket.org/jakimowb/sensecarbontsviewer/wiki/Home) for more information. ## Licence and Use ## diff --git a/qgis_add_ins.py b/qgis_add_ins.py index 5f6df12755fb1a3ec5dc81bf1ebc5eb93ee036f1..9fac5d7f7c8fcb54a26b69578cc2e9b9b4679185 100644 --- a/qgis_add_ins.py +++ b/qgis_add_ins.py @@ -14,7 +14,20 @@ def add_QgsRasterLayer(iface, path, rgb): if not layer.isValid(): six.print_('Failed to load {}'.format(path)) else: - iface.addRasterLayer(path, fi.baseName()) + rasterLyr = iface.addRasterLayer(path, fi.baseName()) + + + renderer = rasterLyr.renderer() + print(type(renderer)) + + if type(renderer) is QgsMultiBandColorRenderer: + renderer.setRedBand(rgb[0]) + renderer.setGreenBand(rgb[0]) + renderer.setBlueBand(rgb[0]) + + if hasattr(layer, "triggerRepaint"): + #layer.repaintRequested() + layer.triggerRepaint() s = "" @@ -85,7 +98,7 @@ class RectangleMapTool(QgsMapToolEmitPoint): r = self.rectangle() self.reset() - if wkt: + if wkt is not None and r is not None: self.rectangleDrawed.emit(r, wkt) diff --git a/sensecarbon_tsv.py b/sensecarbon_tsv.py index c8ada3cbb497fa02b7b4a72d6e7d861d769cbe43..7a1bb8f0a1ac8d6cca1e5060c5d3cd3802bd39db 100644 --- a/sensecarbon_tsv.py +++ b/sensecarbon_tsv.py @@ -28,7 +28,7 @@ from qgis.core import * from osgeo import gdal, ogr, osr, gdal_array - +DEBUG = True try: from qgis.gui import * @@ -39,32 +39,44 @@ except: qgis_available = False import numpy as np -import tsv_widgets import six import multiprocessing +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +#abbreviations +mkdir = lambda p: os.makedirs(p, exist_ok=True) +jp = os.path.join -#I don't know why but this is required to run this in QGIS +def expand_python_path(path): + if path not in sys.path: + sys.path.append(path) -path = os.path.abspath(os.path.join(sys.exec_prefix, '../../bin/pythonw.exe')) + + +#I don't know why, but this is required to run this in QGIS +path = os.path.abspath(jp(sys.exec_prefix, '../../bin/pythonw.exe')) if os.path.exists(path): multiprocessing.set_executable(path) sys.argv = [ None ] -pluginDir = os.path.dirname(__file__) -sys.path.append(pluginDir) -sys.path.append(os.path.join(pluginDir, 'libs')) -#sys.path.append(os.path.join(pluginDir, *['libs','qimage2ndarray'])) -sys.path.append(os.path.join(pluginDir, *['libs','qrangeslider-0.1.1'])) -sys.path.append(os.path.join(pluginDir, *['libs','pyqtgraph'])) +#ensure that required non-standard modules are available +PLUGIN_DIR = os.path.dirname(__file__) +LIB_DIR = jp(PLUGIN_DIR, 'libs') +expand_python_path(PLUGIN_DIR) +expand_python_path(LIB_DIR) +try: + import pyqtgraph +except: + expand_python_path(jp(LIB_DIR,'pyqtgraph')) import pyqtgraph as pg -from PyQt4.QtCore import * -from PyQt4.QtGui import * -from sensecarbon_tsv_gui import SenseCarbon_TSVGui +import tsv_widgets +from sensecarbon_tsv_gui import * + -DEBUG = True regLandsatSceneID = re.compile(r"L[EMCT][1234578]{1}[12]\d{12}[a-zA-Z]{3}\d{2}") @@ -85,6 +97,7 @@ def file_search(rootdir, wildcard, recursive=False, ignoreCase=False): return results + class TimeSeriesTableModel(QAbstractTableModel): columnames = ['date','sensor','ns','nl','nb','image','mask'] @@ -239,13 +252,9 @@ LUT_SensorNames = {(6,30.,30.): 'L7 ETM+' \ class BandView(object): - - - - - def __init__(self, TS): + def __init__(self, TS, recommended_bands=None): assert type(TS) is TimeSeries - self.bandMappings = collections.OrderedDict() + self.representation = collections.OrderedDict() self.TS = TS self.TS.sensorAdded.connect(self.initSensor) @@ -253,21 +262,26 @@ class BandView(object): import copy for sensor in self.Sensors: - self.initSensor(copy.deepcopy(sensor)) + self.initSensor(copy.deepcopy(sensor), recommended_bands=recommended_bands) - def initSensor(self, sensor): + def initSensor(self, sensor, recommended_bands=None): assert type(sensor) is SensorConfiguration - if sensor not in self.bandMappings.keys(): + if sensor not in self.representation.keys(): #self.bandMappings[sensor] = ((0, 0, 5000), (1, 0, 5000), (2, 0, 5000)) #x = imagechipviewsettings_widget.ImageChipViewSettings(sensor) #x = tsv_widgets.BandViewSettings(sensor) x = tsv_widgets.ImageChipViewSettings(sensor) + + if recommended_bands is not None: + assert min(recommended_bands) > 0 + if max(recommended_bands) < sensor.nb: + x.setBands(recommended_bands) x.create() - self.bandMappings[sensor] = x + self.representation[sensor] = x def getSensorStats(self, sensor, bands): @@ -281,7 +295,7 @@ class BandView(object): def getWidget(self, sensor): assert type(sensor) is SensorConfiguration - return self.bandMappings[sensor] + return self.representation[sensor] def getBands(self, sensor): return self.getWidget(sensor).getBands() @@ -1874,15 +1888,15 @@ class SenseCarbon_TSV: def ua_addBandView(self, band_recommendation = [3, 2, 1]): - self.BAND_VIEWS.append(BandView(self.TS)) + self.BAND_VIEWS.append(BandView(self.TS, recommended_bands=band_recommendation)) self.refreshBandViews() def refreshBandViews(self): if len(self.BAND_VIEWS) == 0 and len(self.TS) > 0: - self.ua_addBandView([3, 2, 1]) - self.ua_addBandView([4, 5, 3]) + self.ua_addBandView(band_recommendation=[3, 2, 1]) + self.ua_addBandView(band_recommendation=[4, 5, 3]) self.clearLayoutWidgets(self.BVP)