Skip to content

Commit

Permalink
[GRASS] fixed new mapset region, fixes #13784
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Nov 7, 2015
1 parent 061bdde commit 04f3216
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Expand Up @@ -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;
Expand All @@ -600,7 +598,7 @@ void QgsGrassNewMapset::setGrassRegionDefaults()
if ( extSet &&
( mNoProjRadioButton->isChecked() ||
( mProjRadioButton->isChecked()
&& srsid == mProjectionSelector->selectedCrsId() )
&& srs.srsid() == mProjectionSelector->selectedCrsId() )
)
)
{
Expand Down Expand Up @@ -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<QgsPoint> points;

Expand Down Expand Up @@ -1016,17 +1010,17 @@ void QgsGrassNewMapset::drawRegion()
}
}

std::vector<QgsPoint> 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<QgsPoint> 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<QgsPoint> points; //
QList<QgsPoint> points; //
for ( int i = 0; i < 4; i++ )
{
for ( int j = 0; j < 3; j++ )
Expand All @@ -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 )
Expand All @@ -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
Expand All @@ -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] );
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 04f3216

Please sign in to comment.