Skip to content

Commit

Permalink
Fix incorrect GML from QgsPointV2::asGML3
Browse files Browse the repository at this point in the history
Also finish unit tests for QgsPointV2 and mark as a critical class
  • Loading branch information
nyalldawson committed Nov 24, 2015
1 parent b10e708 commit 7443431
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
44 changes: 43 additions & 1 deletion src/core/geometry/qgspointv2.cpp
Expand Up @@ -24,6 +24,12 @@
#include "qgswkbptr.h"
#include <QPainter>

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

QgsPointV2::QgsPointV2( double x, double y )
: QgsAbstractGeometryV2()
, mX( x )
Expand Down Expand Up @@ -65,6 +71,12 @@ QgsPointV2::QgsPointV2( QgsWKBTypes::Type type, double x, double y, double z, do
mWkbType = type;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

bool QgsPointV2::operator==( const QgsPointV2& pt ) const
{
return ( pt.wkbType() == wkbType() &&
Expand Down Expand Up @@ -107,6 +119,12 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
return true;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

bool QgsPointV2::fromWkt( const QString& wkt )
{
clear();
Expand Down Expand Up @@ -155,6 +173,12 @@ int QgsPointV2::wkbSize() const
return size;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

unsigned char* QgsPointV2::asWkb( int& binarySize ) const
{
binarySize = wkbSize();
Expand Down Expand Up @@ -199,7 +223,7 @@ QDomElement QgsPointV2::asGML2( QDomDocument& doc, int precision, const QString&
QDomElement QgsPointV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
{
QDomElement elemPoint = doc.createElementNS( ns, "Point" );
QDomElement elemPosList = doc.createElementNS( ns, "posList" );
QDomElement elemPosList = doc.createElementNS( ns, "pos" );
elemPosList.setAttribute( "srsDimension", is3D() ? 3 : 2 );
QString strCoordinates = qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
if ( is3D() )
Expand All @@ -210,6 +234,12 @@ QDomElement QgsPointV2::asGML3( QDomDocument& doc, int precision, const QString&
return elemPoint;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

QString QgsPointV2::asJSON( int precision ) const
{
return "{\"type\": \"Point\", \"coordinates\": ["
Expand Down Expand Up @@ -243,6 +273,12 @@ void QgsPointV2::coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coor
coord.append( featureCoord );
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
{
Q_UNUSED( position );
Expand Down Expand Up @@ -290,6 +326,12 @@ bool QgsPointV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
}
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
* See details in QEP #17
****************************************************************************/

bool QgsPointV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
Expand Down
6 changes: 6 additions & 0 deletions src/core/geometry/qgspointv2.h
Expand Up @@ -20,6 +20,12 @@

#include "qgsabstractgeometryv2.h"

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests in testqgsgeometry.cpp.
* See details in QEP #17
****************************************************************************/

/** \ingroup core
* \class QgsPointV2
* \brief Point geometry type, with support for z-dimension and m-values.
Expand Down
36 changes: 32 additions & 4 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -514,7 +514,26 @@ void TestQgsGeometry::pointV2()
QVERIFY( !p14.fromWkt( "Polygon()" ) );
QCOMPARE( p14.wkbType(), QgsWKBTypes::Unknown );

//TODO asGML2, asGML3, asJSON
//asGML2
QgsPointV2 exportPoint( 1, 2 );
QgsPointV2 exportPointFloat( 1 / 3.0, 2 / 3.0 );
QDomDocument doc( "gml" );
QString expectedGML2( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">1,2</coordinates></Point>" );
QCOMPARE( elemToString( exportPoint.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667</coordinates></Point>" );
QCOMPARE( elemToString( exportPointFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );

//asGML3
QString expectedGML3( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">1 2</pos></Point>" );
QCOMPARE( elemToString( exportPoint.asGML3( doc ) ), expectedGML3 );
QString expectedGML3prec3( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">0.333 0.667</pos></Point>" );
QCOMPARE( elemToString( exportPointFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );

//asJSON
QString expectedJson( "{\"type\": \"Point\", \"coordinates\": [1, 2]}" );
QCOMPARE( exportPoint.asJSON(), expectedJson );
QString expectedJsonPrec3( "{\"type\": \"Point\", \"coordinates\": [0.333, 0.667]}" );
QCOMPARE( exportPointFloat.asJSON( 3 ), expectedJsonPrec3 );

//bounding box
QgsPointV2 p15( 1.0, 2.0 );
Expand Down Expand Up @@ -1060,7 +1079,7 @@ void TestQgsGeometry::exportToGeoJSON()
QString obtained = geom->exportToGeoJSON();
QString geojson = "{\"type\": \"Point\", \"coordinates\": [40, 50]}";
QCOMPARE( obtained, geojson );

//MultiPoint
wkt = "MultiPoint (0 0, 10 0, 10 10, 20 10)";
geom.reset( QgsGeometry::fromWkt( wkt ) );
Expand All @@ -1074,14 +1093,14 @@ void TestQgsGeometry::exportToGeoJSON()
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"LineString\", \"coordinates\": [ [0, 0], [10, 0], [10, 10], [20, 10]]}";
QCOMPARE( obtained, geojson );

//MultiLineString
wkt = "MultiLineString ((0 0, 10 0, 10 10, 20 10),(30 30, 40 30, 40 40, 50 40))";
geom.reset( QgsGeometry::fromWkt( wkt ) );
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"MultiLineString\", \"coordinates\": [[ [0, 0], [10, 0], [10, 10], [20, 10]], [ [30, 30], [40, 30], [40, 40], [50, 40]]] }";
QCOMPARE( obtained, geojson );

//Polygon
wkt = "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ),(2 2, 4 2, 4 4, 2 4, 2 2))";
geom.reset( QgsGeometry::fromWkt( wkt ) );
Expand Down Expand Up @@ -1162,5 +1181,14 @@ void TestQgsGeometry::dumpPolyline( QgsPolyline &thePolyline )
mpPainter->drawPolyline( myPoints );
}

QString TestQgsGeometry::elemToString( const QDomElement& elem ) const
{
QString s;
QTextStream stream( &s );
elem.save( stream, -1 );

return s;
}

QTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"

0 comments on commit 7443431

Please sign in to comment.