Skip to content

Commit e765cb1

Browse files
committed
[mssql] More sensible srid when adding CRS to MS SQL database
The spatial_ref_sys table has srid column with ID of CRS entries. I believe the IDs can be arbitrary, however it has been a good habit to use EPSG number for srid (at least in GDAL - and the same thing happens in PostGIS - srid values are the same as EPSG numbers). In QGIS import if we add a new row to spatial_ref_sys table, the code was using srsid() as ID which is internal ID in QGIS srs.db and it has nothing to do with other IDs. Some pieces of code (probably incorrectly) expect that srid is actually the EPSG number, so let's use those so that we are consistent with GDAL and fix these minor issues (for example, tooltip of MS SQL layers in browser show srid - which in case of layers loaded with QGIS were meaningless)
1 parent 885267d commit e765cb1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/providers/mssql/qgsmssqlprovider.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ QgsVectorLayerExporter::ExportError QgsMssqlProvider::createEmptyLayer( const QS
18021802
long srid = 0;
18031803
if ( srs.isValid() )
18041804
{
1805-
srid = srs.srsid();
1805+
srid = srs.postgisSrid();
18061806
QString auth_srid = QStringLiteral( "null" );
18071807
QString auth_name = QStringLiteral( "null" );
18081808
QStringList sl = srs.authid().split( ':' );
@@ -1812,7 +1812,7 @@ QgsVectorLayerExporter::ExportError QgsMssqlProvider::createEmptyLayer( const QS
18121812
auth_srid = sl[1];
18131813
}
18141814
sql = QStringLiteral( "IF NOT EXISTS (SELECT * FROM spatial_ref_sys WHERE srid=%1) INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text) VALUES (%1, %2, %3, '%4', '%5')" )
1815-
.arg( srs.srsid() )
1815+
.arg( srid )
18161816
.arg( auth_name,
18171817
auth_srid,
18181818
srs.toWkt(),

0 commit comments

Comments
 (0)