我已经使用以下代码逐一选择功能。但是当我运行脚本时,它只是选择最后一个功能并进行缩放。我想选择每个功能并进行缩放。
def SelectFeatures(self):
layer = self.iface.activeLayer();
iter = layer.getFeatures();
for feature in iter:
geom = feature.geometry()
self.iface.mapCanvas().setSelectionColor(QColor("yellow"));
layer.setSelectedFeatures([feature.id()])
selected_features = layer.selectedFeatures()
self.iface.mapCanvas().zoomToSelected( layer )
self.iface.mapCanvas().refresh()
path = 'D:\Test'+ str(feature.id()) + '.png'
self.iface.mapCanvas().saveAsImage(path)
#QMessageBox.information(None, "DEBUG:", str(path))
现在,缩放过程太快,因为我无法看到缩放的所选特征。除此之外,每次生成的图像都是相同的。 我的目标是实现以下目标。
重复其余功能的步骤。
答案 0 :(得分:0)
这是一个kludge ......但你试过睡觉吗?
def SelectFeatures(self):
layer = self.iface.activeLayer();
iter = layer.getFeatures();
for feature in iter:
geom = feature.geometry()
self.iface.mapCanvas().setSelectionColor(QColor("yellow"));
layer.setSelectedFeatures([feature.id()])
selected_features = layer.selectedFeatures()
self.iface.mapCanvas().zoomToSelected( layer )
self.iface.mapCanvas().refresh()
path = 'D:\Test'+ str(feature.id()) + '.png'
import time
time.sleep(5) # delays for 5 seconds
self.iface.mapCanvas().saveAsImage(path)
#QMessageBox.information(None, "DEBUG:", str(path))