本文整理汇总了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)
示例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 = []
示例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
示例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)
示例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)
示例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
示例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()
示例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
示例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.
示例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
示例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