Skip to content

Commit

Permalink
Update the expression geomFromGML2 to geomFromGML
Browse files Browse the repository at this point in the history
Like we simplified the QgsOgcUtils class, I simplify the expression with
renamed geomFromGML2 to geomFromGML.
This update gives me the ability to debugging geometryFromGML with
Envelope element.
  • Loading branch information
rldhont committed Mar 15, 2013
1 parent 1e30eb0 commit 3b9c688
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ static QVariant fcnGeomFromWKT( const QVariantList& values, QgsFeature*, QgsExpr
else
return QVariant();
}
static QVariant fcnGeomFromGML2( const QVariantList& values, QgsFeature*, QgsExpression* parent )
static QVariant fcnGeomFromGML( const QVariantList& values, QgsFeature*, QgsExpression* parent )
{
QString gml = getStringValue( values.at( 0 ), parent );
QgsGeometry* geom = QgsOgcUtils::geometryFromGML( gml );
Expand Down Expand Up @@ -1087,7 +1087,7 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
<< new StaticFunction( "$y", 0, fcnY, QObject::tr( "Geometry" ), "" , true )
<< new StaticFunction( "$geometry", 0, fcnGeometry, QObject::tr( "Geometry" ), "" , true )
<< new StaticFunction( "geomFromWKT", 1, fcnGeomFromWKT, QObject::tr( "Geometry" ) )
<< new StaticFunction( "geomFromGML2", 1, fcnGeomFromGML2, QObject::tr( "Geometry" ) )
<< new StaticFunction( "geomFromGML", 1, fcnGeomFromGML, QObject::tr( "Geometry" ) )
<< new StaticFunction( "bbox", 2, fcnBbox, QObject::tr( "Geometry" ) )
<< new StaticFunction( "disjoint", 2, fcnDisjoint, QObject::tr( "Geometry" ) )
<< new StaticFunction( "intersects", 2, fcnIntersects, QObject::tr( "Geometry" ) )
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsogcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ QgsRectangle QgsOgcUtils::rectangleFromGMLEnvelope( const QDomNode& envelopeNode
if ( !conversionSuccess )
return rect;

elem = lowerCornerList.at( 0 ).toElement();
elem = upperCornerList.at( 0 ).toElement();
if ( elem.hasAttribute( "srsDimension" ) )
{
srsDimension = elem.attribute( "srsDimension" ).toInt( &conversionSuccess );
Expand Down Expand Up @@ -1605,7 +1605,7 @@ QgsExpression::NodeFunction* QgsOgcUtils::nodeSpatialOperatorFromOgcFilter( QDom

QgsExpression::NodeList *opArgs = new QgsExpression::NodeList();
opArgs->append( new QgsExpression::NodeFunction( QgsExpression::functionIndex( "$geometry" ), new QgsExpression::NodeList() ) );
opArgs->append( new QgsExpression::NodeFunction( QgsExpression::functionIndex( "geomFromGML2" ), gml2Args ) );
opArgs->append( new QgsExpression::NodeFunction( QgsExpression::functionIndex( "geomFromGML" ), gml2Args ) );

return new QgsExpression::NodeFunction( opIdx, opArgs );
}
Expand Down Expand Up @@ -2110,20 +2110,20 @@ QDomElement QgsOgcUtils::expressionFunctionToOgcFilter( const QgsExpression::Nod
otherGeomElem = QgsOgcUtils::geometryToGML( geom, doc );
delete geom;
}
else if ( otherFnDef->name() == "geomFromGML2" )
else if ( otherFnDef->name() == "geomFromGML" )
{
QgsExpression::Node* firstFnArg = otherFn->args()->list()[0];
if ( firstFnArg->nodeType() != QgsExpression::ntLiteral )
{
errorMessage = "geomFromGML2: argument must be string literal";
errorMessage = "geomFromGML: argument must be string literal";
return QDomElement();
}

QDomDocument geomDoc;
QString gml = static_cast<const QgsExpression::NodeLiteral*>( firstFnArg )->value().toString();
if ( !geomDoc.setContent( gml, true ) )
{
errorMessage = "geomFromGML2: unable to parse XML";
errorMessage = "geomFromGML: unable to parse XML";
return QDomElement();
}

Expand Down
14 changes: 7 additions & 7 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,18 @@ class TestQgsExpression: public QObject
QTest::newRow( "geomFromWKT Polygon" ) << "geomFromWKT('" + QgsGeometry::fromPolygon( polygon )->exportToWkt() + "')" << ( void* ) QgsGeometry::fromPolygon( polygon ) << false;

// GML Point
QTest::newRow( "GML Point (coordinates)" ) << "geomFromGML2('<gml:Point><gml:coordinates>123,456</gml:coordinates></gml:Point>')" << ( void * ) QgsGeometry::fromPoint( point ) << false;
QTest::newRow( "GML Point (coordinates)" ) << "geomFromGML('<gml:Point><gml:coordinates>123,456</gml:coordinates></gml:Point>')" << ( void * ) QgsGeometry::fromPoint( point ) << false;
// gml:pos if from GML3
//QTest::newRow( "GML Point (pos)" ) << "geomFromGML2('<gml:Point srsName=\"foo\"><gml:pos srsDimension=\"2\">123 456</gml:pos></gml:Point>')" << ( void * ) QgsGeometry::fromPoint( point ) << false;
QTest::newRow( "GML Point (pos)" ) << "geomFromGML('<gml:Point srsName=\"foo\"><gml:pos srsDimension=\"2\">123 456</gml:pos></gml:Point>')" << ( void * ) QgsGeometry::fromPoint( point ) << false;

// GML Box
QgsRectangle rect( 135.2239, 34.4879, 135.8578, 34.8471 );
QTest::newRow( "GML Box" ) << "geomFromGML2('<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>')" << ( void * ) QgsGeometry::fromRect( rect ) << false;
QTest::newRow( "GML Box" ) << "geomFromGML('<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>')" << ( void * ) QgsGeometry::fromRect( rect ) << false;
// Envelope is from GML3 ?
//QTest::newRow( "GML Envelope" ) << "geomFromGML2('<gml:Envelope>"
// "<gml:lowerCorner>135.2239 34.4879</gml:lowerCorner>"
// "<gml:upperCorner>135.8578 34.8471</gml:upperCorner>"
// "</gml:Envelope>')" << ( void * ) QgsGeometry::fromRect( rect ) << false;
QTest::newRow( "GML Envelope" ) << "geomFromGML('<gml:Envelope>"
"<gml:lowerCorner>135.2239 34.4879</gml:lowerCorner>"
"<gml:upperCorner>135.8578 34.8471</gml:upperCorner>"
"</gml:Envelope>')" << ( void * ) QgsGeometry::fromRect( rect ) << false;
}

void eval_geometry_constructor()
Expand Down
12 changes: 7 additions & 5 deletions tests/src/core/testqgsogcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ void TestQgsOgcUtils::testExpressionFromOgcFilter_data()
"</Filter>" )
<< QString( "FIRST_NAME IS NULL" );

QTest::newRow( "bbox" ) << QString(
QTest::newRow( "bbox with GML2 Box" ) << QString(
"<Filter>"
"<BBOX><PropertyName>Name>NAME</PropertyName><gml:Box srsName='foo'>"
"<gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box></BBOX>"
"</Filter>" )
<< QString( "bbox($geometry, geomFromGML2('<Box srsName=\"foo\"><coordinates>135.2239,34.4879 135.8578,34.8471</coordinates></Box>'))" );
<< QString( "bbox($geometry, geomFromGML('<Box srsName=\"foo\"><coordinates>135.2239,34.4879 135.8578,34.8471</coordinates></Box>'))" );

QTest::newRow( "Intersects" ) << QString(
"<Filter>"
Expand All @@ -188,7 +188,7 @@ void TestQgsOgcUtils::testExpressionFromOgcFilter_data()
"</gml:Point>"
"</Intersects>"
"</Filter>" )
<< QString( "intersects($geometry, geomFromGML2('<Point><coordinates>123,456</coordinates></Point>'))" );
<< QString( "intersects($geometry, geomFromGML('<Point><coordinates>123,456</coordinates></Point>'))" );
}

void TestQgsOgcUtils::testExpressionFromOgcFilter()
Expand Down Expand Up @@ -319,7 +319,7 @@ void TestQgsOgcUtils::testExpressionToOgcFilter_data()
"</ogc:Intersects>"
"</ogc:Filter>" );

QTest::newRow( "contains + gml" ) << QString( "contains($geometry, geomFromGML2('<Point><coordinates cs=\",\" ts=\" \">5.0,6.0</coordinates></Point>'))" ) << QString(
QTest::newRow( "contains + gml" ) << QString( "contains($geometry, geomFromGML('<Point><coordinates cs=\",\" ts=\" \">5.0,6.0</coordinates></Point>'))" ) << QString(
"<ogc:Filter>"
"<ogc:Contains>"
"<ogc:PropertyName>geometry</ogc:PropertyName>"
Expand All @@ -328,7 +328,9 @@ void TestQgsOgcUtils::testExpressionToOgcFilter_data()
"</ogc:Filter>" );

/*
QTest::newRow( "bbox" ) << QString( "bbox(13.0983, )") << QString(
QTest::newRow( "bbox with GML3 Envelope" )
<< QString( "bbox($geometry, geomFromGML('<gml:Envelope><gml:lowerCorner>13.0983 31.5899</gml:lowerCorner><gml:upperCorner>35.5472 42.8143</gml:upperCorner></gml:Envelope>'))" )
<< QString(
"<ogc:Filter>"
"<ogc:BBOX>"
"<ogc:PropertyName>Geometry</ogc:PropertyName>"
Expand Down

0 comments on commit 3b9c688

Please sign in to comment.