[GIS] Geoserver : add extra style (SLD) with Curl

curlgeoserverlinuxsld

In my geoserver I have a layer with a default style (SLD) and i want to add another style to this layer with Curl.

I tried command below with <style></style> instead of <defaultStyle></defaultStyle> but without success :

curl -u admin:pass -XPUT -H 'Content-type: text/xml' -d '<layer><style><name>sld_name</name><workspace>workspace_name</workspace></style></layer>' http://localhost:8080/geoserver/rest/layers/workspace_name:layer_name

Unfortunately I don't have found help in geoserver cookbook : http://docs.geoserver.org/latest/en/user/rest/examples/curl.html.

Anybody know the answer ?

Best Answer

I finally find the solution :

First, to add an extra style additionnal to the defaut style you have to use <styles> (and not <style>):

curl -u admin:pass -XPUT -H 'Content-type: text/xml' -d '<layer><styles><name>sld_name</name><workspace>workspace_name</workspace></styles></layer>' http://localhost:8080/geoserver/rest/layers/workspace_name:layer_name

Second,you can't use this command x times if you want to add more than one extra style. You have to use only one command with several <names> each time you add a style, here is an example :

curl -u admin:pass -XPUT -H 'Content-type: text/xml' -d '<layer><styles><name>Extra_sldname1</name><name>Extra_sldname2</name><name>Extra_sldname3</name><workspace>workspace_name</workspace></styles></layer>' http://localhost:8080/geoserver/rest/layers/workspace_name:layer_name