void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked() { QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector(); if( mCRS >= 0 ) mySelector->setSelectedCrsId( mCRS ); mySelector->setMessage( tr( "Select the coordinate reference system for the vector file. " "The data points will be transformed from the layer coordinate reference system." ) ); if( mySelector->exec() ) { QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId ); mCRS = srs.srsid(); leCRS->setText( srs.description() ); } delete mySelector; }
void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked() { QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this ); mySelector->setMessage(); mySelector->setSelectedCrsId( mCrsId ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs; srs.createFromOgcWmsCrs( mySelector->selectedAuthId() ); mCrsId = srs.srsid(); leSpatialRefSys->setText( srs.authid() + " - " + srs.description() ); } else { QApplication::restoreOverrideCursor(); } delete mySelector; }
void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked() { QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this ); mySelector->setMessage(); mySelector->setSelectedCrsId( layer->crs().srsid() ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId ); layer->setCrs( srs ); } else { QApplication::restoreOverrideCursor(); } delete mySelector; leSpatialRefSys->setText( layer->crs().authid() + " - " + layer->crs().description() ); leSpatialRefSys->setCursorPosition( 0 ); }
void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked() { // first get list of supported SRID from the selected Spatialite database // to build filter for projection selector sqlite3 *db = 0; bool status = true; int rc = sqlite3_open_v2( mDatabaseComboBox->currentText().toUtf8(), &db, SQLITE_OPEN_READONLY, NULL ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "SpatiaLite Database" ), tr( "Unable to open the database" ) ); return; } // load up the srid table const char *pzTail; sqlite3_stmt *ppStmt; QString sql = "select auth_name || ':' || auth_srid from spatial_ref_sys order by srid asc"; QSet<QString> myCRSs; rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail ); // XXX Need to free memory from the error msg if one is set if ( rc == SQLITE_OK ) { // get the first row of the result set while ( sqlite3_step( ppStmt ) == SQLITE_ROW ) { myCRSs.insert( QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) ); } } else { // XXX query failed -- warn the user some how QMessageBox::warning( 0, tr( "Error" ), tr( "Failed to load SRIDS: %1" ).arg( sqlite3_errmsg( db ) ) ); status = false; } // close the statement sqlite3_finalize( ppStmt ); sqlite3_close( db ); if ( !status ) { return; } // prepare projection selector QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this ); mySelector->setMessage(); mySelector->setOgcWmsCrsFilter( myCRSs ); mySelector->setSelectedAuthId( mCrsId ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs; srs.createFromOgcWmsCrs( mySelector->selectedAuthId() ); QString crsId = srs.authid(); if ( crsId != mCrsId ) { mCrsId = crsId; leSRID->setText( srs.authid() + " - " + srs.description() ); } } delete mySelector; }
void QgsLegendLayerFile::saveAsShapefileGeneral( bool saveOnlySelection ) { QgsCoordinateReferenceSystem destCRS; if ( mLyr.layer()->type() != QgsMapLayer::VectorLayer ) return; QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( mLyr.layer() ); // get a name for the shapefile // Get a file to process, starting at the current directory QSettings settings; QString filter = QString( "Shapefiles (*.shp)" ); QString dirName = settings.value( "/UI/lastShapefileDir", "." ).toString(); QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog( 0, tr( "Save layer as..." ), dirName, filter, QString( "UTF-8" ) ); openFileDialog->setAcceptMode( QFileDialog::AcceptSave ); // allow for selection of more than one file //openFileDialog->setMode(QFileDialog::AnyFile); if ( openFileDialog->exec() != QDialog::Accepted ) return; QString encoding = openFileDialog->encoding(); QString shapefileName = openFileDialog->selectedFiles().first(); settings.setValue( "/UI/lastShapefileDir", QFileInfo( shapefileName ).absolutePath() ); if ( shapefileName.isNull() ) return; // add the extension if not present if ( shapefileName.indexOf( ".shp" ) == -1 ) { shapefileName += ".shp"; } destCRS = vlayer->srs(); // Find out if we have projections enabled or not if ( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() ) { destCRS = QgisApp::instance()->mapCanvas()->mapRenderer()->destinationSrs(); } QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector(); mySelector->setSelectedCrsId( destCRS.srsid() ); mySelector->setMessage( tr( "Select the coordinate reference system for the saved shapefile." ) + tr( "The data points will be transformed from the layer coordinate reference system." ) ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId ); destCRS = srs; // destCRS->createFromId(mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId) } else { // Aborted CS selection, don't save. delete mySelector; return; } delete mySelector; // overwrite the file - user will already have been prompted // to verify they want to overwrite by the file dialog above if ( QFile::exists( shapefileName ) ) { if ( !QgsVectorFileWriter::deleteShapeFile( shapefileName ) ) { return; } } // ok if the file existed it should be deleted now so we can continue... QApplication::setOverrideCursor( Qt::WaitCursor ); QgsVectorFileWriter::WriterError error; error = QgsVectorFileWriter::writeAsShapefile( vlayer, shapefileName, encoding, &destCRS, saveOnlySelection ); QApplication::restoreOverrideCursor(); switch ( error ) { case QgsVectorFileWriter::NoError: QMessageBox::information( 0, tr( "Saving done" ), tr( "Export to Shapefile has been completed" ) ); break; case QgsVectorFileWriter::ErrDriverNotFound: QMessageBox::warning( 0, tr( "Driver not found" ), tr( "ESRI Shapefile driver is not available" ) ); break; case QgsVectorFileWriter::ErrCreateDataSource: QMessageBox::warning( 0, tr( "Error creating shapefile" ), tr( "The shapefile could not be created (" ) + shapefileName + ")" ); break; case QgsVectorFileWriter::ErrCreateLayer: QMessageBox::warning( 0, tr( "Error" ), tr( "Layer creation failed" ) ); break; case QgsVectorFileWriter::ErrAttributeTypeUnsupported: QMessageBox::warning( 0, tr( "Error" ), tr( "Layer attribute table contains unsupported datatype(s)" ) ); break; } }