GRASS region transformation resent on mapset change

git-svn-id: http://svn.osgeo.org/qgis/trunk@15758 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
rblazek 2011-04-18 14:48:33 +00:00
parent 492926009c
commit caf52d9dc3
4 changed files with 64 additions and 46 deletions

View File

@ -115,6 +115,8 @@ void QgsGrassPlugin::initGui()
mCanvas = qGisInterface->mapCanvas();
QWidget* qgis = qGisInterface->mainWindow();
connect( mCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setTransform() ) );
// Connect project
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
connect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
@ -244,6 +246,20 @@ void QgsGrassPlugin::mapsetChanged()
{
mTools->mapsetChanged();
}
QString gisdbase = QgsGrass::getDefaultGisdbase();
QString location = QgsGrass::getDefaultLocation();
try
{
mCrs = QgsGrass::crsDirect( gisdbase, location );
}
catch ( QgsGrass::Exception &e )
{
QgsDebugMsg( "Cannot read GRASS CRS : " + QString( e.what() ) );
mCrs = QgsCoordinateReferenceSystem();
}
QgsDebugMsg( "mCrs: " + mCrs.toWkt() );
setTransform();
redrawRegion();
}
}
@ -590,15 +606,6 @@ void QgsGrassPlugin::displayRegion()
QgsGrass::setLocation( gisdbase, location );
// TODO: check better if we have to init + maybe the location can change -> mCrs must be reloaded
if ( !mCrs.isValid() )
{
mCrs = QgsGrass::crs( gisdbase, location );
QgsDebugMsg( "mCrs: " + mCrs.toWkt() );
setTransform();
connect( mCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setTransform() ) );
}
struct Cell_head window;
char *err = G__get_window( &window, ( char * ) "", ( char * ) "WIND", mapset.toLatin1().data() );
@ -877,6 +884,8 @@ void QgsGrassPlugin::setTransform()
{
if ( mCrs.isValid() && mCanvas->mapRenderer()->destinationCrs().isValid() )
{
QgsDebugMsg( "srcCrs: " + mCrs.toWkt() );
QgsDebugMsg( "destCrs " + mCanvas->mapRenderer()->destinationCrs().toWkt() );
mCoordinateTransform.setSourceCrs( mCrs );
mCoordinateTransform.setDestCRS( mCanvas->mapRenderer()->destinationCrs() );
}

View File

@ -38,6 +38,7 @@ extern "C"
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <grass/gprojects.h>
#include <grass/Vect.h>
#include <grass/version.h>
}
@ -1160,6 +1161,47 @@ QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crs( QString gisdbase, QStri
return crs;
}
QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crsDirect( QString gisdbase, QString location )
{
QString Wkt;
struct Cell_head cellhd;
QgsGrass::resetError();
QgsGrass::setLocation( gisdbase, location );
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
setlocale( LC_NUMERIC, "C" );
try
{
G_get_default_window( &cellhd );
}
catch ( QgsGrass::Exception &e )
{
Q_UNUSED( e );
setlocale( LC_NUMERIC, oldlocale );
QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
return QgsCoordinateReferenceSystem();
}
if ( cellhd.proj != PROJECTION_XY )
{
struct Key_Value *projinfo = G_get_projinfo();
struct Key_Value *projunits = G_get_projunits();
char *wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
Wkt = QString( wkt );
G_free( wkt );
}
setlocale( LC_NUMERIC, oldlocale );
QgsCoordinateReferenceSystem srs;
srs.createFromWkt( Wkt );
return srs;
}
QgsRectangle GRASS_EXPORT QgsGrass::extent( QString gisdbase, QString location, QString mapset, QString map, MapType type )
{
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );

View File

@ -196,6 +196,9 @@ class QgsGrass
// ! Get location projection
static GRASS_EXPORT QgsCoordinateReferenceSystem crs( QString gisdbase, QString location );
// ! Get location projection calling directly GRASS library
static GRASS_EXPORT QgsCoordinateReferenceSystem crsDirect( QString gisdbase, QString location );
// ! Get map extent
static GRASS_EXPORT QgsRectangle extent( QString gisdbase, QString location,
QString mapset, QString map, MapType type = None );

View File

@ -1316,43 +1316,7 @@ struct Map_info *QgsGrassProvider::layerMap( int layerId )
QgsCoordinateReferenceSystem QgsGrassProvider::crs()
{
QString Wkt;
struct Cell_head cellhd;
QgsGrass::resetError();
QgsGrass::setLocation( mGisdbase, mLocation );
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
setlocale( LC_NUMERIC, "C" );
try
{
G_get_default_window( &cellhd );
}
catch ( QgsGrass::Exception &e )
{
Q_UNUSED( e );
setlocale( LC_NUMERIC, oldlocale );
QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
return QgsCoordinateReferenceSystem();
}
if ( cellhd.proj != PROJECTION_XY )
{
struct Key_Value *projinfo = G_get_projinfo();
struct Key_Value *projunits = G_get_projunits();
char *wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
Wkt = QString( wkt );
G_free( wkt );
}
setlocale( LC_NUMERIC, oldlocale );
QgsCoordinateReferenceSystem srs;
srs.createFromWkt( Wkt );
return srs;
return QgsGrass::crs( mGisdbase, mLocation );
}
int QgsGrassProvider::grassLayer()