I'm experimenting with a simple web mapping service build on PostGIS/GeoServer/OpenLayers stack on Win 2008 Server.

I overlay vector layer from PostGIS using:

var Index1v = new OpenLayers.Layer.Vector("Index1 v", {
    strategies: [new OpenLayers.Strategy.BBOX()],
        protocol: new OpenLayers.Protocol.WFS({
            version: "1.1.0",
            url: "http://localhost:1979/geoserver/wfs",
            featureType: "bern_poly_s100",
            featureNS: "http://www.ispm.ch",
            srsName: "EPSG:900913"

Layer displays correctly, but in plain, default[?] style from GeoServer.

I've got a SLD style file build with uDig and it seems to be correct since WMS service is using it without any problems. Can I use it to style WFS layer as well?

4 Answers 4


Take a look at OL's "Styled Layer Descriptor (SLD) Example" example. They use SLD to style GML, but should work for WFS (a vector layer) as well.

Credit: OL's Nabble.com forum

  • 1
    That's cool - I didn't know you could do that.
    – Ian Turton
    Dec 8, 2010 at 19:46
  • I've never used it but I thought I saw it somewhere before, so had to research the good old trusty Nabble.com forum. However lets keep filling out the SO GIS board as well.
    – Vadim
    Dec 8, 2010 at 19:51
  • 2
    But in a way you're right that you're still responsible for styling it on the client, right? It's not on the server. But you can style with a pre-made SLD on the client.
    – Vadim
    Dec 8, 2010 at 19:52
  • 6
    It appears that the link is broken. Could you explain how to do this, or provide a new link please?
    – Ravi Mehta
    Jan 24, 2015 at 4:13

Short answer is no - WFS sends you the data and then you are responsible for styling it in the client. OpenLayers uses a stylemap to style a vector layer. See http://docs.openlayers.org/library/feature_styling.html for details of how to style a vector layer.


Yes, you could load the wfs-layer into openlayers, then parse the sld-file into an openlayers-stylemap, and apply it to the wfs-layer.

Alternatively, you could attach the sld to the geoserver-wfs-layer as the default sld. Then load the wfs-layer into openlayers and specify an image-format (e.g. image/png or image/jpeg) in the request parameter. Once loaded, store it as an Openlayers.Layer.WMS-object. This will render the layer as a raster layer with the attached sld already applied by geoserver.


The OGC definition for sld say that is for WMS

The OpenGIS® Styled Layer Descriptor (SLD) Profile of the OpenGIS® Web Map Service (WMS) Encoding Standard

so !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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