Hi Anton,
Thanks again for taking the time to help out.
For me, the problem was that when copying layers/layergroups or entire workspaces programmatically, the style value for each layer was “null” ( in xml).
Here’s an example of a layergroup:
{
}
This meant that when I made a copy of a workspace, for a new customer for example, there were potentially hundreds of layers without styles that would need fixing manually.
Eventually I found a way to copy the folders and files in bulk and batch edit the contents to satisfy the unique ID requirements, etc. although I would have preferred to use the REST interface!
I hope my explanation makes sense? I am relatively new to Geoserver, and am most likely missing something obvious.
Kind regards,
Kris
···
From: Anton Bakker anton.bakker@anonymised.com
Sent: Thursday, 1 February 2018 9:19 PM
To: Kris Powell
Cc: geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] Problem with creating LayerGroup using REST api
Hi Kris,
No problem, I stumbled on your message while looking for a solution to a different problem regarding layergroups and the REST API. Good to hear you got the layer group copy to work.
You can copy over styles to a different workspace in two steps:
- Get the SLD file for the style you want to copy:
GET http:///geoserver/rest/workspaces/workspace_1/styles/my_style.sld
Response body (truncated):
<StyledLayerDescriptor xmlns=“http://www.opengis.net/sld” xmlns:ogc=“http://www.opengis.net/ogc” xmlns:xlink=“http://www.w3.org/1999/xlink” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd”
version=“1.0.0”>
my_style
my_style
…
…
- Create a new style with the same name in the desired workspace (see also http://docs.geoserver.org/stable/en/user/rest/api/styles.html#styles-format), by sending POST request with the SLD in the request body (do forget to set the correct content-type header for the request):
POST http:///geoserver/rest/workspaces/workspace_2/styles
Content-Type: application/vnd.ogc.sld+xml
Request body:
<StyledLayerDescriptor xmlns=“http://www.opengis.net/sld” xmlns:ogc=“http://www.opengis.net/ogc” xmlns:xlink=“http://www.w3.org/1999/xlink” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd”
version=“1.0.0”>
my_style
my_style
my_style
#6E6E6E
0.1
On successful creation the response headers will contain a Location header, specifying the url of the newly created style. In this case http:///geoserver/rest/workspaces/workspace_2/styles/my_style.
If you want to change the name of the style, you will need to edit the SLD request body before sending it. In that case change the UserStyle/Name element in the SLD.
Cheers,
Anton
On 1 Feb 2018, at 05:37, Kris Powell <kris.powell@anonymised.com> wrote:
Hi Anton,
I really appreciate the response. I now have layerGroups copying to the new workspaces nicely.
I retrieve all coverageStores, coverages, dataStores, featureTypes, and layerGroups from a workspace, modify the name and hrefs where necessary, then post back to the newly created workspace’s endpoints.
Everything works well, except the styles - for some reason the styles aren’t copied over to the cloned layers. Have you had any success with layer styles?
Thanks and regards,
Kris
From: Anton Bakker <anton.bakker@anonymised.com>
Sent: Thursday, 1 February 2018 3:03:49 AM
To: Kris Powell
Cc: geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] Problem with creating LayerGroup using REST api
Hi Kris,
For me the following request body works to create a new layergroup (on GeoServer 2.12, but should work for other versions as well):
group_c
CONTAINER
group_c
charts
charts:world_cities
charts:usa_states
-124.731422
151.206955
-37.817532
59.916269143887
EPSG:4326
So the published/name element should use the following format :, the same is true for the url of that layer. Hope this helps!
Kind regards,
Anton Bakker
GeoCat BV
On 25 Jan 2018, at 02:34, Kris Powell <kris.powell@anonymised.com> wrote:
Hi Tam,
Did you ever find out more about this issue?
I’ve been building a tool to clone existing workspaces including stores,
layers and layergroups, and I’m running into the same problem you mention
here. The response I receive from geoserver is:
Layer group within a workspace (testworkspace) can not contain resources from other workspace: existingworkspace
when I POST a new layerGroup to
.../rest/workspaces/testworkspace/layergroups
Any light you or other subscribers could shed on this would be very helpful.
Regards,
Kris
–
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html
Check out the vibrant tech community on one of the world’s most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Geoserver-users mailing list
Please make sure you read the following two resources before posting to this list:
If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users