[Geoserver-users] Using relatesPattern Function

I'm trying to figure out the best way to do a GetFeatures query in
GeoServer 1.3.1 which retrieves all results whose geometries are related
to my supplied geometry according to the following DE-9IM pattern:
T********

I should be able to do an Intersects(geom) AND NOT Touches(geom), but
I'm wondering if I could more efficiently make use of the relatesPattern
function. I created a sample shapefile based on BasicPolygons that
contains two polygons with a shared boundary but whose interiors do not
intersect. As expected, the Intersects AND NOT Touches works fine, but
I can't seem to get the relatesPattern function working.

My GetFeatures query looks like this:

<wfs:GetFeature service="WFS" version="1.0.0"
  outputFormat="GML2"
  xmlns:topp="http://www.openplans.org/topp&quot;
  xmlns:wfs="http://www.opengis.net/wfs&quot;
  xmlns="http://www.opengis.net/ogc&quot;
  xmlns:gml="http://www.opengis.net/gml&quot;
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation="http://www.opengis.net/wfs

http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Function name="relatePattern">
        <PropertyName>the_geom</PropertyName>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:polygonMember>
            <gml:Polygon>
              <gml:outerBoundaryIs>
                <gml:LinearRing>
                  <gml:coordinates decimal="." cs="," ts=" ">-1,-1 -1,1
1,1 1,-1 -1,-1</gml:coordinates>
                </gml:LinearRing>
              </gml:outerBoundaryIs>
            </gml:Polygon>
          </gml:polygonMember>
        </gml:MultiPolygon>
        <Literal>T********</Literal>
      </Function>
    </Filter>
  </wfs:Query>
</wfs:GetFeature>

I get an error message "org.xml.sax.SAXException: Attempted to construct
illegal filter: Attempted to add sub expression in a bad state:
complete" plus associated stack trace. The shapefile I'm using was
constructed (using ogr2ogr) from the following gml:

<?xml version="1.0" encoding="UTF-8"?>
<FeatureCollection>
  <gml:boundedBy>
    <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
      <gml:coordinates decimal="." cs="," ts=" ">-1,-1
3,1</gml:coordinates>
    </gml:Box>
  </gml:boundedBy>
  <gml:featureMember>
    <BasicPolygons fid="BasicPolygons.1">
      <the_geom>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:polygonMember>
            <gml:Polygon>
              <gml:outerBoundaryIs>
                <gml:LinearRing>
                  <gml:coordinates decimal="." cs="," ts=" ">-1,-1 -1,1
1,1 1,-1 -1,-1</gml:coordinates>
                </gml:LinearRing>
              </gml:outerBoundaryIs>
            </gml:Polygon>
          </gml:polygonMember>
        </gml:MultiPolygon>
      </the_geom>
      <ID>ID_LEFT</ID>
    </BasicPolygons>
  </gml:featureMember>
  <gml:featureMember>
    <BasicPolygons fid="BasicPolygons.3">
      <the_geom>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:polygonMember>
            <gml:Polygon>
              <gml:outerBoundaryIs>
                <gml:LinearRing>
                  <gml:coordinates decimal="." cs="," ts=" ">1,1 3,1
3,-1 1,-1 1,1</gml:coordinates>
                </gml:LinearRing>
              </gml:outerBoundaryIs>
            </gml:Polygon>
          </gml:polygonMember>
        </gml:MultiPolygon>
      </the_geom>
      <ID>ID_RIGHT</ID>
    </BasicPolygons>
  </gml:featureMember>
</FeatureCollection>

Has anybody successfully used the relatesPattern function in a
GetFeatures filter before? I'm open to the possibility that I'm using
the function in completely the wrong way. Also, should I even bother
with the relatesPattern function, i.e. will Intersects AND NOT Touches
be just as efficient?

Thanks for the help.

John Fletcher
Latitude Geographics Group Ltd.
jfletcher@anonymised.com www.latitudegeo.com
Head Office: 204 Market Square Victoria, BC Canada V8W 3C6
Tel: (250) 381-8130 Fax: (250) 381-8132

Geocortex Internet Mapping (www.geocortex.net) - Helping people succeed
with web-based geography

Yeah, you're using the filter wrong. A function can't just be used there, it has to be the result of something? A function is an expression, so has to be used in a filter. Like:

<Filter>
<PropertyIsEqualTo>
<Functionname="SIN">
<PropertyName>DISPERSION_ANGLE</PropertyName>
</Function>
<Literal>1</Literal>
</PropertyIsEqualTo>
</Filter>

or

<PropertyIsEqualTo>
<PropertyName>PROPA</PropertyName>
<Add>
<PropertyName>PROPB</PropertyName>
<Literal>100</Literal>
</Add>
</PropertyIsEqualTo>

Sorry, I don't have time to fully check it now, but I _think_ what you need to do is to use PropertyIsEqualTo and use 'true' as the literal. Or maybe you can use 1 to be true? I'm not sure, but basically it has to compare against something, and the result of the function is a boolean.

Chris

John Fletcher wrote:

I'm trying to figure out the best way to do a GetFeatures query in
GeoServer 1.3.1 which retrieves all results whose geometries are related
to my supplied geometry according to the following DE-9IM pattern:
T********

I should be able to do an Intersects(geom) AND NOT Touches(geom), but
I'm wondering if I could more efficiently make use of the relatesPattern
function. I created a sample shapefile based on BasicPolygons that
contains two polygons with a shared boundary but whose interiors do not
intersect. As expected, the Intersects AND NOT Touches works fine, but
I can't seem to get the relatesPattern function working.

My GetFeatures query looks like this:

<wfs:GetFeature service="WFS" version="1.0.0"
  outputFormat="GML2"
  xmlns:topp="http://www.openplans.org/topp&quot;
  xmlns:wfs="http://www.opengis.net/wfs&quot;
  xmlns="http://www.opengis.net/ogc&quot;
  xmlns:gml="http://www.opengis.net/gml&quot;
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Function name="relatePattern">
        <PropertyName>the_geom</PropertyName>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:polygonMember>
            <gml:Polygon>
              <gml:outerBoundaryIs>
                <gml:LinearRing>
                  <gml:coordinates decimal="." cs="," ts=" ">-1,-1 -1,1
1,1 1,-1 -1,-1</gml:coordinates>
                </gml:LinearRing>
              </gml:outerBoundaryIs>
            </gml:Polygon>
          </gml:polygonMember>
        </gml:MultiPolygon>
        <Literal>T********</Literal>
      </Function>
    </Filter>
  </wfs:Query>
</wfs:GetFeature>

I get an error message "org.xml.sax.SAXException: Attempted to construct
illegal filter: Attempted to add sub expression in a bad state:
complete" plus associated stack trace. The shapefile I'm using was
constructed (using ogr2ogr) from the following gml:

<?xml version="1.0" encoding="UTF-8"?>
<FeatureCollection>
  <gml:boundedBy>
    <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
      <gml:coordinates decimal="." cs="," ts=" ">-1,-1
3,1</gml:coordinates>
    </gml:Box>
  </gml:boundedBy>
  <gml:featureMember>
    <BasicPolygons fid="BasicPolygons.1">
      <the_geom>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:polygonMember>
            <gml:Polygon>
              <gml:outerBoundaryIs>
                <gml:LinearRing>
                  <gml:coordinates decimal="." cs="," ts=" ">-1,-1 -1,1
1,1 1,-1 -1,-1</gml:coordinates>
                </gml:LinearRing>
              </gml:outerBoundaryIs>
            </gml:Polygon>
          </gml:polygonMember>
        </gml:MultiPolygon>
      </the_geom>
      <ID>ID_LEFT</ID>
    </BasicPolygons>
  </gml:featureMember>
  <gml:featureMember>
    <BasicPolygons fid="BasicPolygons.3">
      <the_geom>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:polygonMember>
            <gml:Polygon>
              <gml:outerBoundaryIs>
                <gml:LinearRing>
                  <gml:coordinates decimal="." cs="," ts=" ">1,1 3,1
3,-1 1,-1 1,1</gml:coordinates>
                </gml:LinearRing>
              </gml:outerBoundaryIs>
            </gml:Polygon>
          </gml:polygonMember>
        </gml:MultiPolygon>
      </the_geom>
      <ID>ID_RIGHT</ID>
    </BasicPolygons>
  </gml:featureMember>
</FeatureCollection>

Has anybody successfully used the relatesPattern function in a
GetFeatures filter before? I'm open to the possibility that I'm using
the function in completely the wrong way. Also, should I even bother
with the relatesPattern function, i.e. will Intersects AND NOT Touches
be just as efficient?

Thanks for the help.

John Fletcher
Latitude Geographics Group Ltd.
jfletcher@anonymised.com www.latitudegeo.com
Head Office: 204 Market Square Victoria, BC Canada V8W 3C6
Tel: (250) 381-8130 Fax: (250) 381-8132

Geocortex Internet Mapping (www.geocortex.net) - Helping people succeed
with web-based geography

_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

!DSPAM:1003,4491b0a7188242223018498!

--
Chris Holmes
The Open Planning Project
http://topp.openplans.org