Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[API] Add asGml methods to QgsCircle
  • Loading branch information
lbartoletti authored and nyalldawson committed Dec 1, 2020
1 parent c71a2ca commit 5f36925
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
33 changes: 33 additions & 0 deletions python/core/auto_generated/geometry/qgscircle.sip.in
Expand Up @@ -279,6 +279,39 @@ Returns ``True`` if the circle contains the ``point``.
virtual QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const;


QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;
%Docstring
Returns a GML2 representation of the geometry.
Since GML2 does not supports curve, it will be converted to a LineString.

:param doc: DOM document
:param precision: number of decimal places for coordinates
:param ns: XML namespace
:param axisOrder: Axis order for generated GML

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

QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;
%Docstring
Returns a GML3 representation of the geometry.

From the GML3 description:
A Circle is an arc whose ends coincide to form a simple closed loop.
The three control points shall be distinct non-co-linear points for
the circle to be unambiguously defined. The arc is simply extended
past the third control point until the first control point is encountered.

Coordinates are taken from quadrant North, East and South.

:param doc: DOM document
:param precision: number of decimal places for coordinates
:param ns: XML namespace
:param axisOrder: Axis order for generated GML

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

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
Expand Down
22 changes: 22 additions & 0 deletions src/core/geometry/qgscircle.cpp
Expand Up @@ -371,3 +371,25 @@ QString QgsCircle::toString( int pointPrecision, int radiusPrecision, int azimut
return rep;

}

QDomElement QgsCircle::asGml2( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
{
// Gml2 does not support curve. It will be converted to a linestring via CircularString
std::unique_ptr< QgsCircularString > circularString( toCircularString() );
QDomElement gml = circularString->asGml2( doc, precision, ns, axisOrder );
return gml;
}

QDomElement QgsCircle::asGml3( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
{
QgsPointSequence pts;
pts << northQuadrant().at( 0 ) << northQuadrant().at( 1 ) << northQuadrant().at( 2 );

QDomElement elemCircle = doc.createElementNS( ns, QStringLiteral( "Circle" ) );

if ( isEmpty() )
return elemCircle;

elemCircle.appendChild( QgsGeometryUtils::pointsToGML3( pts, doc, precision, ns, mCenter.is3D(), axisOrder ) );
return elemCircle;
}
30 changes: 30 additions & 0 deletions src/core/geometry/qgscircle.h
Expand Up @@ -273,6 +273,36 @@ class CORE_EXPORT QgsCircle : public QgsEllipse

QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const override;

/**
* Returns a GML2 representation of the geometry.
* Since GML2 does not supports curve, it will be converted to a LineString.
* \param doc DOM document
* \param precision number of decimal places for coordinates
* \param ns XML namespace
* \param axisOrder Axis order for generated GML
* \see asGml3()
*/
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

/**
* Returns a GML3 representation of the geometry.
*
* From the GML3 description:
* A Circle is an arc whose ends coincide to form a simple closed loop.
* The three control points shall be distinct non-co-linear points for
* the circle to be unambiguously defined. The arc is simply extended
* past the third control point until the first control point is encountered.
*
* Coordinates are taken from quadrant North, East and South.
*
* \param doc DOM document
* \param precision number of decimal places for coordinates
* \param ns XML namespace
* \param axisOrder Axis order for generated GML
* \see asGml2()
*/
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
Expand Down

0 comments on commit 5f36925

Please sign in to comment.