Skip to content

Commit 969df01

Browse files
committedMar 7, 2013
Moved GML import/export to a new class: QgsOgcUtils
1 parent 290f8fd commit 969df01

17 files changed

+1166
-1041
lines changed
 

‎python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
%Include qgsmimedatautils.sip
4848
%Include qgsnetworkaccessmanager.sip
4949
%Include qgsofflineediting.sip
50+
%Include qgsogcutils.sip
5051
%Include qgsoverlayobject.sip
5152
%Include qgsowsconnection.sip
5253
%Include qgspaintenginehack.sip

‎python/core/qgsgeometry.sip

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ class QgsGeometry
4141
/** static method that creates geometry from Wkt */
4242
static QgsGeometry* fromWkt( QString wkt ) /Factory/;
4343

44-
/** static method that creates geometry from GML2
45-
@param XML representation of the geometry. GML elements are expected to be
46-
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
47-
@note added in 1.9
48-
*/
49-
static QgsGeometry* fromGML2( const QString& xmlString ) /Factory/;
50-
51-
/** static method that creates geometry from GML2
52-
@note added in 1.9
53-
*/
54-
static QgsGeometry* fromGML2( const QDomNode& geometryNode ) /Factory/;
55-
5644
/** construct geometry from a point */
5745
static QgsGeometry* fromPoint( const QgsPoint& point ) /Factory/;
5846
/** construct geometry from a multipoint */

‎python/core/qgsogcutils.sip

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
class QgsOgcUtils
4+
{
5+
%TypeHeaderCode
6+
#include <qgsogcutils.h>
7+
%End
8+
9+
public:
10+
11+
/** static method that creates geometry from GML2
12+
@param XML representation of the geometry. GML elements are expected to be
13+
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
14+
@note added in 1.9
15+
*/
16+
static QgsGeometry* geometryFromGML2( const QString& xmlString ) /Factory/;
17+
18+
/** static method that creates geometry from GML2
19+
@note added in 1.9
20+
*/
21+
static QgsGeometry* geometryFromGML2( const QDomNode& geometryNode ) /Factory/;
22+
23+
/** Exports the geometry to mGML2
24+
@return true in case of success and false else
25+
*/
26+
static QDomElement geometryToGML2( QgsGeometry* geometry, QDomDocument& doc );
27+
28+
/** read rectangle from GML2 Box */
29+
static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );
30+
31+
};
32+

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ SET(QGIS_CORE_SRCS
8686
qgsnetworkreplyparser.cpp
8787
qgscredentials.cpp
8888
qgsofflineediting.cpp
89+
qgsogcutils.cpp
8990
qgsoverlayobject.cpp
9091
qgsowsconnection.cpp
9192
qgspalgeometry.cpp
@@ -404,6 +405,7 @@ SET(QGIS_CORE_HDRS
404405
qgsnetworkreplyparser.h
405406
qgscredentials.h
406407
qgsofflineediting.h
408+
qgsogcutils.h
407409
qgsoverlayobjectpositionmanager.h
408410
qgsowsconnection.h
409411
qgspallabeling.h

‎src/core/qgsexpression.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsfeature.h"
2929
#include "qgsgeometry.h"
3030
#include "qgslogger.h"
31+
#include "qgsogcutils.h"
3132

3233
// from parser
3334
extern QgsExpression::Node* parseExpression( const QString& str, QString& parserErrorMsg );
@@ -796,7 +797,7 @@ static QVariant fcnGeomFromWKT( const QVariantList& values, QgsFeature*, QgsExpr
796797
static QVariant fcnGeomFromGML2( const QVariantList& values, QgsFeature*, QgsExpression* parent )
797798
{
798799
QString gml = getStringValue( values.at( 0 ), parent );
799-
QgsGeometry* geom = QgsGeometry::fromGML2( gml );
800+
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( gml );
800801

801802
if ( geom )
802803
return QVariant::fromValue( *geom );
@@ -2268,11 +2269,10 @@ void QgsExpression::NodeFunction::toOgcFilter( QDomDocument &doc, QDomElement &e
22682269
{
22692270
if ( childElem.attribute( "name" ) == "geomFromWKT" )
22702271
{
2271-
QgsGeometry* geom = 0;
2272-
geom = QgsGeometry::fromWkt( childElem.firstChildElement().text() );
2272+
QgsGeometry* geom = QgsGeometry::fromWkt( childElem.firstChildElement().text() );
22732273
if ( geom )
2274-
funcElem.appendChild( geom->exportToGML2( doc ) );
2275-
2274+
funcElem.appendChild( QgsOgcUtils::geometryToGML2( geom, doc ) );
2275+
delete geom;
22762276
}
22772277
else if ( childElem.attribute( "name" ) == "geomFromGML2" )
22782278
{

‎src/core/qgsgeometry.cpp

Lines changed: 0 additions & 929 deletions
Large diffs are not rendered by default.

‎src/core/qgsgeometry.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,6 @@ class CORE_EXPORT QgsGeometry
8989
/** static method that creates geometry from Wkt */
9090
static QgsGeometry* fromWkt( QString wkt );
9191

92-
/** static method that creates geometry from GML2
93-
@param XML representation of the geometry. GML elements are expected to be
94-
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
95-
@note added in 1.9
96-
*/
97-
static QgsGeometry* fromGML2( const QString& xmlString );
98-
99-
/** static method that creates geometry from GML2
100-
@note added in 1.9
101-
*/
102-
static QgsGeometry* fromGML2( const QDomNode& geometryNode );
103-
10492
/** construct geometry from a point */
10593
static QgsGeometry* fromPoint( const QgsPoint& point );
10694
/** construct geometry from a multipoint */
@@ -395,12 +383,6 @@ class CORE_EXPORT QgsGeometry
395383
*/
396384
QString exportToGeoJSON();
397385

398-
/** Exports the geometry to mGML2
399-
@return true in case of success and false else
400-
* @note added in 1.9
401-
*/
402-
QDomElement exportToGML2( QDomDocument& doc );
403-
404386
/* Accessor functions for getting geometry data */
405387

406388
/** return contents of the geometry as a point
@@ -506,24 +488,6 @@ class CORE_EXPORT QgsGeometry
506488

507489
// Private functions
508490

509-
/** static method that creates geometry from GML2 Point */
510-
bool setFromGML2Point( const QDomElement& geometryElement );
511-
/** static method that creates geometry from GML2 LineString */
512-
bool setFromGML2LineString( const QDomElement& geometryElement );
513-
/** static method that creates geometry from GML2 Polygon */
514-
bool setFromGML2Polygon( const QDomElement& geometryElement );
515-
/** static method that creates geometry from GML2 MultiPoint */
516-
bool setFromGML2MultiPoint( const QDomElement& geometryElement );
517-
/** static method that creates geometry from GML2 MultiLineString */
518-
bool setFromGML2MultiLineString( const QDomElement& geometryElement );
519-
/** static method that creates geometry from GML2 MultiPolygon */
520-
bool setFromGML2MultiPolygon( const QDomElement& geometryElement );
521-
/**Reads the <gml:coordinates> element and extracts the coordinates as points
522-
@param coords list where the found coordinates are appended
523-
@param elem the <gml:coordinates> element
524-
@return boolean for success*/
525-
bool readGML2Coordinates( std::list<QgsPoint>& coords, const QDomElement elem ) const;
526-
527491
/** Converts from the WKB geometry to the GEOS geometry.
528492
@return true in case of success and false else
529493
*/

‎src/core/qgsogcutils.cpp

Lines changed: 969 additions & 0 deletions
Large diffs are not rendered by default.

‎src/core/qgsogcutils.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef QGSOGCUTILS_H
2+
#define QGSOGCUTILS_H
3+
4+
class QDomNode;
5+
class QDomElement;
6+
class QDomDocument;
7+
class QString;
8+
9+
#include <list>
10+
11+
class QgsGeometry;
12+
class QgsPoint;
13+
class QgsRectangle;
14+
15+
/**
16+
* @brief The QgsOgcUtils class provides various utility functions for conversion between
17+
* OGC (Open Geospatial Consortium) standards and QGIS internal representations.
18+
*
19+
* Currently supported standards:
20+
* - GML2 - Geography Markup Language (import, export)
21+
*
22+
* @note added in 2.0
23+
*/
24+
class CORE_EXPORT QgsOgcUtils
25+
{
26+
public:
27+
28+
29+
/** static method that creates geometry from GML2
30+
@param XML representation of the geometry. GML elements are expected to be
31+
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
32+
*/
33+
static QgsGeometry* geometryFromGML2( const QString& xmlString );
34+
35+
/** static method that creates geometry from GML2
36+
*/
37+
static QgsGeometry* geometryFromGML2( const QDomNode& geometryNode );
38+
39+
/** Exports the geometry to mGML2
40+
@return true in case of success and false else
41+
*/
42+
static QDomElement geometryToGML2( QgsGeometry* geometry, QDomDocument& doc );
43+
44+
/** read rectangle from GML2 Box */
45+
static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );
46+
47+
private:
48+
/** static method that creates geometry from GML2 Point */
49+
static QgsGeometry* geometryFromGML2Point( const QDomElement& geometryElement );
50+
/** static method that creates geometry from GML2 LineString */
51+
static QgsGeometry* geometryFromGML2LineString( const QDomElement& geometryElement );
52+
/** static method that creates geometry from GML2 Polygon */
53+
static QgsGeometry* geometryFromGML2Polygon( const QDomElement& geometryElement );
54+
/** static method that creates geometry from GML2 MultiPoint */
55+
static QgsGeometry* geometryFromGML2MultiPoint( const QDomElement& geometryElement );
56+
/** static method that creates geometry from GML2 MultiLineString */
57+
static QgsGeometry* geometryFromGML2MultiLineString( const QDomElement& geometryElement );
58+
/** static method that creates geometry from GML2 MultiPolygon */
59+
static QgsGeometry* geometryFromGML2MultiPolygon( const QDomElement& geometryElement );
60+
/** Reads the <gml:coordinates> element and extracts the coordinates as points
61+
@param coords list where the found coordinates are appended
62+
@param elem the <gml:coordinates> element
63+
@return boolean for success*/
64+
static bool readGML2Coordinates( std::list<QgsPoint>& coords, const QDomElement elem );
65+
};
66+
67+
#endif // QGSOGCUTILS_H

‎src/core/qgsrectangle.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,6 @@ QgsRectangle::QgsRectangle( const QgsRectangle &r )
5555
ymax = r.yMaximum();
5656
}
5757

58-
QgsRectangle::QgsRectangle( const QDomNode& boxNode )
59-
{
60-
QDomElement boxElem = boxNode.toElement();
61-
if ( boxElem.tagName() == "Box" )
62-
{
63-
QDomElement bElem = boxElem.firstChild().toElement();
64-
QString coordSeparator = ",";
65-
QString tupelSeparator = " ";
66-
if ( bElem.hasAttribute( "cs" ) )
67-
{
68-
coordSeparator = bElem.attribute( "cs" );
69-
}
70-
if ( bElem.hasAttribute( "ts" ) )
71-
{
72-
tupelSeparator = bElem.attribute( "ts" );
73-
}
74-
75-
QString bString = bElem.text();
76-
bool conversionSuccess;
77-
xmin = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
78-
ymin = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
79-
xmax = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
80-
ymax = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
81-
}
82-
normalize();
83-
}
8458

8559
void QgsRectangle::set( const QgsPoint& p1, const QgsPoint& p2 )
8660
{

‎src/core/qgsrectangle.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ class CORE_EXPORT QgsRectangle
4444
QgsRectangle( const QRectF & qRectF );
4545
//! Copy constructor
4646
QgsRectangle( const QgsRectangle &other );
47-
//! GML2 constructor
48-
//@note added in 1.9
49-
QgsRectangle( const QDomNode& boxNode );
5047
//! Destructor
5148
~QgsRectangle();
5249
//! Set the rectangle from two QgsPoints. The rectangle is

‎src/mapserver/qgsfilter.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "qgslogicalfilter.h"
2222
#include "qgsspatialfilter.h"
2323
#include "qgsvectordataprovider.h"
24+
#include "qgsogcutils.h"
25+
2426
#include <QDomElement>
2527
#include <QStringList>
2628
#include "qgsvectorlayer.h"
@@ -129,7 +131,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
129131
if ( gNodes.size() > 0 )
130132
{
131133
QDomElement gElem = gNodes.at( 0 ).toElement();
132-
geom = QgsGeometry::fromGML2( gElem );
134+
geom = QgsOgcUtils::geometryFromGML2( gElem );
133135
}
134136
}
135137

@@ -139,7 +141,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
139141
if ( gNodes.size() > 0 )
140142
{
141143
QDomElement gElem = gNodes.at( 0 ).toElement();
142-
geom = QgsGeometry::fromGML2( gElem );
144+
geom = QgsOgcUtils::geometryFromGML2( gElem );
143145
}
144146
}
145147

@@ -149,7 +151,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
149151
if ( gNodes.size() > 0 )
150152
{
151153
QDomElement gElem = gNodes.at( 0 ).toElement();
152-
geom = QgsGeometry::fromGML2( gElem );
154+
geom = QgsOgcUtils::geometryFromGML2( gElem );
153155
}
154156
}
155157

@@ -159,7 +161,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
159161
if ( gNodes.size() > 0 )
160162
{
161163
QDomElement gElem = gNodes.at( 0 ).toElement();
162-
geom = QgsGeometry::fromGML2( gElem );
164+
geom = QgsOgcUtils::geometryFromGML2( gElem );
163165
}
164166
}
165167

@@ -169,7 +171,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
169171
if ( gNodes.size() > 0 )
170172
{
171173
QDomElement gElem = gNodes.at( 0 ).toElement();
172-
geom = QgsGeometry::fromGML2( gElem );
174+
geom = QgsOgcUtils::geometryFromGML2( gElem );
173175
}
174176
}
175177

@@ -179,7 +181,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
179181
if ( gNodes.size() > 0 )
180182
{
181183
QDomElement gElem = gNodes.at( 0 ).toElement();
182-
geom = QgsGeometry::fromGML2( gElem );
184+
geom = QgsOgcUtils::geometryFromGML2( gElem );
183185
}
184186
}
185187

‎src/mapserver/qgswfsserver.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "qgslegendmodel.h"
4242
#include "qgscomposerlegenditem.h"
4343
#include "qgsrequesthandler.h"
44+
#include "qgsogcutils.h"
45+
4446
#include <QImage>
4547
#include <QPainter>
4648
#include <QStringList>
@@ -509,11 +511,11 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
509511
{
510512
if ( childElem.tagName() == "Box" )
511513
{
512-
req.setFilterRect( QgsRectangle( childElem ) );
514+
req.setFilterRect( QgsOgcUtils::rectangleFromGMLBox( childElem ) );
513515
}
514516
else if ( childElem.tagName() != "PropertyName" )
515517
{
516-
QgsGeometry *geom = QgsGeometry::fromGML2( childElem );
518+
QgsGeometry *geom = QgsOgcUtils::geometryFromGML2( childElem );
517519
req.setFilterRect( geom->boundingBox() );
518520
delete geom;
519521
}
@@ -892,11 +894,11 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
892894
{
893895
if ( childElem.tagName() == "Box" )
894896
{
895-
req.setFilterRect( QgsRectangle( childElem ) );
897+
req.setFilterRect( QgsOgcUtils::rectangleFromGMLBox( childElem ) );
896898
}
897899
else if ( childElem.tagName() != "PropertyName" )
898900
{
899-
QgsGeometry* geom = QgsGeometry::fromGML2( childElem );
901+
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( childElem );
900902
req.setFilterRect( geom->boundingBox() );
901903
delete geom;
902904
}
@@ -1335,7 +1337,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
13351337

13361338
if ( !geometryElem.isNull() )
13371339
{
1338-
if ( !layer->changeGeometry( *fidIt, QgsGeometry::fromGML2( geometryElem ) ) )
1340+
if ( !layer->changeGeometry( *fidIt, QgsOgcUtils::geometryFromGML2( geometryElem ) ) )
13391341
throw QgsMapServiceException( "RequestNotWellFormed", "Error in change geometry" );
13401342
}
13411343
}
@@ -1451,7 +1453,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
14511453
}
14521454
else //a geometry attribute
14531455
{
1454-
f->setGeometry( QgsGeometry::fromGML2( currentAttributeElement ) );
1456+
f->setGeometry( QgsOgcUtils::geometryFromGML2( currentAttributeElement ) );
14551457
}
14561458
}
14571459
currentAttributeChild = currentAttributeChild.nextSibling();
@@ -1649,7 +1651,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
16491651
QgsGeometry* geom = feat->geometry();
16501652

16511653
QDomElement geomElem = doc.createElement( "qgs:geometry" );
1652-
QDomElement gmlElem = geom->exportToGML2( doc );
1654+
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( geom, doc );
16531655
if ( !gmlElem.isNull() )
16541656
{
16551657
QgsRectangle box = geom->boundingBox();

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "qgsspatialindex.h"
3131
#include "qgslogger.h"
3232
#include "qgsnetworkaccessmanager.h"
33+
#include "qgsogcutils.h"
34+
3335
#include <QDomDocument>
3436
#include <QMessageBox>
3537
#include <QDomNodeList>
@@ -418,7 +420,7 @@ bool QgsWFSProvider::addFeatures( QgsFeatureList &flist )
418420

419421
//add geometry column (as gml)
420422
QDomElement geomElem = transactionDoc.createElementNS( mWfsNamespace, mGeometryAttribute );
421-
QDomElement gmlElem = featureIt->geometry()->exportToGML2( transactionDoc );
423+
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( featureIt->geometry(), transactionDoc );
422424
if ( !gmlElem.isNull() )
423425
{
424426
geomElem.appendChild( gmlElem );
@@ -569,7 +571,7 @@ bool QgsWFSProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
569571
nameElem.appendChild( nameText );
570572
propertyElem.appendChild( nameElem );
571573
QDomElement valueElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Value" );
572-
QDomElement gmlElem = ( &geomIt.value() )->exportToGML2( transactionDoc );
574+
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( &geomIt.value(), transactionDoc );
573575
valueElem.appendChild( gmlElem );
574576
propertyElem.appendChild( valueElem );
575577
updateElem.appendChild( propertyElem );
@@ -1287,7 +1289,7 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
12871289
}
12881290
else //a geometry attribute
12891291
{
1290-
f->setGeometry( QgsGeometry::fromGML2( currentAttributeElement ) );
1292+
f->setGeometry( QgsOgcUtils::geometryFromGML2( currentAttributeElement ) );
12911293
}
12921294
}
12931295
currentAttributeChild = currentAttributeChild.nextSibling();

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
109109
ADD_QGIS_TEST(composerhtmltest testqgscomposerhtml.cpp )
110110
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
111111
ADD_QGIS_TEST(composerscalebartest testqgscomposerscalebar.cpp )
112+
ADD_QGIS_TEST(ogcutilstest testqgsogcutils.cpp)

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class TestQgsGeometry: public QObject
5656
void differenceCheck2();
5757
void bufferCheck();
5858

59-
void gmlTest();
60-
6159
private:
6260
/** A helper method to do a render check to see if the geometry op is as expected */
6361
bool renderCheck( QString theTestName, QString theComment = "" );
@@ -372,18 +370,6 @@ void TestQgsGeometry::dumpPolyline( QgsPolyline &thePolyline )
372370
mpPainter->drawPolyline( myPoints );
373371
}
374372

375-
void TestQgsGeometry::gmlTest()
376-
{
377-
QgsGeometry* geom = QgsGeometry::fromGML2( "<Point><coordinates>123,456</coordinates></Point>" );
378-
QVERIFY( geom );
379-
QVERIFY( geom->wkbType() == QGis::WKBPoint );
380-
QVERIFY( geom->asPoint() == QgsPoint( 123, 456 ) );
381-
382-
QgsGeometry* geomBox = QgsGeometry::fromGML2( "<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>" );
383-
QVERIFY( geomBox );
384-
QVERIFY( geomBox->wkbType() == QGis::WKBPolygon );
385-
}
386-
387373

388374
QTEST_MAIN( TestQgsGeometry )
389375
#include "moc_testqgsgeometry.cxx"

‎tests/src/core/testqgsogcutils.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
/***************************************************************************
3+
testqgsogcutils.cpp
4+
--------------------------------------
5+
Date : March 2013
6+
Copyright : (C) 2013 Martin Dobias
7+
Email : wonder.sk at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include <QtTest>
18+
19+
//qgis includes...
20+
#include <qgsgeometry.h>
21+
#include <qgsogcutils.h>
22+
23+
24+
/** \ingroup UnitTests
25+
* This is a unit test for OGC utilities
26+
*/
27+
class TestQgsOgcUtils : public QObject
28+
{
29+
Q_OBJECT
30+
private slots:
31+
32+
void testGeometryFromGML();
33+
void testGeometryToGML();
34+
};
35+
36+
37+
void TestQgsOgcUtils::testGeometryFromGML()
38+
{
39+
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( "<Point><coordinates>123,456</coordinates></Point>" );
40+
QVERIFY( geom );
41+
QVERIFY( geom->wkbType() == QGis::WKBPoint );
42+
QVERIFY( geom->asPoint() == QgsPoint( 123, 456 ) );
43+
44+
QgsGeometry* geomBox = QgsOgcUtils::geometryFromGML2( "<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>" );
45+
QVERIFY( geomBox );
46+
QVERIFY( geomBox->wkbType() == QGis::WKBPolygon );
47+
}
48+
49+
void TestQgsOgcUtils::testGeometryToGML()
50+
{
51+
QDomDocument doc;
52+
53+
QDomElement elemInvalid = QgsOgcUtils::geometryToGML2( 0, doc );
54+
QVERIFY( elemInvalid.isNull() );
55+
56+
QgsGeometry* geomPoint = QgsGeometry::fromPoint( QgsPoint( 111, 222 ) );
57+
QDomElement elemPoint = QgsOgcUtils::geometryToGML2( geomPoint, doc );
58+
delete geomPoint;
59+
QVERIFY( !elemPoint.isNull() );
60+
61+
doc.appendChild( elemPoint );
62+
QCOMPARE( doc.toString( -1 ), QString( "<gml:Point><gml:coordinates cs=\",\" ts=\" \">111.0,222.0</gml:coordinates></gml:Point>" ) );
63+
}
64+
65+
66+
QTEST_MAIN( TestQgsOgcUtils )
67+
#include "moc_testqgsogcutils.cxx"

0 commit comments

Comments
 (0)
Please sign in to comment.