当前位置: 首页>>代码示例>>Python>>正文


Python core.QgsFeatureRequest方法代码示例

本文整理汇总了Python中qgis.core.QgsFeatureRequest方法的典型用法代码示例。如果您正苦于以下问题:Python core.QgsFeatureRequest方法的具体用法?Python core.QgsFeatureRequest怎么用?Python core.QgsFeatureRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core的用法示例。


在下文中一共展示了core.QgsFeatureRequest方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _updateGeometries

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:22,代码来源:CartoDBLayer.py

示例2: _deleteFeatures

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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 = [] 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:20,代码来源:CartoDBLayer.py

示例3: get_feature_value

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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 
开发者ID:gltn,项目名称:stdm,代码行数:27,代码来源:relation_line_edit.py

示例4: _updateAttributes

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:40,代码来源:CartoDBLayer.py

示例5: getFeaturesFromQgsIterable

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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) 
开发者ID:root676,项目名称:QNEAT3,代码行数:5,代码来源:Qneat3Utilities.py

示例6: mergeFeaturesFromQgsIterable

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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 
开发者ID:root676,项目名称:QNEAT3,代码行数:8,代码来源:Qneat3Utilities.py

示例7: __export

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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() 
开发者ID:Oslandia,项目名称:albion,代码行数:29,代码来源:export_elementary_volume.py

示例8: getCandidates

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:12,代码来源:contour_tool.py

示例9: reshapeSimplify

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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. 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:16,代码来源:acquisitionFreeController.py

示例10: getCandidates

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:11,代码来源:virtual_raster.py

示例11: on_zoomButton_clicked

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsFeatureRequest [as 别名]
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 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:44,代码来源:complexWindow.py


注:本文中的qgis.core.QgsFeatureRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。