@@ -3177,12 +3177,18 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
3177
3177
{
3178
3178
exportGeosToWkb ();
3179
3179
}
3180
+
3180
3181
if ( !mGeos || mDirtyGeos )
3181
3182
{
3182
3183
if ( !exportWkbToGeos () )
3183
3184
return 1 ;
3184
3185
}
3185
3186
3187
+ if ( !GEOSisValid ( mGeos ) )
3188
+ {
3189
+ return 7 ;
3190
+ }
3191
+
3186
3192
// make sure splitLine is valid
3187
3193
if ( splitLine.size () < 2 )
3188
3194
{
@@ -3233,126 +3239,126 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
3233
3239
/* *Replaces a part of this geometry with another line*/
3234
3240
int QgsGeometry::reshapeGeometry ( const QList<QgsPoint>& reshapeWithLine )
3235
3241
{
3236
- if ( reshapeWithLine.size () < 2 )
3237
- {
3238
- return 1 ;
3239
- }
3242
+ if ( reshapeWithLine.size () < 2 )
3243
+ {
3244
+ return 1 ;
3245
+ }
3240
3246
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
+ }
3245
3259
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
+ }
3247
3273
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 )
3250
3281
{
3251
- exportWkbToGeos ( );
3282
+ reshapedGeometry = reshapeLine ( mGeos , reshapeLineGeos );
3252
3283
}
3253
-
3254
- // single or multi?
3255
- int numGeoms = GEOSGetNumGeometries ( mGeos );
3256
- if ( numGeoms == -1 )
3284
+ else
3257
3285
{
3258
- return 1 ;
3286
+ reshapedGeometry = reshapePolygon ( mGeos , reshapeLineGeos ) ;
3259
3287
}
3260
3288
3261
- bool isMultiGeom = false ;
3262
- int geosTypeId = GEOSGeomTypeId ( mGeos );
3263
- if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
3289
+ GEOSGeom_destroy ( reshapeLineGeos );
3290
+ if ( reshapedGeometry )
3264
3291
{
3265
- isMultiGeom = true ;
3292
+ GEOSGeom_destroy ( mGeos );
3293
+ mGeos = reshapedGeometry;
3294
+ mDirtyWkb = true ;
3295
+ return 0 ;
3296
+ }
3297
+ else
3298
+ {
3299
+ return 1 ;
3266
3300
}
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 ;
3267
3306
3268
- bool isLine = ( type () == QGis::Line );
3307
+ GEOSGeometry* currentReshapeGeometry = 0 ;
3308
+ GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
3269
3309
3270
- // polygon or multipolygon?
3271
- if ( !isMultiGeom )
3310
+ for ( int i = 0 ; i < numGeoms; ++i )
3272
3311
{
3273
- GEOSGeometry* reshapedGeometry;
3274
3312
if ( isLine )
3275
3313
{
3276
- reshapedGeometry = reshapeLine ( mGeos , reshapeLineGeos );
3314
+ currentReshapeGeometry = reshapeLine ( GEOSGetGeometryN ( mGeos , i ) , reshapeLineGeos );
3277
3315
}
3278
3316
else
3279
3317
{
3280
- reshapedGeometry = reshapePolygon ( mGeos , reshapeLineGeos );
3318
+ currentReshapeGeometry = reshapePolygon ( GEOSGetGeometryN ( mGeos , i ) , reshapeLineGeos );
3281
3319
}
3282
3320
3283
- GEOSGeom_destroy ( reshapeLineGeos );
3284
- if ( reshapedGeometry )
3321
+ if ( currentReshapeGeometry )
3285
3322
{
3286
- GEOSGeom_destroy ( mGeos );
3287
- mGeos = reshapedGeometry;
3288
- mDirtyWkb = true ;
3289
- return 0 ;
3323
+ newGeoms[i] = currentReshapeGeometry;
3324
+ reshapeTookPlace = true ;
3290
3325
}
3291
3326
else
3292
3327
{
3293
- return 1 ;
3328
+ newGeoms[i] = GEOSGeom_clone ( GEOSGetGeometryN ( mGeos , i ) ) ;
3294
3329
}
3295
3330
}
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 );
3326
3332
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
+ }
3336
3342
3337
- delete[] newGeoms;
3338
- if ( ! newMultiGeom )
3339
- {
3340
- return 3 ;
3341
- }
3343
+ delete[] newGeoms;
3344
+ if ( ! newMultiGeom )
3345
+ {
3346
+ return 3 ;
3347
+ }
3342
3348
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 ;
3355
3355
}
3356
+ else
3357
+ {
3358
+ GEOSGeom_destroy ( newMultiGeom );
3359
+ return 1 ;
3360
+ }
3361
+ }
3356
3362
}
3357
3363
3358
3364
int QgsGeometry::makeDifference ( QgsGeometry* other )
0 commit comments