I'm using the following code to set the project CRS in a Python script:
#creates the project and projectRoot objects
projectObj = QgsProject.instance()
projectRoot = projectObj.layerTreeRoot()
#sets the project CRS
projectCrs = QgsCoordinateReferenceSystem.fromEpsgId(3395)
projectObj.setCrs(projectCrs)
assert projectCrs.isValid()
print(projectCrs.isValid())
I'm using the following code in a for-loop to set the CRS for all layers:
shpSavedLayer.setCrs(projectCrs)
What I get is this:
Although, the QGIS Status Bar, Project Properties Window, and Layer Properties Window for every layer state that the CRS is set to EPSG:3395, there is clearly something wrong with the projection.
If I run the same code with the above lines commented out, then set the project CRS to EPSG:3395 via the Project Properties Window, I get this:
which looks a lot more accurate.
What's happening here? From the discussion on GIS SE, I'm guessing this has to do with the difference between setting the CRS and reprojecting the layer?
setCrs()
method to accomplish this, but they are not "deforming". Does that help clarify the issue? Would it help if I posted the entire script? Thanks for your help.projectObj.setCrs(projectCrs)
, map in the canvas deforms. What is your QGIS version?projectObj.setCrs(projectCrs)
changes the CRS of a project.