Skip to content

Commit 376c5f3

Browse files
committed
new spatialite layer: don't assume epsg id and qgis srsid are the same (fixes #8041)
1 parent 4af8946 commit 376c5f3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/app/qgsnewspatialitelayerdialog.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
7676
QgsCoordinateReferenceSystem srs;
7777
srs.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
7878
srs.validate();
79-
bool ok;
80-
mCrsId = srs.authid().split( ':' ).at( 1 ).toInt( &ok );
79+
mCrsId = srs.authid();
8180
leSRID->setText( srs.authid() + " - " + srs.description() );
8281

8382
pbnFindSRID->setEnabled( mDatabaseComboBox->count() );
@@ -210,7 +209,7 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
210209
// load up the srid table
211210
const char *pzTail;
212211
sqlite3_stmt *ppStmt;
213-
QString sql = "select auth_srid, auth_name, ref_sys_name from spatial_ref_sys order by srid asc";
212+
QString sql = "select auth_name || ':' || auth_srid from spatial_ref_sys order by srid asc";
214213

215214
QSet<QString> myCRSs;
216215

@@ -221,8 +220,7 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
221220
// get the first row of the result set
222221
while ( sqlite3_step( ppStmt ) == SQLITE_ROW )
223222
{
224-
myCRSs.insert( QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) ) +
225-
":" + QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
223+
myCRSs.insert( QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
226224
}
227225
}
228226
else
@@ -244,14 +242,13 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
244242
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
245243
mySelector->setMessage();
246244
mySelector->setOgcWmsCrsFilter( myCRSs );
247-
mySelector->setSelectedCrsId( mCrsId );
245+
mySelector->setSelectedAuthId( mCrsId );
248246

249247
if ( mySelector->exec() )
250248
{
251249
QgsCoordinateReferenceSystem srs;
252250
srs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
253-
bool ok;
254-
int crsId = srs.authid().split( ':' ).value( 1, QString::number( mCrsId ) ).toInt( &ok );
251+
QString crsId = srs.authid();
255252
if ( crsId != mCrsId )
256253
{
257254
mCrsId = crsId;
@@ -375,7 +372,7 @@ bool QgsNewSpatialiteLayerDialog::apply()
375372
QString sqlAddGeom = QString( "select AddGeometryColumn(%1,%2,%3,%4,2)" )
376373
.arg( quotedValue( leLayerName->text() ) )
377374
.arg( quotedValue( leGeometryColumn->text() ) )
378-
.arg( mCrsId )
375+
.arg( mCrsId.split( ':' ).value( 1, "0" ).toInt() )
379376
.arg( quotedValue( selectedType() ) );
380377
QgsDebugMsg( sqlAddGeom ); // OK
381378

src/app/qgsnewspatialitelayerdialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL
6464
static QString quotedValue( QString value );
6565

6666
QPushButton *mOkButton;
67-
int mCrsId;
67+
QString mCrsId;
6868
};
6969

7070
#endif // QGSNEWVECTORLAYERDIALOG_H

0 commit comments

Comments
 (0)