def getFeatures(): fields = [ 'id', 'acquired', 'thumbnail', 'meta_html', 'meta_json', 'meta_jsize' ] # See FIELDs order from createLayer features = [] for item in self.scenes: # Fields meta_json = item['properties'] vFields = {} vFields[fields[0]] = item['id'] vFields[fields[1]] = meta_json['acquired'] del meta_json['acquired'] vFields[fields[2]] = "Need download thumbnail" meta_json['assets_status'] = { 'a_analytic': { 'status': '*Need calculate*' }, 'a_udm': { 'status': '*Need calculate*' } } vFields[fields[ 3]] = API_PlanetLabs.getHtmlTreeMetadata( meta_json, '') vjson = json.dumps(meta_json) vFields[fields[4]] = vjson vFields[fields[5]] = len(vjson) # Geom geomItem = item['geometry'] geomCoords = geomItem['coordinates'] if geomItem['type'] == 'Polygon': qpolygon = map( lambda polyline: map( lambda item: QgsCore.QgsPoint( item[0], item[1]), polyline), geomCoords) geom = QgsCore.QgsGeometry.fromMultiPolygon( [qpolygon]) elif geomItem['type'] == 'MultiPolygon': qmultipolygon = [] for polygon in geomCoords: qpolygon = map( lambda polyline: map( lambda item: QgsCore.QgsPoint( item[0], item[1]), polyline), polygon) qmultipolygon.append(qpolygon) geom = QgsCore.QgsGeometry.fromMultiPolygon( qmultipolygon) else: continue feat = QgsCore.QgsFeature() feat.setGeometry(geom) atts = map(lambda item: vFields[item], fields) feat.setAttributes(atts) features.append(feat) return features
def calculateAssetStatus(self): @QtCore.pyqtSlot(dict) def finished(response): if self.mbcancel.isCancel: self.messagePL = None else: self.messagePL = response['assets_status'] loop.quit() r = self._startProcess(self.apiPL.kill) if not r['isOk']: return iterFeat = r['iterFeat'] id_meta_json = self.layer.fieldNameIndex('meta_json') id_meta_html = self.layer.fieldNameIndex('meta_html') isEditable = self.layer.isEditable() if not isEditable: self.layer.startEditing() totalAssets = { 'analytic': { 'images': 0, 'activate': 0 }, 'udm': { 'images': 0, 'activate': 0 } } loop = QtCore.QEventLoop() step = totalError = 0 for feat in iterFeat: step += 1 self.mbcancel.step(step) meta_json = json.loads(feat['meta_json']) (ok, item_type) = API_PlanetLabs.getValue(meta_json, ['item_type']) if not ok: totalError += 1 continue self.apiPL.getAssetsStatus(item_type, feat['id'], finished) loop.exec_() if self.mbcancel.isCancel or self.layerTree is None: step -= 1 iterFeat.close() break meta_json['assets_status'] = self.messagePL valuesAssets = self._getValuesAssets(meta_json['assets_status']) self._calculateTotalAsset('analytic', valuesAssets, totalAssets) self._calculateTotalAsset('udm', valuesAssets, totalAssets) meta_html = API_PlanetLabs.getHtmlTreeMetadata(meta_json, '') vjson = json.dumps(meta_json) self.messagePL.clear() self.messagePL = None if not self.layer.changeAttributeValue(feat.id(), id_meta_json, vjson): totalError += 1 if not self.layer.changeAttributeValue(feat.id(), id_meta_html, meta_html): totalError += 1 self.layer.commitChanges() if isEditable: self.layer.startEditing() self._endProcessing("Calculate Asset Status", totalError) self.legendCatalogLayer.setAssetImages(totalAssets)