Newer
Older
y = center.y()
dx = geometry.xMaximum() - geometry.xMinimum()
dy = geometry.yMaximum() - geometry.yMinimum()
if type(geometry) is QgsPoint:
x = geometry.x()
y = geometry.y()
if self.TS.srs is not None and not self.TS.srs.IsSame(canvas_srs):
print('Convert canvas coordinates to time series SRS')
g = ogr.Geometry(ogr.wkbPoint)
g.AddPoint(x,y)
g.AssignSpatialReference(canvas_srs)
g.TransformTo(self.TS.srs)
x = g.GetX()
y = g.GetY()
D.doubleSpinBox_subset_size_x.setValue(dx)
D.doubleSpinBox_subset_size_y.setValue(dy)
D.spinBox_coordinate_x.setValue(x)
D.spinBox_coordinate_y.setValue(y)
def qgs_handleMouseDown(self, pt, btn):
print('MOUSE DOWN')
print(pt)
print(btn)
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
def ua_TSprogress(self, v_min, v, v_max):
assert v_min <= v and v <= v_max
P = self.dlg.progressBar
if P.minimum() != v_min or P.maximum() != v_max:
P.setRange(v_min, v_max)
P.setValue(v)
def ua_datumAdded(self):
cb_centerdate = self.dlg.cb_centerdate
cb_centerdate.clear()
if len(self.TS) > 0:
if self.dlg.spinBox_coordinate_x.value() == 0.0 and \
self.dlg.spinBox_coordinate_y.value() == 0.0:
xmin, ymin, xmax, ymax = self.TS.getMaxExtent()
self.dlg.spinBox_coordinate_x.setRange(xmin, xmax)
self.dlg.spinBox_coordinate_y.setRange(ymin, ymax)
self.dlg.spinBox_coordinate_x.setValue(0.5*(xmin+xmax))
self.dlg.spinBox_coordinate_y.setValue(0.5*(ymin+ymax))
s =""
for date in self.TS.getDates():
cb_centerdate.addItem(date.astype('str'), date)
s = ""
self.dlg.tableView_TimeSeries.resizeColumnsToContents()
def check_enabled(self):
D = self.dlg
hasTSV = len(self.VIEWS) > 0
hasQGIS = qgis_available
D.tabWidget_viewsettings.setEnabled(hasTS)
D.btn_showPxCoordinate.setEnabled(hasTS and hasTSV)
D.btn_selectByCoordinate.setEnabled(hasQGIS)
D.btn_selectByRectangle.setEnabled(hasQGIS)
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.
We implement this ourselves since we do not inherit QObject.
:param message: String for translation.
:type message: str, QString
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('EnMAPBox', message)
def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str
:param text: Text that should be shown in menu items for this action.
:type text: str
:param callback: Function to be called when the action is triggered.
:type callback: function
:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool
:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool
:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
:type add_to_toolbar: bool
:param status_tip: Optional text to show in a popup when mouse pointer
hovers over the action.
:type status_tip: str
:param parent: Parent widget for the new action. Defaults None.
:type parent: QWidget
:param whats_this: Optional text to show in the status bar when the
mouse pointer hovers over the action.
:returns: The action that was created. Note that the action is also
added to self.actions list.
:rtype: QAction
"""
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.iface.addPluginToMenu(
self.menu,
action)
self.actions.append(action)
return action
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
callback=self.run,
parent=self.iface.mainWindow())
def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
for action in self.actions:
self.iface.removePluginMenu(
action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar
def run(self):
"""Run method that performs all the real work"""
#self.dlg.setWindowIcon(QIcon(self.icon_path))
# show the GUI
self.dlg.show()
if DEBUG:
pass
def ua_showPxCoordinate_start(self):
cx = D.spinBox_coordinate_x.value()
cy = D.spinBox_coordinate_y.value()
ring.AddPoint(cx - dx, cy + dy)
ring.AddPoint(cx + dx, cy + dy)
ring.AddPoint(cx + dx, cy - dy)
ring.AddPoint(cx - dx, cy - dy)
bb = ogr.Geometry(ogr.wkbPolygon)
bb.AddGeometry(ring)
bbWkt = bb.ExportToWkt()
srsWkt = None
if self.TS.srs:
bb.AssignSpatialReference(self.TS.srs)
srsWkt = bb.GetSpatialReference().ExportToWkt()
self.ImageChipBuffer.setBoundingBox(bb)
D = self.dlg
ratio = dx / dy
size_px = D.spinBox_chipsize_max.value()
if ratio > 1: #x is largest side
size_x = size_px
size_y = int(size_px / ratio)
else: #y is largest
size_y = size_px
size_x = int(size_px * ratio)
#size_x = D.spinBox_chipsize_x.value()
#size_y = D.spinBox_chipsize_y.value()
ScrollArea = D.scrollArea
#S.setWidgetResizable(False)
#remove widgets
#get the dates of interes
dates_of_interest = list()
if D.rb_showEntireTS.isChecked():
dates_of_interest = self.TS.getDates()
elif D.rb_showSelectedDates.isChecked():
dates_of_interest = self.getSelectedDates()
elif D.rb_showTimeWindow.isChecked():
TSD = D.cb_timeWindow_doi.itemData(D.cb_timeWindow_doi.currentIndex())
s = ""
allDates = self.TS.getDates()
i_doi = allDates.index(TSD)
i0 = max([0, i_doi-D.sb_ndates_before.value()])
ie = min([i_doi + D.sb_ndates_after.value(), len(allDates)])
dates_of_interest = allDates[i0:ie]
if self.CPV is None:
ScrollArea.setLayout(QHBoxLayout())
self.CPV = ScrollArea.layout()
else:
self.clearLayoutWidgets(self.CPV)
self.CHIPWIDGETS.clear()
if False:
else:
for date, viewList in self.CHIPWIDGETS.items():
for imageLabel in viewList:
imageLabel.clear()
#initialize image labels
#LV = QVBoxLayout()
#LV.setSizeConstraint(QLayout.SetNoConstraint)
TSD = self.TS.data[date]
textLabel = QLabel('{}'.format(date.astype(str)))
textLabel.setToolTip(str(TSD))
#textLabel.setMinimumWidth(size_x)
#textLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
self.CPV.addWidget(textLabel, 0, i)
viewList = list()
for j, view in enumerate(self.VIEWS):
imageLabel.setFrameShape(QFrame.StyledPanel)
imageLabel.setMinimumSize(size_x, size_y)
imageLabel.setMaximumSize(size_x+1, size_y+1)
imageLabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
viewList.append(imageLabel)
self.CPV.addWidget(imageLabel,j+1, i)
self.CHIPWIDGETS[date] = viewList
#LH.addSpacerItem(Spacer(size_x, size_y))
ScrollArea.show()
#fill image labels
missing_dates = set()
missing_bands = set()
for i, date in enumerate(self.TS.getDates()):
required_bands = set()
for j, view in enumerate(self.VIEWS):
required_bands = required_bands.union(set(view.getBands()))
missing = self.ImageChipBuffer.getMissingBands(date, required_bands)
if len(missing) == 0:
self.ua_showPxCoordinate_addChips(None, date=date)
else:
missing_dates.add(date)
missing_bands = missing_bands.union(missing)
if len(missing_dates) > 0:
self.TS.getSpatialChips_parallel(bbWkt, srsWkt, dates=list(missing_dates), bands=list(missing_bands))
def ua_showPxCoordinate_addChips(self, results, date=None):
if results is not None:
date, chipData = results
self.ImageChipBuffer.addDataCube(date, chipData)
viewList = self.CHIPWIDGETS.get(date)
if viewList:
for j, view in enumerate(self.VIEWS):
imageLabel = viewList[j]
imageLabel.clear()
#imageLabel.setScaledContents(True)
rgb = self.ImageChipBuffer.getChipRGB(date, view)
rgb2 = rgb.transpose([1,2,0]).copy('C')
qImg = qimage2ndarray.array2qimage(rgb2)
#img = QImage(rgb2.data, nl, ns, QImage.Format_RGB888)
pxMap = QPixmap.fromImage(qImg)
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
s = ""
pass
def clearLayoutWidgets(self, L):
if L is not None:
while L.count():
w = L.takeAt(0)
w.widget().deleteLater()
#if w is not None:
# w.widget().deleteLater()
def ua_addTSImages(self, files=None):
if files is None:
files = QFileDialog.getOpenFileNames()
if files:
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
self.TS.addFiles(files)
M.endResetModel()
nb = self.TS.nb
if len(self.VIEWS) == 0 and nb > 0:
if nb < 3:
bands = [1,1,1]
else:
self.ua_addView([3,2,1])
if nb >= 5:
self.ua_addView([4,5,3])
self.check_enabled()
def ua_addTSMasks(self, files=None):
if files is None:
files = QFileDialog.getOpenFileNames()
l = len(files)
if l > 0:
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
M.endResetModel()
self.check_enabled()
def setViewNames(self):
for i, w in enumerate(self.VIEWS):
w.setTitle('View {}'.format(i+1))
self.check_enabled()
def ua_addView(self, bands = [3,2,1]):
import imagechipviewsettings_widget
if len(self.TS.bandnames) > 0:
w = imagechipviewsettings_widget.ImageChipViewSettings(self.TS, parent=self.dlg)
w.setMaximumSize(w.size())
#w.setMinimumSize(w.size())
w.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.MinimumExpanding)
w.setBands(bands)
w.removeView.connect(lambda : self.ua_removeView(w))
L = self.dlg.scrollArea_viewsWidget.layout()
L.addWidget(w)
self.dlg.scrollArea_views.show()
def ua_removeTS(self):
#remove views
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
self.TS.clear()
M.endResetModel()
self.check_enabled()
M = self.dlg.tableView_TimeSeries.model()
M.beginResetModel()
def ua_removeView(self,w):
self.VIEWS.remove(w)
L = self.dlg.scrollArea_viewsWidget.layout()
L.removeWidget(w)
w.deleteLater()
self.setViewNames()
def getSelectedDates(self):
TV = self.dlg.tableView_TimeSeries
TVM = TV.model()
return [TVM.getTimeSeriesDatumFromIndex(idx).getDate() for idx in TV.selectionModel().selectedRows()]
def showRGBData(data):
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
def run_tests():
if False:
pathImg = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted\2014-07-26_LC82270652014207LGN00_BOA.vrt'
pathMsk = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted\2014-07-26_LC82270652014207LGN00_Msk.vrt'
TSD = TimeSeriesDatum(pathImg)
TSD.setMask(pathMsk)
print(TSD)
c = [670949.883,-786288.771]
w_x = w_y = 1000 #1km box
srs = TSD.getSpatialReference()
ring = ogr.Geometry(ogr.wkbLinearRing)
import itertools
for x,y in itertools.product([1000, -1000], repeat=2):
ring.AddPoint(c[0]+x, c[1]+y)
ring.AssignSpatialReference(srs)
bb = ogr.Geometry(ogr.wkbPolygon)
bb.AddGeometry(ring)
bb.AssignSpatialReference(srs)
def getChip3d_OLD(chips, r,g,b, range_r, range_g, range_b):
nl, ns = chips[r].shape
a3d = np.ndarray((3,nl,ns), dtype='float')
rgb_idx = [r,g,b]
ranges = [range_r, range_g, range_b]
for i, rgb_i in enumerate(rgb_idx):
range = ranges[i]
data = chips[rgb_i].astype('float')
data -= range[0]
data *= 255./range[1]
a3d[i,:] = data
np.clip(a3d, 0, 255, out=a3d)
return a3d.astype('uint8')
app=QApplication([])
main=PictureTest()
main.show()
range_r = [0,500]
range_g = [0,500]
range_b = [0,500]
bands = [3,2,1]
chipData = TSD.readSpatialChip(bb,bands=bands )
main.addNumpy(getChip3d(chipData, bands, (range_r, range_g, range_b)))
app.exec_()
exit(0)
if False:
dirSrc = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImg = file_search(dirSrc, '2014*_BOA.vrt')
filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
TS = TimeSeries(imageFiles=filesImg, maskFiles=filesMsk)
print(TS)
exit(0)
S.run()
if True:
dirSrc = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImg = file_search(dirSrc, '2014*_BOA.vrt')
#filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
#S.ua_addTSImages(files=filesImg[0:1])
S.ua_addTSImages(files=filesImg)
#S.ua_addTSMasks(files=filesMsk)
#S.ua_addView(bands=[4,5,3])
a.exec_()
if False:
import qgis.core
# supply path to where is your qgis installed
QgsApplication.setPrefixPath("/Applications/QGIS_2.12.app/Contents/MacOS/QGIS", True)
# load providers
QgsApplication.initQgis()
a = QgsApplication([], True)
dirSrc = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\00_VRTs\02_Cutted'
filesImg = file_search(dirSrc, '2014*_BOA.vrt')
filesMsk = file_search(dirSrc, '2014*_Msk.vrt')
S.ua_addTSImages(files=filesImg)