|
19 | 19 | #include "qgsbetweenfilter.h"
|
20 | 20 | #include "qgscomparisonfilter.h"
|
21 | 21 | #include "qgslogicalfilter.h"
|
| 22 | +#include "qgsspatialfilter.h" |
22 | 23 | #include "qgsvectordataprovider.h"
|
23 | 24 | #include <QDomElement>
|
24 | 25 | #include <QStringList>
|
@@ -56,7 +57,8 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
56 | 57 | }
|
57 | 58 |
|
58 | 59 | //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(); |
60 | 62 |
|
61 | 63 | if ( filterName == "AND" || filterName == "OR" || filterName == "NOT" )
|
62 | 64 | {
|
@@ -91,6 +93,112 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
91 | 93 | }
|
92 | 94 | delete subFilter1; delete subFilter2; return 0;
|
93 | 95 | }
|
| 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 | + } |
94 | 202 |
|
95 | 203 | //assume it must be a comparison filter
|
96 | 204 |
|
@@ -153,33 +261,33 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
153 | 261 | //now create the filter
|
154 | 262 |
|
155 | 263 | //comparison filter?
|
156 |
| - if ( filterName == "PropertyIsEqualTo" ) |
| 264 | + if ( filterName == "PROPERTYISEQUALTO" ) |
157 | 265 | {
|
158 | 266 | return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::EQUAL, literalList.at( 0 ) );
|
159 | 267 | }
|
160 |
| - else if ( filterName == "PropertyIsNotEqualTo" ) |
| 268 | + else if ( filterName == "PROPERTYISNOTEQUALTO" ) |
161 | 269 | {
|
162 | 270 | return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::NOT_EQUAL, literalList.at( 0 ) );
|
163 | 271 | }
|
164 |
| - else if ( filterName == "PropertyIsLessThan" ) |
| 272 | + else if ( filterName == "PROPERTYISLESSTHAN" ) |
165 | 273 | {
|
166 | 274 | return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::LESSER, literalList.at( 0 ) );
|
167 | 275 | }
|
168 |
| - else if ( filterName == "PropertyIsGreaterThan" ) |
| 276 | + else if ( filterName == "PROPERTYISGREATERTHAN" ) |
169 | 277 | {
|
170 | 278 | return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::GREATER, literalList.at( 0 ) );
|
171 | 279 | }
|
172 |
| - else if ( filterName == "PropertyIsLessThanOrEqualTo" ) |
| 280 | + else if ( filterName == "PROPERTYISLESSTHANOREQUALTO" ) |
173 | 281 | {
|
174 | 282 | return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::LESSER_OR_EQUAL, literalList.at( 0 ) );
|
175 | 283 | }
|
176 |
| - else if ( filterName == "PropertyIsGreaterThanOrEqualTo" ) |
| 284 | + else if ( filterName == "PROPERTYISGREATERTHANOREQUALTO" ) |
177 | 285 | {
|
178 | 286 | return new QgsComparisonFilter( attributeIndex, QgsComparisonFilter::GREATER_OR_EQUAL, literalList.at( 0 ) );
|
179 | 287 | }
|
180 | 288 |
|
181 | 289 | //between filter?
|
182 |
| - else if ( filterName == "PropertyIsBetween" ) |
| 290 | + else if ( filterName == "PROPERTYISBETWEEN" ) |
183 | 291 | {
|
184 | 292 | return new QgsBetweenFilter( attributeIndex, literalList.at( 0 ), literalList.at( 1 ) );
|
185 | 293 | }
|
|
0 commit comments