Skip to content

Commit 54303e3

Browse files
vinayanjef-n
authored andcommittedMar 26, 2013
fix gaps,overlaps for invalid goemetry errors by skipping
1 parent 723d597 commit 54303e3

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed
 

‎src/plugins/topology/topolTest.cpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
483483
break;
484484

485485
QgsGeometry* g1 = it->feature.geometry();
486+
487+
if ( g1->isGeosValid() == false )
488+
{
489+
qDebug() << "invalid geometry(g1) found..skipping.." << it->feature.id();
490+
continue;
491+
}
492+
486493
QgsRectangle bb = g1->boundingBox();
487494

488495
QList<QgsFeatureId> crossingIds;
@@ -515,12 +522,22 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
515522
continue;
516523
}
517524

525+
if ( g2->isGeosValid() == false )
526+
{
527+
qDebug() << "invalid geometry(g2) found..skipping.." << it->feature.id();
528+
continue;
529+
}
530+
531+
532+
qDebug() << "checking overlap for" << it->feature.id();
518533
if (g1->overlaps(g2))
519534
{
520535
duplicate = true;
521536
duplicateIds->append( mFeatureMap2[*cit].feature.id() );
522537
}
523538

539+
540+
524541
if ( duplicate )
525542
{
526543
QList<FeatureLayer> fls;
@@ -599,7 +616,30 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
599616
{
600617
continue;
601618
}
602-
geomList.push_back( GEOSGeom_clone( g1->asGeos() ) );
619+
620+
if ( g1->isGeosValid() == false )
621+
{
622+
qDebug() << "invalid geometry found..skipping.." << it->feature.id();
623+
continue;
624+
}
625+
626+
if ( g1->isMultipart() )
627+
{
628+
QgsMultiPolygon polys = g1->asMultiPolygon();
629+
for ( int m = 0; m < polys.count(); m++ )
630+
{
631+
QgsPolygon polygon = polys[m];
632+
633+
QgsGeometry* polyGeom = QgsGeometry::fromPolygon(polygon);
634+
635+
geomList.push_back( GEOSGeom_clone(polyGeom->asGeos()) );
636+
}
637+
638+
}
639+
else
640+
{
641+
geomList.push_back( GEOSGeom_clone( g1->asGeos() ) );
642+
}
603643
}
604644

605645
GEOSGeometry** geomArray = new GEOSGeometry*[geomList.size()];
@@ -629,22 +669,20 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
629669
test.fromGeos( unionGeom );
630670

631671

632-
qDebug() << "wktmerged - " << test.exportToWkt();
672+
//qDebug() << "wktmerged - " << test.exportToWkt();
633673

634674
QString extentWkt = test.boundingBox().asWktPolygon();
635675
QgsGeometry* extentGeom = QgsGeometry::fromWkt( extentWkt );
636676
QgsGeometry* bufferExtent = extentGeom->buffer( 2, 3 );
637677

638-
qDebug() << "extent wkt - " << bufferExtent->exportToWkt();
678+
//qDebug() << "extent wkt - " << bufferExtent->exportToWkt();
639679

640680
QgsGeometry* diffGeoms = bufferExtent->difference( &test );
641681

642-
qDebug() << "difference gometry - " << diffGeoms->exportToWkt() ;
682+
//qDebug() << "difference gometry - " << diffGeoms->exportToWkt() ;
643683

644684
QList<QgsGeometry*> geomColl = diffGeoms->asGeometryCollection();
645685

646-
//QList<QgsGeometry*> geomColl = test.asGeometryCollection();
647-
648686
QgsGeometry* canvasExtentPoly = QgsGeometry::fromWkt(theQgsInterface->mapCanvas()->extent().asWktPolygon());
649687

650688
for ( int i = 1; i < geomColl.count() ; ++i )

0 commit comments

Comments
 (0)
Please sign in to comment.