Skip to content

Commit caf52d9

Browse files
author
rblazek
committedApr 18, 2011
GRASS region transformation resent on mapset change
git-svn-id: http://svn.osgeo.org/qgis/trunk@15758 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4929260 commit caf52d9

File tree

4 files changed

+64
-46
lines changed

4 files changed

+64
-46
lines changed
 

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ void QgsGrassPlugin::initGui()
115115
mCanvas = qGisInterface->mapCanvas();
116116
QWidget* qgis = qGisInterface->mainWindow();
117117

118+
connect( mCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setTransform() ) );
119+
118120
// Connect project
119121
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
120122
connect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
@@ -244,6 +246,20 @@ void QgsGrassPlugin::mapsetChanged()
244246
{
245247
mTools->mapsetChanged();
246248
}
249+
QString gisdbase = QgsGrass::getDefaultGisdbase();
250+
QString location = QgsGrass::getDefaultLocation();
251+
try
252+
{
253+
mCrs = QgsGrass::crsDirect( gisdbase, location );
254+
}
255+
catch ( QgsGrass::Exception &e )
256+
{
257+
QgsDebugMsg( "Cannot read GRASS CRS : " + QString( e.what() ) );
258+
mCrs = QgsCoordinateReferenceSystem();
259+
}
260+
QgsDebugMsg( "mCrs: " + mCrs.toWkt() );
261+
setTransform();
262+
redrawRegion();
247263
}
248264
}
249265

@@ -590,15 +606,6 @@ void QgsGrassPlugin::displayRegion()
590606

591607
QgsGrass::setLocation( gisdbase, location );
592608

593-
// TODO: check better if we have to init + maybe the location can change -> mCrs must be reloaded
594-
if ( !mCrs.isValid() )
595-
{
596-
mCrs = QgsGrass::crs( gisdbase, location );
597-
QgsDebugMsg( "mCrs: " + mCrs.toWkt() );
598-
setTransform();
599-
connect( mCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setTransform() ) );
600-
}
601-
602609
struct Cell_head window;
603610
char *err = G__get_window( &window, ( char * ) "", ( char * ) "WIND", mapset.toLatin1().data() );
604611

@@ -877,6 +884,8 @@ void QgsGrassPlugin::setTransform()
877884
{
878885
if ( mCrs.isValid() && mCanvas->mapRenderer()->destinationCrs().isValid() )
879886
{
887+
QgsDebugMsg( "srcCrs: " + mCrs.toWkt() );
888+
QgsDebugMsg( "destCrs " + mCanvas->mapRenderer()->destinationCrs().toWkt() );
880889
mCoordinateTransform.setSourceCrs( mCrs );
881890
mCoordinateTransform.setDestCRS( mCanvas->mapRenderer()->destinationCrs() );
882891
}

‎src/providers/grass/qgsgrass.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C"
3838
#ifndef _MSC_VER
3939
#include <unistd.h>
4040
#endif
41+
#include <grass/gprojects.h>
4142
#include <grass/Vect.h>
4243
#include <grass/version.h>
4344
}
@@ -1160,6 +1161,47 @@ QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crs( QString gisdbase, QStri
11601161
return crs;
11611162
}
11621163

1164+
QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crsDirect( QString gisdbase, QString location )
1165+
{
1166+
QString Wkt;
1167+
1168+
struct Cell_head cellhd;
1169+
1170+
QgsGrass::resetError();
1171+
QgsGrass::setLocation( gisdbase, location );
1172+
1173+
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
1174+
setlocale( LC_NUMERIC, "C" );
1175+
1176+
try
1177+
{
1178+
G_get_default_window( &cellhd );
1179+
}
1180+
catch ( QgsGrass::Exception &e )
1181+
{
1182+
Q_UNUSED( e );
1183+
setlocale( LC_NUMERIC, oldlocale );
1184+
QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
1185+
return QgsCoordinateReferenceSystem();
1186+
}
1187+
1188+
if ( cellhd.proj != PROJECTION_XY )
1189+
{
1190+
struct Key_Value *projinfo = G_get_projinfo();
1191+
struct Key_Value *projunits = G_get_projunits();
1192+
char *wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
1193+
Wkt = QString( wkt );
1194+
G_free( wkt );
1195+
}
1196+
1197+
setlocale( LC_NUMERIC, oldlocale );
1198+
1199+
QgsCoordinateReferenceSystem srs;
1200+
srs.createFromWkt( Wkt );
1201+
1202+
return srs;
1203+
}
1204+
11631205
QgsRectangle GRASS_EXPORT QgsGrass::extent( QString gisdbase, QString location, QString mapset, QString map, MapType type )
11641206
{
11651207
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );

‎src/providers/grass/qgsgrass.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ class QgsGrass
196196
// ! Get location projection
197197
static GRASS_EXPORT QgsCoordinateReferenceSystem crs( QString gisdbase, QString location );
198198

199+
// ! Get location projection calling directly GRASS library
200+
static GRASS_EXPORT QgsCoordinateReferenceSystem crsDirect( QString gisdbase, QString location );
201+
199202
// ! Get map extent
200203
static GRASS_EXPORT QgsRectangle extent( QString gisdbase, QString location,
201204
QString mapset, QString map, MapType type = None );

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,43 +1316,7 @@ struct Map_info *QgsGrassProvider::layerMap( int layerId )
13161316

13171317
QgsCoordinateReferenceSystem QgsGrassProvider::crs()
13181318
{
1319-
QString Wkt;
1320-
1321-
struct Cell_head cellhd;
1322-
1323-
QgsGrass::resetError();
1324-
QgsGrass::setLocation( mGisdbase, mLocation );
1325-
1326-
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
1327-
setlocale( LC_NUMERIC, "C" );
1328-
1329-
try
1330-
{
1331-
G_get_default_window( &cellhd );
1332-
}
1333-
catch ( QgsGrass::Exception &e )
1334-
{
1335-
Q_UNUSED( e );
1336-
setlocale( LC_NUMERIC, oldlocale );
1337-
QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
1338-
return QgsCoordinateReferenceSystem();
1339-
}
1340-
1341-
if ( cellhd.proj != PROJECTION_XY )
1342-
{
1343-
struct Key_Value *projinfo = G_get_projinfo();
1344-
struct Key_Value *projunits = G_get_projunits();
1345-
char *wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
1346-
Wkt = QString( wkt );
1347-
G_free( wkt );
1348-
}
1349-
1350-
setlocale( LC_NUMERIC, oldlocale );
1351-
1352-
QgsCoordinateReferenceSystem srs;
1353-
srs.createFromWkt( Wkt );
1354-
1355-
return srs;
1319+
return QgsGrass::crs( mGisdbase, mLocation );
13561320
}
13571321

13581322
int QgsGrassProvider::grassLayer()

0 commit comments

Comments
 (0)
Please sign in to comment.