Skip to content
Permalink
Browse files

Update tests for geometry classes

  • Loading branch information
elpaso committed May 2, 2019
1 parent ba81645 commit bbd836f4d31e91597f0a0ec139bb9131007a2d29
Showing with 105 additions and 341 deletions.
  1. +4 −2 python/core/auto_generated/geometry/qgsabstractgeometry.sip.in
  2. +0 −2 python/core/auto_generated/geometry/qgscircularstring.sip.in
  3. +0 −2 python/core/auto_generated/geometry/qgscompoundcurve.sip.in
  4. +0 −2 python/core/auto_generated/geometry/qgscurvepolygon.sip.in
  5. +0 −2 python/core/auto_generated/geometry/qgsgeometrycollection.sip.in
  6. +0 −2 python/core/auto_generated/geometry/qgslinestring.sip.in
  7. +0 −2 python/core/auto_generated/geometry/qgsmulticurve.sip.in
  8. +0 −2 python/core/auto_generated/geometry/qgsmultilinestring.sip.in
  9. +0 −2 python/core/auto_generated/geometry/qgsmultipoint.sip.in
  10. +0 −2 python/core/auto_generated/geometry/qgsmultipolygon.sip.in
  11. +0 −2 python/core/auto_generated/geometry/qgsmultisurface.sip.in
  12. +0 −2 python/core/auto_generated/geometry/qgspoint.sip.in
  13. +5 −0 src/core/geometry/qgsabstractgeometry.cpp
  14. +6 −4 src/core/geometry/qgsabstractgeometry.h
  15. +0 −7 src/core/geometry/qgscircularstring.cpp
  16. +0 −1 src/core/geometry/qgscircularstring.h
  17. +0 −8 src/core/geometry/qgscompoundcurve.cpp
  18. +0 −1 src/core/geometry/qgscompoundcurve.h
  19. +1 −30 src/core/geometry/qgscurvepolygon.cpp
  20. +0 −1 src/core/geometry/qgscurvepolygon.h
  21. +1 −5 src/core/geometry/qgsgeometry.cpp
  22. +2 −17 src/core/geometry/qgsgeometrycollection.cpp
  23. +0 −1 src/core/geometry/qgsgeometrycollection.h
  24. +1 −1 src/core/geometry/qgsgeometryutils.cpp
  25. +0 −8 src/core/geometry/qgslinestring.cpp
  26. +0 −1 src/core/geometry/qgslinestring.h
  27. +1 −23 src/core/geometry/qgsmulticurve.cpp
  28. +0 −1 src/core/geometry/qgsmulticurve.h
  29. +1 −22 src/core/geometry/qgsmultilinestring.cpp
  30. +0 −1 src/core/geometry/qgsmultilinestring.h
  31. +0 −18 src/core/geometry/qgsmultipoint.cpp
  32. +0 −1 src/core/geometry/qgsmultipoint.h
  33. +2 −44 src/core/geometry/qgsmultipolygon.cpp
  34. +0 −1 src/core/geometry/qgsmultipolygon.h
  35. +1 −41 src/core/geometry/qgsmultisurface.cpp
  36. +0 −1 src/core/geometry/qgsmultisurface.h
  37. +0 −6 src/core/geometry/qgspoint.cpp
  38. +0 −1 src/core/geometry/qgspoint.h
  39. +1 −0 src/quickgui/CMakeLists.txt
  40. +44 −44 tests/src/core/testqgsgeometry.cpp
  41. +33 −28 tests/src/core/testqgsjsonutils.cpp
  42. +2 −0 tests/src/quickgui/CMakeLists.txt
@@ -246,9 +246,9 @@ Returns a GML3 representation of the geometry.
.. seealso:: :py:func:`asJson`
%End

virtual QString asJson( int precision = 17 ) const = 0;
QString asJson( int precision = 17 );
%Docstring
Returns a GeoJSON representation of the geometry.
Returns a GeoJSON representation of the geometry as a QString.

:param precision: number of decimal places for coordinates

@@ -259,6 +259,8 @@ Returns a GeoJSON representation of the geometry.
.. seealso:: :py:func:`asGml2`

.. seealso:: :py:func:`asGml3`

.. seealso:: :py:func:`asJsonObject`
%End


@@ -79,8 +79,6 @@ to ``p2`` will be used (i.e. winding the other way around the circle).

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

virtual bool isEmpty() const;

virtual int numPoints() const;
@@ -50,8 +50,6 @@ Compound curve geometry type

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;


virtual double length() const;

@@ -54,8 +54,6 @@ Curve polygon geometry type

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;


virtual double area() const;

@@ -152,8 +152,6 @@ An IndexError will be raised if no geometry with the specified index exists.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;


virtual QgsRectangle boundingBox() const;

@@ -412,8 +412,6 @@ segment in the line.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;


virtual double length() const;

@@ -35,8 +35,6 @@ Multi curve geometry collection.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

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

virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );
@@ -34,8 +34,6 @@ Multi line string geometry collection.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

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

virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );
@@ -36,8 +36,6 @@ Multi point geometry collection.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

virtual int nCoordinates() const;

virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ );
@@ -33,8 +33,6 @@ Multi polygon geometry collection.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

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

virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );
@@ -35,8 +35,6 @@ Multi surface geometry collection.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

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

virtual bool insertGeometry( QgsAbstractGeometry *g /Transfer/, int index );
@@ -355,8 +355,6 @@ M value is preserved.

virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

virtual QString asJson( int precision = 17 ) const;

virtual void draw( QPainter &p ) const;

virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) throw( QgsCsException );
@@ -153,6 +153,11 @@ QString QgsAbstractGeometry::wktTypeStr() const
return wkt;
}

QString QgsAbstractGeometry::asJson( int precision )
{
return QString::fromStdString( asJsonObject( precision ).dump() );
}

QgsPoint QgsAbstractGeometry::centroid() const
{
// http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
@@ -277,23 +277,25 @@ class CORE_EXPORT QgsAbstractGeometry
virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const = 0;

/**
* Returns a GeoJSON representation of the geometry.
* Returns a GeoJSON representation of the geometry as a QString.
* \param precision number of decimal places for coordinates
* \see asWkb()
* \see asWkt()
* \see asGml2()
* \see asGml3()
* \see asJsonObject()
*/
virtual QString asJson( int precision = 17 ) const = 0;
QString asJson( int precision = 17 );

/**
* Returns a json obejct representation of the geometry.
* Returns a json object representation of the geometry.
* \see asWkb()
* \see asWkt()
* \see asGml2()
* \see asGml3()
* \see asJson()
* \since QGIS 3.8
* \note not available in Python bindings
* \since QGIS 3.10
*/
virtual json asJsonObject( int precision = 17 ) const SIP_SKIP { Q_UNUSED( precision ); return nullptr; }

@@ -368,13 +368,6 @@ QDomElement QgsCircularString::asGml3( QDomDocument &doc, int precision, const Q
return elemCurve;
}

QString QgsCircularString::asJson( int precision ) const
{
// GeoJSON does not support curves
std::unique_ptr< QgsLineString > line( curveToLine() );
QString json = line->asJson( precision );
return json;
}

json QgsCircularString::asJsonObject( int precision ) const
{
@@ -79,7 +79,6 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
QString asWkt( int precision = 17 ) const override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;
bool isEmpty() const override;
int numPoints() const override;
@@ -292,14 +292,6 @@ QDomElement QgsCompoundCurve::asGml3( QDomDocument &doc, int precision, const QS
return compoundCurveElem;
}

QString QgsCompoundCurve::asJson( int precision ) const
{
// GeoJSON does not support curves
std::unique_ptr< QgsLineString > line( curveToLine() );
QString json = line->asJson( precision );
return json;
}

json QgsCompoundCurve::asJsonObject( int precision ) const
{
// GeoJSON does not support curves
@@ -50,7 +50,6 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
QString asWkt( int precision = 17 ) const override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;

//curve interface
@@ -401,38 +401,9 @@ QDomElement QgsCurvePolygon::asGml3( QDomDocument &doc, int precision, const QSt
return elemCurvePolygon;
}

QString QgsCurvePolygon::asJson( int precision ) const
{
// GeoJSON does not support curves
QString json = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [" );

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

std::unique_ptr< QgsLineString > interiorLineString;
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
interiorLineString.reset( interiorRing( i )->curveToLine() );
QgsPointSequence interiorPts;
interiorLineString->points( interiorPts );
json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + QLatin1String( ", " );
}
if ( json.endsWith( QLatin1String( ", " ) ) )
{
json.chop( 2 ); // Remove last ", "
}
}
json += QLatin1String( "] }" );
return json;
}

json QgsCurvePolygon::asJsonObject( int precision ) const
{
json coordinates;
json coordinates { json::array( )};
if ( exteriorRing() )
{
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
@@ -55,7 +55,6 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
QString asWkt( int precision = 17 ) const override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;

//surface interface
@@ -1263,11 +1263,7 @@ QString QgsGeometry::asWkt( int precision ) const

QString QgsGeometry::asJson( int precision ) const
{
if ( !d->geometry )
{
return QStringLiteral( "null" );
}
return d->geometry->asJson( precision );
return QString::fromStdString( asJsonObject( precision ).dump() );
}

json QgsGeometry::asJsonObject( int precision ) const
@@ -417,32 +417,17 @@ QDomElement QgsGeometryCollection::asGml3( QDomDocument &doc, int precision, con
return elemMultiGeometry;
}

QString QgsGeometryCollection::asJson( int precision ) const
{
QString json = QStringLiteral( "{\"type\": \"GeometryCollection\", \"geometries\": [" );
for ( const QgsAbstractGeometry *geom : mGeometries )
{
json += geom->asJson( precision ) + QLatin1String( ", " );
}
if ( json.endsWith( QLatin1String( ", " ) ) )
{
json.chop( 2 ); // Remove last ", "
}
json += QLatin1String( "] }" );
return json;
}

json QgsGeometryCollection::asJsonObject( int precision ) const
{
json coordinates;
json coordinates { json::array( ) };
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
{
coordinates.push_back( geom->asJsonObject( precision ) );
}
return
{
{ "type", "GeometryCollection" },
{ "coordinates", coordinates }
{ "geometries", coordinates }
};
}

@@ -173,7 +173,6 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
QString asWkt( int precision = 17 ) const override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;

QgsRectangle boundingBox() const override;
@@ -1200,7 +1200,7 @@ QString QgsGeometryUtils::pointsToJSON( const QgsPointSequence &points, int prec

json QgsGeometryUtils::pointsToJson( const QgsPointSequence &points, int precision )
{
json coordinates;
json coordinates { json::array() };
for ( const QgsPoint &p : points )
{
if ( p.is3D() )
@@ -412,14 +412,6 @@ QDomElement QgsLineString::asGml3( QDomDocument &doc, int precision, const QStri
return elemLineString;
}

QString QgsLineString::asJson( int precision ) const
{
QgsPointSequence pts;
points( pts );

return "{\"type\": \"LineString\", \"coordinates\": " + QgsGeometryUtils::pointsToJSON( pts, precision ) + '}';
}

json QgsLineString::asJsonObject( int precision ) const
{
QgsPointSequence pts;
@@ -560,7 +560,6 @@ class CORE_EXPORT QgsLineString: public QgsCurve
QString asWkt( int precision = 17 ) const override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;

//curve interface
@@ -110,31 +110,9 @@ QDomElement QgsMultiCurve::asGml3( QDomDocument &doc, int precision, const QStri
return elemMultiCurve;
}

QString QgsMultiCurve::asJson( int precision ) const
{
// GeoJSON does not support curves
QString json = QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [" );
for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsCurve *>( geom ) )
{
std::unique_ptr< QgsLineString > lineString( static_cast<const QgsCurve *>( geom )->curveToLine() );
QgsPointSequence pts;
lineString->points( pts );
json += QgsGeometryUtils::pointsToJSON( pts, precision ) + QLatin1String( ", " );
}
}
if ( json.endsWith( QLatin1String( ", " ) ) )
{
json.chop( 2 ); // Remove last ", "
}
json += QLatin1String( "] }" );
return json;
}

json QgsMultiCurve::asJsonObject( int precision ) const
{
json coordinates;
json coordinates { json::array( ) };
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
{
if ( qgsgeometry_cast<const QgsCurve *>( geom ) )
@@ -37,7 +37,6 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
bool fromWkt( const QString &wkt ) override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;
bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override;
bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override;

0 comments on commit bbd836f

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