[OpenLayers-Users] Making simple WFS GetFeature requests using OpenLayers

Ian Turton ijturton at gmail.com
Wed Jun 8 10:44:11 EDT 2011


On 8 June 2011 06:26, Jon Britton <jonbritton3 at googlemail.com> wrote:
> Hi,
> I'm trying to use GWT-OpenLayers to carry out some simple WFS requests.
> However, I'm having some trouble with OpenLayers not displaying my data.
> I'm using GeoServer as my WFS, which names its layers like "sf:roads", where
> "sf" is the namespace.  This first example, where I specify the namespace
> URL, works fine:
> ### JAVA CODE ###
> WFSProtocolOptions wfsProtocolOptions = new WFSProtocolOptions();
> wfsProtocolOptions.setUrl("http://li199-25.members.linode.com:8080/geoserver/wfs");
> wfsProtocolOptions.setFeatureType("roads");
> wfsProtocolOptions.setFeatureNameSpace("http://www.openplans.org/spearfish");
> wfsProtocolOptions.setSrsName("EPSG:4326");
> wfsProtocolOptions.setVersion("1.1.0");
> This results in OpenLayers making the following XML request, which leads to
> a valid response which is displayed correctly:
> ### XML GetFeature REQUEST ###
> <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs
> http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <wfs:Query typeName="feature:roads" srsName="EPSG:4326" xmlns:feature="http://www.openplans.org/spearfish"></wfs:Query>
> </wfs:GetFeature>
> However, this next example does not work. Here, I'm only specifying the full
> layer title "sf:road" and not specifying the namespace.
> ### JAVA CODE ###
> WFSProtocolOptions wfsProtocolOptions = new WFSProtocolOptions();
> wfsProtocolOptions.setUrl("http://li199-25.members.linode.com:8080/geoserver/wfs");
> wfsProtocolOptions.setFeatureType("sf:roads");
> wfsProtocolOptions.setSrsName("EPSG:4326");
> wfsProtocolOptions.setVersion("1.1.0");
> This results in the following XML request being sent. GeoServer handles this
> request fine and returns a valid FeatureCollection (as far as I can tell,
> it's exactly the same as the previous example).  However, for some reason
> OpenLayers just won't display it!
> ### XML GetFeature REQUEST ###
> <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS"
> version="1.1.0"
> xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wfs:Query
> typeName="sf:streams" srsName="EPSG:4326"/></wfs:GetFeature>
> Does anyone have any idea why OpenLayers won't display the results of this
> kind of request?

It is GeoServer that is refusing to handle the second request not
OpenLayers (check the log file or firebug) - in the second case you
have a namespace (sf) that GeoServer can't process since you haven't
defined it. If you look at the first request you'll see
xmlns:feature="http://www.openplans.org/spearfish" which is what
GeoServer uses to work out which roads features you want.

Ian
-- 
Ian Turton


More information about the Users mailing list