Skip to content

Commit

Permalink
Merge pull request #5428 from lbartoletti/triangleGML
Browse files Browse the repository at this point in the history
ADD GML export to QgsTriangle
  • Loading branch information
nyalldawson authored Oct 25, 2017
2 parents a89dfde + 650a122 commit a9f8e60
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 8 deletions.
4 changes: 4 additions & 0 deletions python/core/geometry/qgstriangle.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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/;

Expand Down
4 changes: 4 additions & 0 deletions src/core/geometry/qgscircularstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down
4 changes: 4 additions & 0 deletions src/core/geometry/qgscompoundcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgscurvepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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" ) )
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgslinestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgsmulticurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgsmultilinestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgsmultipoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgsmultipolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand Down
8 changes: 8 additions & 0 deletions src/core/geometry/qgsmultisurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand Down
31 changes: 25 additions & 6 deletions src/core/geometry/qgstriangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgstriangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit a9f8e60

Please sign in to comment.