Skip to main content
Edited post
Source Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286

To setThe following code should allow you to add a vector layer without the canvas CRS, you can use popup window from appearing (atleast it doesn't appear for me):

from qgis import *
from qgis.utils import *

my_crs#replace ="shapefile_path" core.QgsCoordinateReferenceSystem(4326,with core.QgsCoordinateReferenceSystem.EpsgCrsId)
your layer's path; replace "Layer_name" with whatever name you want to give the layer in the TOC
ifaceqgis.mapCanvas()utils.mapRenderer()iface.setDestinationCrsaddVectorLayer(my_crs"shapefile_path", "Layer_name", "ogr")

To set the layer CRS, you can use:


#Use loaded layer as active layer to set the CRS
myLayer = qgis.utils.iface.activeLayer()
 
myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))

#Sets canvas CRS
my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId)
iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)

Simply change the 4326 CRS value in both cases to the Authority ID of your choice as shown in the image:

CRS options

To set the canvas CRS, you can use:

from qgis import *
from qgis.utils import *

my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId)

iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)

To set the layer CRS, you can use:

myLayer = qgis.utils.iface.activeLayer()
 
myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))

Simply change the 4326 in both cases to the Authority ID of your choice as shown in the image:

CRS options

The following code should allow you to add a vector layer without the CRS popup window from appearing (atleast it doesn't appear for me):

from qgis import *
from qgis.utils import *

#replace "shapefile_path" with your layer's path; replace "Layer_name" with whatever name you want to give the layer in the TOC
qgis.utils.iface.addVectorLayer("shapefile_path", "Layer_name", "ogr")

#Use loaded layer as active layer to set the CRS
myLayer = qgis.utils.iface.activeLayer()
myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))

#Sets canvas CRS
my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId)
iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)

Simply change the 4326 CRS value in both cases to the Authority ID of your choice as shown in the image:

CRS options

Added extra information concerning CRS for canvas and layer
Source Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286

YouTo set the canvas CRS, you can use the following which should work:

from qgis import *
from qgis.utils import *

my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId) 

iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)
 

To set the layer CRS, you can use:

myLayer = qgis.utils.iface.activeLayer()

myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))

Simply change the 4326 in both cases to the Authority ID of your choice as shown in the image:

CRS options

You can use the following which should work:

from qgis import *
from qgis.utils import *

my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId)
iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)

Simply change the 4326 to the Authority ID of your choice as shown in the image:

CRS options

To set the canvas CRS, you can use:

from qgis import *
from qgis.utils import *

my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId) 

iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)
 

To set the layer CRS, you can use:

myLayer = qgis.utils.iface.activeLayer()

myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))

Simply change the 4326 in both cases to the Authority ID of your choice as shown in the image:

CRS options

Source Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286

You can use the following which should work:

from qgis import *
from qgis.utils import *

my_crs = core.QgsCoordinateReferenceSystem(4326, core.QgsCoordinateReferenceSystem.EpsgCrsId)
iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)

Simply change the 4326 to the Authority ID of your choice as shown in the image:

CRS options