如何使用Python选择和缩放QGIS中的图层

问题描述 投票:1回答:1

我正在使用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)
python pyqt pyqt4 qgis
1个回答
1
投票

由于您的wb层已被注册,因此只需在循环后激活该层:

qgis.utils.iface.setActiveLayer(wb)

并缩放到活动层的范围:

qgis.utils.iface.zoomToActiveLayer()
© www.soinside.com 2019 - 2024. All rights reserved.