From 04f3216472d79ba7cf23882c11773b40070ebcc8 Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Sat, 7 Nov 2015 14:25:50 +0000 Subject: [PATCH] [GRASS] fixed new mapset region, fixes #13784 --- src/plugins/grass/qgsgrassnewmapset.cpp | 54 ++++++++++--------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/plugins/grass/qgsgrassnewmapset.cpp b/src/plugins/grass/qgsgrassnewmapset.cpp index 53c9f0798a6d..c88ac8bf4db0 100644 --- a/src/plugins/grass/qgsgrassnewmapset.cpp +++ b/src/plugins/grass/qgsgrassnewmapset.cpp @@ -585,10 +585,8 @@ void QgsGrassNewMapset::setGrassRegionDefaults() { QgsDebugMsg( QString( "mCellHead.proj = %1" ).arg( mCellHead.proj ) ); - int srsid = QgsProject::instance()->readNumEntry( - "SpatialRefSys", "/ProjectCRSID", 0 ); - - QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) ); + QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs(); + QgsDebugMsg( "srs = " + srs.toWkt() ); QgsRectangle ext = mIface->mapCanvas()->extent(); bool extSet = false; @@ -600,7 +598,7 @@ void QgsGrassNewMapset::setGrassRegionDefaults() if ( extSet && ( mNoProjRadioButton->isChecked() || ( mProjRadioButton->isChecked() - && srsid == mProjectionSelector->selectedCrsId() ) + && srs.srsid() == mProjectionSelector->selectedCrsId() ) ) ) { @@ -924,12 +922,8 @@ void QgsGrassNewMapset::setCurrentRegion() QgsRectangle ext = mIface->mapCanvas()->extent(); - int srsid = QgsProject::instance()->readNumEntry( - "SpatialRefSys", "/ProjectCRSID", 0 ); - - QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId ); - QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) ); - QgsDebugMsg( QString( "srs.isValid() = %1" ).arg( srs.isValid() ) ); + QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs(); + QgsDebugMsg( "srs = " + srs.toWkt() ); std::vector points; @@ -1016,17 +1010,17 @@ void QgsGrassNewMapset::drawRegion() } } - std::vector tpoints; // ll lr ur ul ll - tpoints.push_back( QgsPoint( w, s ) ); - tpoints.push_back( QgsPoint( e, s ) ); - tpoints.push_back( QgsPoint( e, n ) ); - tpoints.push_back( QgsPoint( w, n ) ); - tpoints.push_back( QgsPoint( w, s ) ); + QList tpoints; // ll lr ur ul ll + tpoints << QgsPoint( w, s ); + tpoints << QgsPoint( e, s ); + tpoints << QgsPoint( e, n ); + tpoints << QgsPoint( w, n ); + tpoints << QgsPoint( w, s ); // Because of possible shift +/- 360 in LL we have to split // the lines at least in 3 parts - std::vector points; // + QList points; // for ( int i = 0; i < 4; i++ ) { for ( int j = 0; j < 3; j++ ) @@ -1036,11 +1030,11 @@ void QgsGrassNewMapset::drawRegion() double dx = ( tpoints[i+1].x() - x ) / 3; double dy = ( tpoints[i+1].y() - y ) / 3; QgsDebugMsg( QString( "dx = %1 x = %2" ).arg( dx ).arg( x + j*dx ) ); - points.push_back( QgsPoint( x + j*dx, y + j*dy ) ); + points << QgsPoint( x + j*dx, y + j*dy ); } } - points.push_back( QgsPoint( points[0] ) ); // close polygon + points << points[0]; // close polygon // Warning: seems that crashes if source == dest if ( mProjectionSelector->selectedCrsId() != GEOCRS_ID ) @@ -1064,9 +1058,7 @@ void QgsGrassNewMapset::drawRegion() QgsCoordinateTransform trans( source, dest ); - - bool ok = true; - for ( int i = 0; i < 13; i++ ) + for ( int i = points.size() - 1; i >= 0; i-- ) { // Warning: I found that with some projections (e.g. Abidjan 1987) // if N = 90 or S = -90 the coordinate projected to @@ -1082,6 +1074,7 @@ void QgsGrassNewMapset::drawRegion() QgsDebugMsg( QString( "%1,%2" ).arg( points[i].x() ).arg( points[i].y() ) ); + // exclude points if transformation failed try { points[i] = trans.transform( points[i] ); @@ -1091,12 +1084,11 @@ void QgsGrassNewMapset::drawRegion() { Q_UNUSED( cse ); QgsDebugMsg( "Cannot transform point" ); - ok = false; - break; + points.removeAt( i ); } } - if ( !ok ) + if ( points.size() < 3 ) { QgsDebugMsg( "Cannot reproject region." ); return; @@ -1396,16 +1388,12 @@ void QgsGrassNewMapset::pageSelected( int index ) connect( mProjectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( sridSelected( QString ) ) ); - // Se current QGIS projection - int srsid = QgsProject::instance()->readNumEntry( - "SpatialRefSys", "/ProjectCRSID", 0 ); + QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs(); + QgsDebugMsg( "srs = " + srs.toWkt() ); - QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId ); - QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) ); - QgsDebugMsg( QString( "srs.isValid() = %1" ).arg( srs.isValid() ) ); if ( srs.isValid() ) { - mProjectionSelector->setSelectedCrsId( srsid ); + mProjectionSelector->setSelectedCrsId( srs.srsid() ); mProjRadioButton->setChecked( true ); projRadioSwitched(); }