/// <summary> /// Creates a WFS XML filter string. /// </summary> /// <param name="filter">The filter string.</param> /// <param name="geometryName">Name of the geometry object.</param> /// <param name="boundingBox">The bounding box.</param> /// <returns>A string containing WFS XML-text.</returns> private static string CreateWfsXmlFilterString(string filter, string geometryName, WfsBoundingBox boundingBox) { FormulaOperation formulaOperation; SpatialOperation bboxOperation = null; if (string.IsNullOrEmpty(geometryName)) { geometryName = "the_geom"; } if (boundingBox != null) { SpatialBoundingBox spatialBoundingBox = new SpatialBoundingBox(boundingBox.MinX, boundingBox.MinY, boundingBox.MaxX, boundingBox.MaxY, boundingBox.SrsName); bboxOperation = new SpatialOperation(new SpatialFieldValue(geometryName), spatialBoundingBox, WFSSpatialOperator.InsideBbox); } if (string.IsNullOrEmpty(filter)) { formulaOperation = bboxOperation ?? null; } else { WfsFormulaParser parser = new WfsFormulaParser(); formulaOperation = parser.Parse(filter); if (bboxOperation != null) { formulaOperation = new BinaryLogicalOperation(formulaOperation, bboxOperation, WFSBinaryLogicalOperator.And); } } WFSFilter wfsFilter = new WFSFilter { Formula = formulaOperation }; string strWfsXmlRepresentation = wfsFilter.WfsXmlRepresentation(); return(strWfsXmlRepresentation); }
public void WfsXmlRepresentation_OrFormula_CorrectXmlRepresentationIsCreated() { string strFilter = "<Filter><Or><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>5</Literal></PropertyIsEqualTo><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>6</Literal></PropertyIsEqualTo></Or></Filter>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); string strWfsXmlRepresentation = formulaOperation.WfsXmlRepresentation(); string expectedXmlString = "<ogc:Or><ogc:PropertyIsEqualTo matchCase=\"true\"><ogc:PropertyName>LänSKOD</ogc:PropertyName><ogc:Literal>5</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo matchCase=\"true\"><ogc:PropertyName>LänSKOD</ogc:PropertyName><ogc:Literal>6</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or>"; Assert.IsNotNull(formulaOperation); Assert.AreEqual(expectedXmlString, strWfsXmlRepresentation); }
public void Parse_PropertyIsLike_FormulaIsParsedSuccessfully() { string strFilter = "<Filter><PropertyIsLike wildcard='*' singleChar='.' escape='!'><PropertyName>NAMN</PropertyName><Literal>*land</Literal></PropertyIsLike></Filter>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); string strWfsRepresentation = formulaOperation.WFSRepresentation(); strFilter = strFilter.Replace("<Filter>", "").Replace("</Filter>", ""); Assert.IsNotNull(formulaOperation); Assert.AreEqual(strFilter, strWfsRepresentation); }
public void Parse_PropertyIsLessThan_FormulaIsParsedSuccessfully() { string strFilter = "<PropertyIsLessThan><PropertyName>LänSBOKSTA</PropertyName><Literal>25</Literal></PropertyIsLessThan>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); string strWfsRepresentation = formulaOperation.WFSRepresentation(); strFilter = strFilter.Replace("<Filter>", "").Replace("</Filter>", ""); Assert.IsNotNull(formulaOperation); Assert.AreEqual(strFilter, strWfsRepresentation); }
public void Parse_ComplexFormula_FormulaIsParsedSuccessfully() { string strFilter = "<Filter><Or><Or><And><Not><PropertyIsLessThan><PropertyName>LänSBOKSTA</PropertyName><Literal>K</Literal></PropertyIsLessThan></Not><PropertyIsNotEqualTo><PropertyName>NAMN</PropertyName><Literal>Småland</Literal></PropertyIsNotEqualTo></And><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>25</Literal></PropertyIsEqualTo></Or><PropertyIsEqualTo><PropertyName>NAMN</PropertyName><Literal>Dalarna</Literal></PropertyIsEqualTo></Or></Filter>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); string strWfsRepresentation = formulaOperation.WFSRepresentation(); strFilter = strFilter.Replace("<Filter>", "").Replace("</Filter>", ""); Assert.IsNotNull(formulaOperation); Assert.AreEqual(strFilter, strWfsRepresentation); }
public void Parse_AndFormula_FormulaIsParsedSuccessfully() { string strFilter = "<Filter><And><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>5</Literal></PropertyIsEqualTo><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>6</Literal></PropertyIsEqualTo></And></Filter>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); string strWfsRepresentation = formulaOperation.WFSRepresentation(); strFilter = strFilter.Replace("<Filter>", "").Replace("</Filter>", ""); Assert.IsNotNull(formulaOperation); Assert.AreEqual(strFilter, strWfsRepresentation); }
public void WfsFilterWfsXmlRepresentation_BoundingBox_CorrectXmlRepresentationIsCreated() { string strFilter = "<Filter><Or><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>5</Literal></PropertyIsEqualTo><PropertyIsEqualTo><PropertyName>LänSKOD</PropertyName><Literal>6</Literal></PropertyIsEqualTo></Or></Filter>"; WfsFormulaParser parser = new WfsFormulaParser(); FormulaOperation formulaOperation = parser.Parse(strFilter); SpatialBoundingBox spatialBoundingBox = new SpatialBoundingBox(-180, -90, 180, 90, "EPSG:4326"); var bboxOperation = new SpatialOperation(new SpatialFieldValue("the_geom"), spatialBoundingBox, WFSSpatialOperator.InsideBbox); formulaOperation = new BinaryLogicalOperation(formulaOperation, bboxOperation, WFSBinaryLogicalOperator.And); WFSFilter wfsFilter = new WFSFilter { Formula = formulaOperation }; string strWfsXmlRepresentation = wfsFilter.WfsXmlRepresentation(); string expectedXmlString = "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\"><ogc:And><ogc:Or><ogc:PropertyIsEqualTo matchCase=\"true\"><ogc:PropertyName>LänSKOD</ogc:PropertyName><ogc:Literal>5</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo matchCase=\"true\"><ogc:PropertyName>LänSKOD</ogc:PropertyName><ogc:Literal>6</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or><ogc:BBOX><ogc:PropertyName>the_geom</ogc:PropertyName><gml:Envelope xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"EPSG:4326\"><gml:lowerCorner>-180 -90</gml:lowerCorner><gml:upperCorner>180 90</gml:upperCorner></gml:Envelope></ogc:BBOX></ogc:And></ogc:Filter>"; Assert.IsNotNull(formulaOperation); Assert.AreEqual(expectedXmlString, strWfsXmlRepresentation); }