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 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(
    'nlcd',
    '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="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
    xmlns="http://www.opengis.net/sld"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
    <Name>nlcd</Name>
    <UserStyle>
      <Title>ncld test</Title>
      <FeatureTypeStyle>
        <Rule>
          <RasterSymbolizer>
            <ColorMap>
              <ColorMapEntry opacity="0" color="#000000" quantity="11" />
            </ColorMap>
          </RasterSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

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:   
OpenLayers.Request.GET({
    url: "sldcode.sld",
    success: complete
});  

//function that attempts to apply SLD
function complete(req) {
    mySLD = format.read(req.responseXML || req.responseText);
    map.layers[3].mergeNewParams({sld_body:mySLD});
}   

Here a link to the dev site: http://rain.nemac.org/~derek/ol/sldTest.html Any help would be greatly appreciated.

Thanks,

Derek

share|improve this question

1 Answer 1

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 = format.read('yourSLDstring'); var myWMSLayer = new OpenLayers.Layer.WMS("yourparams", ..., {SLD : mySLD}); –  Tony 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
    
Tony, 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. My updated code is here: rain.nemac.org/~derek/ol/sldTest.html –  geo derek Oct 20 '12 at 18:40

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.