929 changes: 0 additions & 929 deletions src/core/qgsgeometry.cpp

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions src/core/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ class CORE_EXPORT QgsGeometry
/** static method that creates geometry from Wkt */
static QgsGeometry* fromWkt( QString wkt );

/** static method that creates geometry from GML2
@param XML representation of the geometry. GML elements are expected to be
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
@note added in 1.9
*/
static QgsGeometry* fromGML2( const QString& xmlString );

/** static method that creates geometry from GML2
@note added in 1.9
*/
static QgsGeometry* fromGML2( const QDomNode& geometryNode );

/** construct geometry from a point */
static QgsGeometry* fromPoint( const QgsPoint& point );
/** construct geometry from a multipoint */
Expand Down Expand Up @@ -395,12 +383,6 @@ class CORE_EXPORT QgsGeometry
*/
QString exportToGeoJSON();

/** Exports the geometry to mGML2
@return true in case of success and false else
* @note added in 1.9
*/
QDomElement exportToGML2( QDomDocument& doc );

/* Accessor functions for getting geometry data */

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

// Private functions

/** static method that creates geometry from GML2 Point */
bool setFromGML2Point( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 LineString */
bool setFromGML2LineString( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 Polygon */
bool setFromGML2Polygon( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 MultiPoint */
bool setFromGML2MultiPoint( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 MultiLineString */
bool setFromGML2MultiLineString( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 MultiPolygon */
bool setFromGML2MultiPolygon( const QDomElement& geometryElement );
/**Reads the <gml:coordinates> element and extracts the coordinates as points
@param coords list where the found coordinates are appended
@param elem the <gml:coordinates> element
@return boolean for success*/
bool readGML2Coordinates( std::list<QgsPoint>& coords, const QDomElement elem ) const;

/** Converts from the WKB geometry to the GEOS geometry.
@return true in case of success and false else
*/
Expand Down
969 changes: 969 additions & 0 deletions src/core/qgsogcutils.cpp

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions src/core/qgsogcutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef QGSOGCUTILS_H
#define QGSOGCUTILS_H

class QDomNode;
class QDomElement;
class QDomDocument;
class QString;

#include <list>

class QgsGeometry;
class QgsPoint;
class QgsRectangle;

/**
* @brief The QgsOgcUtils class provides various utility functions for conversion between
* OGC (Open Geospatial Consortium) standards and QGIS internal representations.
*
* Currently supported standards:
* - GML2 - Geography Markup Language (import, export)
*
* @note added in 2.0
*/
class CORE_EXPORT QgsOgcUtils
{
public:


/** static method that creates geometry from GML2
@param XML representation of the geometry. GML elements are expected to be
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
*/
static QgsGeometry* geometryFromGML2( const QString& xmlString );

/** static method that creates geometry from GML2
*/
static QgsGeometry* geometryFromGML2( const QDomNode& geometryNode );

/** Exports the geometry to mGML2
@return true in case of success and false else
*/
static QDomElement geometryToGML2( QgsGeometry* geometry, QDomDocument& doc );

/** read rectangle from GML2 Box */
static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );

private:
/** static method that creates geometry from GML2 Point */
static QgsGeometry* geometryFromGML2Point( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 LineString */
static QgsGeometry* geometryFromGML2LineString( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 Polygon */
static QgsGeometry* geometryFromGML2Polygon( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 MultiPoint */
static QgsGeometry* geometryFromGML2MultiPoint( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 MultiLineString */
static QgsGeometry* geometryFromGML2MultiLineString( const QDomElement& geometryElement );
/** static method that creates geometry from GML2 MultiPolygon */
static QgsGeometry* geometryFromGML2MultiPolygon( const QDomElement& geometryElement );
/** Reads the <gml:coordinates> element and extracts the coordinates as points
@param coords list where the found coordinates are appended
@param elem the <gml:coordinates> element
@return boolean for success*/
static bool readGML2Coordinates( std::list<QgsPoint>& coords, const QDomElement elem );
};

#endif // QGSOGCUTILS_H
26 changes: 0 additions & 26 deletions src/core/qgsrectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,6 @@ QgsRectangle::QgsRectangle( const QgsRectangle &r )
ymax = r.yMaximum();
}

QgsRectangle::QgsRectangle( const QDomNode& boxNode )
{
QDomElement boxElem = boxNode.toElement();
if ( boxElem.tagName() == "Box" )
{
QDomElement bElem = boxElem.firstChild().toElement();
QString coordSeparator = ",";
QString tupelSeparator = " ";
if ( bElem.hasAttribute( "cs" ) )
{
coordSeparator = bElem.attribute( "cs" );
}
if ( bElem.hasAttribute( "ts" ) )
{
tupelSeparator = bElem.attribute( "ts" );
}

QString bString = bElem.text();
bool conversionSuccess;
xmin = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
ymin = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
xmax = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
ymax = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
}
normalize();
}

void QgsRectangle::set( const QgsPoint& p1, const QgsPoint& p2 )
{
Expand Down
3 changes: 0 additions & 3 deletions src/core/qgsrectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class CORE_EXPORT QgsRectangle
QgsRectangle( const QRectF & qRectF );
//! Copy constructor
QgsRectangle( const QgsRectangle &other );
//! GML2 constructor
//@note added in 1.9
QgsRectangle( const QDomNode& boxNode );
//! Destructor
~QgsRectangle();
//! Set the rectangle from two QgsPoints. The rectangle is
Expand Down
14 changes: 8 additions & 6 deletions src/mapserver/qgsfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "qgslogicalfilter.h"
#include "qgsspatialfilter.h"
#include "qgsvectordataprovider.h"
#include "qgsogcutils.h"

#include <QDomElement>
#include <QStringList>
#include "qgsvectorlayer.h"
Expand Down Expand Up @@ -129,7 +131,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
if ( gNodes.size() > 0 )
{
QDomElement gElem = gNodes.at( 0 ).toElement();
geom = QgsGeometry::fromGML2( gElem );
geom = QgsOgcUtils::geometryFromGML2( gElem );
}
}

Expand All @@ -139,7 +141,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
if ( gNodes.size() > 0 )
{
QDomElement gElem = gNodes.at( 0 ).toElement();
geom = QgsGeometry::fromGML2( gElem );
geom = QgsOgcUtils::geometryFromGML2( gElem );
}
}

Expand All @@ -149,7 +151,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
if ( gNodes.size() > 0 )
{
QDomElement gElem = gNodes.at( 0 ).toElement();
geom = QgsGeometry::fromGML2( gElem );
geom = QgsOgcUtils::geometryFromGML2( gElem );
}
}

Expand All @@ -159,7 +161,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
if ( gNodes.size() > 0 )
{
QDomElement gElem = gNodes.at( 0 ).toElement();
geom = QgsGeometry::fromGML2( gElem );
geom = QgsOgcUtils::geometryFromGML2( gElem );
}
}

Expand All @@ -169,7 +171,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
if ( gNodes.size() > 0 )
{
QDomElement gElem = gNodes.at( 0 ).toElement();
geom = QgsGeometry::fromGML2( gElem );
geom = QgsOgcUtils::geometryFromGML2( gElem );
}
}

Expand All @@ -179,7 +181,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
if ( gNodes.size() > 0 )
{
QDomElement gElem = gNodes.at( 0 ).toElement();
geom = QgsGeometry::fromGML2( gElem );
geom = QgsOgcUtils::geometryFromGML2( gElem );
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/mapserver/qgswfsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "qgslegendmodel.h"
#include "qgscomposerlegenditem.h"
#include "qgsrequesthandler.h"
#include "qgsogcutils.h"

#include <QImage>
#include <QPainter>
#include <QStringList>
Expand Down Expand Up @@ -509,11 +511,11 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
{
if ( childElem.tagName() == "Box" )
{
req.setFilterRect( QgsRectangle( childElem ) );
req.setFilterRect( QgsOgcUtils::rectangleFromGMLBox( childElem ) );
}
else if ( childElem.tagName() != "PropertyName" )
{
QgsGeometry *geom = QgsGeometry::fromGML2( childElem );
QgsGeometry *geom = QgsOgcUtils::geometryFromGML2( childElem );
req.setFilterRect( geom->boundingBox() );
delete geom;
}
Expand Down Expand Up @@ -892,11 +894,11 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
{
if ( childElem.tagName() == "Box" )
{
req.setFilterRect( QgsRectangle( childElem ) );
req.setFilterRect( QgsOgcUtils::rectangleFromGMLBox( childElem ) );
}
else if ( childElem.tagName() != "PropertyName" )
{
QgsGeometry* geom = QgsGeometry::fromGML2( childElem );
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( childElem );
req.setFilterRect( geom->boundingBox() );
delete geom;
}
Expand Down Expand Up @@ -1335,7 +1337,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )

if ( !geometryElem.isNull() )
{
if ( !layer->changeGeometry( *fidIt, QgsGeometry::fromGML2( geometryElem ) ) )
if ( !layer->changeGeometry( *fidIt, QgsOgcUtils::geometryFromGML2( geometryElem ) ) )
throw QgsMapServiceException( "RequestNotWellFormed", "Error in change geometry" );
}
}
Expand Down Expand Up @@ -1451,7 +1453,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
}
else //a geometry attribute
{
f->setGeometry( QgsGeometry::fromGML2( currentAttributeElement ) );
f->setGeometry( QgsOgcUtils::geometryFromGML2( currentAttributeElement ) );
}
}
currentAttributeChild = currentAttributeChild.nextSibling();
Expand Down Expand Up @@ -1649,7 +1651,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
QgsGeometry* geom = feat->geometry();

QDomElement geomElem = doc.createElement( "qgs:geometry" );
QDomElement gmlElem = geom->exportToGML2( doc );
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( geom, doc );
if ( !gmlElem.isNull() )
{
QgsRectangle box = geom->boundingBox();
Expand Down
8 changes: 5 additions & 3 deletions src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "qgsspatialindex.h"
#include "qgslogger.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsogcutils.h"

#include <QDomDocument>
#include <QMessageBox>
#include <QDomNodeList>
Expand Down Expand Up @@ -418,7 +420,7 @@ bool QgsWFSProvider::addFeatures( QgsFeatureList &flist )

//add geometry column (as gml)
QDomElement geomElem = transactionDoc.createElementNS( mWfsNamespace, mGeometryAttribute );
QDomElement gmlElem = featureIt->geometry()->exportToGML2( transactionDoc );
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( featureIt->geometry(), transactionDoc );
if ( !gmlElem.isNull() )
{
geomElem.appendChild( gmlElem );
Expand Down Expand Up @@ -569,7 +571,7 @@ bool QgsWFSProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
nameElem.appendChild( nameText );
propertyElem.appendChild( nameElem );
QDomElement valueElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Value" );
QDomElement gmlElem = ( &geomIt.value() )->exportToGML2( transactionDoc );
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( &geomIt.value(), transactionDoc );
valueElem.appendChild( gmlElem );
propertyElem.appendChild( valueElem );
updateElem.appendChild( propertyElem );
Expand Down Expand Up @@ -1287,7 +1289,7 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
}
else //a geometry attribute
{
f->setGeometry( QgsGeometry::fromGML2( currentAttributeElement ) );
f->setGeometry( QgsOgcUtils::geometryFromGML2( currentAttributeElement ) );
}
}
currentAttributeChild = currentAttributeChild.nextSibling();
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
ADD_QGIS_TEST(composerhtmltest testqgscomposerhtml.cpp )
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
ADD_QGIS_TEST(composerscalebartest testqgscomposerscalebar.cpp )
ADD_QGIS_TEST(ogcutilstest testqgsogcutils.cpp)
14 changes: 0 additions & 14 deletions tests/src/core/testqgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class TestQgsGeometry: public QObject
void differenceCheck2();
void bufferCheck();

void gmlTest();

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

void TestQgsGeometry::gmlTest()
{
QgsGeometry* geom = QgsGeometry::fromGML2( "<Point><coordinates>123,456</coordinates></Point>" );
QVERIFY( geom );
QVERIFY( geom->wkbType() == QGis::WKBPoint );
QVERIFY( geom->asPoint() == QgsPoint( 123, 456 ) );

QgsGeometry* geomBox = QgsGeometry::fromGML2( "<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>" );
QVERIFY( geomBox );
QVERIFY( geomBox->wkbType() == QGis::WKBPolygon );
}


QTEST_MAIN( TestQgsGeometry )
#include "moc_testqgsgeometry.cxx"
Expand Down
67 changes: 67 additions & 0 deletions tests/src/core/testqgsogcutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

/***************************************************************************
testqgsogcutils.cpp
--------------------------------------
Date : March 2013
Copyright : (C) 2013 Martin Dobias
Email : wonder.sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QtTest>

//qgis includes...
#include <qgsgeometry.h>
#include <qgsogcutils.h>


/** \ingroup UnitTests
* This is a unit test for OGC utilities
*/
class TestQgsOgcUtils : public QObject
{
Q_OBJECT
private slots:

void testGeometryFromGML();
void testGeometryToGML();
};


void TestQgsOgcUtils::testGeometryFromGML()
{
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( "<Point><coordinates>123,456</coordinates></Point>" );
QVERIFY( geom );
QVERIFY( geom->wkbType() == QGis::WKBPoint );
QVERIFY( geom->asPoint() == QgsPoint( 123, 456 ) );

QgsGeometry* geomBox = QgsOgcUtils::geometryFromGML2( "<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>" );
QVERIFY( geomBox );
QVERIFY( geomBox->wkbType() == QGis::WKBPolygon );
}

void TestQgsOgcUtils::testGeometryToGML()
{
QDomDocument doc;

QDomElement elemInvalid = QgsOgcUtils::geometryToGML2( 0, doc );
QVERIFY( elemInvalid.isNull() );

QgsGeometry* geomPoint = QgsGeometry::fromPoint( QgsPoint( 111, 222 ) );
QDomElement elemPoint = QgsOgcUtils::geometryToGML2( geomPoint, doc );
delete geomPoint;
QVERIFY( !elemPoint.isNull() );

doc.appendChild( elemPoint );
QCOMPARE( doc.toString( -1 ), QString( "<gml:Point><gml:coordinates cs=\",\" ts=\" \">111.0,222.0</gml:coordinates></gml:Point>" ) );
}


QTEST_MAIN( TestQgsOgcUtils )
#include "moc_testqgsogcutils.cxx"