I am trying to create a memory layer:

tempLayer = QgsVectorLayer('LineString', 'my_temp_layer', 'memory')

But as soon as this line is excecuted (not when I add it to the map!) the CRS dialog pops up. How do I intercept that?

I know I can set the CRS, but that does not help, since the dialog pops up when the first line is executed...

tempLayer = QgsVectorLayer('LineString', 'trassen_tmp_bfp', 'memory')
  • 1
    Does it work if you specify the CRS while creating the memory layer? : gis.stackexchange.com/a/73981/67477 – markgraeflerland Jul 4 '18 at 14:54
  • I create a layer like this: layer = QgsVectorLayer("Polygon?crs=EPSG:4326&index=yes","isoLayer","memory") ... Same problem occurs here as well. – Riccardo Jan 23 at 13:29

You have to include the crs in the path argument of the QgsVectorLayer constructor

tempLayer = QgsVectorLayer('LineString?crs=EPSG:4326', 'my_temp_layer', 'memory')

Alternatively, you can also set up QGis so that newly added layers use the project's CRS, or a default CRS (in Settings/Options/CRS/Crs for new layers)

QGIS Options dialog

You can also set those properties via the pyQGIS API

QSettings().setValue('/Projections/defaultBehavior', 'useProject')  # Use project's crs


QSettings().setValue('/Projections/defaultBehavior', 'useGlobal')  # Use default crs
QSettings().setValue('Projections/layerDefaultCrs', 'EPSG:4326')

Note that the default value for '/Projections/defaultBehavior' is 'prompt'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.