Skip to content
Permalink
Browse files

Change the approach: returns an empty element

  • Loading branch information
lbartoletti committed Oct 25, 2017
1 parent 52e9a48 commit 7922608ef3f8d176477acd95c642c6cad2e7c7a7
@@ -68,10 +68,6 @@ class QgsTriangle : QgsPolygonV2
virtual bool fromWkt( const QString &wkt );


QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;
%Docstring
:rtype: QDomElement
%End
QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const;
%Docstring
:rtype: QDomElement
@@ -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" ) )
@@ -223,30 +223,24 @@ bool QgsTriangle::fromWkt( const QString &wkt )
return true;
}

QDomElement QgsTriangle::asGML2( QDomDocument &doc, int precision, const QString &ns ) const
QDomElement QgsTriangle::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
if ( !isEmpty() ) /* else crash */
return QgsPolygonV2::asGML2( doc, precision, ns );

return QDomElement(); /* Crash: "QgsPolygonV2().asGML2( doc, precision, ns )"*/
}
QDomElement elemTriangle = doc.createElementNS( ns, QStringLiteral( "Triangle" ) );

QDomElement QgsTriangle::asGML3( QDomDocument &doc, int precision, const QString &ns ) const
{
if ( isEmpty() ) /* else crash */
return QDomElement();
if ( isEmpty() )
return elemTriangle;

QDomElement elemCurveTriangle = doc.createElementNS( ns, QStringLiteral( "Triangle" ) );
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 );
elemCurveTriangle.appendChild( elemExterior );
elemTriangle.appendChild( elemExterior );

return elemCurveTriangle;
return elemTriangle;
}

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

// inherited: QString asWkt( int precision = 17 ) const;
QDomElement asGML2( 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;

@@ -5977,16 +5977,18 @@ void TestQgsGeometry::triangle()
QGSCOMPAREGML( elemToString( exportTriangle.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( QStringLiteral( "<Polygon xmlns=\"gml\"><outerBoundaryIs xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">1.333,2.667 3.333,4.667 6.333,5.667 1.333,2.667</coordinates></LinearRing></outerBoundaryIs></Polygon>" ) );
QGSCOMPAREGML( elemToString( exportTriangleFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );
QString expectedGML2empty( QStringLiteral( "" ) ); // TODO: FIXME?
QString expectedGML2empty( QStringLiteral( "<Polygon xmlns=\"gml\"/>" ) );
QGSCOMPAREGML( elemToString( exportEmptyTriangle.asGML2( doc ) ), expectedGML2empty );
QGSCOMPAREGML( elemToString( QgsTriangle().asGML2( doc ) ), expectedGML2empty );

//asGML3
QString expectedGML3( QStringLiteral( "<Triangle xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">1 2 3 4 6 5 1 2</posList></LinearRing></exterior></Triangle>" ) );
QCOMPARE( elemToString( exportTriangle.asGML3( doc ) ), expectedGML3 );
QString expectedGML3prec3( QStringLiteral( "<Triangle xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">1.333 2.667 3.333 4.667 6.333 5.667 1.333 2.667</posList></LinearRing></exterior></Triangle>" ) );
QCOMPARE( elemToString( exportTriangleFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );
QString expectedGML3empty( QStringLiteral( "" ) ); // TODO: FIXME?
QString expectedGML3empty( QStringLiteral( "<Triangle xmlns=\"gml\"/>" ) );
QGSCOMPAREGML( elemToString( exportEmptyTriangle.asGML3( doc ) ), expectedGML3empty );
QGSCOMPAREGML( elemToString( QgsTriangle().asGML3( doc ) ), expectedGML3empty );
QString expectedGML3Z( QStringLiteral( "<Triangle xmlns=\"gml\"><exterior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"3\">1 2 3 11 12 13 1 12 23 1 2 3</posList></LinearRing></exterior></Triangle>" ) );
QCOMPARE( elemToString( exportTriangleZ.asGML3( doc ) ), expectedGML3Z );

0 comments on commit 7922608

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