Skip to content

Commit 0e11e93

Browse files
committed
QgsRectangle From GML2
1 parent aac9538 commit 0e11e93

File tree

4 files changed

+72
-33
lines changed

4 files changed

+72
-33
lines changed

src/core/qgsexpression.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -795,25 +795,7 @@ static QVariant fcnGeomFromGML2( const QVariantList& values, QgsFeature*, QgsExp
795795
QDomElement elem = doc.documentElement();
796796
if ( elem.tagName() == "Box" )
797797
{
798-
QDomElement bElem = elem.firstChild().toElement();
799-
QString coordSeparator = ",";
800-
QString tupelSeparator = " ";
801-
if ( bElem.hasAttribute( "cs" ) )
802-
{
803-
coordSeparator = bElem.attribute( "cs" );
804-
}
805-
if ( bElem.hasAttribute( "ts" ) )
806-
{
807-
tupelSeparator = bElem.attribute( "ts" );
808-
}
809-
810-
QString bString = bElem.text();
811-
bool conversionSuccess;
812-
double minx = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
813-
double miny = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
814-
double maxx = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
815-
double maxy = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
816-
QgsRectangle* rect = new QgsRectangle( minx, miny, maxx, maxy );
798+
QgsRectangle* rect = new QgsRectangle( elem );
817799
geom = QgsGeometry::fromRect( *rect );
818800
}
819801
else

src/core/qgsrectangle.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QRectF>
2222
#include <QString>
2323
#include <QTextStream>
24+
#include <QRegExp>
2425
#include <qnumeric.h>
2526

2627
#include "qgspoint.h"
@@ -54,6 +55,33 @@ QgsRectangle::QgsRectangle( const QgsRectangle &r )
5455
ymax = r.yMaximum();
5556
}
5657

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+
}
84+
5785
void QgsRectangle::set( const QgsPoint& p1, const QgsPoint& p2 )
5886
{
5987
xmin = p1.x();
@@ -185,10 +213,10 @@ bool QgsRectangle::isEmpty() const
185213
QString QgsRectangle::asWktCoordinates() const
186214
{
187215
QString rep =
188-
QString::number( xmin, 'f', 16 ) + " " +
189-
QString::number( ymin, 'f', 16 ) + ", " +
190-
QString::number( xmax, 'f', 16 ) + " " +
191-
QString::number( ymax, 'f', 16 );
216+
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
217+
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
218+
QString::number( xmax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
219+
QString::number( ymax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) );
192220

193221
return rep;
194222
}
@@ -197,16 +225,16 @@ QString QgsRectangle::asWktPolygon() const
197225
{
198226
QString rep =
199227
QString( "POLYGON((" ) +
200-
QString::number( xmin, 'f', 16 ) + " " +
201-
QString::number( ymin, 'f', 16 ) + ", " +
202-
QString::number( xmax, 'f', 16 ) + " " +
203-
QString::number( ymin, 'f', 16 ) + ", " +
204-
QString::number( xmax, 'f', 16 ) + " " +
205-
QString::number( ymax, 'f', 16 ) + ", " +
206-
QString::number( xmin, 'f', 16 ) + " " +
207-
QString::number( ymax, 'f', 16 ) + ", " +
208-
QString::number( xmin, 'f', 16 ) + " " +
209-
QString::number( ymin, 'f', 16 ) +
228+
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
229+
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
230+
QString::number( xmax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
231+
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
232+
QString::number( xmax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
233+
QString::number( ymax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
234+
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
235+
QString::number( ymax, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + ", " +
236+
QString::number( xmin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) + " " +
237+
QString::number( ymin, 'f', 16 ).remove( QRegExp( "[0]{1,15}$" ) ) +
210238
QString( "))" );
211239

212240
return rep;

src/core/qgsrectangle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define QGSRECT_H
2020

2121
#include <iosfwd>
22+
#include <QDomDocument>
2223

2324
class QString;
2425
class QRectF;
@@ -43,6 +44,9 @@ class CORE_EXPORT QgsRectangle
4344
QgsRectangle( const QRectF & qRectF );
4445
//! Copy constructor
4546
QgsRectangle( const QgsRectangle &other );
47+
//! GML2 constructor
48+
//@note added in 1.9
49+
QgsRectangle( const QDomNode& boxNode );
4650
//! Destructor
4751
~QgsRectangle();
4852
//! Set the rectangle from two QgsPoints. The rectangle is

src/mapserver/qgswfsserver.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,31 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
431431
++featureCounter;
432432
}
433433
}
434+
else if ( filterElem.firstChildElement().tagName() == "BBOX" )
435+
{
436+
QDomElement bboxElem = filterElem.firstChildElement();
437+
QDomElement childElem = bboxElem.firstChildElement();
438+
while ( !childElem.isNull() )
439+
{
440+
if ( childElem.tagName() == "Box" )
441+
{
442+
QgsRectangle* rect = new QgsRectangle( childElem );
443+
provider->select( attrIndexes, *rect, mWithGeom, true );
444+
}
445+
else if ( childElem.tagName() != "PropertyName" )
446+
{
447+
QgsGeometry* geom = QgsGeometry::fromGML2( childElem );
448+
provider->select( attrIndexes, geom->boundingBox(), mWithGeom, true );
449+
}
450+
childElem = childElem.nextSiblingElement();
451+
}
452+
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
453+
{
454+
sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
455+
++featCounter;
456+
++featureCounter;
457+
}
458+
}
434459
else
435460
{
436461
QgsExpression *mFilter = QgsExpression::createFromOgcFilter( filterElem );

0 commit comments

Comments
 (0)