@@ -17,13 +17,13 @@ email : jef at norbit dot de
17
17
#include " qgsgeometryvalidator.h"
18
18
#include " qgsgeometry.h"
19
19
#include " qgslogger.h"
20
- #include " qgssettings.h"
21
20
22
- QgsGeometryValidator::QgsGeometryValidator ( const QgsGeometry *g, QList<QgsGeometry::Error> *errors )
21
+ QgsGeometryValidator::QgsGeometryValidator ( const QgsGeometry *g, QList<QgsGeometry::Error> *errors, QgsGeometry::ValidationMethod method )
23
22
: QThread()
24
23
, mErrors( errors )
25
24
, mStop( false )
26
25
, mErrorCount( 0 )
26
+ , mMethod( method )
27
27
{
28
28
Q_ASSERT ( g );
29
29
if ( g )
@@ -215,134 +215,140 @@ void QgsGeometryValidator::validatePolygon( int idx, const QgsPolygon &polygon )
215
215
void QgsGeometryValidator::run ()
216
216
{
217
217
mErrorCount = 0 ;
218
- QgsSettings settings;
219
- if ( settings.value ( QStringLiteral ( " qgis/digitizing/validate_geometries" ), 1 ).toInt () == 2 )
218
+ switch ( mMethod )
220
219
{
221
- char *r = nullptr ;
222
- GEOSGeometry *g0 = mG .exportToGeos ();
223
- GEOSContextHandle_t handle = QgsGeometry::getGEOSHandler ();
224
- if ( !g0 )
220
+ case QgsGeometry::ValidatorGeos:
225
221
{
226
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " GEOS error:could not produce geometry for GEOS (check log window) " ) ) ) ;
227
- }
228
- else
229
- {
230
- GEOSGeometry *g1 = nullptr ;
231
- char res = GEOSisValidDetail_r ( handle, g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 );
232
- GEOSGeom_destroy_r ( handle, g0 );
233
- if ( res != 1 )
222
+ char *r = nullptr ;
223
+ GEOSGeometry *g0 = mG . exportToGeos ();
224
+ GEOSContextHandle_t handle = QgsGeometry::getGEOSHandler ();
225
+ if ( !g0 )
226
+ {
227
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " GEOS error:could not produce geometry for GEOS (check log window) " ) ) );
228
+ }
229
+ else
234
230
{
235
- if ( g1 )
231
+ GEOSGeometry *g1 = nullptr ;
232
+ char res = GEOSisValidDetail_r ( handle, g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 );
233
+ GEOSGeom_destroy_r ( handle, g0 );
234
+ if ( res != 1 )
236
235
{
237
- const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r ( handle, g1 );
238
-
239
- unsigned int n;
240
- if ( GEOSCoordSeq_getSize_r ( handle, cs, &n ) && n == 1 )
236
+ if ( g1 )
237
+ {
238
+ const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r ( handle, g1 );
239
+
240
+ unsigned int n;
241
+ if ( GEOSCoordSeq_getSize_r ( handle, cs, &n ) && n == 1 )
242
+ {
243
+ double x, y;
244
+ GEOSCoordSeq_getX_r ( handle, cs, 0 , &x );
245
+ GEOSCoordSeq_getY_r ( handle, cs, 0 , &y );
246
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " GEOS error:%1" ).arg ( r ), QgsPointXY ( x, y ) ) );
247
+ mErrorCount ++;
248
+ }
249
+
250
+ GEOSGeom_destroy_r ( handle, g1 );
251
+ }
252
+ else
241
253
{
242
- double x, y;
243
- GEOSCoordSeq_getX_r ( handle, cs, 0 , &x );
244
- GEOSCoordSeq_getY_r ( handle, cs, 0 , &y );
245
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " GEOS error:%1" ).arg ( r ), QgsPointXY ( x, y ) ) );
254
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " GEOS error:%1" ).arg ( r ) ) );
246
255
mErrorCount ++;
247
256
}
248
257
249
- GEOSGeom_destroy_r ( handle, g1 );
250
- }
251
- else
252
- {
253
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " GEOS error:%1" ).arg ( r ) ) );
254
- mErrorCount ++;
258
+ GEOSFree_r ( handle, r );
255
259
}
256
-
257
- GEOSFree_r ( handle, r );
258
260
}
259
- }
260
-
261
- return ;
262
- }
263
261
264
- QgsDebugMsg ( " validation thread started." );
265
-
266
- QgsWkbTypes::Type flatType = QgsWkbTypes::flatType ( mG .wkbType () );
267
- // if ( flatType == QgsWkbTypes::Point || flatType == QgsWkbTypes::MultiPoint )
268
- // break;
269
- if ( flatType == QgsWkbTypes::LineString )
270
- {
271
- validatePolyline ( 0 , mG .asPolyline () );
272
- }
273
- else if ( flatType == QgsWkbTypes::MultiLineString )
274
- {
275
- QgsMultiPolyline mp = mG .asMultiPolyline ();
276
- for ( int i = 0 ; !mStop && i < mp.size (); i++ )
277
- validatePolyline ( i, mp[i] );
278
- }
279
- else if ( flatType == QgsWkbTypes::Polygon )
280
- {
281
- validatePolygon ( 0 , mG .asPolygon () );
282
- }
283
- else if ( flatType == QgsWkbTypes::MultiPolygon )
284
- {
285
- QgsMultiPolygon mp = mG .asMultiPolygon ();
286
- for ( int i = 0 ; !mStop && i < mp.size (); i++ )
287
- {
288
- validatePolygon ( i, mp[i] );
262
+ break ;
289
263
}
290
264
291
- for ( int i = 0 ; ! mStop && i < mp. size (); i++ )
265
+ case QgsGeometry::ValidatorQgisInternal:
292
266
{
293
- if ( mp[i].isEmpty () )
267
+ QgsDebugMsg ( " validation thread started." );
268
+
269
+ QgsWkbTypes::Type flatType = QgsWkbTypes::flatType ( mG .wkbType () );
270
+ // if ( flatType == QgsWkbTypes::Point || flatType == QgsWkbTypes::MultiPoint )
271
+ // break;
272
+ if ( flatType == QgsWkbTypes::LineString )
294
273
{
295
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " polygon %1 has no rings" ).arg ( i ) ) );
296
- mErrorCount ++;
297
- continue ;
274
+ validatePolyline ( 0 , mG .asPolyline () );
298
275
}
299
-
300
- for ( int j = i + 1 ; !mStop && j < mp.size (); j++ )
276
+ else if ( flatType == QgsWkbTypes::MultiLineString )
301
277
{
302
- if ( mp[j].isEmpty () )
303
- continue ;
304
-
305
- if ( ringInRing ( mp[i][0 ], mp[j][0 ] ) )
306
- {
307
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " polygon %1 inside polygon %2" ).arg ( i ).arg ( j ) ) );
308
- mErrorCount ++;
309
- }
310
- else if ( ringInRing ( mp[j][0 ], mp[i][0 ] ) )
278
+ QgsMultiPolyline mp = mG .asMultiPolyline ();
279
+ for ( int i = 0 ; !mStop && i < mp.size (); i++ )
280
+ validatePolyline ( i, mp[i] );
281
+ }
282
+ else if ( flatType == QgsWkbTypes::Polygon )
283
+ {
284
+ validatePolygon ( 0 , mG .asPolygon () );
285
+ }
286
+ else if ( flatType == QgsWkbTypes::MultiPolygon )
287
+ {
288
+ QgsMultiPolygon mp = mG .asMultiPolygon ();
289
+ for ( int i = 0 ; !mStop && i < mp.size (); i++ )
311
290
{
312
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " polygon %1 inside polygon %2" ).arg ( j ).arg ( i ) ) );
313
- mErrorCount ++;
291
+ validatePolygon ( i, mp[i] );
314
292
}
315
- else
293
+
294
+ for ( int i = 0 ; !mStop && i < mp.size (); i++ )
316
295
{
317
- checkRingIntersections ( i, 0 , mp[i][0 ], j, 0 , mp[j][0 ] );
296
+ if ( mp[i].isEmpty () )
297
+ {
298
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " polygon %1 has no rings" ).arg ( i ) ) );
299
+ mErrorCount ++;
300
+ continue ;
301
+ }
302
+
303
+ for ( int j = i + 1 ; !mStop && j < mp.size (); j++ )
304
+ {
305
+ if ( mp[j].isEmpty () )
306
+ continue ;
307
+
308
+ if ( ringInRing ( mp[i][0 ], mp[j][0 ] ) )
309
+ {
310
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " polygon %1 inside polygon %2" ).arg ( i ).arg ( j ) ) );
311
+ mErrorCount ++;
312
+ }
313
+ else if ( ringInRing ( mp[j][0 ], mp[i][0 ] ) )
314
+ {
315
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " polygon %1 inside polygon %2" ).arg ( j ).arg ( i ) ) );
316
+ mErrorCount ++;
317
+ }
318
+ else
319
+ {
320
+ checkRingIntersections ( i, 0 , mp[i][0 ], j, 0 , mp[j][0 ] );
321
+ }
322
+ }
318
323
}
319
324
}
320
- }
321
- }
322
325
323
- else if ( flatType == QgsWkbTypes::Unknown )
324
- {
325
- QgsDebugMsg ( QObject::tr ( " Unknown geometry type" ) );
326
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " Unknown geometry type %1" ).arg ( mG .wkbType () ) ) );
327
- mErrorCount ++;
328
- }
326
+ else if ( flatType == QgsWkbTypes::Unknown )
327
+ {
328
+ QgsDebugMsg ( QObject::tr ( " Unknown geometry type" ) );
329
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " Unknown geometry type %1" ).arg ( mG .wkbType () ) ) );
330
+ mErrorCount ++;
331
+ }
329
332
330
- QgsDebugMsg ( " validation finished." );
333
+ QgsDebugMsg ( " validation finished." );
331
334
332
- if ( mStop )
333
- {
334
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " Geometry validation was aborted." ) ) );
335
- }
336
- else if ( mErrorCount > 0 )
337
- {
338
- emit errorFound ( QgsGeometry::Error ( QObject::tr ( " Geometry has %1 errors." ).arg ( mErrorCount ) ) );
339
- }
335
+ if ( mStop )
336
+ {
337
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " Geometry validation was aborted." ) ) );
338
+ }
339
+ else if ( mErrorCount > 0 )
340
+ {
341
+ emit errorFound ( QgsGeometry::Error ( QObject::tr ( " Geometry has %1 errors." ).arg ( mErrorCount ) ) );
342
+ }
340
343
#if 0
341
- else
342
- {
343
- emit errorFound( QgsGeometry::Error( QObject::tr( "Geometry is valid." ) ) );
344
- }
344
+ else
345
+ {
346
+ emit errorFound( QgsGeometry::Error( QObject::tr( "Geometry is valid." ) ) );
347
+ }
345
348
#endif
349
+ break ;
350
+ }
351
+ }
346
352
}
347
353
348
354
void QgsGeometryValidator::addError ( const QgsGeometry::Error &e )
@@ -351,9 +357,9 @@ void QgsGeometryValidator::addError( const QgsGeometry::Error &e )
351
357
*mErrors << e;
352
358
}
353
359
354
- void QgsGeometryValidator::validateGeometry ( const QgsGeometry *g, QList<QgsGeometry::Error> &errors )
360
+ void QgsGeometryValidator::validateGeometry ( const QgsGeometry *g, QList<QgsGeometry::Error> &errors, QgsGeometry::ValidationMethod method )
355
361
{
356
- QgsGeometryValidator *gv = new QgsGeometryValidator ( g, &errors );
362
+ QgsGeometryValidator *gv = new QgsGeometryValidator ( g, &errors, method );
357
363
connect ( gv, &QgsGeometryValidator::errorFound, gv, &QgsGeometryValidator::addError );
358
364
gv->run ();
359
365
gv->wait ();
0 commit comments