[OpenLayers-Users] Creating an ogc:Filter combining ogc:BBOX
and others
Roald de Wit
roald.dewit at lisasoft.com
Fri Apr 24 22:08:56 EDT 2009
Hi David,
As you figured and Chris advised, use the new WFS protocol (available in
2.8-rc1 onwards).
Have a look here how to have OL create the filter for you [1].
A 'hidden' feature of the new WFS Protocol, or better: the BBOX strategy
is to combine the BBOX with your own filter!
Here is an example of how to do it:
var propertyFilter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: 'STATE_NAME',
value: 'New York'
});
var layer = new OpenLayers.Layer.Vector("WFS", {
strategies: [new OpenLayers.Strategy.BBOX()],
filter: propertyFilter, // undocumented!
protocol: new OpenLayers.Protocol.WFS({
url: "http://publicus.opengeo.org/geoserver/wfs",
featureType: "states",
featureNS: "http://www.openplans.org/topp"
}),
});
This is an undocument feature that probably deserves some more attention
since your use case is far from unique.
[1] http://www.openlayers.org/dev/examples/filter.html
dalsinao wrote:
> Hello,
>
> I have seen that there are some changes in the WFS protocol coming in the
> next release.
> One that particularly affects me is that now the BBOX parameter is not
> always added in the WFS requests as before. That's fine, but now I have a
> related question.
>
> If you have your own ogc:filter and you want to combine it with BBOX, how
> can you do it?
> I would like to combine my ogc:filter (static) with the dynamically
> generated ogc:BBOX filter (changing according to the viewport I understand).
>
> Is it possible to do so? and if so, how?
>
> I have seen the example in wfs-protocol.html, using "strategies" and
> "protocol", which at the end produces an HTTP/POST request having an
> ogc:filter like the one (for WFS 1.1.0):
>
> <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
> <ogc:BBOX>
> <ogc:PropertyName>the_geom</ogc:PropertyName>
> <gml:Envelope xmlns:gml="http://www.opengis.net/gml"
> srsName="EPSG:4326">
> <gml:lowerCorner>-37.4060546875 15.1189453125</gml:lowerCorner>
> <gml:upperCorner>-14.9939453125 26.2810546875</gml:upperCorner>
> </gml:Envelope>
> </ogc:BBOX>
> </ogc:Filter>
>
> What I would like to do is to combine this ogc:filter with mine to get e.g
> something like this:
>
> <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
> <ogc:And>
> <ogc:BBOX>
> <ogc:PropertyName>the_geom</ogc:PropertyName>
> <gml:Envelope xmlns:gml="http://www.opengis.net/gml"
> srsName="EPSG:4326">
> <gml:lowerCorner>-37.4060546875
> 15.1189453125</gml:lowerCorner>
> <gml:upperCorner>-14.9939453125
> 26.2810546875</gml:upperCorner>
> </gml:Envelope>
> </ogc:BBOX>
> <ogc:PropertyIsEqualTo>
> <ogc:PropertyName>Scenario</ogc:PropertyName>
> <ogc:Literal>Demo</
> ogc:Literal>
> </ogc:PropertyIsEqualTo>
> </ogc:And>
> </ogc:Filter>
>
>
> And parallel to this. Is it the intention in the long term to get rid of the
> OpenLayers.Layer.WFS layer and use only the OpenLayers.Layer.Vector?
>
> Any info you may have or reference on where to look at will be appreciated.
>
> Thanks in advance and regards.
> David
>
More information about the Users
mailing list