[QGIS Commit] r15758 - in trunk/qgis/src: plugins/grass providers/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Apr 18 10:48:33 EDT 2011


Author: rblazek
Date: 2011-04-18 07:48:33 -0700 (Mon, 18 Apr 2011)
New Revision: 15758

Modified:
   trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
   trunk/qgis/src/providers/grass/qgsgrass.cpp
   trunk/qgis/src/providers/grass/qgsgrass.h
   trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
Log:
GRASS region transformation resent on mapset change

Modified: trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp	2011-04-18 13:04:08 UTC (rev 15757)
+++ trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp	2011-04-18 14:48:33 UTC (rev 15758)
@@ -115,6 +115,8 @@
   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 @@
     {
       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 @@
 
   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 @@
 {
   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() );
   }

Modified: trunk/qgis/src/providers/grass/qgsgrass.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.cpp	2011-04-18 13:04:08 UTC (rev 15757)
+++ trunk/qgis/src/providers/grass/qgsgrass.cpp	2011-04-18 14:48:33 UTC (rev 15758)
@@ -38,6 +38,7 @@
 #ifndef _MSC_VER
 #include <unistd.h>
 #endif
+#include <grass/gprojects.h>
 #include <grass/Vect.h>
 #include <grass/version.h>
 }
@@ -1160,6 +1161,47 @@
   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 ) );

Modified: trunk/qgis/src/providers/grass/qgsgrass.h
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.h	2011-04-18 13:04:08 UTC (rev 15757)
+++ trunk/qgis/src/providers/grass/qgsgrass.h	2011-04-18 14:48:33 UTC (rev 15758)
@@ -196,6 +196,9 @@
     // ! 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 );

Modified: trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrassprovider.cpp	2011-04-18 13:04:08 UTC (rev 15757)
+++ trunk/qgis/src/providers/grass/qgsgrassprovider.cpp	2011-04-18 14:48:33 UTC (rev 15758)
@@ -1316,43 +1316,7 @@
 
 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()



More information about the QGIS-commit mailing list