Skip to content
Permalink
Browse files

Fix incorrect GML from QgsPointV2::asGML3

Also finish unit tests for QgsPointV2 and mark as a critical class
  • Loading branch information
nyalldawson committed Nov 24, 2015
1 parent b10e708 commit 7443431ee42132e32b9b2801c65df1355c98cde7
Showing with 81 additions and 5 deletions.
  1. +43 −1 src/core/geometry/qgspointv2.cpp
  2. +6 −0 src/core/geometry/qgspointv2.h
  3. +32 −4 tests/src/core/testqgsgeometry.cpp
@@ -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 )
@@ -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() &&
@@ -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();
@@ -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();
@@ -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() )
@@ -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\": ["
@@ -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 );
@@ -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 ) )
@@ -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.
@@ -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 );
@@ -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 ) );
@@ -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 ) );
@@ -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.
You can’t perform that action at this time.