Time for action – adding a new style
Adding a new style is a routine task if you are going to publish data with REST. We will retrieve an existing style from GeoServer, update it, and then upload to GeoServer as a new one.
We will use
PopulatedPlacesLabeled
as a template for our new style. Send a request to GeoServer to retrieve it and save to thePopulatedPlacesBlueLabeled.xml
file. Please note that we are sending a header to tell GeoServer that we want the SLD format. If you specifytext/xml
, you will get only a description of what the SLD is:curl -u admin:password -XGET -H 'Accept: application/vnd.ogc.sld+xml' http://localhost:8080/geoserver/rest/styles/PopulatedPlacesLabeled -o PopulatedPlacesBlueLabeled.xml
In Python, the code is as follows:
>>> myUrl = 'http://localhost:8080/geoserver/rest/styles/PopulatedPlacesLabeled' >>> headers = {'Accept: application/vnd.ogc.sld+xml'} >>> resp = requests.get(myUrl, auth=('admin','password'), headers=headers)
Now, open...