Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am running GeoServer 2.1.1, and have a datastore from ArcSDE populated with features projected in EPSG:26918. I can successfully add a WMS to an OpenLayers map, but am having issues with WFS. I have the map set to EPSG:900913 in preparation for a mashup with Google base layers.

I am under the impression that vector layers are reprojected on the fly, and that absent of any user specification, features will be rendered using the default style.

Here is the main chunk of my script:

    map = new OpenLayers.Map('map', {
        maxExtent: new OpenLayers.Bounds(
            -128 * 156543.0339,
            -128 * 156543.0339,
            128 * 156543.0339,
            128 * 156543.0339),
        maxResolution: 156543.0039,
        projection: "EPSG:900913",
        units: "m"
    });

    var bridgeLayer = new OpenLayers.Layer.WMS(
        "Bridge",
        "http://localhost/geoserver/geodatabase/wms", {
        layers: "geodatabase:Bridge",
        format: "image/png",
        transparent: true
    },{
        isBaseLayer: true
    });

    var wfsLayer = new OpenLayers.Layer.Vector(
        "Photo Points", {
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.0.0",
                url: "http://localhost/geoserver/wfs",
                featureType: "Photo Point",
                srsName:"EPSG:26918",
                featureNS: "http://dev.geodatabase.org",
                geometryName: "SHAPE"
            }),
            visibility: true
    });

    map.addLayers([bridgeLayer, wfsLayer]);

And so, the WMS displays correctly (and when I add a Google base layer, it lines up correctly). However, the WFS layer fails to appear.

According to Firebug, however, my POST request is successful, and I receive an response. Furthermore, the layer object I defined looks to be a fully formed layer, although it does not appear to have any features in its "features" array. Not sure what that means. Screenshots appear below.

Something also that I don't understand, when I switch versions to "1.1.0", my POST request fails with a "NoApplicableCode" exception.

Additionally, I have tried reprojecting the data in GeoServer to spherical mercator EPSG:900918, and also redefining the srsName parameter, but both experiments have failed.

Thanks so much.

share|improve this question

1 Answer 1

If you use WFS 1.0.0 the srsName parameter is not supported, so you can’t use OpenLayers to decide in which projection you want your features returned. Therefore you'll need 1.1.0

Also you need to request the WFS in the same SRS as your basemap otherwise no features will appear as they will be outside the map's bounding box. So the srsName should be set to EPSG:900913 (not EPSG:900918 as in your question - a typo maybe?).

Finally you need to make sure that Geoserver can reproject the WFS into EPSG:900913. You can check this by issuing a request similar to:

http://localhost/geoserver/wfs?service=WFS&request=GetCapabilities&version=1.1.0

I had similar issues with MapServer rather than GeoServer, but the same principles probably apply:

http://geographika.co.uk/mapserver-openlayers-and-the-wfs-maze

You can reproject features on the client side, but this may take longer than doing it on the server. You will also need to include the Proj4JS library in your web application and the EPSG:26918 definition in your code to take this approach. You'll also need to set the layers's projection:

Proj4js.defs["EPSG:26918"] = "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";
var myproj =new OpenLayers.Projection("EPSG:26918");
var wfsLayer = new OpenLayers.Layer.Vector(
    "Photo Points", {
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.WFS({
            version: "1.0.0",
            url: "http://localhost/geoserver/wfs",
            featureType: "Photo Point",
            srsName:"EPSG:26918",
            featureNS: "http://dev.geodatabase.org",
            geometryName: "SHAPE"
        }),
        visibility: true,
        projection: myproj 
});

Have a look at the source in this example - http://openlayers.org/dev/examples/wfs-reprojection.html for more details. Also you may want to change the strategy to BBox or you will load all the features in in one go.

strategies: [new OpenLayers.Strategy.BBOX()]
share|improve this answer
    
Thanks for the tips I'll give them a go tomorrow morning... though, when I switch to version "1.1.0", I get an error using the same parameters... any thoughts as to why that is? –  Duncan Rager Oct 19 '11 at 0:34
    
@DuncanRanger That sounds like it is a geoserver error, and the wfs is not set up for that projection. The 1.0.0 protocol is probably not asking for a different projection hence no error. –  geographika Oct 19 '11 at 7:07
    
What should localhost/geoserver/… say that tells you it is capable of projecting to google? I have an instance that used to work, but after a reset has stopped being able to project to google. –  zod Mar 15 '13 at 11:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.