Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PostgreSQL provider] Retrieve CRS from spatial_ref_sys #43338

Merged
merged 2 commits into from
May 22, 2021

Conversation

rouault
Copy link
Contributor

@rouault rouault commented May 21, 2021

instead of relying on QgsCoordinateReferenceSystem::createFromPostgisSrid()
which contrary to what its name suggest doesn't use postgis at all, but
the QGIS CRS database.

I detected the issue initially on a database where my spatial_ref_sys
table had been emptied and a few entries where assigned with SRIDs in
the EPSG range but with definitions that weren't the ones from EPSG.
There is no guarantee that EPSG:XXXX gets a SRID of XXXX

And the past implementation of the fallback case of QgsPostgresProvider::crs()
only looked at proj4text instead of using the WKT from srtext.

instead of relying on QgsCoordinateReferenceSystem::createFromPostgisSrid()
which contrary to what its name suggest doesn't use postgis at all, but
the QGIS CRS database.

I detected the issue initially on a database where my spatial_ref_sys
table had been emptied and a few entries where assigned with SRIDs in
the EPSG range but with definitions that weren't the ones from EPSG.
There is no guarantee that EPSG:XXXX gets a SRID of XXXX

And the past implementation of the fallback case of QgsPostgresProvider::crs()
only looked at proj4text instead of using the WKT from srtext.
@github-actions github-actions bot added this to the 3.20.0 milestone May 21, 2021
Copy link
Collaborator

@nyalldawson nyalldawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this has been on my wishlist for a long time!

Is the postgres id in QgsCoordinateReferenceSystem still used anywhere? Would be nice to deprecated that as it's quite dangerous/misleading API.

@rouault
Copy link
Contributor Author

rouault commented May 21, 2021

Is the postgres id in QgsCoordinateReferenceSystem still used anywhere?

createFromPostgisSrid() is no longer needed, and I've added a commit removing it (was private), but I see postgisSrid() is called in quite a few place. I guess in most of them it must be wrong, except the 2 places in the postgres provider where we might actually get a spatial_ref_sys SRID and should do that in another way. But I'd say cleanup for later...

@nyalldawson
Copy link
Collaborator

But I'd say cleanup for later.

Thanks, it's a good step forward!

This method was private and only used by the Postgres provider through
friend class.
@rouault rouault force-pushed the fix_postgis_srs_retrieval branch from b2a159c to f79be39 Compare May 21, 2021 21:31
@nyalldawson nyalldawson merged commit 9da78ed into qgis:master May 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants