screenshots.py 4.21 KB
Newer Older
Benjamin Jakimow's avatar
Benjamin Jakimow committed
1
2
3


#
Benjamin Jakimow's avatar
Benjamin Jakimow committed
4
5
6
7
8
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtWidgets import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
Benjamin Jakimow's avatar
Benjamin Jakimow committed
9
10
from timeseriesviewer.utils import *
from timeseriesviewer.main import TimeSeriesViewer
Benjamin Jakimow's avatar
Benjamin Jakimow committed
11
12
13
from timeseriesviewer.mapvisualization import *
from timeseriesviewer.profilevisualization import *
from timeseriesviewer.timeseries import *
Benjamin Jakimow's avatar
Benjamin Jakimow committed
14
15
16
17
18
19
20
21
22
from timeseriesviewer import DIR_REPO, DIR_QGIS_RESOURCES
DIR_SCREENSHOTS = jp(DIR_REPO, 'screenshots')
os.makedirs(DIR_SCREENSHOTS, exist_ok=True)

app = initQgisApplication(qgisResourceDir=DIR_QGIS_RESOURCES)

TS = TimeSeriesViewer(None)
TS.show()

Benjamin Jakimow's avatar
Benjamin Jakimow committed
23
24
25
26
#set up example settings
from example.Images import Img_2014_04_21_LC82270652014111LGN00_BOA, re_2014_06_25
#TS.loadExampleTimeSeries()
TS.loadImageFiles([Img_2014_04_21_LC82270652014111LGN00_BOA, re_2014_06_25])
Benjamin Jakimow's avatar
Benjamin Jakimow committed
27
28
29



Benjamin Jakimow's avatar
Benjamin Jakimow committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
sensorLS = None
sensorRE = None
for sensor in TS.TS.sensors():
    assert isinstance(sensor, SensorInstrument)

    if sensor.id() == '6b30.0m0.49;0.56;0.66;0.84;1.65;2.2um':
        sensor.setName('Landsat')
        sensorLS = sensor
    if sensor.id() == '5b5.0m':
        sensor.setName('RapidEye')
        sensorRE = sensor

assert isinstance(sensorLS, SensorInstrument)
assert isinstance(sensorRE, SensorInstrument)


#add second MapView
TS.createMapView()

mv1 = TS.mapViews()[0]
mv2 = TS.mapViews()[1]
assert isinstance(mv1, MapView)
assert isinstance(mv2, MapView)
mv1.setTitle('True Color')
mv2.setTitle('Short-Wave IR')

#set True Color Bands
for sensor in [sensorLS, sensorRE]:
    rendering = mv1.sensorWidget(sensor)
    assert isinstance(rendering, MapViewRenderSettings)
    renderer = rendering.rasterRenderer()
    assert isinstance(renderer, QgsMultiBandColorRenderer)
    renderer.setRedBand(3)
    renderer.setGreenBand(2)
    renderer.setBlueBand(1)
    rendering.setRasterRenderer(renderer)

#set swIR-nIR-R Bands
rendering = mv2.sensorWidget(sensorLS)
assert isinstance(rendering, MapViewRenderSettings)
renderer = rendering.rasterRenderer()
assert isinstance(renderer, QgsMultiBandColorRenderer)
renderer.setRedBand(4)
renderer.setGreenBand(5)
renderer.setBlueBand(3)
rendering.setRasterRenderer(renderer)

rendering = mv2.sensorWidget(sensorRE)
assert isinstance(rendering, MapViewRenderSettings)
renderer = rendering.rasterRenderer()
assert isinstance(renderer, QgsMultiBandColorRenderer)
renderer.setRedBand(5)
renderer.setGreenBand(4)
renderer.setBlueBand(3)
rendering.setRasterRenderer(renderer)
Benjamin Jakimow's avatar
Benjamin Jakimow committed
85
86
87



Benjamin Jakimow's avatar
Benjamin Jakimow committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
134
135
136
137
138
139
140
141
142
143
def widgetScreenshot(widget, path):
    assert isinstance(widget, QWidget)
    rect = widget.rect()
    pixmap = QPixmap(rect.size())
    widget.render(pixmap, QPoint(), QRegion(rect))
    pixmap.save(path, quality=100)

def makePNG(widget, name):
    path = jp(DIR_SCREENSHOTS, name+'.png')
    widgetScreenshot(widget, path)

# makePNG(TS.ui, 'mainGUI')

for dockWidget in TS.ui.findChildren(QDockWidget):
    assert isinstance(dockWidget, QDockWidget)
    #dockWidget.setFloating(True)
    name = dockWidget.objectName()
    dSize = dockWidget.size()
    #change sizes
    if name == 'cursorLocationInfoPanel':
        center = TS.TS.getMaxSpatialExtent().spatialCenter()
        from timeseriesviewer.mapcanvas import MapTools
        TS.onShowProfile(center, mv1.mapCanvases()[0], MapTools.CursorLocation)
        dockWidget.reloadCursorLocation()
        dockWidget.resize(QSize(300, 150))
        dockWidget.update()

    if name == 'mapViewPanel':
        dockWidget.setCurrentMapView(mv1)
        dockWidget.gbMapProperties.setCollapsed(True)
        dockWidget.gbMapProperties.update()
        mv1.ui.gbVectorRendering.setCollapsed(True)
        mv1.ui.gbVectorRendering.setChecked(False)
        mv1.ui.update()
        dockWidget.resize(QSize(300, 600))
        dockWidget.update()

    if name == 'sensorPanel':
        #dockWidget.setFixedHeight(200)
        dockWidget.setFixedSize(QSize(550, 100))
    if name == 'systemInfoPanel':
        dockWidget.setFixedHeight(400)

    if name == 'spectralLibraryPanel':
        dockWidget.setFixedSize(QSize(800, 250))
    if name == 'temporalProfilePanel':
        dockWidget.setFixedSize(QSize(800, 250))
    if name == 'timeseriesPanel':
        dockWidget.setFixedSize(QSize(800, 250))

    makePNG(dockWidget, name)
    #dockWidget.setFloating(False)


app.exec_()
#print('Done')