[QGIS Commit] r9304 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Sep 12 06:35:00 EDT 2008


Author: jef
Date: 2008-09-12 06:35:00 -0400 (Fri, 12 Sep 2008)
New Revision: 9304

Modified:
   trunk/qgis/src/core/qgsgeometry.cpp
   trunk/qgis/src/core/qgsvectorlayer.cpp
Log:
fix geometry editing:
- store geometry changes to added features
- fix GEOS exception handling
- fix QgsGeometry::vertexAt() and QgsGeometry::closestVertexWithContext()


Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2008-09-11 19:59:21 UTC (rev 9303)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2008-09-12 10:35:00 UTC (rev 9304)
@@ -38,26 +38,46 @@
 class GEOSException
 {
   public:
-    GEOSException( const char *theMsg )
+    GEOSException( char *theMsg )
     {
-      msg  = theMsg;
+      if ( strcmp( theMsg, "Unknown exception thrown" ) == 0 && lastMsg )
+      {
+        delete [] theMsg;
+        msg = new char[strlen( lastMsg )+1];
+        strcpy( msg, lastMsg );
+      }
+      else
+      {
+        msg = theMsg;
+        lastMsg = msg;
+      }
     }
 
+    // copy constructor
+    GEOSException( const GEOSException &rhs )
+    {
+      *this = rhs;
+    }
+
     ~GEOSException()
     {
+      if ( lastMsg == msg )
+        lastMsg = NULL;
       delete [] msg;
     }
 
-
     const char *what()
     {
       return msg;
     }
 
   private:
-    const char *msg;
+    char *msg;
+    static const char *lastMsg;
 };
 
+const char *GEOSException::lastMsg = NULL;
+
 void throwGEOSException( const char *fmt, ... )
 {
   va_list ap;
@@ -2080,7 +2100,11 @@
   {
     try
     {
-      const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( mGeos );
+      const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
+      if ( !g )
+        return QgsPoint( 0, 0 );
+
+      const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g );
       GEOSCoordSeq_getX( cs, atVertex, &x );
       GEOSCoordSeq_getY( cs, atVertex, &y );
       return QgsPoint( x, y );
@@ -2317,8 +2341,12 @@
     // set up the GEOS geometry
     exportWkbToGeos();
 
-    const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( mGeos );
+    const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
+    if ( g == NULL )
+      return -1;
 
+    const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( g );
+
     unsigned int n;
     GEOSCoordSeq_getSize( sequence, &n );
 

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2008-09-11 19:59:21 UTC (rev 9303)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2008-09-12 10:35:00 UTC (rev 9304)
@@ -2745,6 +2745,14 @@
     //
     if ( mAddedFeatures.size() > 0 )
     {
+      for ( QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter )
+      {
+        if ( mChangedGeometries.contains( iter->featureId() ) )
+        {
+          iter->setGeometry( mChangedGeometries.take( iter->featureId() ) );
+        }
+      }
+
       if (( cap & QgsVectorDataProvider::AddFeatures ) && mDataProvider->addFeatures( mAddedFeatures ) )
       {
         mCommitErrors << tr( "SUCCESS: %1 features added." ).arg( mAddedFeatures.size() );



More information about the QGIS-commit mailing list