This is already an old question, but I haven't found many example documenting this on he Web. On GeoServer version 2.5.1 the following should work (it should also work with older versions). :
Example XML
<layerGroup>
<workspace>workspace</workspace>
<name>014531_layer_group</name>
<layers>
<layer>014531_layer</layer>
<layer>014531_layer_watermark</layer>
</layers>
<styles>
<style>raster</style>
<style>sld_watermark</style>
</styles>
<bounds>
<minx>12.91</minx>
<miny>-6.97</miny>
<maxx>14.32</maxx>
<maxy>-5.44</maxy>
<crs>EPSG:4326</crs>
</bounds>
</layerGroup>
Example REST statement
sudo curl -v -u user:pwd -XPOST -d @yourxmlfile.xml -H "Content-type: text/xml" http://localhost:8080/geoserver/rest/layergroups
It doesn't take the bounding box of the underlying layer, but you could retrieve it by using a Selenium script
As already mentioned slightly by Slslam, you can use Python's requests module to send the same POST requests to GeoServer's REST API as you could do from the command line with cUrl.
This is an example that I recently used to activate a layer not yet known to GeoServer but already available in the connected DataStore of the given workspace (a PostGIS database in my case), including activation of the TIME dimension.
In fact, the only thing that is different to the examples given on the cUrl page above is how to fire the POST request. Apart from that, the XML you send to the REST API can contain whatever you want as long as it is valid (otherwise, you'll get an error message back from the server in your requests variable).
To use the module, either install it via pip install requests
or, preferably on Windows systems, by downloading this binary and installing it via pip install path\to\the\file.whl
.
import requests
# define your parameters
url = 'http://localhost:8080/geoserver/rest/workspaces/my_workspace/datastores/my_datastore/featuretypes'
headers = {'Content-Type': 'text/xml'}
auth = ('admin', 'geoserver')
# define your XML string that you want to send to the server
data = """
<featureType>
<name>my_layer_name</name>
<srs>EPSG:4326</srs>
<enabled>true</enabled>
<metadata>
<entry key="time">
<dimensionInfo>
<enabled>true</enabled>
<attribute>datetime</attribute>
<presentation>CONTINUOUS_INTERVAL</presentation>
<units>ISO8601</units>
<defaultValue><strategy>MAXIMUM</strategy></defaultValue>
</dimensionInfo>
</entry>
</metadata>
<store class="dataStore">
<name>my_datastore</name>
</store>
</featureType>
"""
# fire the request
r = requests.post(url, headers=headers, auth=auth, data=data)
# inspect the response
print(r.text)
Best Answer
You should update the
FeatureType
of your layer. The feature type API is useful for this purpose.You can use Geoserver-manager (java library) for calling rest APIs.