Skip to content
Permalink
Browse files

toJsonV2

  • Loading branch information
elpaso committed Apr 5, 2019
1 parent 7222828 commit 6967a21882e8e087e81e635424642835db32d795
Showing with 316 additions and 16 deletions.
  1. +13 −0 python/core/auto_generated/geometry/qgsabstractgeometry.sip.in
  2. +1 −0 python/core/auto_generated/geometry/qgscircularstring.sip.in
  3. +2 −0 python/core/auto_generated/geometry/qgscompoundcurve.sip.in
  4. +2 −0 python/core/auto_generated/geometry/qgscurvepolygon.sip.in
  5. +5 −0 python/core/auto_generated/geometry/qgsgeometry.sip.in
  6. +2 −0 python/core/auto_generated/geometry/qgsgeometrycollection.sip.in
  7. +1 −0 python/core/auto_generated/geometry/qgsgeometryutils.sip.in
  8. +2 −0 python/core/auto_generated/geometry/qgslinestring.sip.in
  9. +2 −0 python/core/auto_generated/geometry/qgsmulticurve.sip.in
  10. +2 −0 python/core/auto_generated/geometry/qgsmultilinestring.sip.in
  11. +2 −0 python/core/auto_generated/geometry/qgsmultipoint.sip.in
  12. +2 −0 python/core/auto_generated/geometry/qgsmultipolygon.sip.in
  13. +2 −0 python/core/auto_generated/geometry/qgsmultisurface.sip.in
  14. +2 −0 python/core/auto_generated/geometry/qgspoint.sip.in
  15. +9 −0 src/core/geometry/qgsabstractgeometry.h
  16. +8 −0 src/core/geometry/qgscircularstring.cpp
  17. +1 −1 src/core/geometry/qgscircularstring.h
  18. +8 −0 src/core/geometry/qgscompoundcurve.cpp
  19. +1 −0 src/core/geometry/qgscompoundcurve.h
  20. +28 −0 src/core/geometry/qgscurvepolygon.cpp
  21. +1 −0 src/core/geometry/qgscurvepolygon.h
  22. +9 −0 src/core/geometry/qgsgeometry.cpp
  23. +6 −0 src/core/geometry/qgsgeometry.h
  24. +14 −0 src/core/geometry/qgsgeometrycollection.cpp
  25. +1 −0 src/core/geometry/qgsgeometrycollection.h
  26. +11 −0 src/core/geometry/qgsgeometryutils.cpp
  27. +7 −0 src/core/geometry/qgsgeometryutils.h
  28. +12 −0 src/core/geometry/qgslinestring.cpp
  29. +1 −0 src/core/geometry/qgslinestring.h
  30. +21 −0 src/core/geometry/qgsmulticurve.cpp
  31. +1 −0 src/core/geometry/qgsmulticurve.h
  32. +22 −0 src/core/geometry/qgsmultilinestring.cpp
  33. +1 −0 src/core/geometry/qgsmultilinestring.h
  34. +21 −0 src/core/geometry/qgsmultipoint.cpp
  35. +1 −0 src/core/geometry/qgsmultipoint.h
  36. +33 −0 src/core/geometry/qgsmultipolygon.cpp
  37. +1 −0 src/core/geometry/qgsmultipolygon.h
  38. +32 −0 src/core/geometry/qgsmultisurface.cpp
  39. +1 −0 src/core/geometry/qgsmultisurface.h
  40. +11 −0 src/core/geometry/qgspoint.cpp
  41. +1 −0 src/core/geometry/qgspoint.h
  42. +5 −5 src/core/qgsjsonutils.cpp
  43. +8 −10 tests/src/core/testqgsjsonutils.cpp
@@ -256,6 +256,19 @@ Returns a GeoJSON representation of the geometry.

.. seealso:: :py:func:`asGml2`

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

virtual QJsonObject asJsonV2( ) const = 0;
%Docstring
Returns a GeoJSON object of the geometry.

.. seealso:: :py:func:`asWkb`

.. seealso:: :py:func:`asWkt`

.. seealso:: :py:func:`asGml2`

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

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

virtual bool isEmpty() const;

@@ -52,6 +52,8 @@ Compound curve geometry type

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;


virtual double length() const;

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2() const;


virtual double area() const;

@@ -1439,6 +1439,11 @@ Exports the geometry to WKT
QString asJson( int precision = 17 ) const;
%Docstring
Exports the geometry to a GeoJSON string.
%End

QJsonObject asJsonV2( ) const;
%Docstring
Exports the geometry to a GeoJSON object.
%End

QgsGeometry convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart = false ) const /Factory/;
@@ -154,6 +154,8 @@ An IndexError will be raised if no geometry with the specified index exists.

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;


virtual QgsRectangle boundingBox() const;

@@ -375,6 +375,7 @@ Interpolate a value at given angle on circular arc given values (zm1, zm2, zm3)




static double normalizedAngle( double angle );
%Docstring
Ensures that an angle is in the range 0 <= angle < 2 pi.
@@ -414,6 +414,8 @@ segment in the line.

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;


virtual double length() const;

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

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

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

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

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

virtual int nCoordinates() const;

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

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

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

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

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

virtual QString asJson( int precision = 17 ) const;

virtual QJsonObject asJsonV2( ) const;

virtual void draw( QPainter &p ) const;

virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) throw( QgsCsException );
@@ -280,6 +280,15 @@ class CORE_EXPORT QgsAbstractGeometry
*/
virtual QString asJson( int precision = 17 ) const = 0;

/**
* Returns a GeoJSON object of the geometry.
* \see asWkb()
* \see asWkt()
* \see asGml2()
* \see asGml3()
*/
virtual QJsonObject asJsonV2( ) const = 0;

//render pipeline

/**
@@ -24,6 +24,7 @@
#include "qgspoint.h"
#include "qgswkbptr.h"
#include "qgslogger.h"
#include <QJsonObject>
#include <QPainter>
#include <QPainterPath>
#include <memory>
@@ -374,6 +375,13 @@ QString QgsCircularString::asJson( int precision ) const
return json;
}

QJsonObject QgsCircularString::asJsonV2() const
{
// GeoJSON does not support curves
std::unique_ptr< QgsLineString > line( curveToLine() );
return line->asJsonV2( );
}

bool QgsCircularString::isEmpty() const
{
return mX.isEmpty();
@@ -80,7 +80,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
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;

QJsonObject asJsonV2( ) const override;
bool isEmpty() const override;
int numPoints() const override;

@@ -21,6 +21,7 @@
#include "qgsgeometryutils.h"
#include "qgslinestring.h"
#include "qgswkbptr.h"
#include <QJsonObject>
#include <QPainter>
#include <QPainterPath>
#include <memory>
@@ -298,6 +299,13 @@ QString QgsCompoundCurve::asJson( int precision ) const
return json;
}

QJsonObject QgsCompoundCurve::asJsonV2() const
{
// GeoJSON does not support curves
std::unique_ptr< QgsLineString > line( curveToLine() );
return line->asJsonV2();
}

double QgsCompoundCurve::length() const
{
double length = 0;
@@ -51,6 +51,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
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;
QJsonObject asJsonV2( ) const override;

//curve interface
double length() const override;
@@ -24,6 +24,8 @@
#include "qgspolygon.h"
#include "qgswkbptr.h"
#include "qgsmulticurve.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QPainter>
#include <QPainterPath>
#include <memory>
@@ -426,6 +428,32 @@ QString QgsCurvePolygon::asJson( int precision ) const
return json;
}

QJsonObject QgsCurvePolygon::asJsonV2() const
{
QJsonArray coordinates;
if ( exteriorRing() )
{
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
QgsPointSequence exteriorPts;
exteriorLineString->points( exteriorPts );
coordinates.append( QgsGeometryUtils::pointsToJsonV2( exteriorPts ) );

std::unique_ptr< QgsLineString > interiorLineString;
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
interiorLineString.reset( interiorRing( i )->curveToLine() );
QgsPointSequence interiorPts;
interiorLineString->points( interiorPts );
coordinates.append( QgsGeometryUtils::pointsToJsonV2( interiorPts ) );
}
}
return
{
{ QLatin1String( "type" ), QLatin1String( "Point" ) },
{ QLatin1String( "coordinates" ), coordinates }
};
}

double QgsCurvePolygon::area() const
{
if ( !mExteriorRing )
@@ -56,6 +56,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
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;
QJsonObject asJsonV2() const override;

//surface interface
double area() const override;
@@ -1268,6 +1268,15 @@ QString QgsGeometry::asJson( int precision ) const
return d->geometry->asJson( precision );
}

QJsonObject QgsGeometry::asJsonV2() const
{
if ( !d->geometry )
{
return QJsonObject( );
}
return d->geometry->asJsonV2( );
}

QgsGeometry QgsGeometry::convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart ) const
{
switch ( destType )
@@ -19,6 +19,7 @@ email : morb at ozemail dot com dot au
#include <functional>

#include <QDomDocument>
#include <QJsonObject>
#include <QSet>
#include <QString>
#include <QVector>
@@ -1429,6 +1430,11 @@ class CORE_EXPORT QgsGeometry
*/
QString asJson( int precision = 17 ) const;

/**
* Exports the geometry to a GeoJSON object.
*/
QJsonObject asJsonV2( ) const;

/**
* Try to convert the geometry to the requested type
* \param destType the geometry type to be converted to
@@ -431,6 +431,20 @@ QString QgsGeometryCollection::asJson( int precision ) const
return json;
}

QJsonObject QgsGeometryCollection::asJsonV2() const
{
QJsonArray coordinates;
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
{
coordinates.append( geom->asJsonV2() );
}
return
{
{ QLatin1String( "type" ), QLatin1String( "GeometryCollection" ) },
{ QLatin1String( "coordinates" ), coordinates }
};
}

QgsRectangle QgsGeometryCollection::boundingBox() const
{
if ( mBoundingBox.isNull() )
@@ -174,6 +174,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
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;
QJsonObject asJsonV2( ) const override;

QgsRectangle boundingBox() const override;

@@ -27,6 +27,7 @@ email : marco.hugentobler at sourcepole dot com
#include <QVector>
#include <QRegularExpression>


QVector<QgsLineString *> QgsGeometryUtils::extractLineStrings( const QgsAbstractGeometry *geom )
{
QVector< QgsLineString * > linestrings;
@@ -1194,6 +1195,16 @@ QString QgsGeometryUtils::pointsToJSON( const QgsPointSequence &points, int prec
return json;
}

QJsonArray QgsGeometryUtils::pointsToJsonV2( const QgsPointSequence &points )
{
QJsonArray coordinates;
for ( const QgsPoint &p : points )
{
coordinates.append( QJsonArray( { p.x(), p.y() } ) );
}
return coordinates;
}

double QgsGeometryUtils::normalizedAngle( double angle )
{
double clippedAngle = angle;
@@ -24,6 +24,7 @@ email : marco.hugentobler at sourcepole dot com
#include "qgsabstractgeometry.h"
#include "qgsvector3d.h"

#include <QJsonArray>

class QgsLineString;

@@ -420,6 +421,12 @@ class CORE_EXPORT QgsGeometryUtils
*/
static QString pointsToJSON( const QgsPointSequence &points, int precision ) SIP_SKIP;

/**
* Returns a geoJSON coordinates object.
* \note not available in Python bindings
*/
static QJsonArray pointsToJsonV2( const QgsPointSequence &points ) SIP_SKIP;

/**
* Ensures that an angle is in the range 0 <= angle < 2 pi.
* \param angle angle in radians

0 comments on commit 6967a21

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