Skip to content
Permalink
Browse files

Return subclasses where possible to fix build on older compilers

  • Loading branch information
nyalldawson committed Aug 17, 2017
1 parent 2693c6f commit 43536a66e39359d246d967d0bcac36550474e4c3
@@ -164,7 +164,7 @@ QgsGeometry QgsGeometry::fromPolyline( const QgsPolyline &polyline )

QgsGeometry QgsGeometry::fromPolygon( const QgsPolygon &polygon )
{
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeometryFactory::fromPolygon( polygon );
std::unique_ptr< QgsPolygonV2 > geom = QgsGeometryFactory::fromPolygon( polygon );
if ( geom )
{
return QgsGeometry( geom.release() );
@@ -174,7 +174,7 @@ QgsGeometry QgsGeometry::fromPolygon( const QgsPolygon &polygon )

QgsGeometry QgsGeometry::fromMultiPoint( const QgsMultiPoint &multipoint )
{
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeometryFactory::fromMultiPoint( multipoint );
std::unique_ptr< QgsMultiPointV2 > geom = QgsGeometryFactory::fromMultiPoint( multipoint );
if ( geom )
{
return QgsGeometry( geom.release() );
@@ -184,7 +184,7 @@ QgsGeometry QgsGeometry::fromMultiPoint( const QgsMultiPoint &multipoint )

QgsGeometry QgsGeometry::fromMultiPolyline( const QgsMultiPolyline &multiline )
{
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeometryFactory::fromMultiPolyline( multiline );
std::unique_ptr< QgsMultiLineString > geom = QgsGeometryFactory::fromMultiPolyline( multiline );
if ( geom )
{
return QgsGeometry( geom.release() );
@@ -194,7 +194,7 @@ QgsGeometry QgsGeometry::fromMultiPolyline( const QgsMultiPolyline &multiline )

QgsGeometry QgsGeometry::fromMultiPolygon( const QgsMultiPolygon &multipoly )
{
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeometryFactory::fromMultiPolygon( multipoly );
std::unique_ptr< QgsMultiPolygonV2 > geom = QgsGeometryFactory::fromMultiPolygon( multipoly );
if ( geom )
{
return QgsGeometry( geom.release() );
@@ -135,7 +135,7 @@ std::unique_ptr< QgsAbstractGeometry > QgsGeometryFactory::fromPoint( const QgsP
return std::unique_ptr< QgsAbstractGeometry >( new QgsPoint( point.x(), point.y() ) );
}

std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromMultiPoint( const QgsMultiPoint &multipoint )
std::unique_ptr<QgsMultiPointV2> QgsGeometryFactory::fromMultiPoint( const QgsMultiPoint &multipoint )
{
std::unique_ptr< QgsMultiPointV2 > mp( new QgsMultiPointV2() );
QgsMultiPoint::const_iterator ptIt = multipoint.constBegin();
@@ -152,7 +152,7 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromPolyline( const Qgs
return linestringFromPolyline( polyline );
}

std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromMultiPolyline( const QgsMultiPolyline &multiline )
std::unique_ptr<QgsMultiLineString> QgsGeometryFactory::fromMultiPolyline( const QgsMultiPolyline &multiline )
{
std::unique_ptr< QgsMultiLineString > mLine( new QgsMultiLineString() );
for ( int i = 0; i < multiline.size(); ++i )
@@ -162,7 +162,7 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromMultiPolyline( cons
return mLine;
}

std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromPolygon( const QgsPolygon &polygon )
std::unique_ptr<QgsPolygonV2> QgsGeometryFactory::fromPolygon( const QgsPolygon &polygon )
{
std::unique_ptr< QgsPolygonV2 > poly( new QgsPolygonV2() );

@@ -185,7 +185,7 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromPolygon( const QgsP
return poly;
}

std::unique_ptr< QgsAbstractGeometry > QgsGeometryFactory::fromMultiPolygon( const QgsMultiPolygon &multipoly )
std::unique_ptr< QgsMultiPolygonV2 > QgsGeometryFactory::fromMultiPolygon( const QgsMultiPolygon &multipoly )
{
std::unique_ptr< QgsMultiPolygonV2 > mp( new QgsMultiPolygonV2() );
for ( int i = 0; i < multipoly.size(); ++i )
@@ -195,7 +195,7 @@ std::unique_ptr< QgsAbstractGeometry > QgsGeometryFactory::fromMultiPolygon( con
return mp;
}

std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::fromRect( const QgsRectangle &rect )
std::unique_ptr<QgsPolygonV2> QgsGeometryFactory::fromRect( const QgsRectangle &rect )
{
QgsPolyline ring;
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
@@ -29,6 +29,10 @@ class QgsLineString;
class QgsConstWkbPtr;
class QgsRectangle;
class QgsGeometryCollection;
class QgsMultiPointV2;
class QgsMultiLineString;
class QgsPolygonV2;
class QgsMultiPolygonV2;

//compatibility with old classes
#include "qgspointxy.h"
@@ -60,17 +64,17 @@ class CORE_EXPORT QgsGeometryFactory
//! Construct geometry from a point
static std::unique_ptr< QgsAbstractGeometry > fromPoint( const QgsPointXY &point );
//! Construct geometry from a multipoint
static std::unique_ptr< QgsAbstractGeometry > fromMultiPoint( const QgsMultiPoint &multipoint );
static std::unique_ptr<QgsMultiPointV2> fromMultiPoint( const QgsMultiPoint &multipoint );
//! Construct geometry from a polyline
static std::unique_ptr< QgsAbstractGeometry > fromPolyline( const QgsPolyline &polyline );
//! Construct geometry from a multipolyline
static std::unique_ptr< QgsAbstractGeometry > fromMultiPolyline( const QgsMultiPolyline &multiline );
static std::unique_ptr<QgsMultiLineString> fromMultiPolyline( const QgsMultiPolyline &multiline );
//! Construct geometry from a polygon
static std::unique_ptr< QgsAbstractGeometry > fromPolygon( const QgsPolygon &polygon );
static std::unique_ptr<QgsPolygonV2> fromPolygon( const QgsPolygon &polygon );
//! Construct geometry from a multipolygon
static std::unique_ptr< QgsAbstractGeometry > fromMultiPolygon( const QgsMultiPolygon &multipoly );
static std::unique_ptr<QgsMultiPolygonV2> fromMultiPolygon( const QgsMultiPolygon &multipoly );
//! Construct geometry from a rectangle
static std::unique_ptr< QgsAbstractGeometry > fromRect( const QgsRectangle &rect );
static std::unique_ptr<QgsPolygonV2> fromRect( const QgsRectangle &rect );
//! Return empty geometry from wkb type
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType( QgsWkbTypes::Type t );

@@ -385,7 +385,7 @@ void TestQgsDistanceArea::regression16820()
QgsDistanceArea calc;
calc.setEllipsoid( QStringLiteral( "WGS84" ) );
calc.setSourceCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:32634" ) ) );
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( QStringLiteral( "Polygon ((110250.54038314701756462 5084495.57398066483438015, 110243.46975068224128336 5084507.17200060561299324, 110251.23908144699817058 5084506.68309532757848501, 110251.2394439501222223 5084506.68307251576334238, 110250.54048078990308568 5084495.57553235255181789, 110250.54038314701756462 5084495.57398066483438015))" ) ) );
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( QStringLiteral( "Polygon ((110250.54038314701756462 5084495.57398066483438015, 110243.46975068224128336 5084507.17200060561299324, 110251.23908144699817058 5084506.68309532757848501, 110251.2394439501222223 5084506.68307251576334238, 110250.54048078990308568 5084495.57553235255181789, 110250.54038314701756462 5084495.57398066483438015))" ) ).release() );
//lots of tolerance here - the formulas get quite unstable with small areas due to division by very small floats
QGSCOMPARENEAR( calc.measureArea( geom ), 43.3280029296875, 0.2 );
}

0 comments on commit 43536a6

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