Newer
Older
self.plot3D.removeItems(toRemove)
toAdd = [item for item in allPlotItems if item not in self.plot3D.items]
self.plot3D.addItems(toAdd)
# 3. add new plot items
for plotStyle3D in self.plotSettingsModel3D:
assert isinstance(plotStyle3D, TemporalProfile3DPlotStyle)
items = plotStyle3D.createPlotItem(None)
plotItems.extend(items)
self.plot3D.addItems(plotItems)
self.plot3D.updateDataRanges()
self.plot3D.resetScaling()
@QtCore.pyqtSlot()
def updatePlot2D(self):
if isinstance(self.plotSettingsModel2D, PlotSettingsModel2D):
for plotStyle in self.plotSettingsModel2D:
assert isinstance(plotStyle, TemporalProfile2DPlotStyle)
if plotStyle.isPlotable():
locations.add(plotStyle.temporalProfile().mCoordinate)
for pdi in plotStyle.mPlotItems:
assert isinstance(pdi, TemporalProfilePlotDataItem)
pdi.updateDataAndStyle()
#2. load pixel data
self.loadCoordinate(list(locations))
# https://github.com/pyqtgraph/pyqtgraph/blob/5195d9dd6308caee87e043e859e7e553b9887453/examples/customPlot.py
return
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
# prepare QGIS environment
if sys.platform == 'darwin':
PATH_QGS = r'/Applications/QGIS.app/Contents/MacOS'
os.environ['GDAL_DATA'] = r'/usr/local/Cellar/gdal/1.11.3_1/share'
else:
# assume OSGeo4W startup
PATH_QGS = os.environ['QGIS_PREFIX_PATH']
assert os.path.exists(PATH_QGS)
qgsApp = QgsApplication([], True)
QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns')
QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns/qgis')
qgsApp.setPrefixPath(PATH_QGS, True)
qgsApp.initQgis()
gb = QGroupBox()
gb.setTitle('Sandbox')
PL = PixelLoader()
if False:
files = ['observationcloud/testdata/2014-07-26_LC82270652014207LGN00_BOA.bsq',
'observationcloud/testdata/2014-08-03_LE72270652014215CUB00_BOA.bsq'
]
else:
from timeseriesviewer.utils import file_search
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
searchDir = r'H:\LandsatData\Landsat_NovoProgresso'
files = file_search(searchDir, '*227065*band4.img', recursive=True)
#files = files[0:3]
lyr = QgsRasterLayer(files[0])
coord = lyr.extent().center()
crs = lyr.crs()
l = QVBoxLayout()
btnStart = QPushButton()
btnStop = QPushButton()
prog = QProgressBar()
tboxResults = QPlainTextEdit()
tboxResults.setMaximumHeight(300)
tboxThreads = QPlainTextEdit()
tboxThreads.setMaximumHeight(200)
label = QLabel()
label.setText('Progress')
def showProgress(n,m,md):
prog.setMinimum(0)
prog.setMaximum(m)
prog.setValue(n)
info = []
for k, v in md.items():
info.append('{} = {}'.format(k,str(v)))
tboxResults.setPlainText('\n'.join(info))
#tboxThreads.setPlainText(PL.threadInfo())
qgsApp.processEvents()
PL.sigPixelLoaded.connect(showProgress)
btnStart.setText('Start loading')
btnStart.clicked.connect(lambda : PL.startLoading(files, coord, crs))
btnStop.setText('Cancel')
btnStop.clicked.connect(lambda: PL.cancelLoading())
lh = QHBoxLayout()
lh.addWidget(btnStart)
lh.addWidget(btnStop)
l.addLayout(lh)
l.addWidget(prog)
l.addWidget(tboxThreads)
l.addWidget(tboxResults)
gb.setLayout(l)
gb.show()
#rs.setBackgroundStyle('background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #222, stop:1 #333);')
#rs.handle.setStyleSheet('background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #282, stop:1 #393);')
qgsApp.exec_()
qgsApp.exitQgis()
if __name__ == '__main__':
import site, sys
qgsApp = utils.initQgisApplication(qgisDebug=True)
import itertools
lot = list(itertools.product([1,2,3,4,5,6,7], [87,88,89]))
arr = np.asanyarray(lot, dtype=tuple)
lot = [(1,2),(2,3)]
t1 =(1,2)
t2 =(2,3,3,4,5)
arr[0,0] = t1
arr[1,1] = t2
if False:
f = QgsFeature()
fields = QgsFields()
field = QgsField('b', QVariant.Double, 'double', 40, 5)
fields.append(field)
f.setFields(fields)
expr = QgsExpression('b')
for n in [23, 42.24, None]:
f.setAttribute('b', n)
context = QgsExpressionContextUtils.createFeatureBasedContext(f, f.fields())
r = expr.evaluate(context)
if False: #the ultimative test for floating point division correctness, at least on a DOY-level
date1 = np.datetime64('1960-12-31','D')
assert date1 == num2date(date2num(date1))
#1960 - 12 - 31
for year in range(1960, 2057):
for doy in range(1, daysPerYear(year)+1):
dt = datetime.timedelta(days=doy - 1)
date1 = np.datetime64('{}-01-01'.format(year)) + np.timedelta64(doy-1,'D')
date2 = datetime.date(year=year, month=1, day=1) + datetime.timedelta(days=doy-1)
assert date1 == num2date(date2num(date1), dt64=True), 'date1: {}'.format(date1)
assert date2 == num2date(date2num(date2), dt64=False), 'date2: {}'.format(date1)
STVis = SpectralTemporalVisualization(ui)
STVis.setTimeSeries(TS)
files = file_search(os.path.dirname(example.Images.__file__), '*.tif')
for tsd in TS:
ext = tsd.spatialExtent()
if ext.crs().description() != '':
break
cpND = SpatialPoint(ext.crs(), 681151.214,-752388.476)
cp2 = SpatialPoint(ext.crs(), ext.center())
cp3 = SpatialPoint(ext.crs(), ext.center().x()+500, ext.center().y()+250)
STVis.createNewPlotStyle2D()
def addProfile():
x0,y1 = ext.upperLeftPt()
x1,y0 = ext.lowerRightPt()
x = x0 + (x1 - x0) * np.random.sample()
y = y0 + (y1 - y0) * np.random.sample()
pt = SpatialPoint(ext.crs(), x, y)
btn = QPushButton('Add Profile')
btn.clicked.connect(addProfile)
btn.show()
if False:
for tp in STVis.tpCollection:
assert isinstance(tp, TemporalProfile)
tp.plot()
#STVis.tpCollection.removeTemporalProfiles(STVis.tpCollection[-1])
STVis.createNewPlotStyle3D()
STVis.loadCoordinate(cpND, backgroundProcess=False)
STVis.tpCollection.mTemporalProfiles[0].setName('My Name')

Benjamin Jakimow
committed
from example import exampleEvents
#STVis.loadCoordinatesFromOgr(exampleEvents)
# STVis.loadCoordinate(cp2)
# STVis.loadCoordinate(cp3)