void QgsDistanceArea::setSourceAuthId( const QString& authId ) { QgsCoordinateReferenceSystem srcCRS; srcCRS.createFromOgcWmsCrs( authId ); mCoordTransform->setSourceCrs( srcCRS ); }
bool QgsDecorationNorthArrow::calculateNorthDirection() { QgsMapCanvas* mapCanvas = QgisApp::instance()->mapCanvas(); bool goodDirn = false; // Get the shown extent... QgsRectangle canvasExtent = mapCanvas->extent(); // ... and all layers extent, ... QgsRectangle fullExtent = mapCanvas->fullExtent(); // ... and combine QgsRectangle extent = canvasExtent.intersect( & fullExtent ); // If no layers are added or shown, we can't get any direction if ( mapCanvas->layerCount() > 0 && ! extent.isEmpty() ) { QgsCoordinateReferenceSystem outputCRS = mapCanvas->mapRenderer()->destinationCrs(); if ( outputCRS.isValid() && !outputCRS.geographicFlag() ) { // Use a geographic CRS to get lat/long to work out direction QgsCoordinateReferenceSystem ourCRS; ourCRS.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID ); assert( ourCRS.isValid() ); QgsCoordinateTransform transform( outputCRS, ourCRS ); QgsPoint p1( extent.center() ); // A point a bit above p1. XXX assumes that y increases up!! // May need to involve the maptopixel transform if this proves // to be a problem. QgsPoint p2( p1.x(), p1.y() + extent.height() * 0.25 ); // project p1 and p2 to geographic coords try { p1 = transform.transform( p1 ); p2 = transform.transform( p2 ); } catch ( QgsCsException &e ) { Q_UNUSED( e ); // just give up QgsDebugMsg( "North Arrow: Transformation error, quitting" ); return false; } // Work out the value of the initial heading one takes to go // from point p1 to point p2. The north direction is then that // many degrees anti-clockwise or vertical. // Take some care to not divide by zero, etc, and ensure that we // get sensible results for all possible values for p1 and p2. goodDirn = true; double angle = 0.0; // convert to radians for the equations below p1.multiply( PI / 180.0 ); p2.multiply( PI / 180.0 ); double y = sin( p2.x() - p1.x() ) * cos( p2.y() ); double x = cos( p1.y() ) * sin( p2.y() ) - sin( p1.y() ) * cos( p2.y() ) * cos( p2.x() - p1.x() ); // Use TOL to decide if the quotient is big enough. // Both x and y can be very small, if heavily zoomed // For small y/x, we set directly angle 0. Not sure // if this is needed. if ( y > 0.0 ) { if ( x > 0.0 && ( y / x ) > TOL ) angle = atan( y / x ); else if ( x < 0.0 && ( y / x ) < -TOL ) angle = PI - atan( -y / x ); else angle = 0.5 * PI; } else if ( y < 0.0 ) { if ( x > 0.0 && ( y / x ) < -TOL ) angle = -atan( -y / x ); else if ( x < 0.0 && ( y / x ) > TOL ) angle = atan( y / x ) - PI; else angle = 1.5 * PI; } else { if ( x > TOL ) angle = 0.0; else if ( x < -TOL ) angle = PI; else { angle = 0.0; // p1 = p2 goodDirn = false; } } // And set the angle of the north arrow. Perhaps do something // different if goodDirn = false. mRotationInt = qRound( fmod( 360.0 - angle * 180.0 / PI, 360.0 ) ); } else { // For geographic CRS and for when there are no layers, set the // direction back to the default mRotationInt = 0; } } return goodDirn; }
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; if ( !db ) { 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_srid, auth_name, ref_sys_name from spatial_ref_sys order by srid asc"; QSet<QString> myCRSs; int 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, 1 ) ) + ":" + 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 ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs; srs.createFromOgcWmsCrs( mySelector->selectedAuthId() ); bool ok; mCrsId = srs.authid().split( ':' ).at( 1 ).toInt( &ok ); leSRID->setText( srs.authid() + " - " + srs.description() ); } delete mySelector; }
QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl ) : QDialog( parent, fl ) { setupUi( this ); QSettings settings; restoreGeometry( settings.value( "/Windows/NewVectorLayer/geometry" ).toByteArray() ); mAddAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) ); mRemoveAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) ); mTypeBox->addItem( tr( "Text data" ), "String" ); mTypeBox->addItem( tr( "Whole number" ), "Integer" ); mTypeBox->addItem( tr( "Decimal number" ), "Real" ); mTypeBox->addItem( tr( "Date" ), "Date" ); mWidth->setValidator( new QIntValidator( 1, 255, this ) ); mPrecision->setValidator( new QIntValidator( 0, 15, this ) ); mPointRadioButton->setChecked( true ); mFileFormatComboBox->addItem( tr( "ESRI Shapefile" ), "ESRI Shapefile" ); #if 0 // Disabled until provider properly supports editing the created file formats mFileFormatComboBox->addItem( tr( "Comma Separated Value" ), "Comma Separated Value" ); mFileFormatComboBox->addItem( tr( "GML" ), "GML" ); mFileFormatComboBox->addItem( tr( "Mapinfo File" ), "Mapinfo File" ); #endif if ( mFileFormatComboBox->count() == 1 ) { mFileFormatComboBox->setVisible( false ); mFileFormatLabel->setVisible( false ); } mFileFormatComboBox->setCurrentIndex( 0 ); mFileEncoding->addItems( QgsVectorDataProvider::availableEncodings() ); // Use default encoding if none supplied QString enc = QSettings().value( "/UI/encoding", "System" ).toString(); // The specified decoding is added if not existing alread, and then set current. // This should select it. int encindex = mFileEncoding->findText( enc ); if ( encindex < 0 ) { mFileEncoding->insertItem( 0, enc ); encindex = 0; } mFileEncoding->setCurrentIndex( encindex ); mOkButton = buttonBox->button( QDialogButtonBox::Ok ); mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << "id" << "Integer" << "10" << "" ) ); QgsCoordinateReferenceSystem srs; srs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() ); srs.validate(); mCrsId = srs.srsid(); leSpatialRefSys->setText( srs.authid() + " - " + srs.description() ); connect( mNameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( nameChanged( QString ) ) ); connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) ); mAddAttributeButton->setEnabled( false ); mRemoveAttributeButton->setEnabled( false ); }
QgsNewGeoPackageLayerDialog::QgsNewGeoPackageLayerDialog( QWidget *parent, Qt::WindowFlags fl ) : QDialog( parent, fl ) , mOkButton( nullptr ) , mTableNameEdited( false ) , mLayerIdentifierEdited( false ) { setupUi( this ); QSettings settings; restoreGeometry( settings.value( "/Windows/NewGeoPackageLayer/geometry" ).toByteArray() ); mAddAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) ); mRemoveAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) ); #ifdef SUPPORT_GEOMETRY_LESS mGeometryTypeBox->addItem( tr( "Non spatial" ), wkbNone ); #endif mGeometryTypeBox->addItem( tr( "Point" ), wkbPoint ); mGeometryTypeBox->addItem( tr( "Line" ), wkbLineString ); mGeometryTypeBox->addItem( tr( "Polygon" ), wkbPolygon ); mGeometryTypeBox->addItem( tr( "Multi point" ), wkbMultiPoint ); mGeometryTypeBox->addItem( tr( "Multi line" ), wkbMultiLineString ); mGeometryTypeBox->addItem( tr( "Multi polygon" ), wkbMultiPolygon ); #ifdef SUPPORT_CURVE_GEOMETRIES #if 0 // QGIS always create CompoundCurve and there's no real interest of having just CircularString. CompoundCurve are more useful mGeometryTypeBox->addItem( tr( "Circular string" ), wkbCircularString ); #endif mGeometryTypeBox->addItem( tr( "Compound curve" ), wkbCompoundCurve ); mGeometryTypeBox->addItem( tr( "Curve polygon" ), wkbCurvePolygon ); mGeometryTypeBox->addItem( tr( "Multi curve" ), wkbMultiCurve ); mGeometryTypeBox->addItem( tr( "Multi surface" ), wkbMultiSurface ); #endif #ifdef SUPPORT_GEOMETRY_LESS mGeometryColumnEdit->setEnabled( false ); mCheckBoxCreateSpatialIndex->setEnabled( false ); mCrsSelector->setEnabled( false ); #endif mFieldTypeBox->addItem( tr( "Text data" ), "text" ); mFieldTypeBox->addItem( tr( "Whole number (integer)" ), "integer" ); #ifdef SUPPORT_INTEGER64 mFieldTypeBox->addItem( tr( "Whole number (integer 64 bit)" ), "integer64" ); #endif mFieldTypeBox->addItem( tr( "Decimal number (real)" ), "real" ); mFieldTypeBox->addItem( tr( "Date" ), "date" ); mFieldTypeBox->addItem( tr( "Date&time" ), "datetime" ); mOkButton = buttonBox->button( QDialogButtonBox::Ok ); mOkButton->setEnabled( false ); // Set the SRID box to a default of WGS84 QgsCoordinateReferenceSystem defaultCrs; defaultCrs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() ); defaultCrs.validate(); mCrsSelector->setCrs( defaultCrs ); connect( mFieldNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( fieldNameChanged( QString ) ) ); connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) ); connect( mTableNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( checkOk() ) ); connect( mDatabaseEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( checkOk() ) ); mAddAttributeButton->setEnabled( false ); mRemoveAttributeButton->setEnabled( false ); #ifndef SUPPORT_SPATIAL_INDEX mCheckBoxCreateSpatialIndex->hide(); mCheckBoxCreateSpatialIndex->setChecked( false ); #else mCheckBoxCreateSpatialIndex->setChecked( true ); #endif #ifndef SUPPORT_IDENTIFIER_DESCRIPTION mLayerIdentifierLabel->hide(); mLayerIdentifierEdit->hide(); mLayerDescriptionLabel->hide(); mLayerDescriptionEdit->hide(); #endif #ifndef SUPPORT_FIELD_WIDTH mFieldLengthLabel->hide(); mFieldLengthEdit->hide(); #endif }
void QgsDistanceArea::setSourceEpsgCrsId( long epsgId ) { QgsCoordinateReferenceSystem srcCRS; srcCRS.createFromOgcWmsCrs( QString( "EPSG:%1" ).arg( epsgId ) ); mCoordTransform->setSourceCrs( srcCRS ); }