/// <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 WfsFilterWfsXmlRepresentation_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); WFSFilter wfsFilter = new WFSFilter { Formula = formulaOperation }; string strWfsXmlRepresentation = wfsFilter.WfsXmlRepresentation(); string expectedXmlString = "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\"><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:Filter>"; Assert.IsNotNull(formulaOperation); Assert.AreEqual(expectedXmlString, strWfsXmlRepresentation); }
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); }