Skip to content

Commit 51299c1

Browse files
author
jef
committedApr 22, 2011
fix #2829
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15812 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

3 files changed

+104
-94
lines changed

3 files changed

+104
-94
lines changed
 

‎src/app/qgsmaptoolsplitfeatures.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )
8686
{
8787
QMessageBox::warning( 0, tr( "No feature split done" ), tr( "Cut edges detected. Make sure the line splits features into multiple parts." ) );
8888
}
89+
else if ( returnCode == 7 )
90+
{
91+
QMessageBox::warning( 0, tr( "No feature split done" ), tr( "The geometry is invalid. Please repair before trying to split it." ) );
92+
}
8993
else if ( returnCode != 0 )
9094
{
9195
//several intersections but only one split (most likely line)

‎src/core/qgsgeometry.cpp

Lines changed: 96 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,12 +3177,18 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
31773177
{
31783178
exportGeosToWkb();
31793179
}
3180+
31803181
if ( !mGeos || mDirtyGeos )
31813182
{
31823183
if ( !exportWkbToGeos() )
31833184
return 1;
31843185
}
31853186

3187+
if ( !GEOSisValid( mGeos ) )
3188+
{
3189+
return 7;
3190+
}
3191+
31863192
//make sure splitLine is valid
31873193
if ( splitLine.size() < 2 )
31883194
{
@@ -3233,126 +3239,126 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
32333239
/**Replaces a part of this geometry with another line*/
32343240
int QgsGeometry::reshapeGeometry( const QList<QgsPoint>& reshapeWithLine )
32353241
{
3236-
if ( reshapeWithLine.size() < 2 )
3237-
{
3238-
return 1;
3239-
}
3242+
if ( reshapeWithLine.size() < 2 )
3243+
{
3244+
return 1;
3245+
}
32403246

3241-
if ( type() == QGis::Point )
3242-
{
3243-
return 1; //cannot reshape points
3244-
}
3247+
if ( type() == QGis::Point )
3248+
{
3249+
return 1; //cannot reshape points
3250+
}
3251+
3252+
GEOSGeometry* reshapeLineGeos = createGeosLineString( reshapeWithLine.toVector() );
3253+
3254+
//make sure this geos geometry is up-to-date
3255+
if ( !mGeos || mDirtyGeos )
3256+
{
3257+
exportWkbToGeos();
3258+
}
32453259

3246-
GEOSGeometry* reshapeLineGeos = createGeosLineString( reshapeWithLine.toVector() );
3260+
//single or multi?
3261+
int numGeoms = GEOSGetNumGeometries( mGeos );
3262+
if ( numGeoms == -1 )
3263+
{
3264+
return 1;
3265+
}
3266+
3267+
bool isMultiGeom = false;
3268+
int geosTypeId = GEOSGeomTypeId( mGeos );
3269+
if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
3270+
{
3271+
isMultiGeom = true;
3272+
}
32473273

3248-
//make sure this geos geometry is up-to-date
3249-
if ( !mGeos || mDirtyGeos )
3274+
bool isLine = ( type() == QGis::Line );
3275+
3276+
//polygon or multipolygon?
3277+
if ( !isMultiGeom )
3278+
{
3279+
GEOSGeometry* reshapedGeometry;
3280+
if ( isLine )
32503281
{
3251-
exportWkbToGeos();
3282+
reshapedGeometry = reshapeLine( mGeos, reshapeLineGeos );
32523283
}
3253-
3254-
//single or multi?
3255-
int numGeoms = GEOSGetNumGeometries( mGeos );
3256-
if ( numGeoms == -1 )
3284+
else
32573285
{
3258-
return 1;
3286+
reshapedGeometry = reshapePolygon( mGeos, reshapeLineGeos );
32593287
}
32603288

3261-
bool isMultiGeom = false;
3262-
int geosTypeId = GEOSGeomTypeId( mGeos );
3263-
if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
3289+
GEOSGeom_destroy( reshapeLineGeos );
3290+
if ( reshapedGeometry )
32643291
{
3265-
isMultiGeom = true;
3292+
GEOSGeom_destroy( mGeos );
3293+
mGeos = reshapedGeometry;
3294+
mDirtyWkb = true;
3295+
return 0;
3296+
}
3297+
else
3298+
{
3299+
return 1;
32663300
}
3301+
}
3302+
else
3303+
{
3304+
//call reshape for each geometry part and replace mGeos with new geometry if reshape took place
3305+
bool reshapeTookPlace = false;
32673306

3268-
bool isLine = ( type() == QGis::Line );
3307+
GEOSGeometry* currentReshapeGeometry = 0;
3308+
GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
32693309

3270-
//polygon or multipolygon?
3271-
if ( !isMultiGeom )
3310+
for ( int i = 0; i < numGeoms; ++i )
32723311
{
3273-
GEOSGeometry* reshapedGeometry;
32743312
if ( isLine )
32753313
{
3276-
reshapedGeometry = reshapeLine( mGeos, reshapeLineGeos );
3314+
currentReshapeGeometry = reshapeLine( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
32773315
}
32783316
else
32793317
{
3280-
reshapedGeometry = reshapePolygon( mGeos, reshapeLineGeos );
3318+
currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
32813319
}
32823320

3283-
GEOSGeom_destroy( reshapeLineGeos );
3284-
if ( reshapedGeometry )
3321+
if ( currentReshapeGeometry )
32853322
{
3286-
GEOSGeom_destroy( mGeos );
3287-
mGeos = reshapedGeometry;
3288-
mDirtyWkb = true;
3289-
return 0;
3323+
newGeoms[i] = currentReshapeGeometry;
3324+
reshapeTookPlace = true;
32903325
}
32913326
else
32923327
{
3293-
return 1;
3328+
newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN( mGeos, i ) );
32943329
}
32953330
}
3296-
else
3297-
{
3298-
//call reshape for each geometry part and replace mGeos with new geometry if reshape took place
3299-
bool reshapeTookPlace = false;
3300-
3301-
GEOSGeometry* currentReshapeGeometry = 0;
3302-
GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
3303-
3304-
for ( int i = 0; i < numGeoms; ++i )
3305-
{
3306-
if ( isLine )
3307-
{
3308-
currentReshapeGeometry = reshapeLine( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
3309-
}
3310-
else
3311-
{
3312-
currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos );
3313-
}
3314-
3315-
if ( currentReshapeGeometry )
3316-
{
3317-
newGeoms[i] = currentReshapeGeometry;
3318-
reshapeTookPlace = true;
3319-
}
3320-
else
3321-
{
3322-
newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN( mGeos, i ) );
3323-
}
3324-
}
3325-
GEOSGeom_destroy( reshapeLineGeos );
3331+
GEOSGeom_destroy( reshapeLineGeos );
33263332

3327-
GEOSGeometry* newMultiGeom = 0;
3328-
if ( isLine )
3329-
{
3330-
newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms );
3331-
}
3332-
else //multipolygon
3333-
{
3334-
newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms );
3335-
}
3333+
GEOSGeometry* newMultiGeom = 0;
3334+
if ( isLine )
3335+
{
3336+
newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms );
3337+
}
3338+
else //multipolygon
3339+
{
3340+
newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms );
3341+
}
33363342

3337-
delete[] newGeoms;
3338-
if ( ! newMultiGeom )
3339-
{
3340-
return 3;
3341-
}
3343+
delete[] newGeoms;
3344+
if ( ! newMultiGeom )
3345+
{
3346+
return 3;
3347+
}
33423348

3343-
if ( reshapeTookPlace )
3344-
{
3345-
GEOSGeom_destroy( mGeos );
3346-
mGeos = newMultiGeom;
3347-
mDirtyWkb = true;
3348-
return 0;
3349-
}
3350-
else
3351-
{
3352-
GEOSGeom_destroy( newMultiGeom );
3353-
return 1;
3354-
}
3349+
if ( reshapeTookPlace )
3350+
{
3351+
GEOSGeom_destroy( mGeos );
3352+
mGeos = newMultiGeom;
3353+
mDirtyWkb = true;
3354+
return 0;
33553355
}
3356+
else
3357+
{
3358+
GEOSGeom_destroy( newMultiGeom );
3359+
return 1;
3360+
}
3361+
}
33563362
}
33573363

33583364
int QgsGeometry::makeDifference( QgsGeometry* other )

‎src/core/qgsvectorlayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ int QgsVectorLayer::splitFeatures( const QList<QgsPoint>& splitLine, bool topolo
22722272
QgsRectangle bBox; //bounding box of the split line
22732273
int returnCode = 0;
22742274
int splitFunctionReturn; //return code of QgsGeometry::splitGeometry
2275-
int numberOfSplitedFeatures = 0;
2275+
int numberOfSplittedFeatures = 0;
22762276

22772277
QgsFeatureList featureList;
22782278
const QgsFeatureIds selectedIds = selectedFeaturesIds();
@@ -2352,15 +2352,15 @@ int QgsVectorLayer::splitFeatures( const QList<QgsPoint>& splitLine, bool topolo
23522352
addTopologicalPoints( *topol_it );
23532353
}
23542354
}
2355-
++numberOfSplitedFeatures;
2355+
++numberOfSplittedFeatures;
23562356
}
23572357
else if ( splitFunctionReturn > 1 ) //1 means no split but also no error
23582358
{
2359-
returnCode = 3;
2359+
returnCode = splitFunctionReturn;
23602360
}
23612361
}
23622362

2363-
if ( numberOfSplitedFeatures == 0 && selectedIds.size() > 0 )
2363+
if ( numberOfSplittedFeatures == 0 && selectedIds.size() > 0 )
23642364
{
23652365
//There is a selection but no feature has been split.
23662366
//Maybe user forgot that only the selected features are split

0 commit comments

Comments
 (0)
Please sign in to comment.