Newer
Older
# -*- coding: utf-8 -*-
"""
/***************************************************************************
EnMAPBox
A QGIS plugin
EnMAP-Box V3
-------------------
begin : 2015-08-20
git sha : $Format:%H$
copyright : (C) 2015 by HU-Berlin
email : bj@geo.hu-berlin.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os, sys, re, fnmatch, collections, copy, traceback, six
from qgis.core import *
#os.environ['PATH'] += os.pathsep + r'C:\OSGeo4W64\bin'
from osgeo import gdal, ogr, osr, gdal_array

Benjamin Jakimow
committed
#import console.console_output
#console.show_console()
#sys.stdout = console.console_output.writeOut()
#sys.stderr = console.console_output.writeOut()

Benjamin Jakimow
committed
print('Can not find QGIS instance')

Benjamin Jakimow
committed

Benjamin Jakimow
committed
import code
import codecs
from timeseriesviewer import jp, mkdir, DIR_SITE_PACKAGES, file_search, dprint
from timeseriesviewer.timeseries import *
#I don't know why, but this is required to run this in QGIS
#todo: still required?
path = os.path.abspath(jp(sys.exec_prefix, '../../bin/pythonw.exe'))
if os.path.exists(path):
multiprocessing.set_executable(path)
sys.argv = [ None ]
#ensure that required non-standard modules are available
import pyqtgraph as pg
"""
Object to keep QgsRectangle and QgsCoordinateReferenceSystem together
"""

benjamin.jakimow@geo.hu-berlin.de
committed
@staticmethod
def fromMapCanvas(mapCanvas):
assert isinstance(mapCanvas, QgsMapCanvas)
extent = mapCanvas.extent()
crs = mapCanvas.mapSettings().destinationCrs()
return SpatialExtent(crs, extent)
def __init__(self, crs, *args):
assert isinstance(crs, QgsCoordinateReferenceSystem)
super(SpatialExtent, self).__init__(*args)
self.mCrs = crs
def setCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
self.mCrs = crs
def crs(self):
return self.mCrs
def toCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
if self.mCrs != crs:
trans = QgsCoordinateTransform(self.mCrs, crs)
box = trans.transformBoundingBox(box)
return SpatialExtent(crs, box)
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def __copy__(self):
return SpatialExtent(self.crs(), QgsRectangle(self))
def combineExtentWith(self, *args):
if args is None:
return
elif isinstance(args[0], SpatialExtent):
extent2 = args[0].toCrs(self.crs())
self.combineExtentWith(QgsRectangle(extent2))
else:
super(SpatialExtent, self).combineExtentWith(*args)
def setCenter(self, centerPoint, crs=None):
if crs and crs != self.crs():
trans = QgsCoordinateTransform(crs, self.crs())
centerPoint = trans.transform(centerPoint)
delta = centerPoint - self.center()
self.setXMaximum(self.xMaximum() + delta.x())
self.setXMinimum(self.xMinimum() + delta.x())
self.setYMaximum(self.yMaximum() + delta.y())
self.setYMinimum(self.yMinimum() + delta.y())
def __cmp__(self, other):
if other is None: return 1
def __eq__(self, other):
s = ""
def __sub__(self, other):
raise NotImplementedError()
def __mul__(self, other):
raise NotImplementedError()

benjamin.jakimow@geo.hu-berlin.de
committed
def upperLeft(self):
return self.xMinimum(), self.yMaximum()
def lowerRight(self):
return self.xMaximum(), self.yMinimum()
def __repr__(self):
return '{} {} {}'.format(self.upperLeft(), self.lowerRight(), self.crs().authid())
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
class TsvMimeDataUtils(QObject):
def __init__(self, mimeData):
assert isinstance(mimeData, QMimeData)
super(TsvMimeDataUtils, self).__init__()
self.mimeData = mimeData
self.xmlDoc = QDomDocument()
if self.mimeData.hasText():
self.xmlDoc.setContent(self.mimeData.text())
self.xmlRoot = self.xmlDoc.documentElement()
pass
def hasRasterStyle(self):
if self.xmlRoot.tagName() == 'qgis':
elem = self.xmlRoot.elementsByTagName('rasterrenderer')
return elem.count() != 0
return False
def rasterStyle(self, qgisDataType):
elem = self.xmlRoot.elementsByTagName('rasterrenderer').item(0).toElement()
type = str(elem.attribute('type'))
from qgis.core import QGis, QgsContrastEnhancement
def bandSettings(colorName):
band = int(elem.attribute(colorName + 'Band'))
ceNode = elem.elementsByTagName(colorName + 'ContrastEnhancement').item(0)
vMin = float(ceNode.firstChildElement('minValue').firstChild().nodeValue())
vMax = float(ceNode.firstChildElement('maxValue').firstChild().nodeValue())
ceName = ceNode.firstChildElement('algorithm').firstChild().nodeValue()
ceAlg = QgsContrastEnhancement.contrastEnhancementAlgorithmFromString(ceName)
ce = QgsContrastEnhancement(qgisDataType)
ce.setContrastEnhancementAlgorithm(ceAlg)
ce.setMinimumValue(vMin)
ce.setMaximumValue(vMax)
return band, ce
style = None
if type == 'multibandcolor':
A = int(elem.attribute('alphaBand'))
O = int(elem.attribute('opacity'))
R, ceR = bandSettings('red')
Loading
Loading full blame...