Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to adjust the symbology of a loaded WMS raster layer (img file through MapServer). It is the NLCD dataset. The WMS layer loads find with

nlcd = new OpenLayers.Layer.WMS(
    'http://server /fswms/html/rlayers',
        layers: 'nlcd-2006', transparent: true,
        projection: new OpenLayers.Projection("EPSG:4326")
        isBaseLayer: false

And I have a SLD file that I have created in which I am attempting to make all of the pixels with the value of 11 opacity of 0.

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
    xsi:schemaLocation=" StyledLayerDescriptor.xsd"
      <Title>ncld test</Title>
              <ColorMapEntry opacity="0" color="#000000" quantity="11" />

The WML layer ends up being map.layers[3] in my test application so I attempting to apply the SLD by the following code but it is not working.

//this is in the init:   
    url: "sldcode.sld",
    success: complete

//function that attempts to apply SLD
function complete(req) {
    mySLD = || req.responseText);

Here a link to the dev site: Any help would be greatly appreciated.



share|improve this question

I spent an hour picking at this thing before I found this. You need to have the Style file before you submit the WMS Request, as the rendering is applied on the server side.

It looks like you borrowed a lot from this example, correct? You're loading up your SLD code with AJAX, which is probably unnecessary--The SLD file is small and straightforward. If you don't need to specify the contents of the file programatically, then you can cut the AJAX exchange out of the picture and just pass the XML in as a string--it looks like you're already trying to parse it in that fashion anyway.

So, load the SLD file and then pass the request for the WMS layer. That should fix the problem.

share|improve this answer
Thanks Tony and yes I was looking at the example you mentioned. One more question though if I load the SLD ahead of time how to I pass it into the request for the WMS layer? Is it as a text string, or a "OpenLayers.Format.SLD" object? – geo derek Oct 20 '12 at 13:28
I'd try something like this: //Create the OL.Format.SLD var format = new OpenLayers.Format.SLD(); //Read the SLD Data var mySLD ='yourSLDstring'); var myWMSLayer = new OpenLayers.Layer.WMS("yourparams", ..., {SLD : mySLD}); – AABoyles Oct 20 '12 at 15:55
I really appreciate your feedback. I have tried exactly has you suggested. I don't get an error, but my style does not see to be applied. – geo derek Oct 20 '12 at 18:28

Your Answer


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.