Bug report #17781

QgsCoordinateReferenceSystem.fromProj4() does not create user-generated crs (authid() empty)

Added by Maik Riechert over 3 years ago. Updated over 3 years ago.

Category:Projection Support
Affected QGIS version:master Regression?:No
Operating System:Windows 10 Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:25677


crs = QgsCoordinateReferenceSystem.fromProj4('+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +a=6370000 +b=6370000 +towgs84=0,0,0 +units=m +no_defs')
print(crs.authid()) # empty

I'd then like to use the authid when creating an in-memory vector layer. My work-around is to dump the proj4 string directly into the crs argument:

layer = QgsVectorLayer('Polygon?crs=PROJ4:' + proj4, 'Layer', 'memory')

But this is not how it should be, right?


#1 Updated by Denis Rouzaud over 3 years ago

  • Assignee deleted (Denis Rouzaud)
  • Category changed from Python bindings / sipify to Projection Support

#2 Updated by Nyall Dawson over 3 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

Just need to tweak your code a bit:

crs = QgsCoordinateReferenceSystem.fromProj4('+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +a=6370000 +b=6370000 +towgs84=0,0,0 +units=m +no_defs')
crs_id = crs.saveAsUserCrs('my super crs!')


other_crs = QgsCoordinateReferenceSystem('user:' + crs_id)

will work, same as

layer = QgsVectorLayer('Polygon?crs=USER:' + crs_id, 'Layer', 'memory')

I.e., it's not automatically saved to the user database - the saveAsUserCrs call is required to do that.

Also available in: Atom PDF