Bug report #17254
Wrong output CRS when input layer uses generated CRS
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||fixed/implemented|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||25152|
Tested with qgis:fixeddistancebuffer, native:dissolve, and native:buffer using OSGeo4W 2.99
If the input layer uses a generated / custom CRS, the output layer is loaded in a wrong CRS. In my case, the layers were wrongly assigned WGS84. Note that, in settings, I've configured that QGIS should "prompt for CRS" if a layer without CRS info is loaded.
#1 Updated by Steven Mizuno over 2 years ago
I was making a run at this problem to better understand QGIS and found that trying to create a scratch (memory) vector layer with a user CRS would get a CRS selection dialog, even though the CRS field was filled, where a standard EPSG:... did not.
Using Python console I tried this, which works (no CRS selection dialog):
v=QgsVectorLayer("Polygon?crs=epsg:4326", "Layer Name", "memory")
v1=QgsVectorLayer("Polygon?crs=user:100028", "Layer Name", "memory")
which pops the CRS selection dialog; choosing USER:100028 works. I thought that the selection dialog shouldn't have been invoked.
So it seems that the USER:... CRS is NOT being interpreted properly -- where, I'm not sure yet, as I was calling QgsVectorLayer directly.
I had noticed before (another issue) that
QgsCoordinateReferenceSystem::createFromString() expects 'INTERNAL' for any srsid incl. the notion of 'USER', else 'EPSG' or 'POSTGIS' or 'PROJ4' or 'WKT'.
It seemed to me that this function could be amended to include 'USER' and would handle the value same as for INTERNAL.
YES! -- added '|user' to the regex string -- this works -- is there any side effect?
Have tried Processing:Buffer with this fix, with data in USER:100028 and now creates the memory layer correctly.
Alternative is to detect and replace 'USER' with 'INTERNAL' everywhere createFromString is called in a layer provider or any other use of USER CRSes.
QgsCoordinateReferenceSystem::createFromOgcWmsCrs()does deal with 'USER', but has still other notions, like: 'custom', and 'qgis' -- this is confusing.
Note that in the original problem described the layer data actually is in the expected CRS; it is just that the layer was assigned the wrong CRS when loaded.