12 #include <netinet/in.h>
26 if ( !( geomType ==
"Point" || geomType ==
"LineString" || geomType ==
"Polygon" ||
27 geomType ==
"MultiPoint" || geomType ==
"MultiLineString" || geomType ==
"MultiPolygon" ||
28 geomType ==
"Box" || geomType ==
"Envelope" ) )
31 if ( geometryChild.
isNull() )
35 geometryTypeElement = geometryChild.
toElement();
36 geomType = geometryTypeElement.
tagName();
39 if ( !( geomType ==
"Point" || geomType ==
"LineString" || geomType ==
"Polygon" ||
40 geomType ==
"MultiPoint" || geomType ==
"MultiLineString" || geomType ==
"MultiPolygon" ||
41 geomType ==
"Box" || geomType ==
"Envelope" ) )
44 if ( geomType ==
"Point" )
46 return geometryFromGMLPoint( geometryTypeElement );
48 else if ( geomType ==
"LineString" )
50 return geometryFromGMLLineString( geometryTypeElement );
52 else if ( geomType ==
"Polygon" )
54 return geometryFromGMLPolygon( geometryTypeElement );
56 else if ( geomType ==
"MultiPoint" )
58 return geometryFromGMLMultiPoint( geometryTypeElement );
60 else if ( geomType ==
"MultiLineString" )
62 return geometryFromGMLMultiLineString( geometryTypeElement );
64 else if ( geomType ==
"MultiPolygon" )
66 return geometryFromGMLMultiPolygon( geometryTypeElement );
68 else if ( geomType ==
"Box" )
72 else if ( geomType ==
"Envelope" )
85 QString xml =
QString(
"<tmp xmlns=\"%1\" xmlns:gml=\"%1\">%2</tmp>" ).
arg( GML_NAMESPACE, xmlString );
99 if ( coordList.
size() > 0 )
102 if ( readGMLCoordinates( pointCoordinate, coordElement ) != 0 )
110 if ( posList.
size() < 1 )
115 if ( readGMLPositions( pointCoordinate, posElement ) != 0 )
121 if ( pointCoordinate.
size() < 1 )
127 char e = htonl( 1 ) != 1;
128 double x = point_it->x();
129 double y = point_it->y();
130 int size = 1 +
sizeof( int ) + 2 *
sizeof(
double );
133 unsigned char* wkb =
new unsigned char[size];
136 memcpy( &( wkb )[wkbPosition], &e, 1 );
138 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
139 wkbPosition +=
sizeof( int );
140 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
141 wkbPosition +=
sizeof( double );
142 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
154 if ( coordList.
size() > 0 )
157 if ( readGMLCoordinates( lineCoordinates, coordElement ) != 0 )
165 if ( posList.
size() < 1 )
170 if ( readGMLPositions( lineCoordinates, posElement ) != 0 )
176 char e = htonl( 1 ) != 1;
177 int size = 1 + 2 *
sizeof( int ) + lineCoordinates.
size() * 2 *
sizeof( double );
180 unsigned char* wkb =
new unsigned char[size];
184 int nPoints = lineCoordinates.
size();
187 memcpy( &( wkb )[wkbPosition], &e, 1 );
189 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
190 wkbPosition +=
sizeof( int );
191 memcpy( &( wkb )[wkbPosition], &nPoints,
sizeof(
int ) );
192 wkbPosition +=
sizeof( int );
195 for ( iter = lineCoordinates.
begin(); iter != lineCoordinates.
end(); ++iter )
199 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
200 wkbPosition +=
sizeof( double );
201 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
202 wkbPosition +=
sizeof( double );
218 if ( outerBoundaryList.
size() > 0 )
221 if ( coordinatesElement.
isNull() )
225 if ( readGMLCoordinates( exteriorPointList, coordinatesElement ) != 0 )
229 ringCoordinates.
push_back( exteriorPointList );
233 for (
int i = 0; i < innerBoundaryList.
size(); ++i )
237 if ( coordinatesElement.
isNull() )
241 if ( readGMLCoordinates( interiorPointList, coordinatesElement ) != 0 )
245 ringCoordinates.
push_back( interiorPointList );
252 if ( exteriorList.
size() < 1 )
257 if ( posElement.
isNull() )
261 if ( readGMLPositions( exteriorPointList, posElement ) != 0 )
265 ringCoordinates.
push_back( exteriorPointList );
269 for (
int i = 0; i < interiorList.
size(); ++i )
273 if ( posElement.
isNull() )
277 if ( readGMLPositions( interiorPointList, posElement ) != 0 )
281 ringCoordinates.
push_back( interiorPointList );
286 int nrings = ringCoordinates.
size();
293 npoints += it->size();
295 int size = 1 + 2 *
sizeof( int ) + nrings *
sizeof(
int ) + 2 * npoints *
sizeof( double );
298 unsigned char* wkb =
new unsigned char[size];
301 char e = htonl( 1 ) != 1;
303 int nPointsInRing = 0;
307 memcpy( &( wkb )[wkbPosition], &e, 1 );
309 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
310 wkbPosition +=
sizeof( int );
311 memcpy( &( wkb )[wkbPosition], &nrings,
sizeof(
int ) );
312 wkbPosition +=
sizeof( int );
315 nPointsInRing = it->size();
316 memcpy( &( wkb )[wkbPosition], &nPointsInRing,
sizeof(
int ) );
317 wkbPosition +=
sizeof( int );
320 for ( iter = it->begin(); iter != it->end(); ++iter )
325 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
326 wkbPosition +=
sizeof( double );
327 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
328 wkbPosition +=
sizeof( double );
342 if ( pointMemberList.
size() < 1 )
350 for (
int i = 0; i < pointMemberList.
size(); ++i )
354 if ( pointNodeList.
size() < 1 )
360 if ( coordinatesList.
size() > 0 )
362 currentPoint.
clear();
363 if ( readGMLCoordinates( currentPoint, coordinatesList.
at( 0 ).
toElement() ) != 0 )
367 if ( currentPoint.
size() < 1 )
378 if ( posList.
size() < 1 )
382 currentPoint.
clear();
383 if ( readGMLPositions( currentPoint, posList.
at( 0 ).
toElement() ) != 0 )
387 if ( currentPoint.
size() < 1 )
395 int nPoints = pointList.
size();
400 int size = 1 + 2 *
sizeof( int ) + pointList.
size() * ( 2 *
sizeof( double ) + 1 +
sizeof(
int ) );
403 unsigned char* wkb =
new unsigned char[size];
406 char e = htonl( 1 ) != 1;
409 memcpy( &( wkb )[wkbPosition], &e, 1 );
411 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
412 wkbPosition +=
sizeof( int );
413 memcpy( &( wkb )[wkbPosition], &nPoints,
sizeof(
int ) );
414 wkbPosition +=
sizeof( int );
418 memcpy( &( wkb )[wkbPosition], &e, 1 );
420 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
421 wkbPosition +=
sizeof( int );
423 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
424 wkbPosition +=
sizeof( double );
426 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
427 wkbPosition +=
sizeof( double );
452 if ( lineStringMemberList.
size() > 0 )
454 for (
int i = 0; i < lineStringMemberList.
size(); ++i )
457 if ( lineStringNodeList.
size() < 1 )
461 currentLineStringElement = lineStringNodeList.
at( 0 ).
toElement();
462 currentCoordList = currentLineStringElement.
elementsByTagNameNS( GML_NAMESPACE,
"coordinates" );
463 if ( currentCoordList.
size() > 0 )
466 if ( readGMLCoordinates( currentPointList, currentCoordList.
at( 0 ).
toElement() ) != 0 )
470 lineCoordinates.
push_back( currentPointList );
475 if ( currentPosList.
size() < 1 )
480 if ( readGMLPositions( currentPointList, currentPosList.
at( 0 ).
toElement() ) != 0 )
484 lineCoordinates.
push_back( currentPointList );
491 if ( lineStringList.
size() > 0 )
493 for (
int i = 0; i < lineStringList.
size(); ++i )
495 currentLineStringElement = lineStringList.
at( i ).
toElement();
496 currentCoordList = currentLineStringElement.
elementsByTagNameNS( GML_NAMESPACE,
"coordinates" );
497 if ( currentCoordList.
size() > 0 )
500 if ( readGMLCoordinates( currentPointList, currentCoordList.
at( 0 ).
toElement() ) != 0 )
504 lineCoordinates.
push_back( currentPointList );
510 if ( currentPosList.
size() < 1 )
515 if ( readGMLPositions( currentPointList, currentPosList.
at( 0 ).
toElement() ) != 0 )
519 lineCoordinates.
push_back( currentPointList );
529 int nLines = lineCoordinates.
size();
534 int size = ( lineCoordinates.
size() + 1 ) * ( 1 + 2 *
sizeof(
int ) );
537 size += it->size() * 2 *
sizeof( double );
541 unsigned char* wkb =
new unsigned char[size];
544 char e = htonl( 1 ) != 1;
548 memcpy( &( wkb )[wkbPosition], &e, 1 );
550 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
551 wkbPosition +=
sizeof( int );
552 memcpy( &( wkb )[wkbPosition], &nLines,
sizeof(
int ) );
553 wkbPosition +=
sizeof( int );
557 memcpy( &( wkb )[wkbPosition], &e, 1 );
559 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
560 wkbPosition +=
sizeof( int );
561 nPoints = it->size();
562 memcpy( &( wkb )[wkbPosition], &nPoints,
sizeof(
int ) );
563 wkbPosition +=
sizeof( int );
569 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
570 wkbPosition +=
sizeof( double );
571 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
572 wkbPosition +=
sizeof( double );
606 for (
int i = 0; i < polygonMemberList.
size(); ++i )
609 currentPolygonMemberElement = polygonMemberList.
at( i ).
toElement();
611 if ( polygonList.
size() < 1 )
615 currentPolygonElement = polygonList.
at( 0 ).
toElement();
618 outerBoundaryList = currentPolygonElement.
elementsByTagNameNS( GML_NAMESPACE,
"outerBoundaryIs" );
619 if ( outerBoundaryList.
size() > 0 )
621 currentOuterBoundaryElement = outerBoundaryList.
at( 0 ).
toElement();
624 linearRingNodeList = currentOuterBoundaryElement.
elementsByTagNameNS( GML_NAMESPACE,
"LinearRing" );
625 if ( linearRingNodeList.
size() < 1 )
629 currentLinearRingElement = linearRingNodeList.
at( 0 ).
toElement();
630 currentCoordinateList = currentLinearRingElement.
elementsByTagNameNS( GML_NAMESPACE,
"coordinates" );
631 if ( currentCoordinateList.
size() < 1 )
635 if ( readGMLCoordinates( ringCoordinates, currentCoordinateList.
at( 0 ).
toElement() ) != 0 )
639 currentPolygonList.
push_back( ringCoordinates );
643 for (
int j = 0; j < innerBoundaryList.
size(); ++j )
646 currentInnerBoundaryElement = innerBoundaryList.
at( j ).
toElement();
647 linearRingNodeList = currentInnerBoundaryElement.
elementsByTagNameNS( GML_NAMESPACE,
"LinearRing" );
648 if ( linearRingNodeList.
size() < 1 )
652 currentLinearRingElement = linearRingNodeList.
at( 0 ).
toElement();
653 currentCoordinateList = currentLinearRingElement.
elementsByTagNameNS( GML_NAMESPACE,
"coordinates" );
654 if ( currentCoordinateList.
size() < 1 )
658 if ( readGMLCoordinates( ringCoordinates, currentCoordinateList.
at( 0 ).
toElement() ) != 0 )
662 currentPolygonList.
push_back( ringCoordinates );
669 if ( exteriorList.
size() < 1 )
674 currentExteriorElement = exteriorList.
at( 0 ).
toElement();
677 linearRingNodeList = currentExteriorElement.
elementsByTagNameNS( GML_NAMESPACE,
"LinearRing" );
678 if ( linearRingNodeList.
size() < 1 )
682 currentLinearRingElement = linearRingNodeList.
at( 0 ).
toElement();
684 if ( currentPosList.
size() < 1 )
688 if ( readGMLPositions( ringPositions, currentPosList.
at( 0 ).
toElement() ) != 0 )
692 currentPolygonList.
push_back( ringPositions );
696 for (
int j = 0; j < interiorList.
size(); ++j )
699 currentInteriorElement = interiorList.
at( j ).
toElement();
700 linearRingNodeList = currentInteriorElement.
elementsByTagNameNS( GML_NAMESPACE,
"LinearRing" );
701 if ( linearRingNodeList.
size() < 1 )
705 currentLinearRingElement = linearRingNodeList.
at( 0 ).
toElement();
707 if ( currentPosList.
size() < 1 )
711 if ( readGMLPositions( ringPositions, currentPosList.
at( 0 ).
toElement() ) != 0 )
715 currentPolygonList.
push_back( ringPositions );
718 multiPolygonPoints.
push_back( currentPolygonList );
721 int nPolygons = multiPolygonPoints.
size();
725 int size = 1 + 2 *
sizeof( int );
729 size += 1 + 2 *
sizeof( int );
732 size +=
sizeof( int ) + 2 * iter->size() *
sizeof( double );
737 unsigned char* wkb =
new unsigned char[size];
739 char e = htonl( 1 ) != 1;
746 memcpy( &( wkb )[wkbPosition], &e, 1 );
748 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
749 wkbPosition +=
sizeof( int );
750 memcpy( &( wkb )[wkbPosition], &nPolygons,
sizeof(
int ) );
751 wkbPosition +=
sizeof( int );
757 memcpy( &( wkb )[wkbPosition], &e, 1 );
759 memcpy( &( wkb )[wkbPosition], &type,
sizeof(
int ) );
760 wkbPosition +=
sizeof( int );
762 memcpy( &( wkb )[wkbPosition], &nRings,
sizeof(
int ) );
763 wkbPosition +=
sizeof( int );
766 nPointsInRing = iter->size();
767 memcpy( &( wkb )[wkbPosition], &nPointsInRing,
sizeof(
int ) );
768 wkbPosition +=
sizeof( int );
773 memcpy( &( wkb )[wkbPosition], &x,
sizeof(
double ) );
774 wkbPosition +=
sizeof( double );
775 memcpy( &( wkb )[wkbPosition], &y,
sizeof(
double ) );
776 wkbPosition +=
sizeof( double );
806 bool conversionSuccess;
811 tupel_coords = ( *it ).
split( coordSeparator, QString::SkipEmptyParts );
812 if ( tupel_coords.
size() < 2 )
816 x = tupel_coords.
at( 0 ).toDouble( &conversionSuccess );
817 if ( !conversionSuccess )
821 y = tupel_coords.
at( 1 ).toDouble( &conversionSuccess );
822 if ( !conversionSuccess )
836 if ( boxElem.
tagName() !=
"Box" )
844 coordSeparator = bElem.
attribute(
"cs" );
848 tupelSeparator = bElem.
attribute(
"ts" );
852 bool ok1, ok2, ok3, ok4;
858 if ( ok1 && ok2 && ok3 && ok4 )
879 bool conversionSuccess;
880 int posSize = pos.
size();
882 int srsDimension = 2;
885 srsDimension = elem.
attribute(
"srsDimension" ).
toInt( &conversionSuccess );
886 if ( !conversionSuccess )
893 srsDimension = elem.
attribute(
"dimension" ).
toInt( &conversionSuccess );
894 if ( !conversionSuccess )
900 for (
int i = 0; i < posSize / srsDimension; i++ )
902 x = pos.
at( i * srsDimension ).toDouble( &conversionSuccess );
903 if ( !conversionSuccess )
907 y = pos.
at( i * srsDimension + 1 ).toDouble( &conversionSuccess );
908 if ( !conversionSuccess )
923 if ( envelopeElem.
tagName() !=
"Envelope" )
927 if ( lowerCornerList.
size() < 1 )
931 if ( upperCornerList.
size() < 1 )
934 bool conversionSuccess;
935 int srsDimension = 2;
940 srsDimension = elem.
attribute(
"srsDimension" ).
toInt( &conversionSuccess );
941 if ( !conversionSuccess )
948 srsDimension = elem.
attribute(
"dimension" ).
toInt( &conversionSuccess );
949 if ( !conversionSuccess )
956 double xmin = bString.
section(
" ", 0, 0 ).
toDouble( &conversionSuccess );
957 if ( !conversionSuccess )
959 double ymin = bString.
section(
" ", 1, 1 ).
toDouble( &conversionSuccess );
960 if ( !conversionSuccess )
966 srsDimension = elem.
attribute(
"srsDimension" ).
toInt( &conversionSuccess );
967 if ( !conversionSuccess )
974 srsDimension = elem.
attribute(
"dimension" ).
toInt( &conversionSuccess );
975 if ( !conversionSuccess )
981 Q_UNUSED( srsDimension );
983 bString = elem.
text();
984 double xmax = bString.
section(
" ", 0, 0 ).
toDouble( &conversionSuccess );
985 if ( !conversionSuccess )
987 double ymax = bString.
section(
" ", 1, 1 ).
toDouble( &conversionSuccess );
988 if ( !conversionSuccess )
1056 if ( !geometry || !geometry->
asWkb() )
1066 bool hasZValue =
false;
1070 if ( format ==
"GML3" )
1072 switch ( geometry->
wkbType() )
1094 switch ( geometry->
wkbType() )
1120 for (
int idx = 0; idx < nPoints; ++idx )
1122 wkbPtr += 1 +
sizeof( int );
1136 wkbPtr +=
sizeof( double );
1141 return multiPointElem;
1156 for (
int idx = 0; idx < nPoints; ++idx )
1169 wkbPtr +=
sizeof( double );
1175 return lineStringElem;
1187 for (
int jdx = 0; jdx < nLines; jdx++ )
1191 wkbPtr += 1 +
sizeof( int );
1198 for (
int idx = 0; idx < nPoints; idx++ )
1212 wkbPtr +=
sizeof( double );
1218 lineStringMemberElem.
appendChild( lineStringElem );
1219 multiLineStringElem.
appendChild( lineStringMemberElem );
1221 return multiLineStringElem;
1234 if ( numRings == 0 )
1237 int *ringNumPoints =
new int[numRings];
1239 for (
int idx = 0; idx < numRings; idx++ )
1241 QString boundaryName =
"gml:outerBoundaryIs";
1244 boundaryName =
"gml:innerBoundaryIs";
1251 ringNumPoints[idx] = nPoints;
1255 for (
int jdx = 0; jdx < nPoints; jdx++ )
1268 wkbPtr +=
sizeof( double );
1277 delete [] ringNumPoints;
1288 wkbPtr >> numPolygons;
1290 for (
int kdx = 0; kdx < numPolygons; kdx++ )
1295 wkbPtr += 1 +
sizeof( int );
1300 for (
int idx = 0; idx < numRings; idx++ )
1302 QString boundaryName =
"gml:outerBoundaryIs";
1305 boundaryName =
"gml:innerBoundaryIs";
1315 for (
int jdx = 0; jdx < nPoints; jdx++ )
1329 wkbPtr +=
sizeof( double );
1338 multiPolygonElem.
appendChild( polygonMemberElem );
1341 return multiPolygonElem;
1361 for ( ; pointIt != points.
constEnd(); ++pointIt )
1380 if ( points.
size() > 1 )
1386 for ( ; pointIt != points.
constEnd(); ++pointIt )
1417 while ( !cssElem.
isNull() )
1419 cssName = cssElem.
attribute(
"name",
"not_found" );
1420 if ( cssName !=
"not_found" )
1422 elemText = cssElem.
text();
1423 if ( cssName ==
"fill" )
1427 else if ( cssName ==
"fill-opacity" )
1430 double opacity = elemText.
toDouble( &ok );
1453 while ( !childElem.
isNull() )
1531 spatialOps <<
"BBOX" <<
"Intersects" <<
"Contians" <<
"Crosses" <<
"Equals"
1532 <<
"Disjoint" <<
"Overlaps" <<
"Touches" <<
"Within";
1535 return spatialOps.
contains( tagName );
1548 return nodeBinaryOperatorFromOgcFilter( element, errorMessage );
1554 return nodeSpatialOperatorFromOgcFilter( element, errorMessage );
1559 if ( element.
tagName() ==
"Not" )
1561 return nodeNotFromOgcFilter( element, errorMessage );
1563 else if ( element.
tagName() ==
"PropertyIsNull" )
1565 return nodePropertyIsNullFromOgcFilter( element, errorMessage );
1567 else if ( element.
tagName() ==
"Literal" )
1569 return nodeLiteralFromOgcFilter( element, errorMessage );
1571 else if ( element.
tagName() ==
"Function" )
1573 return nodeFunctionFromOgcFilter( element, errorMessage );
1575 else if ( element.
tagName() ==
"PropertyName" )
1577 return nodeColumnRefFromOgcFilter( element, errorMessage );
1579 else if ( element.
tagName() ==
"PropertyIsBetween" )
1581 return nodeIsBetweenFromOgcFilter( element, errorMessage );
1584 errorMessage +=
QString(
"unable to convert '%1' element to a valid expression: it is not supported yet or it has invalid arguments" ).
arg( element.
tagName() );
1599 errorMessage =
QString(
"'%1' binary operator not supported." ).
arg( element.
tagName() );
1604 QgsExpression::Node *expr = nodeFromOgcFilter( operandElem, errorMessage ), *leftOp = expr;
1608 errorMessage =
QString(
"invalid left operand for '%1' binary operator" ).
arg( element.
tagName() );
1618 errorMessage =
QString(
"invalid right operand for '%1' binary operator" ).
arg( element.
tagName() );
1626 if ( expr == leftOp )
1629 errorMessage =
QString(
"only one operand for '%1' binary operator" ).
arg( element.
tagName() );
1652 if ( childElem.
tagName() !=
"PropertyName" )
1655 childElem.
save( gml2Stream, 0 );
1665 errorMessage =
"No OGC Geometry found";
1680 if ( element.
tagName() !=
"Not" )
1688 errorMessage =
QString(
"invalid operand for '%1' unary operator" ).
arg( element.
tagName() );
1700 errorMessage =
QString(
"ogc:Function expected, got %1" ).
arg( element.
tagName() );
1714 while ( !operandElem.
isNull() )
1739 errorMessage =
QString(
"ogc:Literal expected, got %1" ).
arg( element.
tagName() );
1747 while ( !childNode.
isNull() )
1751 if ( childNode.
nodeType() == QDomNode::ElementNode )
1755 operand = nodeFromOgcFilter( operandElem, errorMessage );
1761 errorMessage =
QString(
"'%1' is an invalid or not supported content for ogc:Literal" ).
arg( operandElem.
tagName() );
1804 if ( element.
isNull() || element.
tagName() !=
"PropertyName" )
1806 errorMessage =
QString(
"ogc:PropertyName expected, got %1" ).
arg( element.
tagName() );
1821 while ( !operandElem.
isNull() )
1823 if ( operandElem.
tagName() ==
"LowerBoundary" )
1826 lowerBound = nodeFromOgcFilter( lowerBoundElem, errorMessage );
1828 else if ( operandElem.
tagName() ==
"UpperBoundary" )
1831 upperBound = nodeFromOgcFilter( upperBoundElem, errorMessage );
1838 operand = nodeFromOgcFilter( operandElem, errorMessage );
1839 operand2 = nodeFromOgcFilter( operandElem, errorMessage );
1842 if ( operand && lowerBound && operand2 && upperBound )
1848 if ( !operand || !lowerBound || !operand2 || !upperBound )
1859 errorMessage =
"missing some required sub-elements in ogc:PropertyIsBetween";
1872 if ( element.
tagName() !=
"PropertyIsNull" )
1896 QString& refErrorMessage = ( errorMessage ? *errorMessage : localErrorMessage );
1897 refErrorMessage.
clear();
1899 QDomElement exprRootElem = expressionNodeToOgcFilter( exp.
rootNode(), doc, refErrorMessage );
1900 if ( exprRootElem.
isNull() )
1914 return expressionUnaryOperatorToOgcFilter( static_cast<const QgsExpression::NodeUnaryOperator*>( node ), doc, errorMessage );
1916 return expressionBinaryOperatorToOgcFilter( static_cast<const QgsExpression::NodeBinaryOperator*>( node ), doc, errorMessage );
1918 return expressionInOperatorToOgcFilter( static_cast<const QgsExpression::NodeInOperator*>( node ), doc, errorMessage );
1920 return expressionFunctionToOgcFilter( static_cast<const QgsExpression::NodeFunction*>( node ), doc, errorMessage );
1922 return expressionLiteralToOgcFilter( static_cast<const QgsExpression::NodeLiteral*>( node ), doc, errorMessage );
1924 return expressionColumnRefToOgcFilter( static_cast<const QgsExpression::NodeColumnRef*>( node ), doc, errorMessage );
1936 QDomElement operandElem = expressionNodeToOgcFilter( node->
operand(), doc, errorMessage );
1937 if ( !errorMessage.
isEmpty() )
1941 switch ( node->
op() )
1954 errorMessage =
QString(
"This use of unary operator not implemented yet" );
1974 QDomElement leftElem = expressionNodeToOgcFilter( node->
opLeft(), doc, errorMessage );
1975 if ( !errorMessage.
isEmpty() )
2008 QDomElement rightElem = expressionNodeToOgcFilter( node->
opRight(), doc, errorMessage );
2009 if ( !errorMessage.
isEmpty() )
2049 case QVariant::Double:
2052 case QVariant::String:
2078 if ( node->
list()->
list().size() == 1 )
2079 return expressionNodeToOgcFilter( node->
list()->
list()[0], doc, errorMessage );
2082 QDomElement leftNode = expressionNodeToOgcFilter( node->
node(), doc, errorMessage );
2086 QDomElement listNode = expressionNodeToOgcFilter( n, doc, errorMessage );
2087 if ( !errorMessage.
isEmpty() )
2102 if ( binSpatialOps.
isEmpty() )
2104 binSpatialOps.
insert(
"disjoint",
"Disjoint" );
2105 binSpatialOps.
insert(
"intersects",
"Intersects" );
2106 binSpatialOps.
insert(
"touches",
"Touches" );
2107 binSpatialOps.
insert(
"crosses",
"Crosses" );
2108 binSpatialOps.
insert(
"contains",
"Contains" );
2109 binSpatialOps.
insert(
"overlaps",
"Overlaps" );
2110 binSpatialOps.
insert(
"within",
"Within" );
2112 return binSpatialOps;
2132 return fd->
name() ==
"$geometry";
2144 if ( fnDef->
name() ==
"geom_from_wkt" )
2162 if ( fd->
name() ==
"intersects_bbox" )
2165 Q_ASSERT( argNodes.
count() == 2 );
2187 errorMessage =
QString(
"<BBOX> is currently supported only in form: bbox($geometry, geomFromWKT('...'))" );
2195 Q_ASSERT( argNodes.
count() == 2 );
2199 otherNode = argNodes[1];
2201 otherNode = argNodes[0];
2204 errorMessage =
QString(
"Unable to translate spatial operator: at least one must refer to geometry." );
2213 errorMessage =
"spatial operator: the other operator must be a geometry constructor function";
2219 if ( otherFnDef->
name() ==
"geom_from_wkt" )
2224 errorMessage =
"geom_from_wkt: argument must be string literal";
2232 else if ( otherFnDef->
name() ==
"geom_from_gml" )
2237 errorMessage =
"geom_from_gml: argument must be string literal";
2245 errorMessage =
"geom_from_gml: unable to parse XML";
2254 errorMessage =
"spatial operator: unknown geometry constructor function";
2268 errorMessage =
QString(
"Special columns / constants are not supported." );
2277 QDomElement childElem = expressionNodeToOgcFilter( n, doc, errorMessage );
2278 if ( !errorMessage.
isEmpty() )
Class for parsing and evaluation of expressions (formerly called "search strings").
virtual NodeType nodeType() const =0
Abstract virtual that returns the type of this node.
A rectangle specified with double values.
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName) const
bool contains(const Key &key) const
QDomNode appendChild(const QDomNode &newChild)
void push_back(const T &value)
QString attribute(const QString &name, const QString &defValue) const
A abstract base class for defining QgsExpression functions.
QString nodeValue() const
double yMaximum() const
Get the y maximum value (top side of rectangle)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const_iterator constEnd() const
const T & at(int i) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QDomElement nextSiblingElement(const QString &tagName) const
static bool isGeometryColumn(const QgsExpression::Node *node)
A geometry is the spatial representation of a feature.
QDomElement documentElement() const
QString dump() const
Return the expression string that represents this QgsExpression.
NodeType nodeType() const
WkbType
Used for symbology operations.
QString & remove(int position, int n)
QDomElement createElementNS(const QString &nsURI, const QString &qName)
void setNamedColor(const QString &name)
double toDouble(bool *ok) const
static QMap< QString, QString > binarySpatialOpsMap()
static QgsRectangle rectangleFromGMLBox(const QDomNode &boxNode)
Read rectangle from GML2 Box.
QDomNode nextSibling() const
QString mParserErrorString
QDomNode importNode(const QDomNode &importedNode, bool deep)
static QgsRectangle rectangleFromGMLEnvelope(const QDomNode &envelopeNode)
Read rectangle from GML3 Envelope.
QDomElement toElement() const
static const QList< Function * > & Functions()
static int binaryOperatorFromTagName(const QString &tagName)
static QDomElement expressionToOgcFilter(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=0)
Creates OGC filter XML element.
static bool isBinaryOperator(const QString &tagName)
QString number(int n, int base)
int count(const T &value) const
static const QString GML_NAMESPACE
int toInt(bool *ok) const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
static int functionIndex(const QString &name)
bool hasAttribute(const QString &name) const
double xMaximum() const
Get the x maximum value (right side of rectangle)
void setAttribute(const QString &name, const QString &value)
static QgsGeometry * geometryFromGML(const QString &xmlString)
Static method that creates geometry from GML.
int toInt(bool *ok, int base) const
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
static bool isBinarySpatialOperator(const QString &fnName)
QString name()
The name of the function.
static QString tagNameForSpatialOperator(const QString &fnName)
A class to represent a point.
bool hasChildNodes() const
static const QMap< QString, int > & binaryOperatorsTagNamesMap()
QDomText createTextNode(const QString &value)
BinaryOperator op() const
QDomNode removeChild(const QDomNode &oldChild)
QString qgsDoubleToString(const double &a, const int &precision=17)
static const QString OGC_NAMESPACE
const Key key(const T &value) const
static bool isSpatialOperator(const QString &tagName)
const_iterator constBegin() const
void save(QTextStream &str, int indent) const
QDomNode firstChild() const
static const char * UnaryOperatorText[]
BinaryOperator
list of binary operators
QDomNode cloneNode(bool deep) const
void fromWkb(unsigned char *wkb, size_t length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length...
int params()
The number of parameters this function takes.
QDomElement firstChildElement(const QString &tagName) const
static QgsExpression * expressionFromOgcFilter(const QDomElement &element)
Parse XML with OGC filter into QGIS expression.
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
static QgsGeometry * fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QgsGeometry * geometryFromConstExpr(const QgsExpression::Node *node)
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
static QString binaryOperatorToTagName(QgsExpression::BinaryOperator op)
static QColor colorFromOgcFill(const QDomElement &fillElement)
Parse XML with OGC fill into QColor.
void push_back(const T &value)
void setAlphaF(qreal alpha)
double toDouble(bool *ok) const
iterator insert(const Key &key, const T &value)
void append(Node *node)
Takes ownership of the provided node.
static QgsGeometry * fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
void normalize()
Normalize the rectangle so it has non-negative width/height.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
static QDomElement rectangleToGMLBox(QgsRectangle *box, QDomDocument &doc, const int &precision=17)
Exports the rectangle to GML2 Box.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
double xMinimum() const
Get the x minimum value (left side of rectangle)
static QDomElement rectangleToGMLEnvelope(QgsRectangle *env, QDomDocument &doc, const int &precision=17)
Exports the rectangle to GML2 Envelope.
static QDomElement geometryToGML(const QgsGeometry *geometry, QDomDocument &doc, const QString &format, const int &precision=17)
Exports the geometry to GML2 or GML3.
QDomNode at(int index) const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
const T value(const Key &key) const
static const char * BinaryOperatorText[]