def test_disjoint_linestring_attr(): result = parse('DISJOINT(LINESTRING(1 1,2 2), geometry)') assert result == ast.GeometryDisjoint( values.Geometry( geometry.LineString([(1, 1), (2, 2)]).__geo_interface__, ), ast.Attribute('geometry'), )
def test_overlaps_attr_multilinestring(): result = parse( { "op": "s_overlaps", "args": [ {"property": "geometry"}, { "type": "MultiLineString", "coordinates": [[[1, 1], [2, 2]], [[0, 3], [1, 1]]], "bbox": [0.0, 1.0, 2.0, 3.0], }, ], } ) assert result == ast.GeometryOverlaps( ast.Attribute("geometry"), values.Geometry( normalize_geom( geometry.MultiLineString( [ geometry.LineString([(1, 1), (2, 2)]), geometry.LineString([(0, 3), (1, 1)]), ] ).__geo_interface__ ), ), )
def test_geom_within(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Within> <fes:ValueReference>attr</fes:ValueReference> <gml:Envelope xmlns:gml="http://www.opengis.net/gml"> <gml:lowerCorner>0.0 1.0</gml:lowerCorner> <gml:upperCorner>2.0 3.0</gml:upperCorner> </gml:Envelope> </fes:Within> </fes:Filter> ''') assert result == ast.GeometryWithin( ast.Attribute('attr'), values.Geometry({ 'type': 'Polygon', 'coordinates': [ [ (0.0, 1.0), (0.0, 3.0), (2.0, 3.0), (2.0, 1.0), (0.0, 1.0), ], ] }))
def test_geom_touches(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Touches> <fes:ValueReference>attr</fes:ValueReference> <gml:Polygon xmlns:gml="http://www.opengis.net/gml"> <gml:exterior> <gml:LinearRing> <gml:posList>0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0</gml:posList> </gml:LinearRing> </gml:exterior> <gml:interior> <gml:LinearRing> <gml:posList>0.2 0.2 0.5 0.2 0.2 0.5 0.2 0.2</gml:posList> </gml:LinearRing> </gml:interior> </gml:Polygon> </fes:Touches> </fes:Filter> ''') assert result == ast.GeometryTouches( ast.Attribute('attr'), values.Geometry({ 'type': 'Polygon', 'coordinates': [ [(0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)], [(0.2, 0.2), (0.5, 0.2), (0.2, 0.5), (0.2, 0.2)], ] }))
def test_geom_equals(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Equals> <fes:ValueReference>attr</fes:ValueReference> <gml:Point gml:id="ID" srsName="http://www.opengis.net/def/crs/epsg/0/4326" xmlns:gml="http://www.opengis.net/gml"> <gml:pos>1.0 1.0</gml:pos> </gml:Point> </fes:Equals> </fes:Filter> ''') assert result == ast.GeometryEquals( ast.Attribute('attr'), values.Geometry({ 'type': 'Point', 'coordinates': (1.0, 1.0), 'crs': { 'type': 'name', 'properties': { 'name': 'http://www.opengis.net/def/crs/epsg/0/4326' } } }))
def test_intersects_attr_point_ewkt(): result = parse('INTERSECTS(geometry, SRID=4326;POINT(1 1))') assert result.rhs.geometry['crs']['properties']['name'] == \ "urn:ogc:def:crs:EPSG::4326" assert result == ast.GeometryIntersects( ast.Attribute('geometry'), values.Geometry(geometry.Point(1, 1).__geo_interface__), )
def test_contains_attr_polygon(): result = parse('CONTAINS(geometry, POLYGON((1 1,2 2,0 3,1 1)))') assert result == ast.GeometryContains( ast.Attribute('geometry'), values.Geometry( geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)]).__geo_interface__, ), )
def test_within_multipolygon_attr(): result = parse('WITHIN(MULTIPOLYGON(((1 1,2 2,0 3,1 1))), geometry)') assert result == ast.GeometryWithin( values.Geometry( geometry.MultiPolygon( [geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])]).__geo_interface__, ), ast.Attribute('geometry'), )
def test_overlaps_attr_multilinestring(): result = parse('OVERLAPS(geometry, MULTILINESTRING((1 1,2 2),(0 3,1 1)))') assert result == ast.GeometryOverlaps( ast.Attribute('geometry'), values.Geometry( geometry.MultiLineString([ geometry.LineString([(1, 1), (2, 2)]), geometry.LineString([(0, 3), (1, 1)]), ]).__geo_interface__, ), )
def test_relate_attr_polygon(): result = parse( 'RELATE(geometry, POLYGON((1 1,2 2,0 3,1 1)), \'1*T***T**\')') assert result == ast.Relate( ast.Attribute('geometry'), values.Geometry( geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)]).__geo_interface__, ), pattern='1*T***T**', )
def test_dwithin_attr_polygon(): result = parse('DWITHIN(geometry, POLYGON((1 1,2 2,0 3,1 1)), 5, feet)') assert result == ast.DistanceWithin( ast.Attribute('geometry'), values.Geometry( geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)]).__geo_interface__, ), distance=5, units='feet', )
def test_beyond_attr_polygon(): result = parse( 'BEYOND(geometry, POLYGON((1 1,2 2,0 3,1 1)), 5, nautical miles)') assert result == ast.DistanceBeyond( ast.Attribute('geometry'), values.Geometry( geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)]).__geo_interface__, ), distance=5, units='nautical miles', )
def test_intersects_attr_point(): result = parse([ 'intersects', ['geometry'], { 'type': 'Point', 'coordinates': [1, 1], } ]) assert result == ast.GeometryIntersects( ast.Attribute('geometry'), values.Geometry(normalize_geom(geometry.Point(1, 1).__geo_interface__)), )
def test_intersects_attr_geometrycollection(): result = parse('INTERSECTS(geometry, GEOMETRYCOLLECTION(POINT(1 1),' 'LINESTRING(1 1,2 2),' 'POLYGON((1 1,2 2,0 3,1 1))' '))') assert result == ast.GeometryIntersects( ast.Attribute('geometry'), values.Geometry( geometry.GeometryCollection([ geometry.Point(1, 1), geometry.LineString([(1, 1), (2, 2)]), geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)]) ]).__geo_interface__), )
def test_geom_crosses(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Crosses> <fes:ValueReference>attr</fes:ValueReference> <georss:line xmlns:georss="http://www.georss.org/georss"> 1.0 2.0 2.0 1.0 </georss:line> </fes:Crosses> </fes:Filter> ''') assert result == ast.GeometryCrosses( ast.Attribute('attr'), values.Geometry({ 'type': 'LineString', 'coordinates': [(2.0, 1.0), (1.0, 2.0)] }))
def test_within_multipolygon_attr(): result = parse([ 'within', { 'type': 'MultiPolygon', 'coordinates': [[[[1, 1], [2, 2], [0, 3], [1, 1]]]], 'bbox': [0.0, 1.0, 2.0, 3.0] }, ['geometry'], ]) assert result == ast.GeometryWithin( values.Geometry( normalize_geom( geometry.MultiPolygon( [geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])]).__geo_interface__), ), ast.Attribute('geometry'), )
def test_intersects_attr_point(): result = parse({ "intersects": [ {"property": "geometry"}, { "type": "Point", "coordinates": [1, 1], } ] }) assert result == ast.GeometryIntersects( ast.Attribute('geometry'), values.Geometry( normalize_geom( geometry.Point(1, 1).__geo_interface__ ) ), )
def test_disjoint_linestring_attr(): result = parse({ "disjoint": [ { "type": "LineString", "coordinates": [[1, 1], [2, 2]], "bbox": [1.0, 1.0, 2.0, 2.0] }, {"property": "geometry"}, ] }) assert result == ast.GeometryDisjoint( values.Geometry( normalize_geom( geometry.LineString([(1, 1), (2, 2)]).__geo_interface__ ), ), ast.Attribute('geometry'), )
def test_geom_contains(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Contains> <fes:ValueReference>attr</fes:ValueReference> <georss:polygon xmlns:georss="http://www.georss.org/georss"> 1.0 0.5 2.0 0.5 2.0 1.5 1.0 1.5 1.0 0.5 </georss:polygon> </fes:Contains> </fes:Filter> ''') assert result == ast.GeometryContains( ast.Attribute('attr'), values.Geometry({ 'type': 'Polygon', 'coordinates': [[(0.5, 1.0), (0.5, 2.0), (1.5, 2.0), (1.5, 1.0), (0.5, 1.0)]] }))
def test_geom_disjoint(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Disjoint> <fes:ValueReference>attr</fes:ValueReference> <gml:LineString xmlns:gml="http://www.opengis.net/gml"> <gml:posList>1.0 1.0 2.0 2.0</gml:posList> </gml:LineString> </fes:Disjoint> </fes:Filter> ''') assert result == ast.GeometryDisjoint( ast.Attribute('attr'), values.Geometry({ 'type': 'LineString', 'coordinates': [ (1.0, 1.0), (2.0, 2.0), ], }))
def test_geom_intersects(): result = parse(''' <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <ogc:Intersects> <ogc:ValueReference>attr</ogc:ValueReference> <georss:box xmlns:georss="http://www.georss.org/georss"> 1.0 0.5 2.0 1.5 </georss:box> </ogc:Intersects> </ogc:Filter> ''') assert result == ast.GeometryIntersects( ast.Attribute('attr'), values.Geometry({ 'type': 'Polygon', 'bbox': (0.5, 1.0, 1.5, 2.0), 'coordinates': [[(0.5, 1.0), (0.5, 2.0), (1.5, 2.0), (1.5, 1.0), (0.5, 1.0)]] }))
def test_crosses_attr_multilinestring(): result = parse({ "crosses": [ {"property": "geometry"}, { "type": "MultiLineString", "coordinates": [[[1, 1], [2, 2]], [[0, 3], [1, 1]]], "bbox": [0.0, 1.0, 2.0, 3.0] }, ] }) assert result == ast.GeometryCrosses( ast.Attribute('geometry'), values.Geometry( normalize_geom( geometry.MultiLineString([ geometry.LineString([(1, 1), (2, 2)]), geometry.LineString([(0, 3), (1, 1)]), ]).__geo_interface__ ) ), )
def test_geom_dwithin(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:DWithin> <fes:ValueReference>attr</fes:ValueReference> <georss:point xmlns:georss="http://www.georss.org/georss"> 1.0 1.0 </georss:point> <fes:Distance uom="m">10</fes:Distance> </fes:DWithin> </fes:Filter> ''') assert result == ast.DistanceWithin( ast.Attribute('attr'), values.Geometry({ "type": "Point", "coordinates": (1.0, 1.0), }), distance=10, units="m", )
def test_within_multipolygon_attr(): result = parse({ "within": [ { "type": "MultiPolygon", "coordinates": [ [[[1, 1], [2, 2], [0, 3], [1, 1]]] ], 'bbox': [0.0, 1.0, 2.0, 3.0] }, {"property": "geometry"}, ] }) assert result == ast.GeometryWithin( values.Geometry( normalize_geom( geometry.MultiPolygon([ geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)]) ]).__geo_interface__ ), ), ast.Attribute('geometry'), )
def test_contains_attr_polygon(): result = parse({ "contains": [ {"property": "geometry"}, { "type": "Polygon", "coordinates": [ [[1, 1], [2, 2], [0, 3], [1, 1]] ], 'bbox': [0.0, 1.0, 2.0, 3.0] }, ] }) assert result == ast.GeometryContains( ast.Attribute('geometry'), values.Geometry( normalize_geom( geometry.Polygon( [(1, 1), (2, 2), (0, 3), (1, 1)] ).__geo_interface__ ), ), )
def test_geom_overlaps(): result = parse(''' <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <fes:Overlaps> <fes:ValueReference>attr</fes:ValueReference> <gml:MultiSurface xmlns:gml="http://www.opengis.net/gml"> <gml:surfaceMember> <gml:Polygon> <gml:exterior> <gml:LinearRing> <gml:posList>0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 </gml:posList> </gml:LinearRing> </gml:exterior> <gml:interior> <gml:LinearRing> <gml:posList>0.2 0.2 0.5 0.2 0.2 0.5 0.2 0.2 </gml:posList> </gml:LinearRing> </gml:interior> </gml:Polygon> </gml:surfaceMember> <gml:surfaceMember> <gml:Polygon> <gml:exterior> <gml:LinearRing> <gml:posList> 10.0 10.0 11.0 10.0 10.0 11.0 10.0 10.0 </gml:posList> </gml:LinearRing> </gml:exterior> <gml:interior> <gml:LinearRing> <gml:posList> 10.2 10.2 10.5 10.2 10.2 10.5 10.2 10.2 </gml:posList> </gml:LinearRing> </gml:interior> </gml:Polygon> </gml:surfaceMember> </gml:MultiSurface> </fes:Overlaps> </fes:Filter> ''') assert result == ast.GeometryOverlaps( ast.Attribute('attr'), values.Geometry({ 'type': 'MultiPolygon', 'coordinates': [[ [(0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)], [(0.2, 0.2), (0.5, 0.2), (0.2, 0.5), (0.2, 0.2)], ], [ [(10.0, 10.0), (11.0, 10.0), (10.0, 11.0), (10.0, 10.0)], [(10.2, 10.2), (10.5, 10.2), (10.2, 10.5), (10.2, 10.2)], ]] }))
def test_intersects_attr_point(): result = parse('INTERSECTS(geometry, POINT(1 1))') assert result == ast.GeometryIntersects( ast.Attribute('geometry'), values.Geometry(geometry.Point(1, 1).__geo_interface__), )