@@ -569,6 +569,20 @@ class TestQgsExpression: public QObject
569
569
QTest::newRow ( " geomFromWKT Line" ) << " geomFromWKT('" + QgsGeometry::fromPolyline ( line )->exportToWkt () + " ')" << ( void * ) QgsGeometry::fromPolyline ( line ) << false ;
570
570
QTest::newRow ( " geomFromWKT Polyline" ) << " geomFromWKT('" + QgsGeometry::fromPolyline ( polyline )->exportToWkt () + " ')" << ( void * ) QgsGeometry::fromPolyline ( polyline ) << false ;
571
571
QTest::newRow ( " geomFromWKT Polygon" ) << " geomFromWKT('" + QgsGeometry::fromPolygon ( polygon )->exportToWkt () + " ')" << ( void * ) QgsGeometry::fromPolygon ( polygon ) << false ;
572
+
573
+ // GML Point
574
+ QTest::newRow ( " GML Point (coordinates)" ) << " geomFromGML2('<gml:Point><gml:coordinates>123,456</gml:coordinates></gml:Point>')" << ( void * ) QgsGeometry::fromPoint ( point ) << false ;
575
+ // gml:pos if from GML3
576
+ // 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;
577
+
578
+ // GML Box
579
+ QgsRectangle rect ( 135.2239 , 34.4879 , 135.8578 , 34.8471 );
580
+ 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 ;
581
+ // Envelope is from GML3 ?
582
+ // QTest::newRow( "GML Envelope" ) << "geomFromGML2('<gml:Envelope>"
583
+ // "<gml:lowerCorner>135.2239 34.4879</gml:lowerCorner>"
584
+ // "<gml:upperCorner>135.8578 34.8471</gml:upperCorner>"
585
+ // "</gml:Envelope>')" << ( void * ) QgsGeometry::fromRect( rect ) << false;
572
586
}
573
587
574
588
void eval_geometry_constructor ()
@@ -744,6 +758,113 @@ class TestQgsExpression: public QObject
744
758
QgsExpression::unsetSpecialColumn ( " $var1" );
745
759
}
746
760
761
+
762
+ void test_from_ogc_filter_data ()
763
+ {
764
+ QTest::addColumn<QString>( " xmlText" );
765
+ QTest::addColumn<QString>( " dumpText" );
766
+
767
+ QTest::newRow ( " =" ) << QString (
768
+ " <Filter><PropertyIsEqualTo>"
769
+ " <PropertyName>NAME</PropertyName>"
770
+ " <Literal>New York</Literal>"
771
+ " </PropertyIsEqualTo></Filter>" )
772
+ << QString ( " NAME = 'New York'" );
773
+
774
+ QTest::newRow ( " >" ) << QString (
775
+ " <Filter><PropertyIsGreaterThan>"
776
+ " <PropertyName>COUNT</PropertyName>"
777
+ " <Literal>3</Literal>"
778
+ " </PropertyIsGreaterThan></Filter>" )
779
+ << QString ( " COUNT > 3" );
780
+
781
+ QTest::newRow ( " AND" ) << QString (
782
+ " <ogc:Filter>"
783
+ " <ogc:And>"
784
+ " <ogc:PropertyIsGreaterThanOrEqualTo>"
785
+ " <ogc:PropertyName>pop</ogc:PropertyName>"
786
+ " <ogc:Literal>50000</ogc:Literal>"
787
+ " </ogc:PropertyIsGreaterThanOrEqualTo>"
788
+ " <ogc:PropertyIsLessThan>"
789
+ " <ogc:PropertyName>pop</ogc:PropertyName>"
790
+ " <ogc:Literal>100000</ogc:Literal>"
791
+ " </ogc:PropertyIsLessThan>"
792
+ " </ogc:And>"
793
+ " </ogc:Filter>" )
794
+ << QString ( " pop >= 50000 AND pop < 100000" );
795
+
796
+ // TODO: should work also without <Literal> tags in Lower/Upper-Boundary tags?
797
+ QTest::newRow ( " between" ) << QString (
798
+ " <Filter>"
799
+ " <PropertyIsBetween><PropertyName>POPULATION</PropertyName>"
800
+ " <LowerBoundary><Literal>100</Literal></LowerBoundary>"
801
+ " <UpperBoundary><Literal>200</Literal></UpperBoundary></PropertyIsBetween>"
802
+ " </Filter>" )
803
+ << QString ( " POPULATION >= 100 AND POPULATION <= 200" );
804
+
805
+ // TODO: needs to handle different wildcards, single chars, escape chars
806
+ QTest::newRow ( " like" ) << QString (
807
+ " <Filter>"
808
+ " <PropertyIsLike wildcard='*' singleChar='.' escape='!'>"
809
+ " <PropertyName>NAME</PropertyName><Literal>*QGIS*</Literal></PropertyIsLike>"
810
+ " </Filter>" )
811
+ << QString ( " NAME LIKE '*QGIS*'" );
812
+
813
+ QTest::newRow ( " is null" ) << QString (
814
+ " <Filter>"
815
+ " <ogc:PropertyIsNull>"
816
+ " <ogc:PropertyName>FIRST_NAME</ogc:PropertyName>"
817
+ " </ogc:PropertyIsNull>"
818
+ " </Filter>" )
819
+ << QString ( " FIRST_NAME IS NULL" );
820
+
821
+ QTest::newRow ( " bbox" ) << QString (
822
+ " <Filter>"
823
+ " <BBOX><PropertyName>Name>NAME</PropertyName><gml:Box srsName='foo'>"
824
+ " <gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box></BBOX>"
825
+ " </Filter>" )
826
+ << QString ( " bbox($geometry, geomFromGML2('<Box srsName=\" foo\" ><coordinates>135.2239,34.4879 135.8578,34.8471</coordinates></Box>'))" );
827
+
828
+ QTest::newRow ( " Intersects" ) << QString (
829
+ " <Filter>"
830
+ " <Intersects>"
831
+ " <PropertyName>GEOMETRY</PropertyName>"
832
+ " <gml:Point>"
833
+ " <gml:coordinates>123,456</gml:coordinates>"
834
+ " </gml:Point>"
835
+ " </Intersects>"
836
+ " </Filter>" )
837
+ << QString ( " intersects($geometry, geomFromGML2('<Point><coordinates>123,456</coordinates></Point>'))" );
838
+ }
839
+
840
+ void test_from_ogc_filter ()
841
+ {
842
+ QFETCH ( QString, xmlText );
843
+ QFETCH ( QString, dumpText );
844
+
845
+ QDomDocument doc;
846
+ QVERIFY (doc.setContent (xmlText, true ));
847
+ QDomElement rootElem = doc.documentElement ();
848
+
849
+ QgsExpression* expr = QgsExpression::createFromOgcFilter ( rootElem );
850
+ QVERIFY ( expr );
851
+
852
+ qDebug (" OGC XML : %s" , xmlText.toAscii ().data () );
853
+ qDebug (" EXPR-DUMP: %s" , expr->dump ().toAscii ().data () );
854
+
855
+ if ( expr->hasParserError () )
856
+ qDebug ( " ERROR: %s " , expr->parserErrorString ().toAscii ().data () );
857
+ QVERIFY ( !expr->hasParserError () );
858
+
859
+ QCOMPARE ( dumpText, expr->dump () );
860
+
861
+ delete expr;
862
+ }
863
+
864
+ void test_to_ogc_filter ()
865
+ {
866
+ // TODO
867
+ }
747
868
};
748
869
749
870
QTEST_MAIN ( TestQgsExpression )
0 commit comments