Skip to content
Permalink
Browse files

Merge pull request #5254 from nyalldawson/geometry_coverage

Geometry unit test coverage
  • Loading branch information
nyalldawson committed Sep 26, 2017
2 parents 7705179 + ac7fede commit 270c45d12ba20cc727d5a93acb40517dff9e59a5
@@ -60,7 +60,7 @@ Adds a geometry and takes ownership. Returns true in case of success.
:rtype: bool
%End

virtual bool insertGeometry( QgsAbstractGeometry *g, int index /Transfer/ );
virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );
%Docstring
Inserts a geometry before a specified index and takes ownership. Returns true in case of success.
\param g geometry to insert. Ownership is transferred to the collection.
@@ -24,25 +24,22 @@ class QgsMultiCurve: QgsGeometryCollection

virtual QgsMultiCurve *clone() const /Factory/;

virtual QgsMultiCurve *toCurveType() const /Factory/;
virtual void clear();

virtual QgsMultiCurve *toCurveType() const /Factory/;

virtual bool fromWkt( const QString &wkt );


virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QString asJSON( int precision = 17 ) const;


virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ );

%Docstring
Adds a geometry and takes ownership. Returns true in case of success
:rtype: bool
%End
virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );


QgsMultiCurve *reversed() const /Factory/;
%Docstring
@@ -20,27 +20,25 @@ class QgsMultiLineString: QgsMultiCurve
%End
public:
QgsMultiLineString();

virtual QString geometryType() const;

virtual QgsMultiLineString *clone() const /Factory/;

virtual void clear();

virtual bool fromWkt( const QString &wkt );


virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QString asJSON( int precision = 17 ) const;


virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ );

%Docstring
Adds a geometry and takes ownership. Returns true in case of success
:rtype: bool
%End
virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );


virtual QgsMultiCurve *toCurveType() const /Factory/;

@@ -20,32 +20,28 @@ class QgsMultiPointV2: QgsGeometryCollection
%End
public:
QgsMultiPointV2();

virtual QString geometryType() const;

virtual QgsMultiPointV2 *clone() const /Factory/;

virtual QgsMultiPointV2 *toCurveType() const /Factory/;


virtual bool fromWkt( const QString &wkt );

virtual void clear();

virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QString asJSON( int precision = 17 ) const;


virtual int nCoordinates() const;


virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ );

%Docstring
Adds a geometry and takes ownership. Returns true in case of success
:rtype: bool
%End
virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );

virtual QgsAbstractGeometry *boundary() const /Factory/;

@@ -22,25 +22,22 @@ class QgsMultiPolygonV2: QgsMultiSurface
QgsMultiPolygonV2();
virtual QString geometryType() const;

virtual QgsMultiPolygonV2 *clone() const /Factory/;
virtual void clear();

virtual QgsMultiPolygonV2 *clone() const /Factory/;

virtual bool fromWkt( const QString &wkt );


virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QString asJSON( int precision = 17 ) const;


virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ );

%Docstring
Adds a geometry and takes ownership. Returns true in case of success
:rtype: bool
%End
virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );


virtual QgsMultiSurface *toCurveType() const /Factory/;

@@ -22,28 +22,23 @@ class QgsMultiSurface: QgsGeometryCollection
QgsMultiSurface();
virtual QString geometryType() const;

virtual void clear();

virtual QgsMultiSurface *clone() const /Factory/;

virtual QgsMultiSurface *toCurveType() const /Factory/;


virtual bool fromWkt( const QString &wkt );


virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;

virtual QString asJSON( int precision = 17 ) const;



virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ );

%Docstring
Adds a geometry and takes ownership. Returns true in case of success
:rtype: bool
%End
virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );

virtual QgsAbstractGeometry *boundary() const /Factory/;

@@ -26,6 +26,7 @@
#include "qgslogger.h"
#include <QPainter>
#include <QPainterPath>
#include <memory>

QgsCircularString::QgsCircularString(): QgsCurve()
{
@@ -301,9 +302,8 @@ QString QgsCircularString::asWkt( int precision ) const
QDomElement QgsCircularString::asGML2( QDomDocument &doc, int precision, const QString &ns ) const
{
// GML2 does not support curves
QgsLineString *line = curveToLine();
std::unique_ptr< QgsLineString > line( curveToLine() );
QDomElement gml = line->asGML2( doc, precision, ns );
delete line;
return gml;
}

@@ -324,9 +324,8 @@ QDomElement QgsCircularString::asGML3( QDomDocument &doc, int precision, const Q
QString QgsCircularString::asJSON( int precision ) const
{
// GeoJSON does not support curves
QgsLineString *line = curveToLine();
std::unique_ptr< QgsLineString > line( curveToLine() );
QString json = line->asJSON( precision );
delete line;
return json;
}

@@ -23,7 +23,7 @@
#include "qgswkbptr.h"
#include <QPainter>
#include <QPainterPath>

#include <memory>

QgsCompoundCurve::QgsCompoundCurve(): QgsCurve()
{
@@ -263,9 +263,8 @@ QString QgsCompoundCurve::asWkt( int precision ) const
QDomElement QgsCompoundCurve::asGML2( QDomDocument &doc, int precision, const QString &ns ) const
{
// GML2 does not support curves
QgsLineString *line = curveToLine();
std::unique_ptr< QgsLineString > line( curveToLine() );
QDomElement gml = line->asGML2( doc, precision, ns );
delete line;
return gml;
}

@@ -286,9 +285,8 @@ QDomElement QgsCompoundCurve::asGML3( QDomDocument &doc, int precision, const QS
QString QgsCompoundCurve::asJSON( int precision ) const
{
// GeoJSON does not support curves
QgsLineString *line = curveToLine();
std::unique_ptr< QgsLineString > line( curveToLine() );
QString json = line->asJSON( precision );
delete line;
return json;
}

@@ -373,12 +371,11 @@ QgsLineString *QgsCompoundCurve::curveToLine( double tolerance, SegmentationTole
{
QList< QgsCurve * >::const_iterator curveIt = mCurves.constBegin();
QgsLineString *line = new QgsLineString();
QgsLineString *currentLine = nullptr;
std::unique_ptr< QgsLineString > currentLine;
for ( ; curveIt != mCurves.constEnd(); ++curveIt )
{
currentLine = ( *curveIt )->curveToLine( tolerance, toleranceType );
line->append( currentLine );
delete currentLine;
currentLine.reset( ( *curveIt )->curveToLine( tolerance, toleranceType ) );
line->append( currentLine.get() );
}
return line;
}
@@ -333,20 +333,19 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt
// GML2 does not support curves
QDomElement elemPolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) );
QDomElement elemOuterBoundaryIs = doc.createElementNS( ns, QStringLiteral( "outerBoundaryIs" ) );
QgsLineString *exteriorLineString = exteriorRing()->curveToLine();
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
QDomElement outerRing = exteriorLineString->asGML2( doc, precision, ns );
outerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) );
elemOuterBoundaryIs.appendChild( outerRing );
delete exteriorLineString;
elemPolygon.appendChild( elemOuterBoundaryIs );
std::unique_ptr< QgsLineString > interiorLineString;
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) );
QgsLineString *interiorLineString = interiorRing( i )->curveToLine();
interiorLineString.reset( interiorRing( i )->curveToLine() );
QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns );
innerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) );
elemInnerBoundaryIs.appendChild( innerRing );
delete interiorLineString;
elemPolygon.appendChild( elemInnerBoundaryIs );
}
return elemPolygon;
@@ -383,19 +382,18 @@ QString QgsCurvePolygon::asJSON( int precision ) const
// GeoJSON does not support curves
QString json = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [" );

QgsLineString *exteriorLineString = exteriorRing()->curveToLine();
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
QgsPointSequence exteriorPts;
exteriorLineString->points( exteriorPts );
json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", ";
delete exteriorLineString;

std::unique_ptr< QgsLineString > interiorLineString;
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
QgsLineString *interiorLineString = interiorRing( i )->curveToLine();
interiorLineString.reset( interiorRing( i )->curveToLine() );
QgsPointSequence interiorPts;
interiorLineString->points( interiorPts );
json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", ";
delete interiorLineString;
}
if ( json.endsWith( QLatin1String( ", " ) ) )
{
@@ -530,7 +530,10 @@ bool QgsGeometryCollection::fromCollectionWkt( const QString &wkt, const QList<Q
QPair<QgsWkbTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWkbTypes::flatType( parts.first ) != QgsWkbTypes::flatType( wkbType() ) )
{
qDeleteAll( subtypes );
return false;
}
mWkbType = parts.first;

QString defChildWkbType = QStringLiteral( "%1%2%3 " ).arg( defaultChildWkbType, is3D() ? "Z" : "", isMeasure() ? "M" : "" );
@@ -69,7 +69,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
* \param g geometry to insert. Ownership is transferred to the collection.
* \param index position to insert geometry before
*/
virtual bool insertGeometry( QgsAbstractGeometry *g, int index SIP_TRANSFER );
virtual bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index );

/** Removes a geometry from the collection.
* \param nr index of geometry to remove
@@ -274,15 +274,14 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( c
}


QgsAbstractGeometry *combinedGeometries = geomEngine->combine( nearGeometries );
std::unique_ptr< QgsAbstractGeometry > combinedGeometries( geomEngine->combine( nearGeometries ) );
qDeleteAll( nearGeometries );
if ( !combinedGeometries )
{
return nullptr;
}

std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries ) );
std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries.get() ) );

delete combinedGeometries;
return diffGeom;
}
@@ -708,14 +708,14 @@ GEOSGeometry *QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) const
{
int type = GEOSGeomTypeId_r( geosinit.ctxt, mGeos );

QgsMultiCurve *multiCurve = nullptr;
std::unique_ptr< QgsMultiCurve > multiCurve;
if ( type == GEOS_MULTILINESTRING )
{
multiCurve = qgsgeometry_cast<QgsMultiCurve *>( mGeometry->clone() );
multiCurve.reset( qgsgeometry_cast<QgsMultiCurve *>( mGeometry->clone() ) );
}
else if ( type == GEOS_LINESTRING )
{
multiCurve = new QgsMultiCurve();
multiCurve.reset( new QgsMultiCurve() );
multiCurve->addGeometry( mGeometry->clone() );
}
else
@@ -729,11 +729,10 @@ GEOSGeometry *QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) const
}


QgsAbstractGeometry *splitGeom = fromGeos( GEOSsplitPoint );
QgsPoint *splitPoint = qgsgeometry_cast<QgsPoint *>( splitGeom );
std::unique_ptr< QgsAbstractGeometry > splitGeom( fromGeos( GEOSsplitPoint ) );
QgsPoint *splitPoint = qgsgeometry_cast<QgsPoint *>( splitGeom.get() );
if ( !splitPoint )
{
delete splitGeom;
return nullptr;
}

@@ -765,8 +764,6 @@ GEOSGeometry *QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) const
}
}

delete splitGeom;
delete multiCurve;
return asGeos( &lines, mPrecision );
}

@@ -1698,13 +1695,13 @@ bool QgsGeos::isSimple( QString *errorMsg ) const

GEOSCoordSequence *QgsGeos::createCoordinateSequence( const QgsCurve *curve, double precision, bool forceClose )
{
bool segmentize = false;
std::unique_ptr< QgsLineString > segmentized;
const QgsLineString *line = qgsgeometry_cast<const QgsLineString *>( curve );

if ( !line )
{
line = curve->curveToLine();
segmentize = true;
segmentized.reset( curve->curveToLine() );
line = segmentized.get();
}

if ( !line )
@@ -1776,10 +1773,6 @@ GEOSCoordSequence *QgsGeos::createCoordinateSequence( const QgsCurve *curve, dou
}
CATCH_GEOS( nullptr )

if ( segmentize )
{
delete line;
}
return coordSeq;
}

0 comments on commit 270c45d

Please sign in to comment.
You can’t perform that action at this time.