Skip to content

Commit b9f631f

Browse files
committed
#6535 Support WFS Post GetFeature Request in QGIS-Server
1 parent 1fdaa04 commit b9f631f

File tree

5 files changed

+328
-29
lines changed

5 files changed

+328
-29
lines changed

src/core/qgsgeometry.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,24 @@ QgsGeometry* QgsGeometry::fromRect( const QgsRectangle& rect )
536536
static const QString GML_NAMESPACE = "http://www.opengis.net/gml";
537537
QgsGeometry* QgsGeometry::fromGML2( const QDomNode& geometryNode )
538538
{
539-
QDomNode geometryChild = geometryNode.firstChild();
540-
if ( geometryChild.isNull() )
541-
{
542-
return 0;
543-
}
544539
QgsGeometry* g = new QgsGeometry();
545-
QDomElement geometryTypeElement = geometryChild.toElement();
540+
QDomElement geometryTypeElement = geometryNode.toElement();
546541
QString geomType = geometryTypeElement.tagName();
542+
543+
if ( !( geomType == "Point" || geomType == "LineString" || geomType == "Polygon" || geomType == "MultiPoint" || geomType == "MultiLineString" || geomType == "MultiPolygon") )
544+
{
545+
QDomNode geometryChild = geometryNode.firstChild();
546+
if ( geometryChild.isNull() )
547+
{
548+
return 0;
549+
}
550+
geometryTypeElement = geometryChild.toElement();
551+
geomType = geometryTypeElement.tagName();
552+
}
553+
554+
if ( !( geomType == "Point" || geomType == "LineString" || geomType == "Polygon" || geomType == "MultiPoint" || geomType == "MultiLineString" || geomType == "MultiPolygon") )
555+
return 0;
556+
547557
if ( geomType == "Point" )
548558
{
549559
g->setFromGML2Point( geometryTypeElement );

src/mapserver/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SET ( qgis_mapserv_SRCS
3434
qgsbetweenfilter.cpp
3535
qgscomparisonfilter.cpp
3636
qgslogicalfilter.cpp
37+
qgsspatialfilter.cpp
3738
qgsftptransaction.cpp
3839
qgsmslayerbuilder.cpp
3940
qgshostedvdsbuilder.cpp

src/mapserver/qgsfilter.cpp

+116-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsbetweenfilter.h"
2020
#include "qgscomparisonfilter.h"
2121
#include "qgslogicalfilter.h"
22+
#include "qgsspatialfilter.h"
2223
#include "qgsvectordataprovider.h"
2324
#include <QDomElement>
2425
#include <QStringList>
@@ -56,7 +57,8 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
5657
}
5758

5859
//Name of the element indicates the type of filter
59-
QString filterName = filterElem.localName();
60+
//using tagName and to upper for interoperability
61+
QString filterName = filterElem.tagName().toUpper();
6062

6163
if ( filterName == "AND" || filterName == "OR" || filterName == "NOT" )
6264
{
@@ -91,6 +93,112 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
9193
}
9294
delete subFilter1; delete subFilter2; return 0;
9395
}
96+
// if the filter is spatial
97+
if ( filterName == "BBOX" || filterName == "CONTAINS" || filterName == "CROSSES" || filterName == "DISJOINT" || filterName == "EQUALS" || filterName == "INTERSECTS" || filterName == "OVERLAPS" || filterName == "TOUCHES" || filterName == "WITHIN" )
98+
{
99+
QgsGeometry* geom;
100+
101+
QDomNodeList bNodes = filterElem.elementsByTagName( "Box" );
102+
if ( bNodes.size() > 0 ) {
103+
QDomElement bElem = bNodes.at( 0 ).toElement().firstChild().toElement();
104+
QString coordSeparator = ",";
105+
QString tupelSeparator = " ";
106+
if ( bElem.hasAttribute( "cs" ) )
107+
{
108+
coordSeparator = bElem.attribute( "cs" );
109+
}
110+
if ( bElem.hasAttribute( "ts" ) )
111+
{
112+
tupelSeparator = bElem.attribute( "ts" );
113+
}
114+
115+
QString bString = bElem.text();
116+
bool conversionSuccess;
117+
double minx = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
118+
double miny = bString.section( tupelSeparator, 0, 0 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
119+
double maxx = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 0, 0 ).toDouble( &conversionSuccess );
120+
double maxy = bString.section( tupelSeparator, 1, 1 ).section( coordSeparator, 1, 1 ).toDouble( &conversionSuccess );
121+
QgsRectangle* rect = new QgsRectangle( minx, miny, maxx, maxy );
122+
geom = QgsGeometry::fromRect( *rect );
123+
}
124+
125+
if ( !geom )
126+
{
127+
QDomNodeList gNodes = filterElem.elementsByTagName( "Point" );
128+
if ( gNodes.size() > 0 ) {
129+
QDomElement gElem = gNodes.at( 0 ).toElement();
130+
geom = QgsGeometry::fromGML2( gElem );
131+
}
132+
}
133+
134+
if ( !geom )
135+
{
136+
QDomNodeList gNodes = filterElem.elementsByTagName( "LineString" );
137+
if ( gNodes.size() > 0 ) {
138+
QDomElement gElem = gNodes.at( 0 ).toElement();
139+
geom = QgsGeometry::fromGML2( gElem );
140+
}
141+
}
142+
143+
if ( !geom )
144+
{
145+
QDomNodeList gNodes = filterElem.elementsByTagName( "Polygon" );
146+
if ( gNodes.size() > 0 ) {
147+
QDomElement gElem = gNodes.at( 0 ).toElement();
148+
geom = QgsGeometry::fromGML2( gElem );
149+
}
150+
}
151+
152+
if ( !geom )
153+
{
154+
QDomNodeList gNodes = filterElem.elementsByTagName( "MultiPoint" );
155+
if ( gNodes.size() > 0 ) {
156+
QDomElement gElem = gNodes.at( 0 ).toElement();
157+
geom = QgsGeometry::fromGML2( gElem );
158+
}
159+
}
160+
161+
if ( !geom )
162+
{
163+
QDomNodeList gNodes = filterElem.elementsByTagName( "MultiLineString" );
164+
if ( gNodes.size() > 0 ) {
165+
QDomElement gElem = gNodes.at( 0 ).toElement();
166+
geom = QgsGeometry::fromGML2( gElem );
167+
}
168+
}
169+
170+
if ( !geom )
171+
{
172+
QDomNodeList gNodes = filterElem.elementsByTagName( "MultiPolygon" );
173+
if ( gNodes.size() > 0 ) {
174+
QDomElement gElem = gNodes.at( 0 ).toElement();
175+
geom = QgsGeometry::fromGML2( gElem );
176+
}
177+
}
178+
179+
if ( !geom )
180+
return 0;
181+
182+
if ( filterName == "BBOX" )
183+
return new QgsSpatialFilter( QgsSpatialFilter::BBOX, geom );
184+
if ( filterName == "CONTAINS" )
185+
return new QgsSpatialFilter( QgsSpatialFilter::CONTAINS, geom );
186+
if ( filterName == "CROSSES" )
187+
return new QgsSpatialFilter( QgsSpatialFilter::CROSSES, geom );
188+
if ( filterName == "DISJOINT" )
189+
return new QgsSpatialFilter( QgsSpatialFilter::DISJOINT, geom );
190+
if ( filterName == "EQUALS" )
191+
return new QgsSpatialFilter( QgsSpatialFilter::EQUALS, geom );
192+
if ( filterName == "INTERSECTS" )
193+
return new QgsSpatialFilter( QgsSpatialFilter::INTERSECTS, geom );
194+
if ( filterName == "OVERLAPS" )
195+
return new QgsSpatialFilter( QgsSpatialFilter::OVERLAPS, geom );
196+
if ( filterName == "TOUCHES" )
197+
return new QgsSpatialFilter( QgsSpatialFilter::TOUCHES, geom );
198+
if ( filterName == "WITHIN" )
199+
return new QgsSpatialFilter( QgsSpatialFilter::WITHIN, geom );
200+
return 0;
201+
}
94202

95203
//assume it must be a comparison filter
96204

@@ -153,33 +261,33 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
153261
//now create the filter
154262

155263
//comparison filter?
156-
if ( filterName == "PropertyIsEqualTo" )
264+
if ( filterName == "PROPERTYISEQUALTO" )
157265
{
158266
return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::EQUAL, literalList.at( 0 ) );
159267
}
160-
else if ( filterName == "PropertyIsNotEqualTo" )
268+
else if ( filterName == "PROPERTYISNOTEQUALTO" )
161269
{
162270
return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::NOT_EQUAL, literalList.at( 0 ) );
163271
}
164-
else if ( filterName == "PropertyIsLessThan" )
272+
else if ( filterName == "PROPERTYISLESSTHAN" )
165273
{
166274
return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::LESSER, literalList.at( 0 ) );
167275
}
168-
else if ( filterName == "PropertyIsGreaterThan" )
276+
else if ( filterName == "PROPERTYISGREATERTHAN" )
169277
{
170278
return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::GREATER, literalList.at( 0 ) );
171279
}
172-
else if ( filterName == "PropertyIsLessThanOrEqualTo" )
280+
else if ( filterName == "PROPERTYISLESSTHANOREQUALTO" )
173281
{
174282
return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::LESSER_OR_EQUAL, literalList.at( 0 ) );
175283
}
176-
else if ( filterName == "PropertyIsGreaterThanOrEqualTo" )
284+
else if ( filterName == "PROPERTYISGREATERTHANOREQUALTO" )
177285
{
178286
return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::GREATER_OR_EQUAL, literalList.at( 0 ) );
179287
}
180288

181289
//between filter?
182-
else if ( filterName == "PropertyIsBetween" )
290+
else if ( filterName == "PROPERTYISBETWEEN" )
183291
{
184292
return new QgsBetweenFilter( attributeIndex, literalList.at( 0 ), literalList.at( 1 ) );
185293
}

src/mapserver/qgspostrequesthandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ QMap<QString, QString> QgsPostRequestHandler::parseInput()
6060
QDomElement docElem = doc.documentElement();
6161
parameters.insert( "VERSION", docElem.attribute( "version" ) );
6262
parameters.insert( "SERVICE", docElem.attribute( "service" ) );
63-
parameters.insert( "REQUEST", docElem.localName() );
63+
parameters.insert( "REQUEST", docElem.tagName() );
6464
parameters.insert( "REQUEST_BODY", inputString );
6565
}
6666

0 commit comments

Comments
 (0)