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 fairly new to Geoserver and I have a question before I launch into something bigger than me: if i replace the XML code in the SLD style sheet inside geoserver with some PHP which generates the SLD dynamically (i.e. from a database query), will it work? How does Geoserver handle the SLD stored as style?

Thanks in advance

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

No, that won't work. Geoserver is expecting an SLD, so it will fail parsing any PHP code you insert there.

What you can do is generate the SLD outside of Geoserver and pass it over when requesting the map from Geoserver. In OpenLayers it works like this:

var sld = '<StyledLayerDescriptor version ="1.0.0" ...> more xml here </StyledLayerDescriptor>';  

wms = new OpenLayers.Layer.WMS.Post(
   "name",
   "http://localhost:8080/geoserver/wms",
   {
      'layers': 'myNs:layername',
      format: 'image/jpeg',
      sld_body: sld
   },
   {
      unsupportedBrowsers: []
   }
);

More info: Dynamic Styling and Filtering of a Geoserver WMS Using OpenLayers.Layer.WMS.Post


Update: You can find a lot of SLD examples in Geoserver's SLD Cookbook.

share|improve this answer
    
that sounds perfect for my purpose. I should have thought of that... THANKS! –  Barnabe Jun 16 '11 at 8:48
    
Underdark, i am having trouble replicating your result if i simply define a variable called sld and link it to an external file (xml) and then specify an sld or sld_body option for my layer OL/geoserver ignore it completely. I have started reading about sld and it sounds complex. It seems that i need to use something like OpenLayers.Format.SLD().read. Would you mind linking to the working example you mention in your post? Thanks. PS: the openlayers.org/dev/examples/WMSPost.html link in your post is dead –  Barnabe Jun 17 '11 at 14:50
    
Thanks, seems like they removed the example. Check this instead openlayers.org/dev/examples/wms-long-url.html –  underdark Jun 17 '11 at 16:32
    
You don't need to parse the SLD in OpenLayers. Just send it forward to Geoserver. –  underdark Jun 17 '11 at 16:42
add comment

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.