Skip to content
Permalink
Browse files

QgsRectangle From GML2

  • Loading branch information
rldhont committed Nov 14, 2012
1 parent aac9538 commit 0e11e9372bf106280997789cb4fa6af736089c03
Showing with 72 additions and 33 deletions.
  1. +1 −19 src/core/qgsexpression.cpp
  2. +42 −14 src/core/qgsrectangle.cpp
  3. +4 −0 src/core/qgsrectangle.h
  4. +25 −0 src/mapserver/qgswfsserver.cpp
@@ -795,25 +795,7 @@ static QVariant fcnGeomFromGML2( const QVariantList& values, QgsFeature*, QgsExp
QDomElement elem = doc.documentElement();
if ( elem.tagName() == "Box" )
{
QDomElement bElem = elem.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;
double minx = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
double miny = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
double maxx = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
double maxy = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
QgsRectangle* rect = new QgsRectangle( minx, miny, maxx, maxy );
QgsRectangle* rect = new QgsRectangle( elem );
geom = QgsGeometry::fromRect( *rect );
}
else
@@ -21,6 +21,7 @@
#include <QRectF>
#include <QString>
#include <QTextStream>
#include <QRegExp>
#include <qnumeric.h>

#include "qgspoint.h"
@@ -54,6 +55,33 @@ 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 )
{
xmin = p1.x();
@@ -185,10 +213,10 @@ bool QgsRectangle::isEmpty() const
QString QgsRectangle::asWktCoordinates() const
{
QString rep =
QString::number( xmin, 'f', 16 ) + " " +
QString::number( ymin, 'f', 16 ) + ", " +
QString::number( xmax, 'f', 16 ) + " " +
QString::number( ymax, 'f', 16 );
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
QString::number( xmax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) );

return rep;
}
@@ -197,16 +225,16 @@ QString QgsRectangle::asWktPolygon() const
{
QString rep =
QString( "POLYGON((" ) +
QString::number( xmin, 'f', 16 ) + " " +
QString::number( ymin, 'f', 16 ) + ", " +
QString::number( xmax, 'f', 16 ) + " " +
QString::number( ymin, 'f', 16 ) + ", " +
QString::number( xmax, 'f', 16 ) + " " +
QString::number( ymax, 'f', 16 ) + ", " +
QString::number( xmin, 'f', 16 ) + " " +
QString::number( ymax, 'f', 16 ) + ", " +
QString::number( xmin, 'f', 16 ) + " " +
QString::number( ymin, 'f', 16 ) +
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
QString::number( xmax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
QString::number( xmax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) +
QString( "))" );

return rep;
@@ -19,6 +19,7 @@
#define QGSRECT_H

#include <iosfwd>
#include <QDomDocument>

class QString;
class QRectF;
@@ -43,6 +44,9 @@ 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
@@ -431,6 +431,31 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
++featureCounter;
}
}
else if ( filterElem.firstChildElement().tagName() == "BBOX" )
{
QDomElement bboxElem = filterElem.firstChildElement();
QDomElement childElem = bboxElem.firstChildElement();
while ( !childElem.isNull() )
{
if ( childElem.tagName() == "Box" )
{
QgsRectangle* rect = new QgsRectangle( childElem );
provider->select( attrIndexes, *rect, mWithGeom, true );
}
else if ( childElem.tagName() != "PropertyName" )
{
QgsGeometry* geom = QgsGeometry::fromGML2( childElem );
provider->select( attrIndexes, geom->boundingBox(), mWithGeom, true );
}
childElem = childElem.nextSiblingElement();
}
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
{
sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
}
else
{
QgsExpression *mFilter = QgsExpression::createFromOgcFilter( filterElem );

0 comments on commit 0e11e93

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