Exemplo n.º 1
0
def test_fes20_c7_example1():
    """C.7 Temporal filter example

    EXAMPLE 1
    The following examples for temporal comparisons are provided to illustrate
    the proper use of the temporal  The examples are based on the
    following sample GML:"""
    xml_text = """
        <?xml version="1.0"?>
        <fes:Filter
           xmlns:fes="http://www.opengis.net/fes/2.0"
           xmlns:gml="http://www.opengis.net/gml/3.2"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.opengis.net/fes/2.0
           http://schemas.opengis.net/filter/2.0/filterAll.xsd
           http://www.opengis.net/gml/3.2
           http://schemas.opengis.net/gml/3.2.1/gml.xsd">
           <fes:DWithin>
              <fes:ValueReference>geometry</fes:ValueReference>
              <gml:Point gml:id="P1" srsName="http://www.opengis.net/def/crs/epsg/0/4326">
                 <gml:pos>43.716589 -79.340686</gml:pos>
              </gml:Point>
              <fes:Distance uom="m">10</fes:Distance>
           </fes:DWithin>
        </fes:Filter>
    """.strip()
    expected = Filter(predicate=DistanceOperator(
        valueReference=ValueReference(xpath="geometry"),
        operatorType=DistanceOperatorName.DWithin,
        geometry=geometries.GEOSGMLGeometry(
            srs=WGS84,
            geos_data=GEOSGeometry("POINT (43.716589 -79.34068600000001)",
                                   srid=4326),
        ),
        distance=Measure(value=10, uom="m"),
    ))
    result = Filter.from_string(xml_text)
    assert result == expected, f"result={result!r}"

    # Test SQL generating
    query = result.compile_query()
    assert query == CompiledQuery(lookups=[
        Q(geometry__dwithin=(
            GEOSGeometry("POINT (43.716589 -79.34068600000001)", srid=4326),
            measure.Distance(m=10),
        ))
    ]), repr(query)
Exemplo n.º 2
0
def test_fes20_c5_example11_b():
    """Although GML 3.2 is the canonical GML version supported by this
    International Standard, the filter schemas have been crafted is such a way
    as to support any version of GML.  For example, here is the same filter
    expression expect that it GML 2.1.2 to encoding the geometry rather than
    GML 3.2:"""
    xml_text = """
        <?xml version="1.0"?>
        <fes:Filter
           xmlns:fes="http://www.opengis.net/fes/2.0"
           xmlns:gml="http://www.opengis.net/gml"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.opengis.net/fes/2.0
           http://www.pvretano.com/schemas/filter/2.0/filterAll.xsd
           http://www.opengis.net/gml
           http://www.pvretano.com/schemas/gml/2.1.2/geometry.xsd">
           <fes:Overlaps>
              <fes:ValueReference>Geometry</fes:ValueReference>
              <gml:Polygon srsName="http://www.opengis.net/def/crs/epsg/0/4326">
                 <gml:outerBoundaryIs>
                    <gml:LinearRing>
                       <gml:coordinates>10,10 20,20 30,30 40,40 10,10</gml:coordinates>
                    </gml:LinearRing>
                 </gml:outerBoundaryIs>
              </gml:Polygon>
           </fes:Overlaps>
        </fes:Filter>
    """.strip()
    expected = Filter(predicate=BinarySpatialOperator(
        operatorType=SpatialOperatorName.Overlaps,
        operand1=ValueReference(xpath="Geometry"),
        operand2=geometries.GEOSGMLGeometry(
            srs=WGS84,
            geos_data=GEOSGeometry(
                "POLYGON ((10 10, 20 20, 30 30, 40 40, 10 10))", srid=4326),
        ),
    ))
    result = Filter.from_string(xml_text)
    assert result == expected, f"result={result!r}"

    # Test SQL generating
    query = result.compile_query()
    assert query == CompiledQuery(lookups=[
        Q(Geometry__overlaps=GEOSGeometry(
            "POLYGON ((10 10, 20 20, 30 30, 40 40, 10 10))", srid=4326))
    ]), repr(query)
Exemplo n.º 3
0
def test_fes20_c5_example11():
    """This example encodes a spatial filter that identifies all features whose
    geometry property, named Geometry in this example, overlap a polygonal area
    of interest."""
    xml_text = """
        <fes:Filter
        xmlns:fes="http://www.opengis.net/fes/2.0"
        xmlns:gml="http://www.opengis.net/gml/3.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.opengis.net/fes/2.0
        http://schemas.opengis.net/filter/2.0/filterAll.xsd
        http://www.opengis.net/gml/3.2
        http://schemas.opengis.net/gml/3.2.1/gml.xsd">
        <fes:Overlaps>
            <fes:ValueReference>Geometry</fes:ValueReference>
            <gml:Polygon gml:id="P1" srsName="http://www.opengis.net/def/crs/epsg/0/4326">
                <gml:exterior>
                    <gml:LinearRing>
                        <gml:posList>10 10 20 20 30 30 40 40 10 10</gml:posList>
                    </gml:LinearRing>
                </gml:exterior>
            </gml:Polygon>
        </fes:Overlaps>
    </fes:Filter>
    """.strip()
    expected = Filter(predicate=BinarySpatialOperator(
        operatorType=SpatialOperatorName.Overlaps,
        operand1=ValueReference(xpath="Geometry"),
        operand2=geometries.GEOSGMLGeometry(
            srs=WGS84,
            geos_data=GEOSGeometry(
                "POLYGON ((10 10, 20 20, 30 30, 40 40, 10 10))", srid=4326),
        ),
    ))
    result = Filter.from_string(xml_text)
    assert result == expected, f"result={result!r}"

    # Test SQL generating
    query = result.compile_query()
    assert query == CompiledQuery(lookups=[
        Q(Geometry__overlaps=GEOSGeometry(
            "POLYGON ((10 10, 20 20, 30 30, 40 40, 10 10))", srid=4326))
    ]), repr(query)
Exemplo n.º 4
0
def test_fes20_c5_example15():
    """This example finds features within a specified distance of a geometry."""
    xml_text = """
        <?xml version="1.0"?>
        <fes:Filter
           xmlns:fes="http://www.opengis.net/fes/2.0"
           xmlns:gml="http://www.opengis.net/gml/3.2"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.opengis.net/fes/2.0
           http://schemas.opengis.net/filter/2.0/filterAll.xsd
           http://www.opengis.net/gml/3.2
           http://schemas.opengis.net/gml/3.2.1/gml.xsd">
           <fes:DWithin>
              <fes:ValueReference>geometry</fes:ValueReference>
              <gml:Point gml:id="P1" srsName="http://www.opengis.net/def/crs/epsg/0/4326">
                 <gml:pos>43.716589 -79.340686</gml:pos>
              </gml:Point>
              <fes:Distance uom="m">10</fes:Distance>
           </fes:DWithin>
        </fes:Filter>
    """.strip()
    expected = Filter(predicate=DistanceOperator(
        valueReference=ValueReference(xpath="geometry"),
        operatorType=DistanceOperatorName.DWithin,
        geometry=geometries.GEOSGMLGeometry(
            srs=WGS84,
            geos_data=GEOSGeometry("POINT (43.716589 -79.34068600000001)",
                                   srid=4326),
        ),
        distance=Measure(value=D("10"), uom="m"),
    ))
    result = Filter.from_string(xml_text)
    assert result == expected, f"result={result!r}"

    # Test SQL generating
    query = result.compile_query()
    assert query == CompiledQuery(lookups=[
        Q(geometry__dwithin=(
            GEOSGeometry("POINT (43.716589 -79.34068600000001)", srid=4326),
            measure.Distance(m=10.0),
        ))
    ]), repr(query)
Exemplo n.º 5
0
def test_fes20_c5_example13():
    """Spatial and non-spatial predicates can be encoded in a single filter
    expression. In this example, a spatial predicate checks to see if the
    geometric property WKB_GEOMlies within a region of interest defined by a
    polygon and a scalar predicate check to see if the scalar property DEPTH
    lies within a specified range. This example encoding is equivalent to the
    expression:

    (wkb_geom WITHIN "some polygon") AND (depth BETWEEN 400 AND 800)
    """
    xml_text = """
        <fes:Filter
           xmlns:fes="http://www.opengis.net/fes/2.0"
           xmlns:gml="http://www.opengis.net/gml/3.2"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.opengis.net/fes/2.0
           http://schemas.opengis.net/filter/2.0/filterAll.xsd
           http://www.opengis.net/gml/3.2
           http://schemas.opengis.net/gml/3.2.1/gml.xsd">
           <fes:And>
              <fes:Within>
                 <fes:ValueReference>WKB_GEOM</fes:ValueReference>
                 <gml:Polygon gml:id="P1" srsName="http://www.opengis.net/def/crs/epsg/0/4326">
                    <gml:exterior>
                       <gml:LinearRing>
                          <gml:posList>10 10 20 20 30 30 40 40 10 10</gml:posList>
                       </gml:LinearRing>
                    </gml:exterior>
                 </gml:Polygon>
              </fes:Within>
              <fes:PropertyIsBetween>
                 <fes:ValueReference>DEPTH</fes:ValueReference>
                 <fes:LowerBoundary>
                    <fes:Literal>400</fes:Literal>
                 </fes:LowerBoundary>
                 <fes:UpperBoundary>
                    <fes:Literal>800</fes:Literal>
                 </fes:UpperBoundary>
              </fes:PropertyIsBetween>
           </fes:And>
        </fes:Filter>
    """.strip()
    expected = Filter(predicate=BinaryLogicOperator(
        operands=[
            BinarySpatialOperator(
                operatorType=SpatialOperatorName.Within,
                operand1=ValueReference(xpath="WKB_GEOM"),
                operand2=geometries.GEOSGMLGeometry(
                    srs=WGS84,
                    geos_data=GEOSGeometry(
                        "POLYGON ((10 10, 20 20, 30 30, 40 40, 10 10))",
                        srid=4326),
                ),
            ),
            BetweenComparisonOperator(
                expression=ValueReference(xpath="DEPTH"),
                lowerBoundary=Literal(raw_value="400"),
                upperBoundary=Literal(raw_value="800"),
            ),
        ],
        operatorType=BinaryLogicType.And,
    ))
    result = Filter.from_string(xml_text)
    assert result == expected, f"result={result!r}"

    # Test SQL generating
    query = result.compile_query()
    assert query == CompiledQuery(lookups=[
        Q(WKB_GEOM__within=GEOSGeometry(
            "POLYGON ((10 10, 20 20, 30 30, 40 40, 10 10))", srid=4326))
        & Q(DEPTH__range=(400, 800))
    ]), repr(query)