38#include <QRegularExpression>
43#include <netinet/in.h>
49#define GML_NAMESPACE QStringLiteral( "http://www.opengis.net/gml" )
50#define GML32_NAMESPACE QStringLiteral( "http://www.opengis.net/gml/3.2" )
51#define OGC_NAMESPACE QStringLiteral( "http://www.opengis.net/ogc" )
52#define FES_NAMESPACE QStringLiteral( "http://www.opengis.net/fes/2.0" )
53#define SE_NAMESPACE QStringLiteral( "http://www.opengis.net/se" )
58 const QString &namespacePrefix,
59 const QString &namespaceURI,
60 const QString &geometryName,
61 const QString &srsName,
62 bool honourAxisOrientation,
63 bool invertAxisOrientation,
64 const QMap<QString, QString> &fieldNameToXPathMap,
65 const QMap<QString, QString> &namespacePrefixToUriMap )
67 , mGMLVersion( gmlVersion )
68 , mFilterVersion( filterVersion )
69 , mNamespacePrefix( namespacePrefix )
70 , mNamespaceURI( namespaceURI )
71 , mGeometryName( geometryName )
73 , mInvertAxisOrientation( invertAxisOrientation )
74 , mFieldNameToXPathMap( fieldNameToXPathMap )
75 , mNamespacePrefixToUriMap( namespacePrefixToUriMap )
76 , mFilterPrefix( ( filterVersion ==
QgsOgcUtils::FILTER_FES_2_0 ) ?
"fes" :
"ogc" )
77 , mPropertyName( ( filterVersion ==
QgsOgcUtils::FILTER_FES_2_0 ) ?
"ValueReference" :
"PropertyName" )
80 if ( !mSrsName.isEmpty() )
84 if ( honourAxisOrientation && crs.hasAxisInverted() )
86 mInvertAxisOrientation = !mInvertAxisOrientation;
93 QDomElement geometryTypeElement = geometryNode.toElement();
94 QString geomType = geometryTypeElement.tagName();
97 if ( !( geomType == QLatin1String(
"Point" ) || geomType == QLatin1String(
"LineString" ) || geomType == QLatin1String(
"Polygon" ) ||
98 geomType == QLatin1String(
"MultiPoint" ) || geomType == QLatin1String(
"MultiLineString" ) || geomType == QLatin1String(
"MultiPolygon" ) ||
99 geomType == QLatin1String(
"Box" ) || geomType == QLatin1String(
"Envelope" ) || geomType == QLatin1String(
"MultiCurve" ) ) )
101 const QDomNode geometryChild = geometryNode.firstChild();
102 if ( geometryChild.isNull() )
106 geometryTypeElement = geometryChild.toElement();
107 geomType = geometryTypeElement.tagName();
110 if ( !( geomType == QLatin1String(
"Point" ) || geomType == QLatin1String(
"LineString" ) || geomType == QLatin1String(
"Polygon" ) ||
111 geomType == QLatin1String(
"MultiPoint" ) || geomType == QLatin1String(
"MultiLineString" ) || geomType == QLatin1String(
"MultiPolygon" ) ||
112 geomType == QLatin1String(
"Box" ) || geomType == QLatin1String(
"Envelope" ) || geomType == QLatin1String(
"MultiCurve" ) ) )
115 if ( geomType == QLatin1String(
"Point" ) )
117 geometry = geometryFromGMLPoint( geometryTypeElement );
119 else if ( geomType == QLatin1String(
"LineString" ) )
121 geometry = geometryFromGMLLineString( geometryTypeElement );
123 else if ( geomType == QLatin1String(
"Polygon" ) )
125 geometry = geometryFromGMLPolygon( geometryTypeElement );
127 else if ( geomType == QLatin1String(
"MultiPoint" ) )
129 geometry = geometryFromGMLMultiPoint( geometryTypeElement );
131 else if ( geomType == QLatin1String(
"MultiLineString" ) )
133 geometry = geometryFromGMLMultiLineString( geometryTypeElement );
135 else if ( geomType == QLatin1String(
"MultiCurve" ) )
137 geometry = geometryFromGMLMultiCurve( geometryTypeElement );
139 else if ( geomType == QLatin1String(
"MultiPolygon" ) )
141 geometry = geometryFromGMLMultiPolygon( geometryTypeElement );
143 else if ( geomType == QLatin1String(
"Box" ) )
147 else if ( geomType == QLatin1String(
"Envelope" ) )
153 QgsDebugMsgLevel( QStringLiteral(
"Unknown geometry type %1" ).arg( geomType ), 2 );
160 if ( geometryTypeElement.hasAttribute( QStringLiteral(
"srsName" ) ) )
162 QString srsName { geometryTypeElement.attribute( QStringLiteral(
"srsName" ) ) };
165 const bool ignoreAxisOrientation { srsName.startsWith( QLatin1String(
"http://www.opengis.net/gml/srs/" ) ) || srsName.startsWith( QLatin1String(
"EPSG:" ) ) };
169 if ( srsName.startsWith( QLatin1String(
"http://www.opengis.net/gml/srs/" ) ) )
171 const auto parts { srsName.split( QRegularExpression( QStringLiteral( R
"raw(/|#|\.)raw" ) ) ) };
172 if ( parts.length() == 10 )
174 srsName = QStringLiteral(
"http://www.opengis.net/def/crs/%1/0/%2" ).arg( parts[ 7 ].toUpper(), parts[ 9 ] );
208 const QString xml = QStringLiteral(
"<tmp xmlns=\"%1\" xmlns:gml=\"%1\">%2</tmp>" ).arg(
GML_NAMESPACE, xmlString );
210 if ( !doc.setContent( xml,
true ) )
213 return geometryFromGML( doc.documentElement().firstChildElement(), context );
217QgsGeometry QgsOgcUtils::geometryFromGMLPoint(
const QDomElement &geometryElement )
221 const QDomNodeList coordList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
222 if ( !coordList.isEmpty() )
224 const QDomElement coordElement = coordList.at( 0 ).toElement();
225 if ( readGMLCoordinates( pointCoordinate, coordElement ) != 0 )
232 const QDomNodeList posList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"pos" ) );
233 if ( posList.size() < 1 )
235 return QgsGeometry();
237 const QDomElement posElement = posList.at( 0 ).toElement();
238 if ( readGMLPositions( pointCoordinate, posElement ) != 0 )
240 return QgsGeometry();
244 if ( pointCoordinate.empty() )
246 return QgsGeometry();
249 const bool hasZ { !std::isnan( pointCoordinate.first().z() ) };
250 QgsPolyline::const_iterator point_it = pointCoordinate.constBegin();
251 const char e =
static_cast<char>( htonl( 1 ) != 1 );
252 const double x = point_it->x();
253 const double y = point_it->y();
254 const int size = 1 +
static_cast<int>(
sizeof( int ) ) + ( hasZ ? 3 : 2 ) *
static_cast<int>(
sizeof( double ) );
257 unsigned char *wkb =
new unsigned char[size];
260 memcpy( &( wkb )[wkbPosition], &e, 1 );
262 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
263 wkbPosition +=
sizeof( int );
264 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
265 wkbPosition +=
sizeof( double );
266 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
270 wkbPosition +=
sizeof( double );
271 double z = point_it->z();
272 memcpy( &( wkb )[wkbPosition], &z,
sizeof(
double ) );
280QgsGeometry QgsOgcUtils::geometryFromGMLLineString(
const QDomElement &geometryElement )
284 const QDomNodeList coordList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
285 if ( !coordList.isEmpty() )
287 const QDomElement coordElement = coordList.at( 0 ).toElement();
288 if ( readGMLCoordinates( lineCoordinates, coordElement ) != 0 )
290 return QgsGeometry();
295 const QDomNodeList posList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"posList" ) );
296 if ( posList.size() < 1 )
298 return QgsGeometry();
300 const QDomElement posElement = posList.at( 0 ).toElement();
301 if ( readGMLPositions( lineCoordinates, posElement ) != 0 )
303 return QgsGeometry();
307 const bool hasZ { !std::isnan( lineCoordinates.first().z() ) };
309 char e =
static_cast<char>( htonl( 1 ) != 1 );
310 const int size = 1 + 2 *
static_cast<int>(
sizeof( int ) + lineCoordinates.size() ) * ( hasZ ? 3 : 2 ) *
static_cast<int>(
sizeof(
double ) );
313 unsigned char *wkb =
new unsigned char[size];
317 int nPoints = lineCoordinates.size();
320 memcpy( &( wkb )[wkbPosition], &e, 1 );
322 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
323 wkbPosition +=
sizeof( int );
324 memcpy( &( wkb )[wkbPosition], &nPoints,
sizeof(
int ) );
325 wkbPosition +=
sizeof( int );
327 QgsPolyline::const_iterator iter;
328 for ( iter = lineCoordinates.constBegin(); iter != lineCoordinates.constEnd(); ++iter )
332 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
333 wkbPosition +=
sizeof( double );
334 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
335 wkbPosition +=
sizeof( double );
339 double z = iter->z();
340 memcpy( &( wkb )[wkbPosition], &z,
sizeof(
double ) );
341 wkbPosition +=
sizeof( double );
351QgsGeometry QgsOgcUtils::geometryFromGMLPolygon(
const QDomElement &geometryElement )
358 const QDomNodeList outerBoundaryList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"outerBoundaryIs" ) );
359 if ( !outerBoundaryList.isEmpty() )
361 QDomElement coordinatesElement = outerBoundaryList.at( 0 ).firstChild().firstChild().toElement();
362 if ( coordinatesElement.isNull() )
364 return QgsGeometry();
366 if ( readGMLCoordinates( exteriorPointList, coordinatesElement ) != 0 )
368 return QgsGeometry();
370 ringCoordinates.push_back( exteriorPointList );
373 const QDomNodeList innerBoundaryList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"innerBoundaryIs" ) );
374 for (
int i = 0; i < innerBoundaryList.size(); ++i )
377 coordinatesElement = innerBoundaryList.at( i ).firstChild().firstChild().toElement();
378 if ( coordinatesElement.isNull() )
380 return QgsGeometry();
382 if ( readGMLCoordinates( interiorPointList, coordinatesElement ) != 0 )
384 return QgsGeometry();
386 ringCoordinates.push_back( interiorPointList );
392 const QDomNodeList exteriorList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"exterior" ) );
393 if ( exteriorList.size() < 1 )
395 return QgsGeometry();
397 const QDomElement posElement = exteriorList.at( 0 ).firstChild().firstChild().toElement();
398 if ( posElement.isNull() )
400 return QgsGeometry();
402 if ( readGMLPositions( exteriorPointList, posElement ) != 0 )
404 return QgsGeometry();
406 ringCoordinates.push_back( exteriorPointList );
409 const QDomNodeList interiorList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"interior" ) );
410 for (
int i = 0; i < interiorList.size(); ++i )
413 const QDomElement posElement = interiorList.at( i ).firstChild().firstChild().toElement();
414 if ( posElement.isNull() )
416 return QgsGeometry();
419 if ( readGMLPositions( interiorPointList, posElement ) )
421 return QgsGeometry();
423 ringCoordinates.push_back( interiorPointList );
428 int nrings = ringCoordinates.size();
430 return QgsGeometry();
433 for ( QgsMultiPolyline::const_iterator it = ringCoordinates.constBegin(); it != ringCoordinates.constEnd(); ++it )
435 npoints += it->size();
438 const bool hasZ { !std::isnan( ringCoordinates.first().first().z() ) };
440 const int size = 1 + 2 *
static_cast<int>(
sizeof( int ) ) + nrings *
static_cast<int>(
sizeof(
int ) ) + ( hasZ ? 3 : 2 ) * npoints *
static_cast<int>(
sizeof(
double ) );
443 unsigned char *wkb =
new unsigned char[size];
446 char e =
static_cast<char>( htonl( 1 ) != 1 );
448 int nPointsInRing = 0;
452 memcpy( &( wkb )[wkbPosition], &e, 1 );
454 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
455 wkbPosition +=
sizeof( int );
456 memcpy( &( wkb )[wkbPosition], &nrings,
sizeof(
int ) );
457 wkbPosition +=
sizeof( int );
458 for ( QgsMultiPolyline::const_iterator it = ringCoordinates.constBegin(); it != ringCoordinates.constEnd(); ++it )
460 nPointsInRing = it->size();
461 memcpy( &( wkb )[wkbPosition], &nPointsInRing,
sizeof(
int ) );
462 wkbPosition +=
sizeof( int );
464 QgsPolyline::const_iterator iter;
465 for ( iter = it->begin(); iter != it->end(); ++iter )
470 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
471 wkbPosition +=
sizeof( double );
472 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
473 wkbPosition +=
sizeof( double );
478 memcpy( &( wkb )[wkbPosition], &z,
sizeof(
double ) );
479 wkbPosition +=
sizeof( double );
489QgsGeometry QgsOgcUtils::geometryFromGMLMultiPoint(
const QDomElement &geometryElement )
493 const QDomNodeList pointMemberList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"pointMember" ) );
494 if ( pointMemberList.size() < 1 )
496 return QgsGeometry();
498 QDomNodeList pointNodeList;
500 QDomNodeList coordinatesList;
501 QDomNodeList posList;
502 for (
int i = 0; i < pointMemberList.size(); ++i )
505 pointNodeList = pointMemberList.at( i ).toElement().elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"Point" ) );
506 if ( pointNodeList.size() < 1 )
511 coordinatesList = pointNodeList.at( 0 ).toElement().elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
512 if ( !coordinatesList.isEmpty() )
514 currentPoint.clear();
515 if ( readGMLCoordinates( currentPoint, coordinatesList.at( 0 ).toElement() ) != 0 )
519 if ( currentPoint.empty() )
523 pointList.push_back( ( *currentPoint.begin() ) );
529 posList = pointNodeList.at( 0 ).toElement().elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"pos" ) );
530 if ( posList.size() < 1 )
534 currentPoint.clear();
535 if ( readGMLPositions( currentPoint, posList.at( 0 ).toElement() ) != 0 )
539 if ( currentPoint.empty() )
543 pointList.push_back( ( *currentPoint.begin() ) );
547 int nPoints = pointList.size();
549 return QgsGeometry();
551 const bool hasZ { !std::isnan( pointList.first().z() ) };
554 const int size = 1 + 2 *
static_cast<int>(
sizeof( int ) ) +
static_cast<int>( pointList.size() ) * ( ( hasZ ? 3 : 2 ) *
static_cast<int>(
sizeof( double ) ) + 1 +
static_cast<int>(
sizeof( int ) ) );
557 unsigned char *wkb =
new unsigned char[size];
560 char e =
static_cast<char>( htonl( 1 ) != 1 );
563 memcpy( &( wkb )[wkbPosition], &e, 1 );
565 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
566 wkbPosition +=
sizeof( int );
567 memcpy( &( wkb )[wkbPosition], &nPoints,
sizeof(
int ) );
568 wkbPosition +=
sizeof( int );
570 for ( QgsPolyline::const_iterator it = pointList.constBegin(); it != pointList.constEnd(); ++it )
572 memcpy( &( wkb )[wkbPosition], &e, 1 );
574 memcpy( &( wkb )[wkbPosition], &pointType,
sizeof(
int ) );
575 wkbPosition +=
sizeof( int );
577 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
578 wkbPosition +=
sizeof( double );
580 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
581 wkbPosition +=
sizeof( double );
586 memcpy( &( wkb )[wkbPosition], &z,
sizeof(
double ) );
587 wkbPosition +=
sizeof( double );
596QgsGeometry QgsOgcUtils::geometryFromGMLMultiLineString(
const QDomElement &geometryElement )
608 QList< QgsPolyline > lineCoordinates;
609 QDomElement currentLineStringElement;
610 QDomNodeList currentCoordList;
611 QDomNodeList currentPosList;
613 const QDomNodeList lineStringMemberList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"lineStringMember" ) );
614 if ( !lineStringMemberList.isEmpty() )
616 for (
int i = 0; i < lineStringMemberList.size(); ++i )
618 const QDomNodeList lineStringNodeList = lineStringMemberList.at( i ).toElement().elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"LineString" ) );
619 if ( lineStringNodeList.size() < 1 )
621 return QgsGeometry();
623 currentLineStringElement = lineStringNodeList.at( 0 ).toElement();
624 currentCoordList = currentLineStringElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
625 if ( !currentCoordList.isEmpty() )
628 if ( readGMLCoordinates( currentPointList, currentCoordList.at( 0 ).toElement() ) != 0 )
630 return QgsGeometry();
632 lineCoordinates.push_back( currentPointList );
636 currentPosList = currentLineStringElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"posList" ) );
637 if ( currentPosList.size() < 1 )
639 return QgsGeometry();
642 if ( readGMLPositions( currentPointList, currentPosList.at( 0 ).toElement() ) != 0 )
644 return QgsGeometry();
646 lineCoordinates.push_back( currentPointList );
652 const QDomNodeList lineStringList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"LineString" ) );
653 if ( !lineStringList.isEmpty() )
655 for (
int i = 0; i < lineStringList.size(); ++i )
657 currentLineStringElement = lineStringList.at( i ).toElement();
658 currentCoordList = currentLineStringElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
659 if ( !currentCoordList.isEmpty() )
662 if ( readGMLCoordinates( currentPointList, currentCoordList.at( 0 ).toElement() ) != 0 )
664 return QgsGeometry();
666 lineCoordinates.push_back( currentPointList );
667 return QgsGeometry();
671 currentPosList = currentLineStringElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"posList" ) );
672 if ( currentPosList.size() < 1 )
674 return QgsGeometry();
677 if ( readGMLPositions( currentPointList, currentPosList.at( 0 ).toElement() ) != 0 )
679 return QgsGeometry();
681 lineCoordinates.push_back( currentPointList );
687 return QgsGeometry();
691 int nLines = lineCoordinates.size();
693 return QgsGeometry();
695 const bool hasZ { !std::isnan( lineCoordinates.first().first().z() ) };
696 const int coordSize { hasZ ? 3 : 2 };
699 int size =
static_cast<int>( lineCoordinates.size() + 1 ) * ( 1 + 2 *
sizeof( int ) );
700 for ( QList< QgsPolyline >::const_iterator it = lineCoordinates.constBegin(); it != lineCoordinates.constEnd(); ++it )
702 size += it->size() * coordSize *
sizeof( double );
706 unsigned char *wkb =
new unsigned char[size];
709 char e =
static_cast<char>( htonl( 1 ) != 1 );
713 memcpy( &( wkb )[wkbPosition], &e, 1 );
715 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
716 wkbPosition +=
sizeof( int );
717 memcpy( &( wkb )[wkbPosition], &nLines,
sizeof(
int ) );
718 wkbPosition +=
sizeof( int );
720 for ( QList< QgsPolyline >::const_iterator it = lineCoordinates.constBegin(); it != lineCoordinates.constEnd(); ++it )
722 memcpy( &( wkb )[wkbPosition], &e, 1 );
724 memcpy( &( wkb )[wkbPosition], &lineType,
sizeof(
int ) );
725 wkbPosition +=
sizeof( int );
726 nPoints = it->size();
727 memcpy( &( wkb )[wkbPosition], &nPoints,
sizeof(
int ) );
728 wkbPosition +=
sizeof( int );
729 for ( QgsPolyline::const_iterator iter = it->begin(); iter != it->end(); ++iter )
734 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
735 wkbPosition +=
sizeof( double );
736 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
737 wkbPosition +=
sizeof( double );
742 memcpy( &( wkb )[wkbPosition], &z,
sizeof(
double ) );
743 wkbPosition +=
sizeof( double );
753QgsGeometry QgsOgcUtils::geometryFromGMLMultiPolygon(
const QDomElement &geometryElement )
756 QVector<QgsMultiPolyline> multiPolygonPoints;
757 QDomElement currentPolygonMemberElement;
758 QDomNodeList polygonList;
759 QDomElement currentPolygonElement;
761 QDomNodeList outerBoundaryList;
762 QDomElement currentOuterBoundaryElement;
763 QDomElement currentInnerBoundaryElement;
765 QDomNodeList exteriorList;
766 QDomElement currentExteriorElement;
767 QDomElement currentInteriorElement;
769 QDomNodeList linearRingNodeList;
770 QDomElement currentLinearRingElement;
772 QDomNodeList currentCoordinateList;
773 QDomNodeList currentPosList;
775 const QDomNodeList polygonMemberList = geometryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"polygonMember" ) );
777 for (
int i = 0; i < polygonMemberList.size(); ++i )
779 currentPolygonList.resize( 0 );
780 currentPolygonMemberElement = polygonMemberList.at( i ).toElement();
781 polygonList = currentPolygonMemberElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"Polygon" ) );
782 if ( polygonList.size() < 1 )
786 currentPolygonElement = polygonList.at( 0 ).toElement();
789 outerBoundaryList = currentPolygonElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"outerBoundaryIs" ) );
790 if ( !outerBoundaryList.isEmpty() )
792 currentOuterBoundaryElement = outerBoundaryList.at( 0 ).toElement();
795 linearRingNodeList = currentOuterBoundaryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"LinearRing" ) );
796 if ( linearRingNodeList.size() < 1 )
800 currentLinearRingElement = linearRingNodeList.at( 0 ).toElement();
801 currentCoordinateList = currentLinearRingElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
802 if ( currentCoordinateList.size() < 1 )
806 if ( readGMLCoordinates( ringCoordinates, currentCoordinateList.at( 0 ).toElement() ) != 0 )
810 currentPolygonList.push_back( ringCoordinates );
813 const QDomNodeList innerBoundaryList = currentPolygonElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"innerBoundaryIs" ) );
814 for (
int j = 0; j < innerBoundaryList.size(); ++j )
817 currentInnerBoundaryElement = innerBoundaryList.at( j ).toElement();
818 linearRingNodeList = currentInnerBoundaryElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"LinearRing" ) );
819 if ( linearRingNodeList.size() < 1 )
823 currentLinearRingElement = linearRingNodeList.at( 0 ).toElement();
824 currentCoordinateList = currentLinearRingElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"coordinates" ) );
825 if ( currentCoordinateList.size() < 1 )
829 if ( readGMLCoordinates( ringCoordinates, currentCoordinateList.at( 0 ).toElement() ) != 0 )
833 currentPolygonList.push_back( ringCoordinates );
839 exteriorList = currentPolygonElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"exterior" ) );
840 if ( exteriorList.size() < 1 )
845 currentExteriorElement = exteriorList.at( 0 ).toElement();
848 linearRingNodeList = currentExteriorElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"LinearRing" ) );
849 if ( linearRingNodeList.size() < 1 )
853 currentLinearRingElement = linearRingNodeList.at( 0 ).toElement();
854 currentPosList = currentLinearRingElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"posList" ) );
855 if ( currentPosList.size() < 1 )
859 if ( readGMLPositions( ringPositions, currentPosList.at( 0 ).toElement() ) != 0 )
863 currentPolygonList.push_back( ringPositions );
866 const QDomNodeList interiorList = currentPolygonElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"interior" ) );
867 for (
int j = 0; j < interiorList.size(); ++j )
870 currentInteriorElement = interiorList.at( j ).toElement();
871 linearRingNodeList = currentInteriorElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"LinearRing" ) );
872 if ( linearRingNodeList.size() < 1 )
876 currentLinearRingElement = linearRingNodeList.at( 0 ).toElement();
877 currentPosList = currentLinearRingElement.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"posList" ) );
878 if ( currentPosList.size() < 1 )
882 if ( readGMLPositions( ringPositions, currentPosList.at( 0 ).toElement() ) != 0 )
886 currentPolygonList.push_back( ringPositions );
889 multiPolygonPoints.push_back( currentPolygonList );
892 int nPolygons = multiPolygonPoints.size();
894 return QgsGeometry();
896 const bool hasZ { !std::isnan( multiPolygonPoints.first().first().first().z() ) };
898 int size = 1 + 2 *
sizeof( int );
901 for (
auto it = multiPolygonPoints.constBegin(); it != multiPolygonPoints.constEnd(); ++it )
903 size += 1 + 2 *
sizeof( int );
904 for (
auto iter = it->begin(); iter != it->end(); ++iter )
906 size +=
static_cast<int>(
sizeof( int ) ) + ( hasZ ? 3 : 2 ) *
static_cast<int>( iter->size() *
sizeof(
double ) );
911 unsigned char *wkb =
new unsigned char[size];
913 char e =
static_cast<char>( htonl( 1 ) != 1 );
920 memcpy( &( wkb )[wkbPosition], &e, 1 );
922 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
923 wkbPosition +=
sizeof( int );
924 memcpy( &( wkb )[wkbPosition], &nPolygons,
sizeof(
int ) );
925 wkbPosition +=
sizeof( int );
929 for (
auto it = multiPolygonPoints.constBegin(); it != multiPolygonPoints.constEnd(); ++it )
931 memcpy( &( wkb )[wkbPosition], &e, 1 );
933 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
934 wkbPosition +=
sizeof( int );
936 memcpy( &( wkb )[wkbPosition], &nRings,
sizeof(
int ) );
937 wkbPosition +=
sizeof( int );
938 for (
auto iter = it->begin(); iter != it->end(); ++iter )
940 nPointsInRing = iter->size();
941 memcpy( &( wkb )[wkbPosition], &nPointsInRing,
sizeof(
int ) );
942 wkbPosition +=
sizeof( int );
943 for (
auto iterator = iter->begin(); iterator != iter->end(); ++iterator )
947 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
948 wkbPosition +=
sizeof( double );
949 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
950 wkbPosition +=
sizeof( double );
953 double z = iterator->z();
954 memcpy( &( wkb )[wkbPosition], &z,
sizeof(
double ) );
955 wkbPosition +=
sizeof( double );
966QDomElement QgsOgcUtils::filterElement( QDomDocument &doc, GMLVersion gmlVersion, FilterVersion filterVersion,
bool GMLUsed )
968 QDomElement filterElem =
970 doc.createElementNS(
FES_NAMESPACE, QStringLiteral(
"fes:Filter" ) ) :
971 doc.createElementNS(
OGC_NAMESPACE, QStringLiteral(
"ogc:Filter" ) );
975 QDomAttr attr = doc.createAttribute( QStringLiteral(
"xmlns:gml" ) );
980 filterElem.setAttributeNode( attr );
986bool QgsOgcUtils::readGMLCoordinates(
QgsPolyline &coords,
const QDomElement &elem )
988 QString coordSeparator = QStringLiteral(
"," );
989 QString tupleSeparator = QStringLiteral(
" " );
994 if ( elem.hasAttribute( QStringLiteral(
"cs" ) ) )
996 coordSeparator = elem.attribute( QStringLiteral(
"cs" ) );
998 if ( elem.hasAttribute( QStringLiteral(
"ts" ) ) )
1000 tupleSeparator = elem.attribute( QStringLiteral(
"ts" ) );
1003 const QStringList tupels = elem.text().split( tupleSeparator, Qt::SkipEmptyParts );
1004 QStringList tuple_coords;
1006 bool conversionSuccess;
1008 QStringList::const_iterator it;
1009 for ( it = tupels.constBegin(); it != tupels.constEnd(); ++it )
1011 tuple_coords = ( *it ).split( coordSeparator, Qt::SkipEmptyParts );
1012 if ( tuple_coords.size() < 2 )
1016 x = tuple_coords.at( 0 ).toDouble( &conversionSuccess );
1017 if ( !conversionSuccess )
1021 y = tuple_coords.at( 1 ).toDouble( &conversionSuccess );
1022 if ( !conversionSuccess )
1026 if ( tuple_coords.size() > 2 )
1028 z = tuple_coords.at( 2 ).toDouble( &conversionSuccess );
1029 if ( !conversionSuccess )
1036 z = std::numeric_limits<double>::quiet_NaN();
1038 coords.append( QgsPoint( x, y, z ) );
1047 const QDomElement boxElem = boxNode.toElement();
1048 if ( boxElem.tagName() != QLatin1String(
"Box" ) )
1051 const QDomElement bElem = boxElem.firstChild().toElement();
1052 QString coordSeparator = QStringLiteral(
"," );
1053 QString tupleSeparator = QStringLiteral(
" " );
1054 if ( bElem.hasAttribute( QStringLiteral(
"cs" ) ) )
1056 coordSeparator = bElem.attribute( QStringLiteral(
"cs" ) );
1058 if ( bElem.hasAttribute( QStringLiteral(
"ts" ) ) )
1060 tupleSeparator = bElem.attribute( QStringLiteral(
"ts" ) );
1063 const QString bString = bElem.text();
1064 bool ok1, ok2, ok3, ok4;
1065 const double xmin = bString.section( tupleSeparator, 0, 0 ).section( coordSeparator, 0, 0 ).toDouble( &ok1 );
1066 const double ymin = bString.section( tupleSeparator, 0, 0 ).section( coordSeparator, 1, 1 ).toDouble( &ok2 );
1067 const double xmax = bString.section( tupleSeparator, 1, 1 ).section( coordSeparator, 0, 0 ).toDouble( &ok3 );
1068 const double ymax = bString.section( tupleSeparator, 1, 1 ).section( coordSeparator, 1, 1 ).toDouble( &ok4 );
1070 if ( ok1 && ok2 && ok3 && ok4 )
1079bool QgsOgcUtils::readGMLPositions(
QgsPolyline &coords,
const QDomElement &elem )
1083 const QStringList pos = elem.text().split(
' ', Qt::SkipEmptyParts );
1085 bool conversionSuccess;
1086 const int posSize = pos.size();
1088 int srsDimension = 2;
1089 if ( elem.hasAttribute( QStringLiteral(
"srsDimension" ) ) )
1091 srsDimension = elem.attribute( QStringLiteral(
"srsDimension" ) ).toInt( &conversionSuccess );
1092 if ( !conversionSuccess )
1097 else if ( elem.hasAttribute( QStringLiteral(
"dimension" ) ) )
1099 srsDimension = elem.attribute( QStringLiteral(
"dimension" ) ).toInt( &conversionSuccess );
1100 if ( !conversionSuccess )
1106 for (
int i = 0; i < posSize / srsDimension; i++ )
1108 x = pos.at( i * srsDimension ).toDouble( &conversionSuccess );
1109 if ( !conversionSuccess )
1113 y = pos.at( i * srsDimension + 1 ).toDouble( &conversionSuccess );
1114 if ( !conversionSuccess )
1118 if ( srsDimension > 2 )
1120 z = pos.at( i * srsDimension + 2 ).toDouble( &conversionSuccess );
1121 if ( !conversionSuccess )
1128 z = std::numeric_limits<double>::quiet_NaN();
1130 coords.append( QgsPoint( x, y, z ) );
1140 const QDomElement envelopeElem = envelopeNode.toElement();
1141 if ( envelopeElem.tagName() != QLatin1String(
"Envelope" ) )
1144 const QDomNodeList lowerCornerList = envelopeElem.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"lowerCorner" ) );
1145 if ( lowerCornerList.size() < 1 )
1148 const QDomNodeList upperCornerList = envelopeElem.elementsByTagNameNS(
GML_NAMESPACE, QStringLiteral(
"upperCorner" ) );
1149 if ( upperCornerList.size() < 1 )
1152 bool conversionSuccess;
1153 int srsDimension = 2;
1155 QDomElement elem = lowerCornerList.at( 0 ).toElement();
1156 if ( elem.hasAttribute( QStringLiteral(
"srsDimension" ) ) )
1158 srsDimension = elem.attribute( QStringLiteral(
"srsDimension" ) ).toInt( &conversionSuccess );
1159 if ( !conversionSuccess )
1164 else if ( elem.hasAttribute( QStringLiteral(
"dimension" ) ) )
1166 srsDimension = elem.attribute( QStringLiteral(
"dimension" ) ).toInt( &conversionSuccess );
1167 if ( !conversionSuccess )
1172 QString bString = elem.text();
1174 const double xmin = bString.section(
' ', 0, 0 ).toDouble( &conversionSuccess );
1175 if ( !conversionSuccess )
1177 const double ymin = bString.section(
' ', 1, 1 ).toDouble( &conversionSuccess );
1178 if ( !conversionSuccess )
1181 elem = upperCornerList.at( 0 ).toElement();
1182 if ( elem.hasAttribute( QStringLiteral(
"srsDimension" ) ) )
1184 srsDimension = elem.attribute( QStringLiteral(
"srsDimension" ) ).toInt( &conversionSuccess );
1185 if ( !conversionSuccess )
1190 else if ( elem.hasAttribute( QStringLiteral(
"dimension" ) ) )
1192 srsDimension = elem.attribute( QStringLiteral(
"dimension" ) ).toInt( &conversionSuccess );
1193 if ( !conversionSuccess )
1199 Q_UNUSED( srsDimension )
1201 bString = elem.text();
1202 const double xmax = bString.section(
' ', 0, 0 ).toDouble( &conversionSuccess );
1203 if ( !conversionSuccess )
1205 const double ymax = bString.section(
' ', 1, 1 ).toDouble( &conversionSuccess );
1206 if ( !conversionSuccess )
1221 const QString &srsName,
1222 bool invertAxisOrientation,
1227 return QDomElement();
1230 QDomElement boxElem = doc.createElement( QStringLiteral(
"gml:Box" ) );
1231 if ( !srsName.isEmpty() )
1233 boxElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1235 QDomElement coordElem = doc.createElement( QStringLiteral(
"gml:coordinates" ) );
1236 coordElem.setAttribute( QStringLiteral(
"cs" ), QStringLiteral(
"," ) );
1237 coordElem.setAttribute( QStringLiteral(
"ts" ), QStringLiteral(
" " ) );
1239 QString coordString;
1248 const QDomText coordText = doc.createTextNode( coordString );
1249 coordElem.appendChild( coordText );
1250 boxElem.appendChild( coordElem );
1261 const QString &srsName,
1262 bool invertAxisOrientation,
1267 return QDomElement();
1270 QDomElement envElem = doc.createElement( QStringLiteral(
"gml:Envelope" ) );
1271 if ( !srsName.isEmpty() )
1273 envElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1277 QDomElement lowerCornerElem = doc.createElement( QStringLiteral(
"gml:lowerCorner" ) );
1281 const QDomText lowerCornerText = doc.createTextNode( posList );
1282 lowerCornerElem.appendChild( lowerCornerText );
1283 envElem.appendChild( lowerCornerElem );
1285 QDomElement upperCornerElem = doc.createElement( QStringLiteral(
"gml:upperCorner" ) );
1289 const QDomText upperCornerText = doc.createTextNode( posList );
1290 upperCornerElem.appendChild( upperCornerText );
1291 envElem.appendChild( upperCornerElem );
1304 const QString &srsName,
1305 bool invertAxisOrientation,
1306 const QString &gmlIdBase,
1310 return QDomElement();
1313 QString cs = QStringLiteral(
"," );
1315 const QString ts = QStringLiteral(
" " );
1317 QDomElement baseCoordElem;
1319 bool hasZValue =
false;
1321 const QByteArray wkb( geometry.
asWkb() );
1331 return QDomElement();
1344 baseCoordElem = doc.createElement( QStringLiteral(
"gml:pos" ) );
1347 baseCoordElem = doc.createElement( QStringLiteral(
"gml:posList" ) );
1354 baseCoordElem = doc.createElement( QStringLiteral(
"gml:coordinates" ) );
1355 baseCoordElem.setAttribute( QStringLiteral(
"cs" ), cs );
1356 baseCoordElem.setAttribute( QStringLiteral(
"ts" ), ts );
1370 QDomElement pointElem = doc.createElement( QStringLiteral(
"gml:Point" ) );
1371 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1372 pointElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase );
1373 if ( !srsName.isEmpty() )
1374 pointElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1375 QDomElement coordElem = baseCoordElem.cloneNode().toElement();
1379 if ( invertAxisOrientation )
1393 const QDomText coordText = doc.createTextNode( coordString );
1395 coordElem.appendChild( coordText );
1397 coordElem.setAttribute( QStringLiteral(
"srsDimension" ), hasZValue ? QStringLiteral(
"3" ) : QStringLiteral(
"2" ) );
1398 pointElem.appendChild( coordElem );
1408 QDomElement multiPointElem = doc.createElement( QStringLiteral(
"gml:MultiPoint" ) );
1409 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1410 multiPointElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase );
1411 if ( !srsName.isEmpty() )
1412 multiPointElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1417 for (
int idx = 0; idx < nPoints; ++idx )
1419 QDomElement pointMemberElem = doc.createElement( QStringLiteral(
"gml:pointMember" ) );
1420 QDomElement pointElem = doc.createElement( QStringLiteral(
"gml:Point" ) );
1421 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1422 pointElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase + QStringLiteral(
".%1" ).arg( idx + 1 ) );
1423 QDomElement coordElem = baseCoordElem.cloneNode().toElement();
1429 if ( invertAxisOrientation )
1443 const QDomText coordText = doc.createTextNode( coordString );
1445 coordElem.appendChild( coordText );
1447 coordElem.setAttribute( QStringLiteral(
"srsDimension" ), hasZValue ? QStringLiteral(
"3" ) : QStringLiteral(
"2" ) );
1448 pointElem.appendChild( coordElem );
1451 pointMemberElem.appendChild( pointElem );
1452 multiPointElem.appendChild( pointMemberElem );
1454 return multiPointElem;
1463 QDomElement lineStringElem = doc.createElement( QStringLiteral(
"gml:LineString" ) );
1464 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1465 lineStringElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase );
1466 if ( !srsName.isEmpty() )
1467 lineStringElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1473 QDomElement coordElem = baseCoordElem.cloneNode().toElement();
1474 QString coordString;
1475 for (
int idx = 0; idx < nPoints; ++idx )
1484 if ( invertAxisOrientation )
1498 const QDomText coordText = doc.createTextNode( coordString );
1499 coordElem.appendChild( coordText );
1501 coordElem.setAttribute( QStringLiteral(
"srsDimension" ), hasZValue ? QStringLiteral(
"3" ) : QStringLiteral(
"2" ) );
1502 lineStringElem.appendChild( coordElem );
1503 return lineStringElem;
1512 QDomElement multiLineStringElem = doc.createElement( QStringLiteral(
"gml:MultiLineString" ) );
1513 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1514 multiLineStringElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase );
1515 if ( !srsName.isEmpty() )
1516 multiLineStringElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1521 for (
int jdx = 0; jdx < nLines; jdx++ )
1523 QDomElement lineStringMemberElem = doc.createElement( QStringLiteral(
"gml:lineStringMember" ) );
1524 QDomElement lineStringElem = doc.createElement( QStringLiteral(
"gml:LineString" ) );
1525 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1526 lineStringElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase + QStringLiteral(
".%1" ).arg( jdx + 1 ) );
1533 QDomElement coordElem = baseCoordElem.cloneNode().toElement();
1534 QString coordString;
1535 for (
int idx = 0; idx < nPoints; idx++ )
1544 if ( invertAxisOrientation )
1559 const QDomText coordText = doc.createTextNode( coordString );
1560 coordElem.appendChild( coordText );
1562 coordElem.setAttribute( QStringLiteral(
"srsDimension" ), hasZValue ? QStringLiteral(
"3" ) : QStringLiteral(
"2" ) );
1563 lineStringElem.appendChild( coordElem );
1564 lineStringMemberElem.appendChild( lineStringElem );
1565 multiLineStringElem.appendChild( lineStringMemberElem );
1567 return multiLineStringElem;
1576 QDomElement polygonElem = doc.createElement( QStringLiteral(
"gml:Polygon" ) );
1577 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1578 polygonElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase );
1579 if ( !srsName.isEmpty() )
1580 polygonElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1586 if ( numRings == 0 )
1587 return QDomElement();
1589 for (
int idx = 0; idx < numRings; idx++ )
1591 QString boundaryName = ( gmlVersion ==
GML_2_1_2 ) ?
"gml:outerBoundaryIs" :
"gml:exterior";
1594 boundaryName = ( gmlVersion ==
GML_2_1_2 ) ?
"gml:innerBoundaryIs" :
"gml:interior";
1596 QDomElement boundaryElem = doc.createElement( boundaryName );
1597 QDomElement ringElem = doc.createElement( QStringLiteral(
"gml:LinearRing" ) );
1602 QDomElement coordElem = baseCoordElem.cloneNode().toElement();
1603 QString coordString;
1604 for (
int jdx = 0; jdx < nPoints; jdx++ )
1613 if ( invertAxisOrientation )
1627 const QDomText coordText = doc.createTextNode( coordString );
1628 coordElem.appendChild( coordText );
1630 coordElem.setAttribute( QStringLiteral(
"srsDimension" ), hasZValue ? QStringLiteral(
"3" ) : QStringLiteral(
"2" ) );
1631 ringElem.appendChild( coordElem );
1632 boundaryElem.appendChild( ringElem );
1633 polygonElem.appendChild( boundaryElem );
1645 QDomElement multiPolygonElem = doc.createElement( QStringLiteral(
"gml:MultiPolygon" ) );
1646 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1647 multiPolygonElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase );
1648 if ( !srsName.isEmpty() )
1649 multiPolygonElem.setAttribute( QStringLiteral(
"srsName" ), srsName );
1652 wkbPtr >> numPolygons;
1654 for (
int kdx = 0; kdx < numPolygons; kdx++ )
1656 QDomElement polygonMemberElem = doc.createElement( QStringLiteral(
"gml:polygonMember" ) );
1657 QDomElement polygonElem = doc.createElement( QStringLiteral(
"gml:Polygon" ) );
1658 if ( gmlVersion ==
GML_3_2_1 && !gmlIdBase.isEmpty() )
1659 polygonElem.setAttribute( QStringLiteral(
"gml:id" ), gmlIdBase + QStringLiteral(
".%1" ).arg( kdx + 1 ) );
1666 for (
int idx = 0; idx < numRings; idx++ )
1668 QString boundaryName = ( gmlVersion ==
GML_2_1_2 ) ?
"gml:outerBoundaryIs" :
"gml:exterior";
1671 boundaryName = ( gmlVersion ==
GML_2_1_2 ) ?
"gml:innerBoundaryIs" :
"gml:interior";
1673 QDomElement boundaryElem = doc.createElement( boundaryName );
1674 QDomElement ringElem = doc.createElement( QStringLiteral(
"gml:LinearRing" ) );
1679 QDomElement coordElem = baseCoordElem.cloneNode().toElement();
1680 QString coordString;
1681 for (
int jdx = 0; jdx < nPoints; jdx++ )
1690 if ( invertAxisOrientation )
1705 const QDomText coordText = doc.createTextNode( coordString );
1706 coordElem.appendChild( coordText );
1708 coordElem.setAttribute( QStringLiteral(
"srsDimension" ), hasZValue ? QStringLiteral(
"3" ) : QStringLiteral(
"2" ) );
1709 ringElem.appendChild( coordElem );
1710 boundaryElem.appendChild( ringElem );
1711 polygonElem.appendChild( boundaryElem );
1712 polygonMemberElem.appendChild( polygonElem );
1713 multiPolygonElem.appendChild( polygonMemberElem );
1716 return multiPolygonElem;
1719 return QDomElement();
1725 return QDomElement();
1731 return geometryToGML( geometry, doc, QStringLiteral(
"GML2" ), precision );
1734QDomElement QgsOgcUtils::createGMLCoordinates(
const QgsPolylineXY &points, QDomDocument &doc )
1736 QDomElement coordElem = doc.createElement( QStringLiteral(
"gml:coordinates" ) );
1737 coordElem.setAttribute( QStringLiteral(
"cs" ), QStringLiteral(
"," ) );
1738 coordElem.setAttribute( QStringLiteral(
"ts" ), QStringLiteral(
" " ) );
1740 QString coordString;
1741 QVector<QgsPointXY>::const_iterator pointIt = points.constBegin();
1742 for ( ; pointIt != points.constEnd(); ++pointIt )
1744 if ( pointIt != points.constBegin() )
1753 const QDomText coordText = doc.createTextNode( coordString );
1754 coordElem.appendChild( coordText );
1758QDomElement QgsOgcUtils::createGMLPositions(
const QgsPolylineXY &points, QDomDocument &doc )
1760 QDomElement posElem = doc.createElement( QStringLiteral(
"gml:pos" ) );
1761 if ( points.size() > 1 )
1762 posElem = doc.createElement( QStringLiteral(
"gml:posList" ) );
1763 posElem.setAttribute( QStringLiteral(
"srsDimension" ), QStringLiteral(
"2" ) );
1765 QString coordString;
1766 QVector<QgsPointXY>::const_iterator pointIt = points.constBegin();
1767 for ( ; pointIt != points.constEnd(); ++pointIt )
1769 if ( pointIt != points.constBegin() )
1778 const QDomText coordText = doc.createTextNode( coordString );
1779 posElem.appendChild( coordText );
1789 if ( fillElement.isNull() || !fillElement.hasChildNodes() )
1797 QDomElement cssElem = fillElement.firstChildElement( QStringLiteral(
"CssParameter" ) );
1798 while ( !cssElem.isNull() )
1800 cssName = cssElem.attribute( QStringLiteral(
"name" ), QStringLiteral(
"not_found" ) );
1801 if ( cssName != QLatin1String(
"not_found" ) )
1803 elemText = cssElem.text();
1804 if ( cssName == QLatin1String(
"fill" ) )
1806 color.setNamedColor( elemText );
1808 else if ( cssName == QLatin1String(
"fill-opacity" ) )
1811 const double opacity = elemText.toDouble( &ok );
1814 color.setAlphaF( opacity );
1819 cssElem = cssElem.nextSiblingElement( QStringLiteral(
"CssParameter" ) );
1833 if ( element.isNull() || !element.hasChildNodes() )
1840 if ( element.firstChild().nodeType() == QDomNode::TextNode )
1850 QDomElement childElem = element.firstChildElement();
1851 while ( !childElem.isNull() )
1863 if ( !expr->d->mRootNode )
1865 expr->d->mRootNode.reset( node );
1872 childElem = childElem.nextSiblingElement();
1876 expr->d->mExp = expr->
dump();
1902static int binaryOperatorFromTagName(
const QString &tagName )
1905 return BINARY_OPERATORS_TAG_NAMES_MAP()->value( tagName, -1 );
1912 return QStringLiteral(
"PropertyIsLike" );
1914 return BINARY_OPERATORS_TAG_NAMES_MAP()->key( op, QString() );
1917static bool isBinaryOperator(
const QString &tagName )
1919 return binaryOperatorFromTagName( tagName ) >= 0;
1923static bool isSpatialOperator(
const QString &tagName )
1925 static QStringList spatialOps;
1926 if ( spatialOps.isEmpty() )
1928 spatialOps << QStringLiteral(
"BBOX" ) << QStringLiteral(
"Intersects" ) << QStringLiteral(
"Contains" ) << QStringLiteral(
"Crosses" ) << QStringLiteral(
"Equals" )
1929 << QStringLiteral(
"Disjoint" ) << QStringLiteral(
"Overlaps" ) << QStringLiteral(
"Touches" ) << QStringLiteral(
"Within" );
1932 return spatialOps.contains( tagName );
1938 QgsExpressionNode *node = utils.nodeFromOgcFilter( element );
1939 errorMessage = utils.errorMessage();
1946 QgsExpressionNodeBinaryOperator *node = utils.nodeBinaryOperatorFromOgcFilter( element );
1947 errorMessage = utils.errorMessage();
1954 QgsExpressionNodeFunction *node = utils.nodeSpatialOperatorFromOgcFilter( element );
1955 errorMessage = utils.errorMessage();
1962 QgsExpressionNodeUnaryOperator *node = utils.nodeNotFromOgcFilter( element );
1963 errorMessage = utils.errorMessage();
1970 QgsExpressionNodeFunction *node = utils.nodeFunctionFromOgcFilter( element );
1971 errorMessage = utils.errorMessage();
1978 QgsExpressionNode *node = utils.nodeLiteralFromOgcFilter( element );
1979 errorMessage = utils.errorMessage();
1986 QgsExpressionNodeColumnRef *node = utils.nodeColumnRefFromOgcFilter( element );
1987 errorMessage = utils.errorMessage();
1991QgsExpressionNode *QgsOgcUtils::nodeIsBetweenFromOgcFilter( QDomElement &element, QString &errorMessage )
1994 QgsExpressionNode *node = utils.nodeIsBetweenFromOgcFilter( element );
1995 errorMessage = utils.errorMessage();
2002 QgsExpressionNodeBinaryOperator *node = utils.nodePropertyIsNullFromOgcFilter( element );
2003 errorMessage = utils.errorMessage();
2014 QStringLiteral(
"geometry" ), QString(),
false,
false, errorMessage );
2020 QStringLiteral(
"geometry" ), QString(),
false,
false, errorMessage, requiresFilterElement );
2025 return doc.createElementNS(
SE_NAMESPACE, QStringLiteral(
"se:ElseFilter" ) );
2033 const QString &namespacePrefix,
2034 const QString &namespaceURI,
2035 const QString &geometryName,
2036 const QString &srsName,
2037 bool honourAxisOrientation,
2038 bool invertAxisOrientation,
2039 QString *errorMessage,
2040 const QMap<QString, QString> &fieldNameToXPathMap,
2041 const QMap<QString, QString> &namespacePrefixToUriMap )
2044 return QDomElement();
2050 QgsOgcUtilsExprToFilter utils( doc, gmlVersion, filterVersion, namespacePrefix, namespaceURI, geometryName, srsName, honourAxisOrientation, invertAxisOrientation, fieldNameToXPathMap, namespacePrefixToUriMap );
2054 if ( exprRootElem.isNull() )
2055 return QDomElement();
2057 QDomElement filterElem = filterElement( doc, gmlVersion, filterVersion, utils.
GMLNamespaceUsed() );
2059 if ( !namespacePrefix.isEmpty() && !namespaceURI.isEmpty() )
2061 QDomAttr attr = doc.createAttribute( QStringLiteral(
"xmlns:" ) + namespacePrefix );
2062 attr.setValue( namespaceURI );
2063 filterElem.setAttributeNode( attr );
2066 filterElem.appendChild( exprRootElem );
2074 const QString &geometryName,
2075 const QString &srsName,
2076 bool honourAxisOrientation,
2077 bool invertAxisOrientation,
2078 QString *errorMessage,
2079 bool requiresFilterElement,
2080 const QMap<QString, QString> &fieldNameToXPathMap,
2081 const QMap<QString, QString> &namespacePrefixToUriMap )
2090 return QDomElement();
2092 QgsOgcUtilsExprToFilter utils( doc, gmlVersion, filterVersion, QString(), QString(), geometryName, srsName, honourAxisOrientation, invertAxisOrientation, fieldNameToXPathMap, namespacePrefixToUriMap );
2100 if ( !exprRootElem.isNull() )
2102 if ( requiresFilterElement )
2104 QDomElement filterElem = filterElement( doc, gmlVersion, filterVersion, utils.
GMLNamespaceUsed() );
2106 filterElem.appendChild( exprRootElem );
2109 return exprRootElem;
2112 return QDomElement();
2119 const QList<LayerProperties> &layerProperties,
2120 bool honourAxisOrientation,
2121 bool invertAxisOrientation,
2122 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
2123 QString *errorMessage,
2124 const QMap<QString, QString> &fieldNameToXPathMap,
2125 const QMap<QString, QString> &namespacePrefixToUriMap )
2128 return QDomElement();
2131 layerProperties, honourAxisOrientation, invertAxisOrientation,
2132 mapUnprefixedTypenameToPrefixedTypename, fieldNameToXPathMap, namespacePrefixToUriMap );
2136 if ( exprRootElem.isNull() )
2137 return QDomElement();
2139 QDomElement filterElem = filterElement( doc, gmlVersion, filterVersion, utils.
GMLNamespaceUsed() );
2141 QSet<QString> setNamespaceURI;
2144 if ( !props.mNamespacePrefix.isEmpty() && !props.mNamespaceURI.isEmpty() &&
2145 !setNamespaceURI.contains( props.mNamespaceURI ) )
2147 setNamespaceURI.insert( props.mNamespaceURI );
2148 QDomAttr attr = doc.createAttribute( QStringLiteral(
"xmlns:" ) + props.mNamespacePrefix );
2149 attr.setValue( props.mNamespaceURI );
2150 filterElem.setAttributeNode( attr );
2153 filterElem.appendChild( exprRootElem );
2178 mErrorMessage = QObject::tr(
"Node type not supported: %1" ).arg( node->
nodeType() );
2179 return QDomElement();
2186 if ( !mErrorMessage.isEmpty() )
2187 return QDomElement();
2190 switch ( node->
op() )
2193 uoElem = mDoc.createElement( mFilterPrefix +
":Literal" );
2198 uoElem.appendChild( mDoc.createTextNode(
"-" + operandElem.text() ) );
2199 mDoc.removeChild( operandElem );
2203 mErrorMessage = QObject::tr(
"This use of unary operator not implemented yet" );
2204 return QDomElement();
2208 uoElem = mDoc.createElement( mFilterPrefix +
":Not" );
2209 uoElem.appendChild( operandElem );
2213 mErrorMessage = QObject::tr(
"Unary operator '%1' not implemented yet" ).arg( node->
text() );
2214 return QDomElement();
2224 if ( !mErrorMessage.isEmpty() )
2225 return QDomElement();
2234 const QgsExpressionNodeLiteral *rightLit =
static_cast<const QgsExpressionNodeLiteral *
>( node->
opRight() );
2238 QDomElement elem = mDoc.createElement( mFilterPrefix +
":PropertyIsNull" );
2239 elem.appendChild( leftElem );
2243 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2244 notElem.appendChild( elem );
2258 if ( !mErrorMessage.isEmpty() )
2259 return QDomElement();
2262 const QString opText = binaryOperatorToTagName( op );
2263 if ( opText.isEmpty() )
2267 mErrorMessage = QObject::tr(
"Binary operator %1 not implemented yet" ).arg( node->
text() );
2268 return QDomElement();
2271 QDomElement boElem = mDoc.createElement( mFilterPrefix +
":" + opText );
2276 boElem.setAttribute( QStringLiteral(
"matchCase" ), QStringLiteral(
"false" ) );
2279 boElem.setAttribute( QStringLiteral(
"wildCard" ), QStringLiteral(
"%" ) );
2280 boElem.setAttribute( QStringLiteral(
"singleChar" ), QStringLiteral(
"_" ) );
2282 boElem.setAttribute( QStringLiteral(
"escape" ), QStringLiteral(
"\\" ) );
2284 boElem.setAttribute( QStringLiteral(
"escapeChar" ), QStringLiteral(
"\\" ) );
2287 boElem.appendChild( leftElem );
2288 boElem.appendChild( rightElem );
2295 Q_UNUSED( expression )
2298 switch ( node->
value().userType() )
2300 case QMetaType::Type::Int:
2301 value = QString::number( node->
value().toInt() );
2303 case QMetaType::Type::Double:
2306 case QMetaType::Type::QString:
2307 value = node->
value().toString();
2309 case QMetaType::Type::QDate:
2310 value = node->
value().toDate().toString( Qt::ISODate );
2312 case QMetaType::Type::QDateTime:
2313 value = node->
value().toDateTime().toString( Qt::ISODate );
2317 mErrorMessage = QObject::tr(
"Literal type not supported: %1" ).arg(
static_cast<QMetaType::Type
>( node->
value().userType() ) );
2318 return QDomElement();
2321 QDomElement litElem = mDoc.createElement( mFilterPrefix +
":Literal" );
2322 litElem.appendChild( mDoc.createTextNode( value ) );
2329 Q_UNUSED( expression )
2331 QDomElement propElem = mDoc.createElement( mFilterPrefix +
":" + mPropertyName );
2332 if ( !mFieldNameToXPathMap.isEmpty() )
2334 const auto iterFieldName = mFieldNameToXPathMap.constFind( node->
name() );
2335 if ( iterFieldName != mFieldNameToXPathMap.constEnd() )
2337 const QString xpath( *iterFieldName );
2339 if ( !mNamespacePrefixToUriMap.isEmpty() )
2341 const QStringList parts = xpath.split(
'/' );
2342 QSet<QString> setNamespacePrefix;
2343 for (
const QString &part : std::as_const( parts ) )
2345 const QStringList subparts = part.split(
':' );
2346 if ( subparts.size() == 2 && !setNamespacePrefix.contains( subparts[0] ) )
2348 const auto iterNamespacePrefix = mNamespacePrefixToUriMap.constFind( subparts[0] );
2349 if ( iterNamespacePrefix != mNamespacePrefixToUriMap.constEnd() )
2351 setNamespacePrefix.insert( subparts[0] );
2352 QDomAttr attr = mDoc.createAttribute( QStringLiteral(
"xmlns:" ) + subparts[0] );
2353 attr.setValue( *iterNamespacePrefix );
2354 propElem.setAttributeNode( attr );
2360 propElem.appendChild( mDoc.createTextNode( xpath ) );
2365 QString columnRef( node->
name() );
2366 if ( !mNamespacePrefix.isEmpty() && !mNamespaceURI.isEmpty() )
2367 columnRef = mNamespacePrefix + QStringLiteral(
":" ) + columnRef;
2368 propElem.appendChild( mDoc.createTextNode( columnRef ) );
2376 if ( node->
list()->
list().size() == 1 )
2380 QDomElement eqElem = mDoc.createElement( mFilterPrefix +
":PropertyIsEqualTo" );
2381 eqElem.appendChild( leftNode );
2382 eqElem.appendChild( firstListNode );
2385 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2386 notElem.appendChild( eqElem );
2392 QDomElement orElem = mDoc.createElement( mFilterPrefix +
":Or" );
2395 const auto constList = node->
list()->
list();
2396 for ( QgsExpressionNode *n : constList )
2399 if ( !mErrorMessage.isEmpty() )
2400 return QDomElement();
2402 QDomElement eqElem = mDoc.createElement( mFilterPrefix +
":PropertyIsEqualTo" );
2403 eqElem.appendChild( leftNode.cloneNode() );
2404 eqElem.appendChild( listNode );
2406 orElem.appendChild( eqElem );
2411 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2412 notElem.appendChild( orElem );
2421 { QLatin1String(
"disjoint" ), QLatin1String(
"Disjoint" ) },
2422 { QLatin1String(
"intersects" ), QLatin1String(
"Intersects" )},
2423 { QLatin1String(
"touches" ), QLatin1String(
"Touches" ) },
2424 { QLatin1String(
"crosses" ), QLatin1String(
"Crosses" ) },
2425 { QLatin1String(
"contains" ), QLatin1String(
"Contains" ) },
2426 { QLatin1String(
"overlaps" ), QLatin1String(
"Overlaps" ) },
2427 { QLatin1String(
"within" ), QLatin1String(
"Within" ) }
2430static bool isBinarySpatialOperator(
const QString &fnName )
2432 return BINARY_SPATIAL_OPS_MAP()->contains( fnName );
2435static QString tagNameForSpatialOperator(
const QString &fnName )
2437 return BINARY_SPATIAL_OPS_MAP()->value( fnName );
2447 return fd->
name() == QLatin1String(
"$geometry" ) || ( fd->
name() == QLatin1String(
"var" ) && fn->
referencedVariables().contains( QLatin1String(
"geometry" ) ) );
2459 if ( fnDef->
name() == QLatin1String(
"geom_from_wkt" ) )
2461 const QList<QgsExpressionNode *> &args = fnNode->
args()->
list();
2477 if ( fd->
name() == QLatin1String(
"intersects_bbox" ) )
2479 QList<QgsExpressionNode *> argNodes = node->
args()->
list();
2480 Q_ASSERT( argNodes.count() == 2 );
2482 const QgsGeometry geom = geometryFromConstExpr( argNodes[1] );
2483 if ( !geom.
isNull() && isGeometryColumn( argNodes[0] ) )
2493 QDomElement funcElem = mDoc.createElement( mFilterPrefix +
":BBOX" );
2495 if ( !mGeometryName.isEmpty() )
2498 QDomElement geomProperty = mDoc.createElement( mFilterPrefix +
":" + mPropertyName );
2499 QString columnRef( mGeometryName );
2500 if ( !mNamespacePrefix.isEmpty() && !mNamespaceURI.isEmpty() )
2501 columnRef = mNamespacePrefix + QStringLiteral(
":" ) + columnRef;
2502 geomProperty.appendChild( mDoc.createTextNode( columnRef ) );
2504 funcElem.appendChild( geomProperty );
2506 funcElem.appendChild( elemBox );
2511 mErrorMessage = QObject::tr(
"<BBOX> is currently supported only in form: bbox(@geometry, geomFromWKT('…'))" );
2512 return QDomElement();
2516 if ( isBinarySpatialOperator( fd->
name() ) )
2518 QList<QgsExpressionNode *> argNodes = node->
args()->
list();
2519 Q_ASSERT( argNodes.count() == 2 );
2521 QgsExpressionNode *otherNode =
nullptr;
2522 if ( isGeometryColumn( argNodes[0] ) )
2523 otherNode = argNodes[1];
2524 else if ( isGeometryColumn( argNodes[1] ) )
2525 otherNode = argNodes[0];
2528 mErrorMessage = QObject::tr(
"Unable to translate spatial operator: at least one must refer to geometry." );
2529 return QDomElement();
2532 QDomElement otherGeomElem;
2537 mErrorMessage = QObject::tr(
"spatial operator: the other operator must be a geometry constructor function" );
2538 return QDomElement();
2541 const QgsExpressionNodeFunction *otherFn =
static_cast<const QgsExpressionNodeFunction *
>( otherNode );
2543 if ( otherFnDef->
name() == QLatin1String(
"geom_from_wkt" ) )
2545 QgsExpressionNode *firstFnArg = otherFn->
args()->
list()[0];
2548 mErrorMessage = QObject::tr(
"geom_from_wkt: argument must be string literal" );
2549 return QDomElement();
2551 const QString wkt =
static_cast<const QgsExpressionNodeLiteral *
>( firstFnArg )->value().toString();
2554 QStringLiteral(
"qgis_id_geom_%1" ).arg( mGeomId ) );
2555 if ( otherGeomElem.isNull() )
2557 mErrorMessage = QObject::tr(
"geom_from_wkt: unable to generate GML from wkt geometry" );
2558 return QDomElement();
2562 else if ( otherFnDef->
name() == QLatin1String(
"geom_from_gml" ) )
2564 QgsExpressionNode *firstFnArg = otherFn->
args()->
list()[0];
2567 mErrorMessage = QObject::tr(
"geom_from_gml: argument must be string literal" );
2568 return QDomElement();
2571 QDomDocument geomDoc;
2572 const QString gml =
static_cast<const QgsExpressionNodeLiteral *
>( firstFnArg )->value().toString();
2574 const QString xml = QStringLiteral(
"<tmp xmlns:gml=\"%1\">%2</tmp>" ).arg(
GML_NAMESPACE, gml );
2575 if ( !geomDoc.setContent( xml,
true ) )
2577 mErrorMessage = QObject::tr(
"geom_from_gml: unable to parse XML" );
2578 return QDomElement();
2581 const QDomNode geomNode = mDoc.importNode( geomDoc.documentElement().firstChildElement(),
true );
2582 otherGeomElem = geomNode.toElement();
2588 QStringLiteral(
"qgis_id_geom_%1" ).arg( mGeomId ) );
2589 if ( otherGeomElem.
isNull() )
2591 mErrorMessage = QObject::tr(
"geom from static value: unable to generate GML from static variable" );
2592 return QDomElement();
2598 mErrorMessage = QObject::tr(
"spatial operator: unknown geometry constructor function" );
2599 return QDomElement();
2604 QDomElement funcElem = mDoc.createElement( mFilterPrefix +
":" + tagNameForSpatialOperator( fd->
name() ) );
2605 QDomElement geomProperty = mDoc.createElement( mFilterPrefix +
":" + mPropertyName );
2606 QString columnRef( mGeometryName );
2607 if ( !mNamespacePrefix.isEmpty() && !mNamespaceURI.isEmpty() )
2608 columnRef = mNamespacePrefix + QStringLiteral(
":" ) + columnRef;
2609 geomProperty.appendChild( mDoc.createTextNode( columnRef ) );
2610 funcElem.appendChild( geomProperty );
2611 funcElem.appendChild( otherGeomElem );
2615 if ( fd->
isStatic( node, expression, context ) )
2617 const QVariant result = fd->
run( node->
args(), context, expression, node );
2618 const QgsExpressionNodeLiteral literal( result );
2619 return expressionLiteralToOgcFilter( &literal, expression, context );
2624 mErrorMessage = QObject::tr(
"Special columns/constants are not supported." );
2625 return QDomElement();
2629 QDomElement funcElem = mDoc.createElement( mFilterPrefix +
":Function" );
2630 funcElem.setAttribute( QStringLiteral(
"name" ), fd->
name() );
2631 const auto constList = node->
args()->
list();
2632 for ( QgsExpressionNode *n : constList )
2635 if ( !mErrorMessage.isEmpty() )
2636 return QDomElement();
2638 funcElem.appendChild( childElem );
2649 const QList<QgsOgcUtils::LayerProperties> &layerProperties,
2650 bool honourAxisOrientation,
2651 bool invertAxisOrientation,
2652 const QMap< QString, QString> &mapUnprefixedTypenameToPrefixedTypename,
2653 const QMap<QString, QString> &fieldNameToXPathMap,
2654 const QMap<QString, QString> &namespacePrefixToUriMap )
2656 , mGMLVersion( gmlVersion )
2657 , mFilterVersion( filterVersion )
2658 , mLayerProperties( layerProperties )
2659 , mHonourAxisOrientation( honourAxisOrientation )
2660 , mInvertAxisOrientation( invertAxisOrientation )
2661 , mFilterPrefix( ( filterVersion ==
QgsOgcUtils::FILTER_FES_2_0 ) ?
"fes" :
"ogc" )
2662 , mPropertyName( ( filterVersion ==
QgsOgcUtils::FILTER_FES_2_0 ) ?
"ValueReference" :
"PropertyName" )
2663 , mMapUnprefixedTypenameToPrefixedTypename( mapUnprefixedTypenameToPrefixedTypename )
2664 , mFieldNameToXPathMap( fieldNameToXPathMap )
2665 , mNamespacePrefixToUriMap( namespacePrefixToUriMap )
2691 mErrorMessage = QObject::tr(
"Node type not supported: %1" ).arg( node->
nodeType() );
2692 return QDomElement();
2701 if ( !mErrorMessage.isEmpty() )
2702 return QDomElement();
2705 switch ( node->
op() )
2708 uoElem = mDoc.createElement( mFilterPrefix +
":Literal" );
2713 uoElem.appendChild( mDoc.createTextNode(
"-" + operandElem.text() ) );
2714 mDoc.removeChild( operandElem );
2718 mErrorMessage = QObject::tr(
"This use of unary operator not implemented yet" );
2719 return QDomElement();
2723 uoElem = mDoc.createElement( mFilterPrefix +
":Not" );
2724 uoElem.appendChild( operandElem );
2729 return QDomElement();
2739 if ( !mErrorMessage.isEmpty() )
2740 return QDomElement();
2749 const QgsSQLStatement::NodeLiteral *rightLit =
static_cast<const QgsSQLStatement::NodeLiteral *
>( node->
opRight() );
2753 QDomElement elem = mDoc.createElement( mFilterPrefix +
":PropertyIsNull" );
2754 elem.appendChild( leftElem );
2758 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2759 notElem.appendChild( elem );
2773 if ( !mErrorMessage.isEmpty() )
2774 return QDomElement();
2779 opText = QStringLiteral(
"Or" );
2781 opText = QStringLiteral(
"And" );
2783 opText = QStringLiteral(
"PropertyIsEqualTo" );
2785 opText = QStringLiteral(
"PropertyIsNotEqualTo" );
2787 opText = QStringLiteral(
"PropertyIsLessThanOrEqualTo" );
2789 opText = QStringLiteral(
"PropertyIsGreaterThanOrEqualTo" );
2791 opText = QStringLiteral(
"PropertyIsLessThan" );
2793 opText = QStringLiteral(
"PropertyIsGreaterThan" );
2795 opText = QStringLiteral(
"PropertyIsLike" );
2797 opText = QStringLiteral(
"PropertyIsLike" );
2799 if ( opText.isEmpty() )
2803 return QDomElement();
2806 QDomElement boElem = mDoc.createElement( mFilterPrefix +
":" + opText );
2811 boElem.setAttribute( QStringLiteral(
"matchCase" ), QStringLiteral(
"false" ) );
2814 boElem.setAttribute( QStringLiteral(
"wildCard" ), QStringLiteral(
"%" ) );
2815 boElem.setAttribute( QStringLiteral(
"singleChar" ), QStringLiteral(
"_" ) );
2817 boElem.setAttribute( QStringLiteral(
"escape" ), QStringLiteral(
"\\" ) );
2819 boElem.setAttribute( QStringLiteral(
"escapeChar" ), QStringLiteral(
"\\" ) );
2822 boElem.appendChild( leftElem );
2823 boElem.appendChild( rightElem );
2831 switch ( node->
value().userType() )
2833 case QMetaType::Type::Int:
2834 value = QString::number( node->
value().toInt() );
2836 case QMetaType::Type::LongLong:
2837 value = QString::number( node->
value().toLongLong() );
2839 case QMetaType::Type::Double:
2842 case QMetaType::Type::QString:
2843 value = node->
value().toString();
2847 mErrorMessage = QObject::tr(
"Literal type not supported: %1" ).arg(
static_cast<QMetaType::Type
>( node->
value().userType() ) );
2848 return QDomElement();
2851 QDomElement litElem = mDoc.createElement( mFilterPrefix +
":Literal" );
2852 litElem.appendChild( mDoc.createTextNode( value ) );
2859 QDomElement propElem = mDoc.createElement( mFilterPrefix +
":" + mPropertyName );
2860 if ( node->
tableName().isEmpty() || mLayerProperties.size() == 1 )
2862 if ( !mFieldNameToXPathMap.isEmpty() )
2864 const auto iterFieldName = mFieldNameToXPathMap.constFind( node->
name() );
2865 if ( iterFieldName != mFieldNameToXPathMap.constEnd() )
2867 const QString xpath( *iterFieldName );
2869 if ( !mNamespacePrefixToUriMap.isEmpty() )
2871 const QStringList parts = xpath.split(
'/' );
2872 QSet<QString> setNamespacePrefix;
2873 for (
const QString &part : std::as_const( parts ) )
2875 const QStringList subparts = part.split(
':' );
2876 if ( subparts.size() == 2 && !setNamespacePrefix.contains( subparts[0] ) )
2878 const auto iterNamespacePrefix = mNamespacePrefixToUriMap.constFind( subparts[0] );
2879 if ( iterNamespacePrefix != mNamespacePrefixToUriMap.constEnd() )
2881 setNamespacePrefix.insert( subparts[0] );
2882 QDomAttr attr = mDoc.createAttribute( QStringLiteral(
"xmlns:" ) + subparts[0] );
2883 attr.setValue( *iterNamespacePrefix );
2884 propElem.setAttributeNode( attr );
2890 propElem.appendChild( mDoc.createTextNode( xpath ) );
2895 if ( mLayerProperties.size() == 1 && !mLayerProperties[0].mNamespacePrefix.isEmpty() && !mLayerProperties[0].mNamespaceURI.isEmpty() )
2896 propElem.appendChild( mDoc.createTextNode(
2897 mLayerProperties[0].mNamespacePrefix + QStringLiteral(
":" ) + node->
name() ) );
2899 propElem.appendChild( mDoc.createTextNode( node->
name() ) );
2903 QString tableName( mMapTableAliasToNames[node->
tableName()] );
2904 if ( mMapUnprefixedTypenameToPrefixedTypename.contains( tableName ) )
2905 tableName = mMapUnprefixedTypenameToPrefixedTypename[tableName];
2906 propElem.appendChild( mDoc.createTextNode( tableName +
"/" + node->
name() ) );
2913 if ( node->
list()->
list().size() == 1 )
2917 QDomElement eqElem = mDoc.createElement( mFilterPrefix +
":PropertyIsEqualTo" );
2918 eqElem.appendChild( leftNode );
2919 eqElem.appendChild( firstListNode );
2922 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2923 notElem.appendChild( eqElem );
2929 QDomElement orElem = mDoc.createElement( mFilterPrefix +
":Or" );
2932 const auto constList = node->
list()->
list();
2933 for ( QgsSQLStatement::Node *n : constList )
2936 if ( !mErrorMessage.isEmpty() )
2937 return QDomElement();
2939 QDomElement eqElem = mDoc.createElement( mFilterPrefix +
":PropertyIsEqualTo" );
2940 eqElem.appendChild( leftNode.cloneNode() );
2941 eqElem.appendChild( listNode );
2943 orElem.appendChild( eqElem );
2948 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2949 notElem.appendChild( orElem );
2958 QDomElement elem = mDoc.createElement( mFilterPrefix +
":PropertyIsBetween" );
2960 QDomElement lowerBoundary = mDoc.createElement( mFilterPrefix +
":LowerBoundary" );
2962 elem.appendChild( lowerBoundary );
2963 QDomElement upperBoundary = mDoc.createElement( mFilterPrefix +
":UpperBoundary" );
2965 elem.appendChild( upperBoundary );
2969 QDomElement notElem = mDoc.createElement( mFilterPrefix +
":Not" );
2970 notElem.appendChild( elem );
2977static QString mapBinarySpatialToOgc(
const QString &name )
2979 QString nameCompare( name );
2980 if ( name.size() > 3 && QStringView {name} .mid( 0, 3 ).toString().compare( QLatin1String(
"ST_" ), Qt::CaseInsensitive ) == 0 )
2981 nameCompare = name.mid( 3 );
2982 QStringList spatialOps;
2983 spatialOps << QStringLiteral(
"BBOX" ) << QStringLiteral(
"Intersects" ) << QStringLiteral(
"Contains" ) << QStringLiteral(
"Crosses" ) << QStringLiteral(
"Equals" )
2984 << QStringLiteral(
"Disjoint" ) << QStringLiteral(
"Overlaps" ) << QStringLiteral(
"Touches" ) << QStringLiteral(
"Within" );
2985 const auto constSpatialOps = spatialOps;
2986 for ( QString op : constSpatialOps )
2988 if ( nameCompare.compare( op, Qt::CaseInsensitive ) == 0 )
2994static QString mapTernarySpatialToOgc(
const QString &name )
2996 QString nameCompare( name );
2997 if ( name.size() > 3 && QStringView {name} .mid( 0, 3 ).compare( QLatin1String(
"ST_" ), Qt::CaseInsensitive ) == 0 )
2998 nameCompare = name.mid( 3 );
2999 if ( nameCompare.compare( QLatin1String(
"DWithin" ), Qt::CaseInsensitive ) == 0 )
3000 return QStringLiteral(
"DWithin" );
3001 if ( nameCompare.compare( QLatin1String(
"Beyond" ), Qt::CaseInsensitive ) == 0 )
3002 return QStringLiteral(
"Beyond" );
3006QString QgsOgcUtilsSQLStatementToFilter::getGeometryColumnSRSName(
const QgsSQLStatement::Node *node )
3011 const QgsSQLStatement::NodeColumnRef *col =
static_cast<const QgsSQLStatement::NodeColumnRef *
>( node );
3014 const auto constMLayerProperties = mLayerProperties;
3015 for (
const QgsOgcUtils::LayerProperties &prop : constMLayerProperties )
3017 if ( prop.mName.compare( mMapTableAliasToNames[col->
tableName()], Qt::CaseInsensitive ) == 0 &&
3018 prop.mGeometryAttribute.compare( col->
name(), Qt::CaseInsensitive ) == 0 )
3020 return prop.mSRSName;
3024 if ( !mLayerProperties.empty() &&
3025 mLayerProperties.at( 0 ).mGeometryAttribute.compare( col->
name(), Qt::CaseInsensitive ) == 0 )
3027 return mLayerProperties.at( 0 ).mSRSName;
3033 QList<QgsSQLStatement::Node *> args,
3034 bool lastArgIsSRSName,
3036 bool &axisInversion )
3038 srsName = mCurrentSRSName;
3039 axisInversion = mInvertAxisOrientation;
3041 if ( lastArgIsSRSName )
3043 QgsSQLStatement::Node *lastArg = args[ args.size() - 1 ];
3046 mErrorMessage = QObject::tr(
"%1: Last argument must be string or integer literal" ).arg( mainNode->
name() );
3049 const QgsSQLStatement::NodeLiteral *lit =
static_cast<const QgsSQLStatement::NodeLiteral *
>( lastArg );
3050 if ( lit->
value().userType() == QMetaType::Type::Int )
3054 srsName =
"EPSG:" + QString::number( lit->
value().toInt() );
3058 srsName =
"urn:ogc:def:crs:EPSG::" + QString::number( lit->
value().toInt() );
3063 srsName = lit->
value().toString();
3064 if ( srsName.startsWith( QLatin1String(
"EPSG:" ), Qt::CaseInsensitive ) )
3069 QgsCoordinateReferenceSystem crs;
3070 if ( !srsName.isEmpty() )
3076 axisInversion = !axisInversion;
3086 if ( node->
name().compare( QLatin1String(
"ST_GeometryFromText" ), Qt::CaseInsensitive ) == 0 )
3088 QList<QgsSQLStatement::Node *> args = node->
args()->
list();
3089 if ( args.size() != 1 && args.size() != 2 )
3091 mErrorMessage = QObject::tr(
"Function %1 should have 1 or 2 arguments" ).arg( node->
name() );
3092 return QDomElement();
3095 QgsSQLStatement::Node *firstFnArg = args[0];
3098 mErrorMessage = QObject::tr(
"%1: First argument must be string literal" ).arg( node->
name() );
3099 return QDomElement();
3104 if ( ! processSRSName( node, args, args.size() == 2, srsName, axisInversion ) )
3106 return QDomElement();
3109 const QString wkt =
static_cast<const QgsSQLStatement::NodeLiteral *
>( firstFnArg )->value().toString();
3112 QStringLiteral(
"qgis_id_geom_%1" ).arg( mGeomId ) );
3114 if ( geomElem.isNull() )
3116 mErrorMessage = QObject::tr(
"%1: invalid WKT" ).arg( node->
name() );
3117 return QDomElement();
3124 if ( node->
name().compare( QLatin1String(
"ST_MakeEnvelope" ), Qt::CaseInsensitive ) == 0 )
3126 QList<QgsSQLStatement::Node *> args = node->
args()->
list();
3127 if ( args.size() != 4 && args.size() != 5 )
3129 mErrorMessage = QObject::tr(
"Function %1 should have 4 or 5 arguments" ).arg( node->
name() );
3130 return QDomElement();
3135 for (
int i = 0; i < 4; i++ )
3137 QgsSQLStatement::Node *arg = args[i];
3140 mErrorMessage = QObject::tr(
"%1: Argument %2 must be numeric literal" ).arg( node->
name() ).arg( i + 1 );
3141 return QDomElement();
3143 const QgsSQLStatement::NodeLiteral *lit =
static_cast<const QgsSQLStatement::NodeLiteral *
>( arg );
3145 if ( lit->
value().userType() == QMetaType::Type::Int )
3146 val = lit->
value().toInt();
3147 else if ( lit->
value().userType() == QMetaType::Type::LongLong )
3148 val = lit->
value().toLongLong();
3149 else if ( lit->
value().userType() == QMetaType::Type::Double )
3150 val = lit->
value().toDouble();
3153 mErrorMessage = QObject::tr(
"%1 Argument %2 must be numeric literal" ).arg( node->
name() ).arg( i + 1 );
3154 return QDomElement();
3168 if ( ! processSRSName( node, args, args.size() == 5, srsName, axisInversion ) )
3170 return QDomElement();
3177 QgsOgcUtils::rectangleToGMLEnvelope( &rect, mDoc, srsName, axisInversion, 15 );
3181 if ( node->
name().compare( QLatin1String(
"ST_GeomFromGML" ), Qt::CaseInsensitive ) == 0 )
3183 QList<QgsSQLStatement::Node *> args = node->
args()->
list();
3184 if ( args.size() != 1 )
3186 mErrorMessage = QObject::tr(
"Function %1 should have 1 argument" ).arg( node->
name() );
3187 return QDomElement();
3190 QgsSQLStatement::Node *firstFnArg = args[0];
3193 mErrorMessage = QObject::tr(
"%1: Argument must be string literal" ).arg( node->
name() );
3194 return QDomElement();
3197 QDomDocument geomDoc;
3198 const QString gml =
static_cast<const QgsSQLStatement::NodeLiteral *
>( firstFnArg )->value().toString();
3200 const QString xml = QStringLiteral(
"<tmp xmlns:gml=\"%1\">%2</tmp>" ).arg(
GML_NAMESPACE, gml );
3201 if ( !geomDoc.setContent( xml,
true ) )
3203 mErrorMessage = QObject::tr(
"ST_GeomFromGML: unable to parse XML" );
3204 return QDomElement();
3207 const QDomNode geomNode = mDoc.importNode( geomDoc.documentElement().firstChildElement(),
true );
3209 return geomNode.toElement();
3213 QString ogcName( mapBinarySpatialToOgc( node->
name() ) );
3214 if ( !ogcName.isEmpty() )
3216 QList<QgsSQLStatement::Node *> args = node->
args()->
list();
3217 if ( args.size() != 2 )
3219 mErrorMessage = QObject::tr(
"Function %1 should have 2 arguments" ).arg( node->
name() );
3220 return QDomElement();
3223 for (
int i = 0; i < 2; i ++ )
3226 (
static_cast<const QgsSQLStatement::NodeFunction *
>( args[i] )->name().compare( QLatin1String(
"ST_GeometryFromText" ), Qt::CaseInsensitive ) == 0 ||
3227 static_cast<const QgsSQLStatement::NodeFunction *
>( args[i] )->name().compare( QLatin1String(
"ST_MakeEnvelope" ), Qt::CaseInsensitive ) == 0 ) )
3229 mCurrentSRSName = getGeometryColumnSRSName( args[1 - i] );
3236 QDomElement funcElem = mDoc.createElement( mFilterPrefix +
":" + ogcName );
3237 const auto constArgs = args;
3238 for ( QgsSQLStatement::Node *n : constArgs )
3241 if ( !mErrorMessage.isEmpty() )
3243 mCurrentSRSName.clear();
3244 return QDomElement();
3247 funcElem.appendChild( childElem );
3250 mCurrentSRSName.clear();
3254 ogcName = mapTernarySpatialToOgc( node->
name() );
3255 if ( !ogcName.isEmpty() )
3257 QList<QgsSQLStatement::Node *> args = node->
args()->
list();
3258 if ( args.size() != 3 )
3260 mErrorMessage = QObject::tr(
"Function %1 should have 3 arguments" ).arg( node->
name() );
3261 return QDomElement();
3264 for (
int i = 0; i < 2; i ++ )
3267 (
static_cast<const QgsSQLStatement::NodeFunction *
>( args[i] )->name().compare( QLatin1String(
"ST_GeometryFromText" ), Qt::CaseInsensitive ) == 0 ||
3268 static_cast<const QgsSQLStatement::NodeFunction *
>( args[i] )->name().compare( QLatin1String(
"ST_MakeEnvelope" ), Qt::CaseInsensitive ) == 0 ) )
3270 mCurrentSRSName = getGeometryColumnSRSName( args[1 - i] );
3275 QDomElement funcElem = mDoc.createElement( mFilterPrefix +
":" + node->
name().mid( 3 ) );
3276 for (
int i = 0; i < 2; i++ )
3278 const QDomElement childElem =
toOgcFilter( args[i] );
3279 if ( !mErrorMessage.isEmpty() )
3281 mCurrentSRSName.clear();
3282 return QDomElement();
3285 funcElem.appendChild( childElem );
3287 mCurrentSRSName.clear();
3289 QgsSQLStatement::Node *distanceNode = args[2];
3292 mErrorMessage = QObject::tr(
"Function %1 3rd argument should be a numeric value or a string made of a numeric value followed by a string" ).arg( node->
name() );
3293 return QDomElement();
3295 const QgsSQLStatement::NodeLiteral *lit =
static_cast<const QgsSQLStatement::NodeLiteral *
>( distanceNode );
3298 mErrorMessage = QObject::tr(
"Function %1 3rd argument should be a numeric value or a string made of a numeric value followed by a string" ).arg( node->
name() );
3299 return QDomElement();
3302 QString unit( QStringLiteral(
"m" ) );
3303 switch ( lit->
value().userType() )
3305 case QMetaType::Type::Int:
3306 distance = QString::number( lit->
value().toInt() );
3308 case QMetaType::Type::LongLong:
3309 distance = QString::number( lit->
value().toLongLong() );
3311 case QMetaType::Type::Double:
3314 case QMetaType::Type::QString:
3316 distance = lit->
value().toString();
3317 for (
int i = 0; i < distance.size(); i++ )
3319 if ( !( ( distance[i] >=
'0' && distance[i] <=
'9' ) || distance[i] ==
'-' || distance[i] ==
'.' || distance[i] ==
'e' || distance[i] ==
'E' ) )
3321 unit = distance.mid( i ).trimmed();
3322 distance = distance.mid( 0, i );
3330 mErrorMessage = QObject::tr(
"Literal type not supported: %1" ).arg(
static_cast<QMetaType::Type
>( lit->
value().userType() ) );
3331 return QDomElement();
3334 QDomElement distanceElem = mDoc.createElement( mFilterPrefix +
":Distance" );
3336 distanceElem.setAttribute( QStringLiteral(
"uom" ), unit );
3338 distanceElem.setAttribute( QStringLiteral(
"unit" ), unit );
3339 distanceElem.appendChild( mDoc.createTextNode( distance ) );
3340 funcElem.appendChild( distanceElem );
3345 QDomElement funcElem = mDoc.createElement( mFilterPrefix +
":Function" );
3346 funcElem.setAttribute( QStringLiteral(
"name" ), node->
name() );
3347 const auto constList = node->
args()->
list();
3348 for ( QgsSQLStatement::Node *n : constList )
3351 if ( !mErrorMessage.isEmpty() )
3352 return QDomElement();
3354 funcElem.appendChild( childElem );
3360 const QString &leftTable )
3362 QgsSQLStatement::Node *onExpr = node->
onExpr();
3368 QList<QDomElement> listElem;
3370 for (
const QString &columnName : constUsingColumns )
3372 QDomElement eqElem = mDoc.createElement( mFilterPrefix +
":PropertyIsEqualTo" );
3373 QDomElement propElem1 = mDoc.createElement( mFilterPrefix +
":" + mPropertyName );
3374 propElem1.appendChild( mDoc.createTextNode( leftTable +
"/" + columnName ) );
3375 eqElem.appendChild( propElem1 );
3376 QDomElement propElem2 = mDoc.createElement( mFilterPrefix +
":" + mPropertyName );
3377 propElem2.appendChild( mDoc.createTextNode( node->
tableDef()->
name() +
"/" + columnName ) );
3378 eqElem.appendChild( propElem2 );
3379 listElem.append( eqElem );
3382 if ( listElem.size() == 1 )
3386 else if ( listElem.size() > 1 )
3388 QDomElement andElem = mDoc.createElement( mFilterPrefix +
":And" );
3389 const auto constListElem = listElem;
3390 for (
const QDomElement &elem : constListElem )
3392 andElem.appendChild( elem );
3397 return QDomElement();
3402 if ( node->
alias().isEmpty() )
3404 mMapTableAliasToNames[ node->
name()] = node->
name();
3408 mMapTableAliasToNames[ node->
alias()] = node->
name();
3414 QList<QDomElement> listElem;
3417 ( node->
tables().size() != 1 || !node->
joins().empty() ) )
3419 mErrorMessage = QObject::tr(
"Joins are only supported with WFS 2.0" );
3420 return QDomElement();
3424 const auto constTables = node->
tables();
3425 for ( QgsSQLStatement::NodeTableDef *table : constTables )
3429 const auto constJoins = node->
joins();
3430 for ( QgsSQLStatement::NodeJoin *join : constJoins )
3432 visit( join->tableDef() );
3436 const QList< QgsSQLStatement::NodeTableDef *> nodeTables = node->
tables();
3437 QString leftTable = nodeTables.at( nodeTables.length() - 1 )->name();
3438 for ( QgsSQLStatement::NodeJoin *join : constJoins )
3440 const QDomElement joinElem =
toOgcFilter( join, leftTable );
3441 if ( !mErrorMessage.isEmpty() )
3442 return QDomElement();
3443 listElem.append( joinElem );
3444 leftTable = join->tableDef()->name();
3448 if ( node->
where() )
3451 if ( !mErrorMessage.isEmpty() )
3452 return QDomElement();
3453 listElem.append( whereElem );
3457 if ( listElem.size() == 1 )
3461 else if ( listElem.size() > 1 )
3463 QDomElement andElem = mDoc.createElement( mFilterPrefix +
":And" );
3464 const auto constListElem = listElem;
3465 for (
const QDomElement &elem : constListElem )
3467 andElem.appendChild( elem );
3472 return QDomElement();
3478 mPropertyName = QStringLiteral(
"PropertyName" );
3479 mPrefix = QStringLiteral(
"ogc" );
3483 mPropertyName = QStringLiteral(
"ValueReference" );
3484 mPrefix = QStringLiteral(
"fes" );
3490 if ( element.isNull() )
3494 if ( isBinaryOperator( element.tagName() ) )
3500 if ( isSpatialOperator( element.tagName() ) )
3506 if ( element.tagName() == QLatin1String(
"Not" ) )
3510 else if ( element.tagName() == QLatin1String(
"PropertyIsNull" ) )
3514 else if ( element.tagName() == QLatin1String(
"Literal" ) )
3518 else if ( element.tagName() == QLatin1String(
"Function" ) )
3522 else if ( element.tagName() == mPropertyName )
3526 else if ( element.tagName() == QLatin1String(
"PropertyIsBetween" ) )
3531 mErrorMessage += QObject::tr(
"unable to convert '%1' element to a valid expression: it is not supported yet or it has invalid arguments" ).arg( element.tagName() );
3537 if ( element.isNull() )
3540 int op = binaryOperatorFromTagName( element.tagName() );
3543 mErrorMessage = QObject::tr(
"'%1' binary operator not supported." ).arg( element.tagName() );
3547 if ( op ==
QgsExpressionNodeBinaryOperator::boLike && element.hasAttribute( QStringLiteral(
"matchCase" ) ) && element.attribute( QStringLiteral(
"matchCase" ) ) == QLatin1String(
"false" ) )
3552 QDomElement operandElem = element.firstChildElement();
3557 mErrorMessage = QObject::tr(
"invalid left operand for '%1' binary operator" ).arg( element.tagName() );
3561 const std::unique_ptr<QgsExpressionNode> leftOp( expr->clone() );
3562 for ( operandElem = operandElem.nextSiblingElement(); !operandElem.isNull(); operandElem = operandElem.nextSiblingElement() )
3567 mErrorMessage = QObject::tr(
"invalid right operand for '%1' binary operator" ).arg( element.tagName() );
3574 if ( element.hasAttribute( QStringLiteral(
"wildCard" ) ) )
3576 wildCard = element.attribute( QStringLiteral(
"wildCard" ) );
3579 if ( element.hasAttribute( QStringLiteral(
"singleChar" ) ) )
3581 singleChar = element.attribute( QStringLiteral(
"singleChar" ) );
3583 QString escape = QStringLiteral(
"\\" );
3584 if ( element.hasAttribute( QStringLiteral(
"escape" ) ) )
3586 escape = element.attribute( QStringLiteral(
"escape" ) );
3588 if ( element.hasAttribute( QStringLiteral(
"escapeChar" ) ) )
3590 escape = element.attribute( QStringLiteral(
"escapeChar" ) );
3594 if ( !wildCard.isEmpty() && wildCard != QLatin1String(
"%" ) )
3596 oprValue.replace(
'%', QLatin1String(
"\\%" ) );
3597 if ( oprValue.startsWith( wildCard ) )
3599 oprValue.replace( 0, 1, QStringLiteral(
"%" ) );
3602 QRegularExpressionMatch match = rx.match( oprValue );
3604 while ( match.hasMatch() )
3606 pos = match.capturedStart();
3607 oprValue.replace( pos + 1, 1, QStringLiteral(
"%" ) );
3609 match = rx.match( oprValue, pos );
3611 oprValue.replace( escape + wildCard, wildCard );
3613 if ( !singleChar.isEmpty() && singleChar != QLatin1String(
"_" ) )
3615 oprValue.replace(
'_', QLatin1String(
"\\_" ) );
3616 if ( oprValue.startsWith( singleChar ) )
3618 oprValue.replace( 0, 1, QStringLiteral(
"_" ) );
3621 QRegularExpressionMatch match = rx.match( oprValue );
3623 while ( match.hasMatch() )
3625 pos = match.capturedStart();
3626 oprValue.replace( pos + 1, 1, QStringLiteral(
"_" ) );
3628 match = rx.match( oprValue, pos );
3630 oprValue.replace( escape + singleChar, singleChar );
3632 if ( !escape.isEmpty() && escape != QLatin1String(
"\\" ) )
3634 oprValue.replace( escape + escape, escape );
3636 opRight = std::make_unique<QgsExpressionNodeLiteral>( oprValue );
3642 if ( expr == leftOp )
3644 mErrorMessage = QObject::tr(
"only one operand for '%1' binary operator" ).arg( element.tagName() );
3657 auto gml2Args = std::make_unique<QgsExpressionNode::NodeList>();
3658 QDomElement childElem = element.firstChildElement();
3660 while ( !childElem.isNull() && gml2Str.isEmpty() )
3662 if ( childElem.tagName() != mPropertyName )
3664 QTextStream gml2Stream( &gml2Str );
3665 childElem.save( gml2Stream, 0 );
3667 childElem = childElem.nextSiblingElement();
3669 if ( !gml2Str.isEmpty() )
3675 mErrorMessage = QObject::tr(
"No OGC Geometry found" );
3679 auto opArgs = std::make_unique<QgsExpressionNode::NodeList>();
3688 if ( element.isNull() || element.tagName() != mPropertyName )
3690 mErrorMessage = QObject::tr(
"%1:PropertyName expected, got %2" ).arg( mPrefix, element.tagName() );
3699 if ( element.isNull() || element.tagName() != QLatin1String(
"Literal" ) )
3701 mErrorMessage = QObject::tr(
"%1:Literal expected, got %2" ).arg( mPrefix, element.tagName() );
3705 std::unique_ptr<QgsExpressionNode> root;
3706 if ( !element.hasChildNodes() )
3708 root = std::make_unique<QgsExpressionNodeLiteral>( QVariant(
"" ) );
3709 return root.release();
3713 QDomNode childNode = element.firstChild();
3714 while ( !childNode.isNull() )
3716 std::unique_ptr<QgsExpressionNode> operand;
3718 if ( childNode.nodeType() == QDomNode::ElementNode )
3721 const QDomElement operandElem = childNode.toElement();
3725 mErrorMessage = QObject::tr(
"'%1' is an invalid or not supported content for %2:Literal" ).arg( operandElem.tagName(), mPrefix );
3732 QVariant value = childNode.nodeValue();
3734 bool converted =
false;
3739 QDomElement propertyNameElement = element.previousSiblingElement( mPropertyName );
3740 if ( propertyNameElement.isNull() || propertyNameElement.tagName() != mPropertyName )
3742 propertyNameElement = element.nextSiblingElement( mPropertyName );
3744 if ( !propertyNameElement.isNull() || propertyNameElement.tagName() == mPropertyName )
3746 const int fieldIndex = mLayer->fields().indexOf( propertyNameElement.firstChild().nodeValue() );
3747 if ( fieldIndex != -1 )
3749 const QgsField field = mLayer->fields().field( propertyNameElement.firstChild().nodeValue() );
3760 const double d = value.toDouble( &ok );
3765 operand = std::make_unique<QgsExpressionNodeLiteral>( value );
3771 root = std::move( operand );
3778 childNode = childNode.nextSibling();
3782 return root.release();
3789 if ( element.tagName() != QLatin1String(
"Not" ) )
3792 const QDomElement operandElem = element.firstChildElement();
3796 mErrorMessage = QObject::tr(
"invalid operand for '%1' unary operator" ).arg( element.tagName() );
3806 if ( element.tagName() != QLatin1String(
"PropertyIsNull" ) )
3811 const QDomElement operandElem = element.firstChildElement();
3822 if ( element.isNull() || element.tagName() != QLatin1String(
"Function" ) )
3824 mErrorMessage = QObject::tr(
"%1:Function expected, got %2" ).arg( mPrefix, element.tagName() );
3832 if ( element.attribute( QStringLiteral(
"name" ) ) != funcDef->
name() )
3835 auto args = std::make_unique<QgsExpressionNode::NodeList>();
3837 QDomElement operandElem = element.firstChildElement();
3838 while ( !operandElem.isNull() )
3845 args->append( op.release() );
3847 operandElem = operandElem.nextSiblingElement();
3859 std::unique_ptr<QgsExpressionNode> operand;
3860 std::unique_ptr<QgsExpressionNode> lowerBound;
3861 std::unique_ptr<QgsExpressionNode> upperBound;
3863 QDomElement operandElem = element.firstChildElement();
3864 while ( !operandElem.isNull() )
3866 if ( operandElem.tagName() == QLatin1String(
"LowerBoundary" ) )
3868 const QDomElement lowerBoundElem = operandElem.firstChildElement();
3871 else if ( operandElem.tagName() == QLatin1String(
"UpperBoundary" ) )
3873 const QDomElement upperBoundElem = operandElem.firstChildElement();
3882 if ( operand && lowerBound && upperBound )
3885 operandElem = operandElem.nextSiblingElement();
3888 if ( !operand || !lowerBound || !upperBound )
3890 mErrorMessage = QObject::tr(
"missing some required sub-elements in %1:PropertyIsBetween" ).arg( mPrefix );
3901 return mErrorMessage;
3906 const thread_local QRegularExpression re_url( QRegularExpression::anchoredPattern( QStringLiteral(
"http://www\\.opengis\\.net/gml/srs/epsg\\.xml#(.+)" ) ), QRegularExpression::CaseInsensitiveOption );
3907 if (
const QRegularExpressionMatch match = re_url.match( crsName ); match.hasMatch() )
3909 authority = QStringLiteral(
"EPSG" );
3910 code = match.captured( 1 );
3914 const thread_local QRegularExpression re_ogc_urn( QRegularExpression::anchoredPattern( QStringLiteral(
"urn:ogc:def:crs:([^:]+).+(?<=:)([^:]+)" ) ), QRegularExpression::CaseInsensitiveOption );
3915 if (
const QRegularExpressionMatch match = re_ogc_urn.match( crsName ); match.hasMatch() )
3917 authority = match.captured( 1 );
3918 code = match.captured( 2 );
3922 const thread_local QRegularExpression re_x_ogc_urn( QRegularExpression::anchoredPattern( QStringLiteral(
"urn:x-ogc:def:crs:([^:]+).+(?<=:)([^:]+)" ) ), QRegularExpression::CaseInsensitiveOption );
3923 if (
const QRegularExpressionMatch match = re_x_ogc_urn.match( crsName ); match.hasMatch() )
3925 authority = match.captured( 1 );
3926 code = match.captured( 2 );
3930 const thread_local QRegularExpression re_http_uri( QRegularExpression::anchoredPattern( QStringLiteral(
"http://www\\.opengis\\.net/def/crs/([^/]+).+/([^/]+)" ) ), QRegularExpression::CaseInsensitiveOption );
3931 if (
const QRegularExpressionMatch match = re_http_uri.match( crsName ); match.hasMatch() )
3933 authority = match.captured( 1 );
3934 code = match.captured( 2 );
3938 const thread_local QRegularExpression re_auth_code( QRegularExpression::anchoredPattern( QStringLiteral(
"([^:]+):(.+)" ) ), QRegularExpression::CaseInsensitiveOption );
3939 if (
const QRegularExpressionMatch match = re_auth_code.match( crsName ); match.hasMatch() )
3941 authority = match.captured( 1 );
3942 code = match.captured( 2 );
3949QgsGeometry QgsOgcUtils::geometryFromGMLUsingGdal(
const QDomElement &geometryElement )
3952 QTextStream gmlStream( &gml );
3953 geometryElement.save( gmlStream, 0 );
3958QgsGeometry QgsOgcUtils::geometryFromGMLMultiCurve(
const QDomElement &geometryElement )
3960 return geometryFromGMLUsingGdal( geometryElement );
GeometryOperationResult
Success or failure of a geometry operation.
@ Success
Operation succeeded.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ LineString25D
LineString25D.
@ MultiPointZ
MultiPointZ.
@ MultiPolygon25D
MultiPolygon25D.
@ MultiLineString25D
MultiLineString25D.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ MultiPoint25D
MultiPoint25D.
@ MultiLineStringZ
MultiLineStringZ.
@ MultiPolygonZ
MultiPolygonZ.
@ LineStringZ
LineStringZ.
virtual void swapXy()=0
Swaps the x and y coordinates from the geometry.
Qgis::WkbType readHeader() const
readHeader
Represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool createFromUserInput(const QString &definition)
Set up this CRS from various text formats.
bool hasAxisInverted() const
Returns whether the axis order is inverted for the CRS compared to the order east/north (longitude/la...
Custom exception class for Coordinate Reference System related exceptions.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
An abstract base class for defining QgsExpression functions.
int params() const
The number of parameters this function takes.
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
QString name() const
The name of the function.
virtual QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node)
Evaluates the function, first evaluating all required arguments before passing them to the function's...
A binary expression operator, which operates on two values.
QgsExpressionNode * opLeft() const
Returns the node to the left of the operator.
QgsExpressionNode * opRight() const
Returns the node to the right of the operator.
QgsExpressionNodeBinaryOperator::BinaryOperator op() const
Returns the binary operator.
QString text() const
Returns a the name of this operator without the operands.
BinaryOperator
list of binary operators
An expression node which takes its value from a feature's field.
QString name() const
The name of the column.
An expression node for expression functions.
int fnIndex() const
Returns the index of the node's function.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
An expression node for value IN or NOT IN clauses.
QgsExpressionNode * node() const
Returns the expression node.
QgsExpressionNode::NodeList * list() const
Returns the list of nodes to search for matching values within.
bool isNotIn() const
Returns true if this node is a "NOT IN" operator, or false if the node is a normal "IN" operator.
An expression node for literal values.
QVariant value() const
The value of the literal.
A unary node is either negative as in boolean (not) or as in numbers (minus).
QgsExpressionNodeUnaryOperator::UnaryOperator op() const
Returns the unary operator.
QString text() const
Returns a the name of this operator without the operands.
QgsExpressionNode * operand() const
Returns the node the operator will operate upon.
A list of expression nodes.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
Abstract base class for all nodes that can appear in an expression.
bool hasCachedStaticValue() const
Returns true if the node can be replaced by a static cached value.
virtual QgsExpressionNode::NodeType nodeType() const =0
Gets the type of this node.
QVariant cachedStaticValue() const
Returns the node's static cached value.
Handles parsing and evaluation of expressions (formerly called "search strings").
static const QList< QgsExpressionFunction * > & Functions()
void setExpression(const QString &expression)
Set the expression string, will reset the whole internal structure.
static int functionIndex(const QString &name)
Returns index of the function in Functions array.
QString dump() const
Returns an expression string, constructed from the internal abstract syntax tree.
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
Encapsulate a field in an attribute table or data source.
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const
Export the geometry to WKB.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
QgsCoordinateReferenceSystem crs
@ HTTP_EPSG_DOT_XML
E.g. http://www.opengis.net/gml/srs/epsg.xml#4326 (called "OGC HTTP URL" in GeoServer WFS configurati...
@ OGC_HTTP_URI
E.g. http://www.opengis.net/def/crs/EPSG/0/4326.
@ X_OGC_URN
E.g. urn:x-ogc:def:crs:EPSG::4326.
@ UNKNOWN
Unknown/unhandled flavor.
@ OGC_URN
E.g. urn:ogc:def:crs:EPSG::4326.
@ AUTH_CODE
E.g EPSG:4326.
static CRSFlavor parseCrsName(const QString &crsName, QString &authority, QString &code)
Parse a CRS name in one of the flavors of OGC services, and decompose it as authority and code.
Internal use by QgsOgcUtils.
QgsOgcUtilsExprToFilter(QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, QgsOgcUtils::FilterVersion filterVersion, const QString &namespacePrefix, const QString &namespaceURI, const QString &geometryName, const QString &srsName, bool honourAxisOrientation, bool invertAxisOrientation, const QMap< QString, QString > &fieldNameToXPathMap, const QMap< QString, QString > &namespacePrefixToUriMap)
Constructor.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
QDomElement expressionNodeToOgcFilter(const QgsExpressionNode *node, QgsExpression *expression, const QgsExpressionContext *context)
Convert an expression to a OGC filter.
QString errorMessage() const
Returns the error message.
Internal use by QgsOgcUtils.
QgsExpressionNodeFunction * nodeSpatialOperatorFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with spatial operators.
QgsExpressionNodeUnaryOperator * nodeNotFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with Not operator.
QgsExpressionNodeColumnRef * nodeColumnRefFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with column references.
QgsExpressionNode * nodeIsBetweenFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with boundaries operator.
QgsOgcUtilsExpressionFromFilter(QgsOgcUtils::FilterVersion version=QgsOgcUtils::FILTER_OGC_1_0, const QgsVectorLayer *layer=nullptr)
Constructor for QgsOgcUtilsExpressionFromFilter.
QgsExpressionNodeBinaryOperator * nodeBinaryOperatorFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with binary operators.
QgsExpressionNodeFunction * nodeFunctionFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with functions.
QgsExpressionNode * nodeFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document element.
QgsExpressionNodeBinaryOperator * nodePropertyIsNullFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with IsNull operator.
QString errorMessage() const
Returns the underlying error message, or an empty string in case of no error.
QgsExpressionNode * nodeLiteralFromOgcFilter(const QDomElement &element)
Returns an expression node from a WFS filter embedded in a document with literal tag.
Internal use by QgsOgcUtils.
QgsOgcUtilsSQLStatementToFilter(QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, QgsOgcUtils::FilterVersion filterVersion, const QList< QgsOgcUtils::LayerProperties > &layerProperties, bool honourAxisOrientation, bool invertAxisOrientation, const QMap< QString, QString > &mapUnprefixedTypenameToPrefixedTypename, const QMap< QString, QString > &fieldNameToXPathMap, const QMap< QString, QString > &namespacePrefixToUriMap)
Constructor.
QDomElement toOgcFilter(const QgsSQLStatement::Node *node)
Convert a SQL statement to a OGC filter.
bool GMLNamespaceUsed() const
Returns whether the gml: namespace is used.
QString errorMessage() const
Returns the error message.
Provides various utility functions for conversion between OGC (Open Geospatial Consortium) standards ...
static QDomElement elseFilterExpression(QDomDocument &doc)
Creates an ElseFilter from doc.
static QgsRectangle rectangleFromGMLBox(const QDomNode &boxNode)
Read rectangle from GML2 Box.
static QDomElement expressionToOgcExpression(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=nullptr, bool requiresFilterElement=false)
Creates an OGC expression XML element from the exp expression with default values for the geometry na...
static QColor colorFromOgcFill(const QDomElement &fillElement)
Parse XML with OGC fill into QColor.
static QDomElement expressionToOgcFilter(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=nullptr)
Creates OGC filter XML element.
FilterVersion
OGC filter version.
static QDomElement SQLStatementToOgcFilter(const QgsSQLStatement &statement, QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, FilterVersion filterVersion, const QList< LayerProperties > &layerProperties, bool honourAxisOrientation, bool invertAxisOrientation, const QMap< QString, QString > &mapUnprefixedTypenameToPrefixedTypename, QString *errorMessage=nullptr, const QMap< QString, QString > &fieldNameToXPathMap=QMap< QString, QString >(), const QMap< QString, QString > &namespacePrefixToUriMap=QMap< QString, QString >())
Creates OGC filter XML element from the WHERE and JOIN clauses of a SQL statement.
static QDomElement rectangleToGMLEnvelope(const QgsRectangle *env, QDomDocument &doc, int precision=17)
Exports the rectangle to GML3 Envelope.
static QgsRectangle rectangleFromGMLEnvelope(const QDomNode &envelopeNode)
Read rectangle from GML3 Envelope.
static QDomElement geometryToGML(const QgsGeometry &geometry, QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, const QString &srsName, bool invertAxisOrientation, const QString &gmlIdBase, int precision=17)
Exports the geometry to GML.
static QgsGeometry geometryFromGML(const QString &xmlString, const QgsOgcUtils::Context &context=QgsOgcUtils::Context())
Static method that creates geometry from GML.
static QgsExpression * expressionFromOgcFilter(const QDomElement &element, QgsVectorLayer *layer=nullptr)
Parse XML with OGC filter into QGIS expression.
static QDomElement rectangleToGMLBox(const QgsRectangle *box, QDomDocument &doc, int precision=17)
Exports the rectangle to GML2 Box.
static QgsGeometry ogrGeometryToQgsGeometry(OGRGeometryH geom)
Converts an OGR geometry representation to a QgsGeometry object.
A rectangle specified with double values.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
void normalize()
Normalize the rectangle so it has non-negative width/height.
An 'X BETWEEN y and z' operator.
QgsSQLStatement::Node * node() const
Variable at the left of BETWEEN.
QgsSQLStatement::Node * minVal() const
Minimum bound.
bool isNotBetween() const
Whether this is a NOT BETWEEN operator.
QgsSQLStatement::Node * maxVal() const
Maximum bound.
Binary logical/arithmetical operator (AND, OR, =, +, ...).
QgsSQLStatement::Node * opLeft() const
Left operand.
QgsSQLStatement::BinaryOperator op() const
Operator.
QgsSQLStatement::Node * opRight() const
Right operand.
QString name() const
The name of the column.
QString tableName() const
The name of the table. May be empty.
Function with a name and arguments node.
QgsSQLStatement::NodeList * args() const
Returns arguments.
QString name() const
Returns function name.
An 'x IN (y, z)' operator.
bool isNotIn() const
Whether this is a NOT IN operator.
QgsSQLStatement::Node * node() const
Variable at the left of IN.
QgsSQLStatement::NodeList * list() const
Values list.
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
QgsSQLStatement::Node * onExpr() const
On expression. Will be nullptr if usingColumns() is not empty.
QList< QString > usingColumns() const
Columns referenced by USING.
QList< QgsSQLStatement::Node * > list()
Returns list.
Literal value (integer, integer64, double, string).
QVariant value() const
The value of the literal.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QgsSQLStatement::Node * where() const
Returns the where clause.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
QString name() const
Table name.
QString alias() const
Table alias.
Unary logical/arithmetical operator ( NOT, - ).
QgsSQLStatement::UnaryOperator op() const
Operator.
QgsSQLStatement::Node * operand() const
Operand.
Abstract node class for SQL statement nodes.
virtual QgsSQLStatement::NodeType nodeType() const =0
Abstract virtual that returns the type of this node.
BinaryOperator
list of binary operators
static const char * BINARY_OPERATOR_TEXT[]
const QgsSQLStatement::Node * rootNode() const
Returns the root node of the statement.
static const char * UNARY_OPERATOR_TEXT[]
static QString qRegExpEscape(const QString &string)
Returns an escaped string matching the behavior of QRegExp::escape.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
Custom exception class for Wkb related exceptions.
std::unique_ptr< std::remove_pointer< OGRGeometryH >::type, OGRGeometryDeleter > ogr_geometry_unique_ptr
Scoped OGR geometry.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
QMap< QString, QString > QgsStringMap
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
QVector< QgsPolyline > QgsMultiPolyline
Multi polyline represented as a vector of polylines.
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
#define QgsDebugMsgLevel(str, level)
Q_GLOBAL_STATIC_WITH_ARGS(IntMap, BINARY_OPERATORS_TAG_NAMES_MAP,({ { QLatin1String("Or"), QgsExpressionNodeBinaryOperator::boOr }, { QLatin1String("And"), QgsExpressionNodeBinaryOperator::boAnd }, { QLatin1String("PropertyIsEqualTo"), QgsExpressionNodeBinaryOperator::boEQ }, { QLatin1String("PropertyIsNotEqualTo"), QgsExpressionNodeBinaryOperator::boNE }, { QLatin1String("PropertyIsLessThanOrEqualTo"), QgsExpressionNodeBinaryOperator::boLE }, { QLatin1String("PropertyIsGreaterThanOrEqualTo"), QgsExpressionNodeBinaryOperator::boGE }, { QLatin1String("PropertyIsLessThan"), QgsExpressionNodeBinaryOperator::boLT }, { QLatin1String("PropertyIsGreaterThan"), QgsExpressionNodeBinaryOperator::boGT }, { QLatin1String("PropertyIsLike"), QgsExpressionNodeBinaryOperator::boLike }, { QLatin1String("Add"), QgsExpressionNodeBinaryOperator::boPlus }, { QLatin1String("Sub"), QgsExpressionNodeBinaryOperator::boMinus }, { QLatin1String("Mul"), QgsExpressionNodeBinaryOperator::boMul }, { QLatin1String("Div"), QgsExpressionNodeBinaryOperator::boDiv }, })) static int binaryOperatorFromTagName(const QString &tagName)
QMap< QString, int > IntMap
The Context struct stores the current layer and coordinate transform context.
const QgsMapLayer * layer
QgsCoordinateTransformContext transformContext