Skip to content
Permalink
Browse files

Merge pull request #5428 from lbartoletti/triangleGML

ADD GML export to QgsTriangle
  • Loading branch information
nyalldawson committed Oct 25, 2017
2 parents a89dfde + 650a122 commit a9f8e600643ff474a32322a4dce4efab6bb7f873
@@ -68,6 +68,10 @@ class QgsTriangle : QgsPolygonV2
virtual bool fromWkt( const QString &wkt );


QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;
%Docstring
:rtype: QDomElement
%End

virtual QgsPolygonV2 *surfaceToPolygon() const /Factory/;

@@ -313,6 +313,10 @@ QDomElement QgsCircularString::asGML3( QDomDocument &doc, int precision, const Q
points( pts );

QDomElement elemCurve = doc.createElementNS( ns, QStringLiteral( "Curve" ) );

if ( isEmpty() )
return elemCurve;

QDomElement elemSegments = doc.createElementNS( ns, QStringLiteral( "segments" ) );
QDomElement elemArcString = doc.createElementNS( ns, QStringLiteral( "ArcString" ) );
elemArcString.appendChild( QgsGeometryUtils::pointsToGML3( pts, doc, precision, ns, is3D() ) );
@@ -271,6 +271,10 @@ QDomElement QgsCompoundCurve::asGML2( QDomDocument &doc, int precision, const QS
QDomElement QgsCompoundCurve::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement compoundCurveElem = doc.createElementNS( ns, QStringLiteral( "CompositeCurve" ) );

if ( isEmpty() )
return compoundCurveElem;

for ( const QgsCurve *curve : mCurves )
{
QDomElement curveMemberElem = doc.createElementNS( ns, QStringLiteral( "curveMember" ) );
@@ -332,6 +332,10 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt
{
// GML2 does not support curves
QDomElement elemPolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) );

if ( isEmpty() )
return elemPolygon;

QDomElement elemOuterBoundaryIs = doc.createElementNS( ns, QStringLiteral( "outerBoundaryIs" ) );
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
QDomElement outerRing = exteriorLineString->asGML2( doc, precision, ns );
@@ -354,6 +358,10 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt
QDomElement QgsCurvePolygon::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemCurvePolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) );

if ( isEmpty() )
return elemCurvePolygon;

QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) );
QDomElement curveElem = exteriorRing()->asGML3( doc, precision, ns );
if ( curveElem.tagName() == QLatin1String( "LineString" ) )
@@ -291,6 +291,10 @@ QDomElement QgsLineString::asGML2( QDomDocument &doc, int precision, const QStri
points( pts );

QDomElement elemLineString = doc.createElementNS( ns, QStringLiteral( "LineString" ) );

if ( isEmpty() )
return elemLineString;

elemLineString.appendChild( QgsGeometryUtils::pointsToGML2( pts, doc, precision, ns ) );

return elemLineString;
@@ -302,6 +306,10 @@ QDomElement QgsLineString::asGML3( QDomDocument &doc, int precision, const QStri
points( pts );

QDomElement elemLineString = doc.createElementNS( ns, QStringLiteral( "LineString" ) );

if ( isEmpty() )
return elemLineString;

elemLineString.appendChild( QgsGeometryUtils::pointsToGML3( pts, doc, precision, ns, is3D() ) );
return elemLineString;
}
@@ -60,6 +60,10 @@ QDomElement QgsMultiCurve::asGML2( QDomDocument &doc, int precision, const QStri
{
// GML2 does not support curves
QDomElement elemMultiLineString = doc.createElementNS( ns, QStringLiteral( "MultiLineString" ) );

if ( isEmpty() )
return elemMultiLineString;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsCurve *>( geom ) )
@@ -78,6 +82,10 @@ QDomElement QgsMultiCurve::asGML2( QDomDocument &doc, int precision, const QStri
QDomElement QgsMultiCurve::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiCurve = doc.createElementNS( ns, QStringLiteral( "MultiCurve" ) );

if ( isEmpty() )
return elemMultiCurve;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsCurve *>( geom ) )
@@ -51,6 +51,10 @@ bool QgsMultiLineString::fromWkt( const QString &wkt )
QDomElement QgsMultiLineString::asGML2( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiLineString = doc.createElementNS( ns, QStringLiteral( "MultiLineString" ) );

if ( isEmpty() )
return elemMultiLineString;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( const QgsLineString *lineString = qgsgeometry_cast<const QgsLineString *>( geom ) )
@@ -67,6 +71,10 @@ QDomElement QgsMultiLineString::asGML2( QDomDocument &doc, int precision, const
QDomElement QgsMultiLineString::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiCurve = doc.createElementNS( ns, QStringLiteral( "MultiCurve" ) );

if ( isEmpty() )
return elemMultiCurve;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( const QgsLineString *lineString = qgsgeometry_cast<const QgsLineString *>( geom ) )
@@ -63,6 +63,10 @@ void QgsMultiPointV2::clear()
QDomElement QgsMultiPointV2::asGML2( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral( "MultiPoint" ) );

if ( isEmpty() )
return elemMultiPoint;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsPoint *>( geom ) )
@@ -79,6 +83,10 @@ QDomElement QgsMultiPointV2::asGML2( QDomDocument &doc, int precision, const QSt
QDomElement QgsMultiPointV2::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral( "MultiPoint" ) );

if ( isEmpty() )
return elemMultiPoint;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsPoint *>( geom ) )
@@ -52,6 +52,10 @@ QDomElement QgsMultiPolygonV2::asGML2( QDomDocument &doc, int precision, const Q
{
// GML2 does not support curves
QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral( "MultiPolygon" ) );

if ( isEmpty() )
return elemMultiPolygon;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsPolygonV2 *>( geom ) )
@@ -68,6 +72,10 @@ QDomElement QgsMultiPolygonV2::asGML2( QDomDocument &doc, int precision, const Q
QDomElement QgsMultiPolygonV2::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral( "MultiPolygon" ) );

if ( isEmpty() )
return elemMultiSurface;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsPolygonV2 *>( geom ) )
@@ -60,6 +60,10 @@ QDomElement QgsMultiSurface::asGML2( QDomDocument &doc, int precision, const QSt
{
// GML2 does not support curves
QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral( "MultiPolygon" ) );

if ( isEmpty() )
return elemMultiPolygon;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsSurface *>( geom ) )
@@ -78,6 +82,10 @@ QDomElement QgsMultiSurface::asGML2( QDomDocument &doc, int precision, const QSt
QDomElement QgsMultiSurface::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral( "MultiSurface" ) );

if ( isEmpty() )
return elemMultiSurface;

for ( const QgsAbstractGeometry *geom : mGeometries )
{
if ( qgsgeometry_cast<const QgsSurface *>( geom ) )
@@ -35,13 +35,12 @@ QgsTriangle::QgsTriangle( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint
{
return;
}
QVector< double > x;
x << p1.x() << p2.x() << p3.x();
QVector< double > y;
y << p1.y() << p2.y() << p3.y();
QgsLineString *ext = new QgsLineString( x, y );
setExteriorRing( ext );

std::unique_ptr<QgsLineString> ext( new QgsLineString() );

ext->setPoints( QgsPointSequence() << p1 << p2 << p3 );

setExteriorRing( ext.release() );
}

QgsTriangle::QgsTriangle( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3 )
@@ -224,6 +223,26 @@ bool QgsTriangle::fromWkt( const QString &wkt )
return true;
}

QDomElement QgsTriangle::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{

QDomElement elemTriangle = doc.createElementNS( ns, QStringLiteral( "Triangle" ) );

if ( isEmpty() )
return elemTriangle;

QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) );
QDomElement curveElem = exteriorRing()->asGML3( doc, precision, ns );
if ( curveElem.tagName() == QLatin1String( "LineString" ) )
{
curveElem.setTagName( QStringLiteral( "LinearRing" ) );
}
elemExterior.appendChild( curveElem );
elemTriangle.appendChild( elemExterior );

return elemTriangle;
}

QgsPolygonV2 *QgsTriangle::surfaceToPolygon() const
{
return toPolygon();
@@ -74,8 +74,8 @@ class CORE_EXPORT QgsTriangle : public QgsPolygonV2
bool fromWkt( const QString &wkt ) override;

// inherited: QString asWkt( int precision = 17 ) const;
// inherited: QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
// inherited: QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
// inherited (as a polygon): QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;
QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;
// inherited: QString asJSON( int precision = 17 ) const;

QgsPolygonV2 *surfaceToPolygon() const override SIP_FACTORY;

0 comments on commit a9f8e60

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