Skip to content

Commit

Permalink
QgsRectangle From GML2
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Nov 14, 2012
1 parent aac9538 commit 0e11e93
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
20 changes: 1 addition & 19 deletions src/core/qgsexpression.cpp
Expand Up @@ -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
Expand Down
56 changes: 42 additions & 14 deletions src/core/qgsrectangle.cpp
Expand Up @@ -21,6 +21,7 @@
#include <QRectF>
#include <QString>
#include <QTextStream>
#include <QRegExp>
#include <qnumeric.h>

#include "qgspoint.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsrectangle.h
Expand Up @@ -19,6 +19,7 @@
#define QGSRECT_H

#include <iosfwd>
#include <QDomDocument>

class QString;
class QRectF;
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/mapserver/qgswfsserver.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit 0e11e93

Please sign in to comment.