6

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 ?

3 Answers 3

4

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
1
  • Thanks for the additional explanation to add extra additional styles
    – Freeze
    Commented Jun 1, 2017 at 12:30
2

You can also use -XPOST to add new availableStyle to your layer:

curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<styles><name>yourstylename</name></style></styles>"
    http://localhost:8080/geoserver/rest/layers/workspace_name:layer_name/styles

For example:

curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<style><name>giant_polygon</name></style>"
http://localhost:8080/geoserver/rest/layers/topp:states/styles

This adds the Style "giant polygon" to your topp:states-Layer as an additional available Style.

Notice: if your style is bound to a specific workspace there seems to be a bug (style not found although i used the workspace tags...) but if the style is not assigned to a specific workspace this code works fine.

0
1

I the geoserver cookbok there are two curl examples about think that in the curl examples there are two about styles.

If you already have the style uploaded in geoserver to change the style of the layer:

curl -v -u admin:pass -XPUT -H "Content-type: text/xml" -d "<layer><defaultStyle> <name>sld_name</name></defaultStyle></layer>"  http://localhost:8080/geoserver/rest/layers/acme:roads

The workspace tag that you are using in the XML is only useful when the style is only valid for a given workspace and is not global.

1
  • I appreciate the answer but it does not solve my question. I said that I already used <defaultStyle> for a default style, and now I want to add new additional styles. Thanks anyway :)
    – Leasye
    Commented Mar 11, 2015 at 12:35

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.