[QGIS Commit] r15812 - in trunk/qgis/src: app core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Apr 22 12:07:49 EDT 2011


Author: jef
Date: 2011-04-22 09:07:49 -0700 (Fri, 22 Apr 2011)
New Revision: 15812

Modified:
   trunk/qgis/src/app/qgsmaptoolsplitfeatures.cpp
   trunk/qgis/src/core/qgsgeometry.cpp
   trunk/qgis/src/core/qgsvectorlayer.cpp
Log:
fix #2829

Modified: trunk/qgis/src/app/qgsmaptoolsplitfeatures.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolsplitfeatures.cpp	2011-04-22 14:35:54 UTC (rev 15811)
+++ trunk/qgis/src/app/qgsmaptoolsplitfeatures.cpp	2011-04-22 16:07:49 UTC (rev 15812)
@@ -86,6 +86,10 @@
     {
       QMessageBox::warning( 0, tr( "No feature split done" ), tr( "Cut edges detected. Make sure the line splits features into multiple parts." ) );
     }
+    else if ( returnCode == 7 )
+    {
+      QMessageBox::warning( 0, tr( "No feature split done" ), tr( "The geometry is invalid. Please repair before trying to split it." ) );
+    }
     else if ( returnCode != 0 )
     {
       //several intersections but only one split (most likely line)

Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2011-04-22 14:35:54 UTC (rev 15811)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2011-04-22 16:07:49 UTC (rev 15812)
@@ -3177,12 +3177,18 @@
   {
     exportGeosToWkb();
   }
+
   if ( !mGeos || mDirtyGeos )
   {
     if ( !exportWkbToGeos() )
       return 1;
   }
 
+  if ( !GEOSisValid( mGeos ) )
+  {
+    return 7;
+  }
+
   //make sure splitLine is valid
   if ( splitLine.size() < 2 )
   {
@@ -3233,126 +3239,126 @@
 /**Replaces a part of this geometry with another line*/
 int QgsGeometry::reshapeGeometry( const QList<QgsPoint>& reshapeWithLine )
 {
-    if ( reshapeWithLine.size() < 2 )
+  if ( reshapeWithLine.size() < 2 )
+  {
+    return 1;
+  }
+
+  if ( type() == QGis::Point )
+  {
+    return 1; //cannot reshape points
+  }
+
+  GEOSGeometry* reshapeLineGeos = createGeosLineString( reshapeWithLine.toVector() );
+
+  //make sure this geos geometry is up-to-date
+  if ( !mGeos || mDirtyGeos )
+  {
+    exportWkbToGeos();
+  }
+
+  //single or multi?
+  int numGeoms = GEOSGetNumGeometries( mGeos );
+  if ( numGeoms == -1 )
+  {
+    return 1;
+  }
+
+  bool isMultiGeom = false;
+  int geosTypeId = GEOSGeomTypeId( mGeos );
+  if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
+  {
+    isMultiGeom = true;
+  }
+
+  bool isLine = ( type() == QGis::Line );
+
+  //polygon or multipolygon?
+  if ( !isMultiGeom )
+  {
+    GEOSGeometry* reshapedGeometry;
+    if ( isLine )
     {
-      return 1;
+      reshapedGeometry = reshapeLine( mGeos, reshapeLineGeos );
     }
-
-    if ( type() == QGis::Point )
+    else
     {
-      return 1; //cannot reshape points
+      reshapedGeometry = reshapePolygon( mGeos, reshapeLineGeos );
     }
 
-    GEOSGeometry* reshapeLineGeos = createGeosLineString( reshapeWithLine.toVector() );
-
-    //make sure this geos geometry is up-to-date
-    if ( !mGeos || mDirtyGeos )
+    GEOSGeom_destroy( reshapeLineGeos );
+    if ( reshapedGeometry )
     {
-      exportWkbToGeos();
+      GEOSGeom_destroy( mGeos );
+      mGeos = reshapedGeometry;
+      mDirtyWkb = true;
+      return 0;
     }
-
-    //single or multi?
-    int numGeoms = GEOSGetNumGeometries( mGeos );
-    if ( numGeoms == -1 )
+    else
     {
       return 1;
     }
+  }
+  else
+  {
+    //call reshape for each geometry part and replace mGeos with new geometry if reshape took place
+    bool reshapeTookPlace = false;
 
-    bool isMultiGeom = false;
-    int geosTypeId = GEOSGeomTypeId( mGeos );
-    if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
-    {
-      isMultiGeom = true;
-    }
+    GEOSGeometry* currentReshapeGeometry = 0;
+    GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
 
-    bool isLine = ( type() == QGis::Line );
-
-    //polygon or multipolygon?
-    if ( !isMultiGeom )
+    for ( int i = 0; i < numGeoms; ++i )
     {
-      GEOSGeometry* reshapedGeometry;
       if ( isLine )
       {
-        reshapedGeometry = reshapeLine( mGeos, reshapeLineGeos );
+        currentReshapeGeometry = reshapeLine( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
       }
       else
       {
-        reshapedGeometry = reshapePolygon( mGeos, reshapeLineGeos );
+        currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
       }
 
-      GEOSGeom_destroy( reshapeLineGeos );
-      if ( reshapedGeometry )
+      if ( currentReshapeGeometry )
       {
-        GEOSGeom_destroy( mGeos );
-        mGeos = reshapedGeometry;
-        mDirtyWkb = true;
-        return 0;
+        newGeoms[i] = currentReshapeGeometry;
+        reshapeTookPlace = true;
       }
       else
       {
-        return 1;
+        newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN( mGeos, i ) );
       }
     }
-    else
+    GEOSGeom_destroy( reshapeLineGeos );
+
+    GEOSGeometry* newMultiGeom = 0;
+    if ( isLine )
     {
-      //call reshape for each geometry part and replace mGeos with new geometry if reshape took place
-      bool reshapeTookPlace = false;
+      newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms );
+    }
+    else //multipolygon
+    {
+      newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms );
+    }
 
-      GEOSGeometry* currentReshapeGeometry = 0;
-      GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
+    delete[] newGeoms;
+    if ( ! newMultiGeom )
+    {
+      return 3;
+    }
 
-      for ( int i = 0; i < numGeoms; ++i )
-      {
-        if ( isLine )
-        {
-          currentReshapeGeometry = reshapeLine( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
-        }
-        else
-        {
-          currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
-        }
-
-        if ( currentReshapeGeometry )
-        {
-          newGeoms[i] = currentReshapeGeometry;
-          reshapeTookPlace = true;
-        }
-        else
-        {
-          newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN( mGeos, i ) );
-        }
-      }
-      GEOSGeom_destroy( reshapeLineGeos );
-
-      GEOSGeometry* newMultiGeom = 0;
-      if ( isLine )
-      {
-        newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms );
-      }
-      else //multipolygon
-      {
-        newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms );
-      }
-
-      delete[] newGeoms;
-      if ( ! newMultiGeom )
-      {
-        return 3;
-      }
-
-      if ( reshapeTookPlace )
-      {
-        GEOSGeom_destroy( mGeos );
-        mGeos = newMultiGeom;
-        mDirtyWkb = true;
-        return 0;
-      }
-      else
-      {
-        GEOSGeom_destroy( newMultiGeom );
-        return 1;
-      }
+    if ( reshapeTookPlace )
+    {
+      GEOSGeom_destroy( mGeos );
+      mGeos = newMultiGeom;
+      mDirtyWkb = true;
+      return 0;
     }
+    else
+    {
+      GEOSGeom_destroy( newMultiGeom );
+      return 1;
+    }
+  }
 }
 
 int QgsGeometry::makeDifference( QgsGeometry* other )

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2011-04-22 14:35:54 UTC (rev 15811)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2011-04-22 16:07:49 UTC (rev 15812)
@@ -2272,7 +2272,7 @@
   QgsRectangle bBox; //bounding box of the split line
   int returnCode = 0;
   int splitFunctionReturn; //return code of QgsGeometry::splitGeometry
-  int numberOfSplitedFeatures = 0;
+  int numberOfSplittedFeatures = 0;
 
   QgsFeatureList featureList;
   const QgsFeatureIds selectedIds = selectedFeaturesIds();
@@ -2352,15 +2352,15 @@
           addTopologicalPoints( *topol_it );
         }
       }
-      ++numberOfSplitedFeatures;
+      ++numberOfSplittedFeatures;
     }
     else if ( splitFunctionReturn > 1 ) //1 means no split but also no error
     {
-      returnCode = 3;
+      returnCode = splitFunctionReturn;
     }
   }
 
-  if ( numberOfSplitedFeatures == 0 && selectedIds.size() > 0 )
+  if ( numberOfSplittedFeatures == 0 && selectedIds.size() > 0 )
   {
     //There is a selection but no feature has been split.
     //Maybe user forgot that only the selected features are split



More information about the QGIS-commit mailing list