Skip to main content
added 76 characters in body
Source Link
Mike -EZUSoft-
  • 1.4k
  • 1
  • 9
  • 20

I think thisyour code worksvl = QgsVectorLayer("Point?crs=user:100001", "Project_center", "memory") only fromworks from QGIS3.0. For 2.xx you can test the following:

from PyQt4.QtCore import QSettings

# save actualy value
crsType = QSettings().value('/Projections/defaultBehaviour') # only 2.x

QSettings().setValue('/Projections/defaultBehaviour','')
target_crs = QgsCoordinateReferenceSystem()
target_crs.createFromId(100001, QgsCoordinateReferenceSystem.InternalCrsId)

vl = QgsVectorLayer("Point", "Project_center", "memory")
vl.setCrs(target_crs)
print vl.crs().authid()

# set saved  value
QSettings().setValue('/Projections/defaultBehaviour',crsType) 

I think this code works only from QGIS3.0. For 2.xx you can test the following:

from PyQt4.QtCore import QSettings

# save actualy value
crsType = QSettings().value('/Projections/defaultBehaviour') # only 2.x

QSettings().setValue('/Projections/defaultBehaviour','')
target_crs = QgsCoordinateReferenceSystem()
target_crs.createFromId(100001, QgsCoordinateReferenceSystem.InternalCrsId)

vl = QgsVectorLayer("Point", "Project_center", "memory")
vl.setCrs(target_crs)
print vl.crs().authid()

# set saved  value
QSettings().setValue('/Projections/defaultBehaviour',crsType) 

I think your code vl = QgsVectorLayer("Point?crs=user:100001", "Project_center", "memory") only works from QGIS3.0. For 2.xx you can test the following:

from PyQt4.QtCore import QSettings

# save actualy value
crsType = QSettings().value('/Projections/defaultBehaviour') # only 2.x

QSettings().setValue('/Projections/defaultBehaviour','')
target_crs = QgsCoordinateReferenceSystem()
target_crs.createFromId(100001, QgsCoordinateReferenceSystem.InternalCrsId)

vl = QgsVectorLayer("Point", "Project_center", "memory")
vl.setCrs(target_crs)
print vl.crs().authid()

# set saved  value
QSettings().setValue('/Projections/defaultBehaviour',crsType) 
Source Link
Mike -EZUSoft-
  • 1.4k
  • 1
  • 9
  • 20

I think this code works only from QGIS3.0. For 2.xx you can test the following:

from PyQt4.QtCore import QSettings

# save actualy value
crsType = QSettings().value('/Projections/defaultBehaviour') # only 2.x

QSettings().setValue('/Projections/defaultBehaviour','')
target_crs = QgsCoordinateReferenceSystem()
target_crs.createFromId(100001, QgsCoordinateReferenceSystem.InternalCrsId)

vl = QgsVectorLayer("Point", "Project_center", "memory")
vl.setCrs(target_crs)
print vl.crs().authid()

# set saved  value
QSettings().setValue('/Projections/defaultBehaviour',crsType)