As a first step of a pyqgis plugin I'm trying to import several shape files at once. To get them aligned, using the GUI, I'd enable on the fly reprojections and set the project crs to WGS84. I'd then set the layer CRS to WGS84 for each layer resulting in all layers being in the same layer extent.
The following code tries to replicate the GUI steps. However, the end result is that there is still no overlay between the layers, unlike when I do the steps via GUI. What am I missing out?
qgis.utils.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True) # Enable on the fly reprojections
qgis.utils.iface.mapCanvas().mapRenderer().setDestinationCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.PostgisCrsId)) # Set project coordinate reference system to WGS84
for path, name in ShapeFileList:
vector = QgsVectorLayer(path, name, "ogr")
if not vector.isValid():
print "Layer failed to load!"
vector.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.PostgisCrsId)) # Set layer coordinate reference system to WGS84
QgsMapLayerRegistry.instance().addMapLayer(vector)
No comments:
Post a Comment