Skip to content

Commit 04f3216

Browse files
committed
[GRASS] fixed new mapset region, fixes #13784
1 parent 061bdde commit 04f3216

1 file changed

Lines changed: 21 additions & 33 deletions

File tree

‎src/plugins/grass/qgsgrassnewmapset.cpp‎

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,8 @@ void QgsGrassNewMapset::setGrassRegionDefaults()
585585
{
586586
QgsDebugMsg( QString( "mCellHead.proj = %1" ).arg( mCellHead.proj ) );
587587

588-
int srsid = QgsProject::instance()->readNumEntry(
589-
"SpatialRefSys", "/ProjectCRSID", 0 );
590-
591-
QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) );
588+
QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs();
589+
QgsDebugMsg( "srs = " + srs.toWkt() );
592590

593591
QgsRectangle ext = mIface->mapCanvas()->extent();
594592
bool extSet = false;
@@ -600,7 +598,7 @@ void QgsGrassNewMapset::setGrassRegionDefaults()
600598
if ( extSet &&
601599
( mNoProjRadioButton->isChecked() ||
602600
( mProjRadioButton->isChecked()
603-
&& srsid == mProjectionSelector->selectedCrsId() )
601+
&& srs.srsid() == mProjectionSelector->selectedCrsId() )
604602
)
605603
)
606604
{
@@ -924,12 +922,8 @@ void QgsGrassNewMapset::setCurrentRegion()
924922

925923
QgsRectangle ext = mIface->mapCanvas()->extent();
926924

927-
int srsid = QgsProject::instance()->readNumEntry(
928-
"SpatialRefSys", "/ProjectCRSID", 0 );
929-
930-
QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId );
931-
QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) );
932-
QgsDebugMsg( QString( "srs.isValid() = %1" ).arg( srs.isValid() ) );
925+
QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs();
926+
QgsDebugMsg( "srs = " + srs.toWkt() );
933927

934928
std::vector<QgsPoint> points;
935929

@@ -1016,17 +1010,17 @@ void QgsGrassNewMapset::drawRegion()
10161010
}
10171011
}
10181012

1019-
std::vector<QgsPoint> tpoints; // ll lr ur ul ll
1020-
tpoints.push_back( QgsPoint( w, s ) );
1021-
tpoints.push_back( QgsPoint( e, s ) );
1022-
tpoints.push_back( QgsPoint( e, n ) );
1023-
tpoints.push_back( QgsPoint( w, n ) );
1024-
tpoints.push_back( QgsPoint( w, s ) );
1013+
QList<QgsPoint> tpoints; // ll lr ur ul ll
1014+
tpoints << QgsPoint( w, s );
1015+
tpoints << QgsPoint( e, s );
1016+
tpoints << QgsPoint( e, n );
1017+
tpoints << QgsPoint( w, n );
1018+
tpoints << QgsPoint( w, s );
10251019

10261020

10271021
// Because of possible shift +/- 360 in LL we have to split
10281022
// the lines at least in 3 parts
1029-
std::vector<QgsPoint> points; //
1023+
QList<QgsPoint> points; //
10301024
for ( int i = 0; i < 4; i++ )
10311025
{
10321026
for ( int j = 0; j < 3; j++ )
@@ -1036,11 +1030,11 @@ void QgsGrassNewMapset::drawRegion()
10361030
double dx = ( tpoints[i+1].x() - x ) / 3;
10371031
double dy = ( tpoints[i+1].y() - y ) / 3;
10381032
QgsDebugMsg( QString( "dx = %1 x = %2" ).arg( dx ).arg( x + j*dx ) );
1039-
points.push_back( QgsPoint( x + j*dx, y + j*dy ) );
1033+
points << QgsPoint( x + j*dx, y + j*dy );
10401034

10411035
}
10421036
}
1043-
points.push_back( QgsPoint( points[0] ) ); // close polygon
1037+
points << points[0]; // close polygon
10441038

10451039
// Warning: seems that crashes if source == dest
10461040
if ( mProjectionSelector->selectedCrsId() != GEOCRS_ID )
@@ -1064,9 +1058,7 @@ void QgsGrassNewMapset::drawRegion()
10641058

10651059
QgsCoordinateTransform trans( source, dest );
10661060

1067-
1068-
bool ok = true;
1069-
for ( int i = 0; i < 13; i++ )
1061+
for ( int i = points.size() - 1; i >= 0; i-- )
10701062
{
10711063
// Warning: I found that with some projections (e.g. Abidjan 1987)
10721064
// if N = 90 or S = -90 the coordinate projected to
@@ -1082,6 +1074,7 @@ void QgsGrassNewMapset::drawRegion()
10821074

10831075
QgsDebugMsg( QString( "%1,%2" ).arg( points[i].x() ).arg( points[i].y() ) );
10841076

1077+
// exclude points if transformation failed
10851078
try
10861079
{
10871080
points[i] = trans.transform( points[i] );
@@ -1091,12 +1084,11 @@ void QgsGrassNewMapset::drawRegion()
10911084
{
10921085
Q_UNUSED( cse );
10931086
QgsDebugMsg( "Cannot transform point" );
1094-
ok = false;
1095-
break;
1087+
points.removeAt( i );
10961088
}
10971089
}
10981090

1099-
if ( !ok )
1091+
if ( points.size() < 3 )
11001092
{
11011093
QgsDebugMsg( "Cannot reproject region." );
11021094
return;
@@ -1396,16 +1388,12 @@ void QgsGrassNewMapset::pageSelected( int index )
13961388
connect( mProjectionSelector, SIGNAL( sridSelected( QString ) ),
13971389
this, SLOT( sridSelected( QString ) ) );
13981390

1399-
// Se current QGIS projection
1400-
int srsid = QgsProject::instance()->readNumEntry(
1401-
"SpatialRefSys", "/ProjectCRSID", 0 );
1391+
QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs();
1392+
QgsDebugMsg( "srs = " + srs.toWkt() );
14021393

1403-
QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId );
1404-
QgsDebugMsg( QString( "current project srsid = %1" ).arg( srsid ) );
1405-
QgsDebugMsg( QString( "srs.isValid() = %1" ).arg( srs.isValid() ) );
14061394
if ( srs.isValid() )
14071395
{
1408-
mProjectionSelector->setSelectedCrsId( srsid );
1396+
mProjectionSelector->setSelectedCrsId( srs.srsid() );
14091397
mProjRadioButton->setChecked( true );
14101398
projRadioSwitched();
14111399
}

0 commit comments

Comments
 (0)