def test_box_or_box(self): """Test a location filter expression using an Intersects(Box) and a Within(Box) filter. Test whether the generated XML is correct. """ box_or_box = Or([ Intersects(Box(50.9850, 3.6214, 51.1270, 3.8071, epsg=4326)), Within(Box(94720, 186910, 112220, 202870)) ]) xml = set_geometry_column(box_or_box, 'geom') assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<ogc:Or><ogc:Intersects><ogc:PropertyName>geom</ogc' ':PropertyName><gml:Envelope srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"><gml' ':lowerCorner>50.985000 ' '3.621400</gml:lowerCorner><gml:upperCorner>51.127000 ' '3.807100</gml:upperCorner></gml:Envelope></ogc:Intersects><ogc' ':Within><ogc:PropertyName>geom</ogc:PropertyName><gml:Envelope ' 'srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml ' ':lowerCorner>94720.000000 ' '186910.000000</gml:lowerCorner><gml:upperCorner>112220.000000 ' '202870.000000</gml:upperCorner></gml:Envelope></ogc:Within' '></ogc:Or>')
def test_box_wgs84(self): """Test the Box type with WGS84 coordinates. Test whether the generated XML is correct. """ box = Box(3.6214, 50.9850, 3.8071, 51.1270, epsg=4326) xml = box.get_element() assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<gml:Envelope srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' '<gml:lowerCorner>3.621400 50.985000</gml:lowerCorner>' '<gml:upperCorner>3.807100 51.127000</gml:upperCorner>' '</gml:Envelope>')
def test_box(self): """Test the default Box type. Test whether the generated XML is correct. """ box = Box(94720, 186910, 112220, 202870) xml = box.get_element() assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<gml:Envelope srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370">' '<gml:lowerCorner>94720.000000 186910.000000</gml:lowerCorner>' '<gml:upperCorner>112220.000000 202870.000000</gml:upperCorner>' '</gml:Envelope>')
def test_wfs_build_getfeature_request_bbox(self): """Test the owsutil.wfs_build_getfeature_request method with a typename, box and geometry_column. Test whether the XML of the WFS GetFeature call is generated correctly. """ xml = owsutil.wfs_build_getfeature_request( 'dov-pub:Boringen', location=Within(Box(151650, 214675, 151750, 214775)), geometry_column='geom') assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" ' 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' 'service="WFS" version="1.1.0" ' 'xsi:schemaLocation="http://www.opengis.net/wfs ' 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"><wfs:Query ' 'typeName="dov-pub:Boringen"><ogc:Filter ' 'xmlns:ogc="http://www.opengis.net/ogc"><ogc:Within> ' '<ogc:PropertyName>geom</ogc:PropertyName><gml:Envelope ' 'xmlns:gml="http://www.opengis.net/gml" srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml' ':lowerCorner>151650.000 ' '214675.000</gml:lowerCorner><gml:upperCorner>151750.000 ' '214775.000</gml:upperCorner></gml:Envelope></ogc:Within></ogc' ':Filter></wfs:Query></wfs:GetFeature>')
def test_polygon_and_box(self): """Test the combination of a Within filter with a GML containing a single polygon geometry in EPSG:31370 and a Box. Test whether the generated XML is correct. """ with open('tests/data/util/location/polygon_single_31370.gml', 'r') as gml_file: gml = gml_file.read() polygon = GmlFilter(gml, Within) box = Box(94720, 186910, 112220, 202870) location_filter = Or([polygon, Within(box)]) set_geometry_column(location_filter, 'geom') xml = location_filter.toXML() assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<ogc:Or><ogc:Within><ogc:PropertyName>geom</ogc:PropertyName' '><gml:Polygon srsName="urn:ogc:def:crs:EPSG::31370"><gml' ':exterior><gml:LinearRing><gml:posList>108636.150020818 ' '194960.844295764 108911.922161617 194291.111953824 ' '109195.573506438 195118.42837622 108636.150020818 ' '194960.844295764</gml:posList></gml:LinearRing></gml:exterior' '></gml:Polygon></ogc:Within><ogc:Within><ogc:PropertyName>geom' '</ogc:PropertyName><gml:Envelope srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml' ':lowerCorner>94720.000000 ' '186910.000000</gml:lowerCorner><gml:upperCorner>112220.000000 ' '202870.000000</gml:upperCorner></gml:Envelope></ogc' ':Within></ogc:Or>')
def test_recursive(self): """Test a location filter expression using a recursive expression with And(Not(WithinDistance(Point) filter. Test whether the generated XML is correct. """ point_and_box = And([ Not([WithinDistance(Point(150000, 150000), 100)]), Within(Box(94720, 186910, 112220, 202870)) ]) xml = set_geometry_column(point_and_box, 'geom') assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<ogc:And><ogc:Not><ogc:DWithin><ogc:PropertyName>geom</ogc' ':PropertyName><gml:Point srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml' ':pos>150000.000000 ' '150000.000000</gml:pos></gml:Point><gml:Distance ' 'units="meter">100.000000</gml:Distance></ogc:DWithin></ogc:Not' '><ogc:Within><ogc:PropertyName>geom</ogc:PropertyName><gml' ':Envelope srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml' ':lowerCorner>94720.000000 ' '186910.000000</gml:lowerCorner><gml:upperCorner>112220.000000 ' '202870.000000</gml:upperCorner></gml:Envelope></ogc:Within' '></ogc:And>')
def test_wfs_build_getfeature_request_bbox_filter(self): """Test the owsutil.wfs_build_getfeature_request method with an attribute filter, a box and a geometry_column. Test whether the XML of the WFS GetFeature call is generated correctly. """ query = PropertyIsEqualTo(propertyname='gemeente', literal='Herstappe') filter_request = FilterRequest() filter_request = filter_request.setConstraint(query) filter_request = etree.tostring(filter_request, encoding='unicode') xml = owsutil.wfs_build_getfeature_request( 'dov-pub:Boringen', filter=filter_request, location=Within(Box(151650, 214675, 151750, 214775)), geometry_column='geom') assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" ' 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' 'service="WFS" version="1.1.0" ' 'xsi:schemaLocation="http://www.opengis.net/wfs ' 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"> <wfs:Query ' 'typeName="dov-pub:Boringen"> <ogc:Filter> <ogc:And> ' '<ogc:PropertyIsEqualTo> ' '<ogc:PropertyName>gemeente</ogc:PropertyName> ' '<ogc:Literal>Herstappe</ogc:Literal> </ogc:PropertyIsEqualTo> ' '<ogc:Within> <ogc:PropertyName>geom</ogc:PropertyName> ' '<gml:Envelope xmlns:gml="http://www.opengis.net/gml" ' 'srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"> ' '<gml:lowerCorner>151650.000000 214675.000000</gml:lowerCorner> ' '<gml:upperCorner>151750.000000 214775.000000</gml:upperCorner> ' '</gml:Envelope> </ogc:Within> </ogc:And> </ogc:Filter> ' '</wfs:Query> </wfs:GetFeature>')
def test_box_invalid_wgs84(self): """Test the Box type with the wrong ordering of WGS84 coordinates. Test whether a ValueError is raised. """ with pytest.raises(ValueError): Box(50.9850, 3.6214, 3.8071, 51.1270, epsg=4326)
def test_box_invalid(self): """Test the Box type with the wrong ordering of coordinates. Test whether a ValueError is raised. """ with pytest.raises(ValueError): Box(94720, 202870, 186910, 112220)
def test_within_nogeom(self): """Test the Within spatial filter without setting a geometry column. Test whether a RuntimeError is raised. """ within = Within(Box(94720, 186910, 112220, 202870)) with pytest.raises(RuntimeError): within.toXML()
def test_wfs_build_getfeature_request_bbox_nogeometrycolumn(self): """Test the owsutil.wfs_build_getfeature_request method with a location argument but without the geometry_column argument. Test whether an AttributeError is raised. """ with pytest.raises(AttributeError): xml = owsutil.wfs_build_getfeature_request( 'dov-pub:Boringen', location=Within(Box(151650, 214675, 151750, 214775)))
def test_intersects_nogeom(self): """Test the Intersects spatial filter without setting a geometry column. Test whether a RuntimeError is raised. """ intersects = Intersects(Box(94720, 186910, 112220, 202870)) with pytest.raises(RuntimeError): intersects.toXML()
def test_intersects_box(self): """Test the Intersects spatial filter with a Box location. Test whether the generated XML is correct. """ intersects = Intersects(Box(94720, 186910, 112220, 202870)) intersects.set_geometry_column('geom') xml = intersects.toXML() assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml( '<ogc:Intersects><ogc:PropertyName>geom</ogc:PropertyName>' '<gml:Envelope srsDimension="2" ' 'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370">' '<gml:lowerCorner>94720.000000 186910.000000</gml:lowerCorner>' '<gml:upperCorner>112220.000000 202870.000000</gml:upperCorner>' '</gml:Envelope></ogc:Intersects>')
def test_search_both_location_query(self, mp_remote_describefeaturetype, mp_remote_wfs_feature): """Test the search method providing both a location and a query. Test whether a dataframe is returned. Parameters ---------- mp_remote_describefeaturetype : pytest.fixture Monkeypatch the call to a remote DescribeFeatureType. mp_remote_wfs_feature : pytest.fixture Monkeypatch the call to get WFS features. """ df = self.get_search_object().search( location=Within(Box(1, 2, 3, 4)), query=self.get_valid_query_single(), return_fields=self.get_valid_returnfields()) assert type(df) is DataFrame
def test_search_both_location_query(self, mp_get_schema, mp_remote_describefeaturetype, mp_remote_wfs_feature): """Test the search method providing both a location and a query. Test whether a dataframe is returned. Parameters ---------- mp_get_schema : pytest.fixture Monkeypatch the call to a remote OWSLib schema. mp_remote_describefeaturetype : pytest.fixture Monkeypatch the call to a remote DescribeFeatureType. mp_remote_wfs_feature : pytest.fixture Monkeypatch the call to get WFS features. """ df = self.search_instance.search(location=Within(Box(1, 2, 3, 4)), query=self.valid_query_single, return_fields=self.valid_returnfields) assert isinstance(df, DataFrame)