Using relatesPattern Function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using relatesPattern Function

John Fletcher
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"
  xmlns:wfs="http://www.opengis.net/wfs"
  xmlns="http://www.opengis.net/ogc"
  xmlns:gml="http://www.opengis.net/gml"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.opengis.net/wfs
 
http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
  <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">
          <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">
      <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">
          <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">
          <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.
[hidden email] 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Using relatesPattern Function

Chris Holmes-2
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"
>   xmlns:wfs="http://www.opengis.net/wfs"
>   xmlns="http://www.opengis.net/ogc"
>   xmlns:gml="http://www.opengis.net/gml"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://www.opengis.net/wfs
>  
> http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
>   <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">
>           <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">
>       <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">
>           <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">
>           <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.
> [hidden email] 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geoserver-users
>
> !DSPAM:1003,4491b0a7188242223018498!
>
--
Chris Holmes
The Open Planning Project
http://topp.openplans.org


_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users

cholmes.vcf (281 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using relatesPattern Function

John Fletcher
In reply to this post by John Fletcher
>>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>

Thanks for the response.  Wrapping the Function in a PropertyIsEqualTo
with a Literal 'true' as the second argument throws the same error as
just using the Function on its own.  I did read in the FE spec that an
expression can't be a child of Filter, but Geoserver does (incorrectly?)
accept one.  The following two Filters return all values in Geoserver:

  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Literal>true</Literal>
    </Filter>
  </wfs:Query>

and:

  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Function name="isValid">
        <PropertyName>the_geom</PropertyName>
      </Function>
    </Filter>
  </wfs:Query>

A valid (but lame) option should be to just wrap the expression in two
nested <Not> elements like this:

  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Not>
        <Not>
          <Function name="isValid">
            <PropertyName>the_geom</PropertyName>
          </Function>
        </Not>
      </Not>
    </Filter>
  </wfs:Query>

but Geoserver doesn't like this at all (IndexOutOfBoundsException).

Perhaps there's an issue with the GML parsing in Functions, as the
following two Queries should return identical results, but the first
operates correctly while the second throws a NPE:

Works:

  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Intersects>
        <PropertyName>the_geom</PropertyName>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
          <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>
      </Intersects>
    </Filter>
  </wfs:Query>

NPE:

  <wfs:Query typeName="topp:TouchingPolygons">
    <Filter>
      <Function name="intersects">
        <PropertyName>the_geom</PropertyName>
        <gml:MultiPolygon
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
          <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>
      </Function>
    </Filter>
  </wfs:Query>

For now I'll use Intersects And Not Touches instead of
Relates(T********).  Perhaps I'll load up Geoserver / Geotools into
eclipse and root around a bit for the problem (if I can summon the
activation energy).  The Filter parser is a bit of a bear...

John


_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Using relatesPattern Function

Chris Holmes-2
Could you file this as a bug in JIRA?  It's probably pretty low
priority, especially since it looks like you've got something that
works.  But I believe the function should work in some way.  Likely
there's a bug, if not then we'd at least need better documentation, so
should be an issue in JIRA.

Chris

John Fletcher wrote:

>>> 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>
>
> Thanks for the response.  Wrapping the Function in a PropertyIsEqualTo
> with a Literal 'true' as the second argument throws the same error as
> just using the Function on its own.  I did read in the FE spec that an
> expression can't be a child of Filter, but Geoserver does (incorrectly?)
> accept one.  The following two Filters return all values in Geoserver:
>
>   <wfs:Query typeName="topp:TouchingPolygons">
>     <Filter>
>       <Literal>true</Literal>
>     </Filter>
>   </wfs:Query>
>
> and:
>
>   <wfs:Query typeName="topp:TouchingPolygons">
>     <Filter>
>       <Function name="isValid">
>         <PropertyName>the_geom</PropertyName>
>       </Function>
>     </Filter>
>   </wfs:Query>
>
> A valid (but lame) option should be to just wrap the expression in two
> nested <Not> elements like this:
>
>   <wfs:Query typeName="topp:TouchingPolygons">
>     <Filter>
>       <Not>
>         <Not>
>           <Function name="isValid">
>             <PropertyName>the_geom</PropertyName>
>           </Function>
>         </Not>
>       </Not>
>     </Filter>
>   </wfs:Query>
>
> but Geoserver doesn't like this at all (IndexOutOfBoundsException).
>
> Perhaps there's an issue with the GML parsing in Functions, as the
> following two Queries should return identical results, but the first
> operates correctly while the second throws a NPE:
>
> Works:
>
>   <wfs:Query typeName="topp:TouchingPolygons">
>     <Filter>
>       <Intersects>
>         <PropertyName>the_geom</PropertyName>
>         <gml:MultiPolygon
> srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
>           <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>
>       </Intersects>
>     </Filter>
>   </wfs:Query>
>
> NPE:
>
>   <wfs:Query typeName="topp:TouchingPolygons">
>     <Filter>
>       <Function name="intersects">
>         <PropertyName>the_geom</PropertyName>
>         <gml:MultiPolygon
> srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
>           <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>
>       </Function>
>     </Filter>
>   </wfs:Query>
>
> For now I'll use Intersects And Not Touches instead of
> Relates(T********).  Perhaps I'll load up Geoserver / Geotools into
> eclipse and root around a bit for the problem (if I can summon the
> activation energy).  The Filter parser is a bit of a bear...
>
> John
>
>
> _______________________________________________
> Geoserver-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geoserver-users
>
> !DSPAM:1003,4492d74b16341510810322!
>
--
Chris Holmes
The Open Planning Project
http://topp.openplans.org


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users

cholmes.vcf (281 bytes) Download Attachment