Skip to content

Commit

Permalink
[Geometry checker] Introduce QgsGeometryCheckerUtils::polygonRings
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 23, 2017
1 parent 7bb5583 commit e5e3fde
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp
Expand Up @@ -18,10 +18,11 @@
#include "qgsgeometry.h"
#include "qgsgeometryutils.h"
#include "qgsfeaturepool.h"
#include <qmath.h>
#include "qgspolygon.h"
#include "qgsgeos.h"
#include "qgsgeometrycollection.h"
#include "qgssurface.h"
#include <qmath.h>

namespace QgsGeometryCheckerUtils
{
Expand Down Expand Up @@ -196,6 +197,23 @@ namespace QgsGeometryCheckerUtils
return geom;
}

QList<const QgsLineString *> polygonRings( const QgsPolygonV2 *polygon )
{
QList<const QgsLineString *> rings;
if ( const QgsLineString *exterior = dynamic_cast<const QgsLineString *>( polygon->exteriorRing() ) )
{
rings.append( exterior );
}
for ( int iInt = 0, nInt = polygon->numInteriorRings(); iInt < nInt; ++iInt )
{
if ( const QgsLineString *interior = dynamic_cast<const QgsLineString *>( polygon->interiorRing( iInt ) ) )
{
rings.append( interior );
}
}
return rings;
}

void filter1DTypes( QgsAbstractGeometry *geom )
{
if ( dynamic_cast<QgsGeometryCollection *>( geom ) )
Expand Down
Expand Up @@ -102,6 +102,8 @@ namespace QgsGeometryCheckerUtils
QgsAbstractGeometry *getGeomPart( QgsAbstractGeometry *geom, int partIdx );
const QgsAbstractGeometry *getGeomPart( const QgsAbstractGeometry *geom, int partIdx );

QList<const QgsLineString *> polygonRings( const QgsPolygonV2 *polygon );

void filter1DTypes( QgsAbstractGeometry *geom );

/**
Expand Down
Expand Up @@ -57,19 +57,7 @@ void QgsGeometryLineLayerIntersectionCheck::collectErrors( QList<QgsGeometryChec
}
else if ( const QgsPolygonV2 *polygon = dynamic_cast<const QgsPolygonV2 *>( part ) )
{
QList<const QgsLineString *> rings;
if ( const QgsLineString *exterior = dynamic_cast<const QgsLineString *>( polygon->exteriorRing() ) )
{
rings.append( exterior );
}
for ( int iInt = 0, nInt = polygon->numInteriorRings(); iInt < nInt; ++iInt )
{
if ( const QgsLineString *interior = dynamic_cast<const QgsLineString *>( polygon->interiorRing( iInt ) ) )
{
rings.append( interior );
}
}
for ( const QgsLineString *ring : rings )
for ( const QgsLineString *ring : QgsGeometryCheckerUtils::polygonRings( polygon ) )
{
if ( QgsGeometryCheckerUtils::linesIntersect( ring, testLine, mContext->tolerance, inter ) )
{
Expand Down

0 comments on commit e5e3fde

Please sign in to comment.