Skip to content

Commit

Permalink
new spatialite layer: don't assume epsg id and qgis srsid are the same (
Browse files Browse the repository at this point in the history
fixes #8041)
  • Loading branch information
jef-n committed Jun 29, 2013
1 parent 4af8946 commit 376c5f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -76,8 +76,7 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
QgsCoordinateReferenceSystem srs;
srs.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
srs.validate();
bool ok;
mCrsId = srs.authid().split( ':' ).at( 1 ).toInt( &ok );
mCrsId = srs.authid();
leSRID->setText( srs.authid() + " - " + srs.description() );

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

QSet<QString> myCRSs;

Expand All @@ -221,8 +220,7 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
// get the first row of the result set
while ( sqlite3_step( ppStmt ) == SQLITE_ROW )
{
myCRSs.insert( QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) ) +
":" + QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
myCRSs.insert( QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
}
}
else
Expand All @@ -244,14 +242,13 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
mySelector->setMessage();
mySelector->setOgcWmsCrsFilter( myCRSs );
mySelector->setSelectedCrsId( mCrsId );
mySelector->setSelectedAuthId( mCrsId );

if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs;
srs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
bool ok;
int crsId = srs.authid().split( ':' ).value( 1, QString::number( mCrsId ) ).toInt( &ok );
QString crsId = srs.authid();
if ( crsId != mCrsId )
{
mCrsId = crsId;
Expand Down Expand Up @@ -375,7 +372,7 @@ bool QgsNewSpatialiteLayerDialog::apply()
QString sqlAddGeom = QString( "select AddGeometryColumn(%1,%2,%3,%4,2)" )
.arg( quotedValue( leLayerName->text() ) )
.arg( quotedValue( leGeometryColumn->text() ) )
.arg( mCrsId )
.arg( mCrsId.split( ':' ).value( 1, "0" ).toInt() )
.arg( quotedValue( selectedType() ) );
QgsDebugMsg( sqlAddGeom ); // OK

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsnewspatialitelayerdialog.h
Expand Up @@ -64,7 +64,7 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL
static QString quotedValue( QString value );

QPushButton *mOkButton;
int mCrsId;
QString mCrsId;
};

#endif // QGSNEWVECTORLAYERDIALOG_H

0 comments on commit 376c5f3

Please sign in to comment.