[Geoserver-users] PostGIS query via WMS request

Apologies for posting a question which probably is more a WMS question, than a Geoserver specific one, but I’m having trouble finding an answer elsewhere. I would like to know if it is possible to pass a PostGIS query through Geoserver via a WMS request? The specific use case being a group of points spread out across a state, and I would like to query for points that lie within the boundaries of a county. I know that I can pass a bbox request, but I’d like something more accurate, and also perhaps to use some of the other PostGIS spatial functions as well. Feel free to RTFM me, but please send me the link to the manual.

Thanks,

Roger

Roger André
GIS Developer/Analyst
Enterprise Management Solutions

CH2M HILL
1100 112th Avenue NE
Suite 400
Bellevue, WA 98004
Direct 425.233.3042
roger.andre@anonymised.com

Developing People through Challenging Projects

Roger.Andre@anonymised.com ha scritto:

Apologies for posting a question which probably is more a WMS question, than a Geoserver specific one, but I'm having trouble finding an answer elsewhere. I would like to know if it is possible to pass a PostGIS query through Geoserver via a WMS request? The specific use case being a group of points spread out across a state, and I would like to query for points that lie within the boundaries of a county. I know that I can pass a bbox request, but I'd like something more accurate, and also perhaps to use some of the other PostGIS spatial functions as well. Feel free to RTFM me, but please send me the link to the manual.

The standard way to do this with the WMS protocol would be to provide
a new full SLD for the layers you're using and use the <Filter> elements
in the Rule to display only part of the features. See the &sld=xxx
parameter in the SLD 1.0 specification (SLD site).

The GeoServer specific way, a lot handier, is to specify a vendor
param that will filter out the data just like in WFS. You can use
either &filter=... with the same syntax as a WFS request, or
a cql_filer=... with a much more human readable syntax, and some
examples here:
http://docs.codehaus.org/display/GEOSDOC/Common+Query+Language+(CQL)+Tutorial+(unfinished)
and here:
http://docs.codehaus.org/display/GEOTDOC/01+CQL+Examples

Hope this helps
Cheers
Andrea

Hi Roger,

We are happy to answer these sorts of questions. Unfortunately no there
is not support for passing a raw sql query into the backend. However
while it is not official part of the wms spec, GeoServer wms supports
ogc style filtesr. I believe MapServer supports this as well. This is
taken from the wfs spec.

Not sure how familiar you are with ogc filters, but this means you can
use the the ogc xml query predicate language to specify a variety of
spatial and non-spatial predicates. An example in this case:

<ogc:Filter>
  <ogc:Intersects>
     <ogc:PropertyName>[the_geom]<ogc:PropertyName>
     <ogc:Literal>
       <gml:Polygon>
     [the county boundary]
       </gml:Polygon>
     </ogc:Literal>
  </ogc:Intersects>
</ogc:Filter>

Could be used to specify a predicate that only includes those geometries
which fall into a particular county boundary.

When specified in a request with "filter=..." GeoServer will then map
this to a backend postgis query predicate "where intersects(the_geom,...)".

While the ogc spatial filter predicates do not make visible all of what
is possible with postgis... it does expose many of the useful ones.

If you check out the sample requests that come with geoserver there are
examples of how to use the filter parameter with WMS.

Feel free to ask away if you have any more questions or anything is unclear.

-Justin

Roger.Andre@anonymised.com wrote:

Apologies for posting a question which probably is more a WMS question,
than a Geoserver specific one, but I'm having trouble finding an answer
elsewhere. I would like to know if it is possible to pass a PostGIS
query through Geoserver via a WMS request? The specific use case being
a group of points spread out across a state, and I would like to query
for points that lie within the boundaries of a county. I know that I
can pass a bbox request, but I'd like something more accurate, and also
perhaps to use some of the other PostGIS spatial functions as well.
Feel free to RTFM me, but please send me the link to the manual.

Thanks,

Roger
--
Roger André
GIS Developer/Analyst
Enterprise Management Solutions

CH2M HILL
1100 112th Avenue NE
Suite 400
Bellevue, WA 98004
Direct 425.233.3042
roger.andre@anonymised.com <mailto:roger.andre@anonymised.com>

Developing People through Challenging Projects

!DSPAM:4007,478ba964133982092453641!

------------------------------------------------------------------------

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

!DSPAM:4007,478ba964133982092453641!

------------------------------------------------------------------------

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

!DSPAM:4007,478ba964133982092453641!

--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org

Excellent! Thank you both for the answers you sent me. I'm not terribly handy with ogc filters yet, but I am using them in my SLD's to create rules for the use of custom icons in my point symbolizers. I think I can figure something out using the information you sent as a starting place.

Thanks again,

Roger
--

-----Original Message-----
From: Justin Deoliveira [mailto:jdeolive@anonymised.com]
Sent: Monday, January 14, 2008 10:52 AM
To: Andre, Roger/SEA
Cc: geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] PostGIS query via WMS request

Hi Roger,

We are happy to answer these sorts of questions. Unfortunately no there is not support for passing a raw sql query into the backend. However while it is not official part of the wms spec, GeoServer wms supports ogc style filtesr. I believe MapServer supports this as well. This is taken from the wfs spec.

Not sure how familiar you are with ogc filters, but this means you can use the the ogc xml query predicate language to specify a variety of spatial and non-spatial predicates. An example in this case:

<ogc:Filter>
  <ogc:Intersects>
     <ogc:PropertyName>[the_geom]<ogc:PropertyName>
     <ogc:Literal>
       <gml:Polygon>
     [the county boundary]
       </gml:Polygon>
     </ogc:Literal>
  </ogc:Intersects>
</ogc:Filter>

Could be used to specify a predicate that only includes those geometries which fall into a particular county boundary.

When specified in a request with "filter=..." GeoServer will then map this to a backend postgis query predicate "where intersects(the_geom,...)".

While the ogc spatial filter predicates do not make visible all of what is possible with postgis... it does expose many of the useful ones.

If you check out the sample requests that come with geoserver there are examples of how to use the filter parameter with WMS.

Feel free to ask away if you have any more questions or anything is unclear.

-Justin

----

The standard way to do this with the WMS protocol would be to provide a new full SLD for the layers you're using and use the <Filter> elements in the Rule to display only part of the features. See the &sld=xxx parameter in the SLD 1.0 specification (SLD site).

The GeoServer specific way, a lot handier, is to specify a vendor param that will filter out the data just like in WFS. You can use either &filter=... with the same syntax as a WFS request, or a cql_filer=... with a much more human readable syntax, and some examples here:
http://docs.codehaus.org/display/GEOSDOC/Common+Query+Language+(CQL)+Tutorial+(unfinished)
and here:
http://docs.codehaus.org/display/GEOTDOC/01+CQL+Examples

Hope this helps
Cheers
Andrea

-----

Roger.Andre@anonymised.com wrote:

Apologies for posting a question which probably is more a WMS
question, than a Geoserver specific one, but I'm having trouble
finding an answer elsewhere. I would like to know if it is possible
to pass a PostGIS query through Geoserver via a WMS request? The
specific use case being a group of points spread out across a state,
and I would like to query for points that lie within the boundaries of
a county. I know that I can pass a bbox request, but I'd like
something more accurate, and also perhaps to use some of the other PostGIS spatial functions as well.
Feel free to RTFM me, but please send me the link to the manual.

Thanks,

Roger
--
Roger André
GIS Developer/Analyst
Enterprise Management Solutions

CH2M HILL
1100 112th Avenue NE
Suite 400
Bellevue, WA 98004
Direct 425.233.3042
roger.andre@anonymised.com <mailto:roger.andre@anonymised.com>

Developing People through Challenging Projects

!DSPAM:4007,478ba964133982092453641!

----------------------------------------------------------------------
--

----------------------------------------------------------------------
--- Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for just about anything
Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
tplace

!DSPAM:4007,478ba964133982092453641!

----------------------------------------------------------------------
--

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

!DSPAM:4007,478ba964133982092453641!

--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org