class PlanetOrderBundleWidget(QFrame): selectionChanged = pyqtSignal() def __init__(self, bundleid, bundle, item_type): super().__init__() self.bundleid = bundleid self.name = bundle["name"] self.description = bundle["description"] self.udm = bundle.get("auxiliaryFiles", "").lower().startswith("udm2") assets = bundle["assets"] self.can_harmonize = ("ortho_analytic_4b_sr" in assets or "ortho_analytic_8b_sr" in assets) self.can_harmonize = bundle.get("canHarmonize", False) self.can_clip = bundle.get("canClip", False) self.rectified = bundle["rectification"] == "orthorectified" bands = [] asset_def = PlanetClient.getInstance( ).asset_types_for_item_type_as_dict(item_type) for asset in assets: asset_bands = asset_def[asset].get("bands", []) for band in asset_bands: bands.append(band["name"]) bands = set(bands) layout = QVBoxLayout() hlayout = QHBoxLayout() hlayout.setMargin(0) self.labelName = QLabel(f"<b>{self.name}</b>") hlayout.addWidget(self.labelName) hlayout.addStretch() self.chkSelected = QCheckBox() self.chkSelected.stateChanged.connect(self.checkStateChanged) hlayout.addWidget(self.chkSelected) layout.addLayout(hlayout) self.labelDescription = QLabel(self.description) self.labelDescription.setWordWrap(True) layout.addWidget(self.labelDescription) self.labelBands = QLabel( f"Bands: {', '.join([str(b) for b in bands])}") layout.addWidget(self.labelBands) hlayouttype = QHBoxLayout() hlayouttype.setMargin(0) self.radioTiff = QRadioButton("GeoTIFF") self.radioTiff.setChecked(True) self.radioTiff.toggled.connect(self.selectionChanged.emit) hlayouttype.addWidget(self.radioTiff) self.radioNitf = QRadioButton("NITF") self.radioNitf.toggled.connect(self.selectionChanged.emit) hlayouttype.addWidget(self.radioNitf) hlayouttype.addStretch() layout.addLayout(hlayouttype) if self.udm: hlayoutudm = QHBoxLayout() hlayoutudm.setMargin(0) self.labelUdm = IconLabel("UDM2", UDM_ICON) hlayoutudm.addWidget(self.labelUdm) hlayoutudm.addStretch() layout.addLayout(hlayoutudm) layout.addStretch() self.setFrameStyle(QFrame.Panel | QFrame.Raised) self.setLayout(layout) self.checkStateChanged() def checkStateChanged(self): self.radioTiff.setEnabled(self.chkSelected.isChecked()) self.radioNitf.setEnabled(self.chkSelected.isChecked()) self.labelName.setEnabled(self.chkSelected.isChecked()) self.labelDescription.setEnabled(self.chkSelected.isChecked()) self.labelBands.setEnabled(self.chkSelected.isChecked()) if self.udm: self.labelUdm.setEnabled(self.chkSelected.isChecked()) self.selectionChanged.emit() def selected(self): return self.chkSelected.isChecked() def setSelected(self, selected, emit=False): if not emit: self.blockSignals(True) self.chkSelected.setChecked(selected) self.blockSignals(False) def filetype(self): if self.radioTiff.isChecked(): return "GeoTIFF" else: return "NITF"
class PlanetOrderBundleWidget(QFrame): selectionChanged = pyqtSignal() def __init__(self, bundleid, name, description, udm, can_harmonize, rectified): super().__init__() self.bundleid = bundleid self.name = name self.description = description self.udm = udm self.can_harmonize = can_harmonize self.rectified = rectified layout = QVBoxLayout() hlayout = QHBoxLayout() hlayout.setMargin(0) self.labelName = QLabel(f"<b>{name}</b>") hlayout.addWidget(self.labelName) hlayout.addStretch() self.chkSelected = QCheckBox() self.chkSelected.stateChanged.connect(self.checkStateChanged) hlayout.addWidget(self.chkSelected) layout.addLayout(hlayout) self.labelDescription = QLabel(description) self.labelDescription.setWordWrap(True) layout.addWidget(self.labelDescription) hlayouttype = QHBoxLayout() hlayouttype.setMargin(0) self.radioTiff = QRadioButton("GeoTIFF") self.radioTiff.setChecked(True) self.radioTiff.toggled.connect(self.selectionChanged.emit) hlayouttype.addWidget(self.radioTiff) self.radioNitf = QRadioButton("NITF") self.radioNitf.toggled.connect(self.selectionChanged.emit) hlayouttype.addWidget(self.radioNitf) hlayouttype.addStretch() layout.addLayout(hlayouttype) if udm: hlayoutudm = QHBoxLayout() hlayoutudm.setMargin(0) self.labelUdm = IconLabel("UDM2", UDM_ICON) hlayoutudm.addWidget(self.labelUdm) hlayoutudm.addStretch() layout.addLayout(hlayoutudm) self.setFrameStyle(QFrame.Panel | QFrame.Raised) self.setLayout(layout) self.checkStateChanged() def checkStateChanged(self): self.radioTiff.setEnabled(self.chkSelected.isChecked()) self.radioNitf.setEnabled(self.chkSelected.isChecked()) self.labelName.setEnabled(self.chkSelected.isChecked()) self.labelDescription.setEnabled(self.chkSelected.isChecked()) if self.udm: self.labelUdm.setEnabled(self.chkSelected.isChecked()) self.selectionChanged.emit() def selected(self): return self.chkSelected.isChecked() def setSelected(self, selected, emit=False): if not emit: self.blockSignals(True) self.chkSelected.setChecked(selected) self.blockSignals(False) def filetype(self): if self.radioTiff.isChecked(): return "GeoTIFF" else: return "NITF"
def stream(self): goForStream = True # Avoid auth exception if you reopen the project and don't open the search if self.mySearch == None: self.mySearch = MySearch(self.iface) # Get selected feature of active layer service = self.selectedFeature['service'] # Setup raster params isWcs = False if service == 'BaseMap': if self.mySearch.bmAuth is None: try: self.mySearch.bmSetAuth() except: return username = self.mySearch.bmUsernameInput.text() password = self.mySearch.bmPasswordInput.text() layers = self.mySearch.bmGetLayer(self.selectedFeature['wmts']) styles = 'default' tileMatrixSet = '4326' urlAttr = 'wmts' elif service == 'Data': if self.mySearch.dtHeaders is None: try: self.mySearch.dtSetAuth() except: return username = '******' password = self.mySearch.dtApikeyInput.text() # Dialog for image choice (panchro/multi & wmts/wcs) self.msgBox = QMessageBox() self.msgBox.setWindowTitle(self.menu) if self.selectedFeature['processingLevel'] == 'ALBUM': self.iface.messageBar().pushMessage("Warning", "The feature can't be displayed (no WMTS for Archive features)", level=Qgis.Warning) goForStream = False else: protocolGroup = QGroupBox('Protocol') protocolGrid = QGridLayout() wmtsRadio = QRadioButton('WMTS') wcsRadio = QRadioButton('WCS') protocolGrid.addWidget(wmtsRadio, 0, 0) protocolGrid.addWidget(wcsRadio, 0, 1) protocolGroup.setLayout(protocolGrid) styleGroup = QGroupBox('Style') styleGrid = QGridLayout() multispectralRadio = QRadioButton('multispectral') panchromaticRadio = QRadioButton('panchromatic') pmsRadio = QRadioButton('pms') styleGrid.addWidget(multispectralRadio, 0, 0) styleGrid.addWidget(panchromaticRadio, 0, 1) styleGrid.addWidget(pmsRadio, 0, 2) styleGroup.setLayout(styleGrid) self.msgBox.layout().addWidget(protocolGroup, 0, 0) self.msgBox.layout().addWidget(styleGroup, 1, 0) wmtsRadio.setChecked(True) if type(self.selectedFeature['wcs_multispectral']) != str and type(self.selectedFeature['wcs_panchromatic']) != str and type(self.selectedFeature['wcs_pms']) != str: protocolGroup.setEnabled(False) if type(self.selectedFeature['wmts_pms']) != str: multispectralRadio.setEnabled(True) panchromaticRadio.setEnabled(True) pmsRadio.setEnabled(False) multispectralRadio.setChecked(True) else: multispectralRadio.setEnabled(True) panchromaticRadio.setEnabled(True) pmsRadio.setEnabled(True) pmsRadio.setChecked(True) self.msgBox.setStandardButtons(QMessageBox.Abort | QMessageBox.Ok) reply = self.msgBox.exec_() if reply == QMessageBox.Abort: return if wmtsRadio.isChecked(): urlAttr = 'wmts_' layers = 'default' styles = 'rgb' tileMatrixSet = 'EPSG4326' else: urlAttr = 'wcs_' isWcs = True if multispectralRadio.isChecked(): urlAttr += 'multispectral' elif panchromaticRadio.isChecked(): urlAttr += 'panchromatic' else: urlAttr += 'pms' else: self.error(f'Service "{service}" of the feature ocg_fid={self.selectedFeature.id()} isn\'t recognized\nIt should be "Basemap" or "Data"') return if goForStream: # Add a WMTS raster layer # Order of url parameters are important ! # Why layers is required, maybe is an internal id for wmts gesture ? # What is styles ? try: url = self.selectedFeature[urlAttr] name = f'{service} {self.selectedFeature["id"]}' if isWcs: rlayer = QgsRasterLayer(f'dpiMode=7&identifier=default&password={password}&url={url}&username={username}', name, 'wcs') else: rlayer = QgsRasterLayer(f'crs=EPSG:4326&dpiMode=7&format=image/png&layers={layers}&password={password}&styles={styles}&tileMatrixSet={tileMatrixSet}&url={url}&username={username}', name, 'wms') except Exception as e: self.error(f'Error in protocol connection\n\n{str(e)}') return if rlayer.isValid() == False: self.error(f'Raster layer is invalid\n\n{rlayer.error()}') return QgsProject.instance().addMapLayer(rlayer)