Python qgis.core.QgsFeatureRequest() Examples
The following are 11
code examples of qgis.core.QgsFeatureRequest().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
qgis.core
, or try the search function
.
Example #1
Source File: CartoDBLayer.py From qgis-cartodb with GNU General Public License v2.0 | 6 votes |
def _updateGeometries(self, changedGeometries): for featureID, geom in changedGeometries.iteritems(): QgsMessageLog.logMessage('Update geometry for feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO) request = QgsFeatureRequest().setFilterFid(featureID) try: sql = "UPDATE " + self._schema() + self.cartoTable + " SET the_geom = " feature = self.getFeatures(request).next() sql = sql + "ST_GeomFromText('" + geom.exportToWkt() + "', ST_SRID(the_geom)) WHERE cartodb_id = " + unicode(feature['cartodb_id']) sql = sql.encode('utf-8') res = self._updateSQL(sql, 'Some error ocurred updating geometry') if isinstance(res, dict) and res['total_rows'] == 1: self.iface.messageBar().pushMessage('Info', 'Geometry for cartodb_id ' + str(feature['cartodb_id']) + ' was updated from ' + str(self.cartoTable) + ' at CartoDB servers', level=self.iface.messageBar().INFO, duration=10) except StopIteration: self.iface.messageBar().pushMessage('Warning', 'Can\'t get feature with fid ' + str(featureID), level=self.iface.messageBar().WARNING, duration=10)
Example #2
Source File: CartoDBLayer.py From qgis-cartodb with GNU General Public License v2.0 | 6 votes |
def _deleteFeatures(self, deletedFeatureIds): provider = self.dataProvider() for featureID in deletedFeatureIds: QgsMessageLog.logMessage('Delete feature with feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO) request = QgsFeatureRequest().setFilterFid(featureID) try: feature = provider.getFeatures(request).next() sql = "DELETE FROM " + self._schema() + self.cartoTable + " WHERE cartodb_id = " + unicode(feature['cartodb_id']) res = self._updateSQL(sql, 'Some error ocurred deleting feature') if isinstance(res, dict) and res['total_rows'] == 1: self.iface.messageBar().pushMessage('Info', 'Feature with cartodb_id ' + str(feature['cartodb_id']) + ' was deleted from ' + str(self.cartoTable) + ' at CartoDB servers', level=self.iface.messageBar().INFO, duration=10) except StopIteration: self.iface.messageBar().pushMessage('Warning', 'Can\'t get feature from dataprovider with fid ' + str(featureID), level=self.iface.messageBar().WARNING, duration=10) self._deletedFeatures = []
Example #3
Source File: relation_line_edit.py From stdm with GNU General Public License v2.0 | 6 votes |
def get_feature_value(self, model=None): self.layer.startEditing() feature = None request = QgsFeatureRequest() if model is None: model = self.host.model() request.setFilterFid(model.id) feature_itr = self.layer.getFeatures(request) for feat in feature_itr: feature = feat break exp = QgsExpression(self.column.expression) if exp.hasParserError(): raise Exception(exp.parserErrorString()) exp.prepare(self.layer.pendingFields()) if feature is not None: value = exp.evaluate(feature) return value else: return None
Example #4
Source File: CartoDBLayer.py From qgis-cartodb with GNU General Public License v2.0 | 5 votes |
def _updateAttributes(self, changedAttributeValues): provider = self.dataProvider() for featureID, v in changedAttributeValues.iteritems(): QgsMessageLog.logMessage('Update attributes for feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO) sql = "UPDATE " + self._schema() + self.cartoTable + " SET " request = QgsFeatureRequest().setFilterFid(featureID) try: feature = self.getFeatures(request).next() addComma = False for fieldID, val in v.iteritems(): if addComma: sql = sql + ", " fieldValue = unicode(val) if fieldValue != 'NULL': fieldValue = "'" + fieldValue + "'" fName = provider.fields().field(fieldID).name() if fName != 'cartodb_id': sql = sql + fName + " = " + fieldValue addComma = True else: # TODO Rollback changes. pass sql = sql + " WHERE cartodb_id = " + unicode(feature['cartodb_id']) sql = sql.encode('utf-8') qDebug('SQL Update: ' + sql) res = self._updateSQL(sql, 'Some error ocurred getting tables') if isinstance(res, dict) and res['total_rows'] == 1: self.iface.messageBar().pushMessage('Info', 'Data for cartodb_id ' + str(feature['cartodb_id']) + ' from ' + str(self.cartoTable) + ' was updated from CartoDB servers', level=self.iface.messageBar().INFO, duration=10) except StopIteration: self.iface.messageBar().pushMessage("Warning", 'Can\'t get feature with fid ' + str(featureID), level=self.iface.messageBar().WARNING, duration=10)
Example #5
Source File: Qneat3Utilities.py From QNEAT3 with GNU General Public License v3.0 | 5 votes |
def getFeaturesFromQgsIterable(qgs_feature_storage):#qgs_feature_storage can be any vectorLayer/QgsProcessingParameterFeatureSource/etc fRequest = QgsFeatureRequest().setFilterFids(qgs_feature_storage.allFeatureIds()) return qgs_feature_storage.getFeatures(fRequest)
Example #6
Source File: Qneat3Utilities.py From QNEAT3 with GNU General Public License v3.0 | 5 votes |
def mergeFeaturesFromQgsIterable(qgs_feature_storage_list): result_feature_list = [] for qgs_feature_storage in qgs_feature_storage_list: fRequest = QgsFeatureRequest().setFilterFids(qgs_feature_storage.allFeatureIds()) result_feature_list.extend(qgs_feature_storage.getFeatures(fRequest)) return result_feature_list
Example #7
Source File: export_elementary_volume.py From albion with GNU General Public License v3.0 | 5 votes |
def __export(self): fids = self.cell_layer.allFeatureIds() if self.mSelection.isChecked(): fids = self.cell_layer.selectedFeaturesIds() closed_only = self.mClosedVolume.isChecked() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() cell_ids = [feature["id"] for fid in fids for feature in self.cell_layer.getFeatures(QgsFeatureRequest(fid)) ] outdir = self.mOutputDir.text() if self.mFormat.currentText() == "OBJ": self.project.export_elementary_volume_obj( self.graph, cell_ids, outdir, closed_only ) else: # DXF self.project.export_elementary_volume_dxf( self.graph, cell_ids, outdir, closed_only ) QApplication.restoreOverrideCursor()
Example #8
Source File: contour_tool.py From DsgTools with GNU General Public License v2.0 | 5 votes |
def getCandidates(self, bbox): """ Gets candidates using the spatial index to speedup the process """ #features that might satisfy the query ids = self.index.intersects(bbox) candidates = [] for id in ids: candidates.append(next(self.reference.getFeatures(QgsFeatureRequest().setFilterFid(id)))) return candidates
Example #9
Source File: acquisitionFreeController.py From DsgTools with GNU General Public License v2.0 | 5 votes |
def reshapeSimplify(self, reshapeLine): canvas = self.getIface().mapCanvas() layer = canvas.currentLayer() tolerance = self.getTolerance(layer) reshapeLine_ = self.reprojectGeometry(reshapeLine) rsLine = self.simplifyGeometry(reshapeLine_, tolerance) request = core.QgsFeatureRequest().setFilterRect(rsLine.boundingBox()) for feat in layer.getSelectedFeatures(request) if layer.selectedFeatureCount() > 0 else layer.getFeatures(request): geom = feat.geometry() # geometria que receberá o reshape. if geom.intersects(rsLine): # Se intersecta e transforma frompolyline em geometria. geom.reshapeGeometry(QgsLineString([QgsPoint(p) for p in rsLine.asPolyline()])) # realiza o reshape entre a linha e a geometria. layer.changeGeometry(feat.id(), geom) canvas.refresh() # Refresh para atualizar, mas não salvar as alterações.
Example #10
Source File: virtual_raster.py From DsgTools with GNU General Public License v2.0 | 5 votes |
def getCandidates(idx, layer, bbox): """ Gets candidates to be processed using the index to speedup the process """ ids = idx.intersects(bbox) candidates = [] for id in ids: candidates.append(next(layer.getFeatures(QgsFeatureRequest().setFilterFid(id)))) return candidates
Example #11
Source File: complexWindow.py From DsgTools with GNU General Public License v2.0 | 4 votes |
def on_zoomButton_clicked(self): """ Slot used to zoom the mapcanvas to the features associated to a complex """ #case no item is selected we should warn the user if len(self.treeWidget.selectedItems()) == 0: QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Please, select an item to zoom.")) return item = self.treeWidget.selectedItems()[0] #checking if the item is a complex (it should have depth = 2) if self.depth(item) == 2: bbox = QgsRectangle() for i in range(item.childCount()): aggregated_item = item.child(i) aggregated_class = aggregated_item.text(0) #getting the layer the needs to be updated aggregated_layer = None layers = self.iface.mapCanvas().layers() for layer in layers: if layer.name() == aggregated_class: aggregated_layer = layer break if not aggregated_layer: QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("The associated classes must be loaded in the table of contents.")) return for j in range(aggregated_item.childCount()): id = aggregated_item.child(j).text(0) freq = QgsFeatureRequest() freq.setFilterFid(int(id)) feature = next(layer.getFeatures( freq )) if j==0 and i == 0: bbox=feature.geometry().boundingBox() bbox.combineExtentWith(feature.geometry().boundingBox()) self.iface.mapCanvas().setExtent(bbox) self.iface.mapCanvas().refresh() else: QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Select a complex.")) return