我正在使用QGIS 2.8.1,我想选择一个名为'tempshpfile'的shapefile,并缩放到该多边形shapefile上的图层。
我的代码是:
import ogr,os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
import qgis.utils
import glob
import processing
from processing.core.Processing import Processing
from PyQt4.QtCore import QTimer
Processing.initialize()
Processing.updateAlgsList()
# Add array of address below
allFiles = ["C:/Shapefiles/Map_0077421.shp"]
filesLen = len(allFiles)
TexLayer = "C:/Texas_NAD27/Texas_NAD27.shp"
for lop in range(filesLen):
wb = QgsVectorLayer(allFiles[lop], 'tempshpfile', 'ogr')
wbTex = QgsVectorLayer(TexLayer, 'TexasGrid', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(wb)
QgsMapLayerRegistry.instance().addMapLayer(wbTex)
由于您的wb
层已被注册,因此只需在循环后激活该层:
qgis.utils.iface.setActiveLayer(wb)
并缩放到活动层的范围:
qgis.utils.iface.zoomToActiveLayer()