Bug report #17781
QgsCoordinateReferenceSystem.fromProj4() does not create user-generated crs (authid() empty)
| Status: | Closed | ||
|---|---|---|---|
| Priority: | Normal | ||
| Assignee: | - | ||
| 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 | 
Description
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?
History
#1
    
    Updated by Denis Rouzaud almost 8 years ago
    - Assignee deleted (
Denis Rouzaud) - Category changed from Python bindings / sipify to Projection Support
 
#2
    
    Updated by Nyall Dawson almost 8 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!')
then
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.