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" (<style 
/> in xml).


Here's an example of a layergroup:


{

  *
layerGroup:
{
     *
name: "example_layergroup",
     *
mode: "NAMED",
     *
title: "Example Layergroup",
     *
abstractTxt: "<strong>Description:</strong> Example Layergroup",
     *
workspace:
{
        *
name: "exampleWorkspace"
},
     *
publishables:
{
        *
published:
[
           *
{
              *
@type: "layer",
              *
name: "layer_one",
              *
href: 
"http://<http://wms.tidetech.org/geoserver/rest/layers/layer_one.json>192.168.1.1:8080<http://wms.tidetech.org/geoserver/rest/layers/mean_sea_level_pressure.json>/geoserver/rest/layers/layer_one.json"
},
           *
{
              *
@type: "layer",
              *
name: "layer_two",
              *
href: 
"http://192.168.1.1:8080/geoserver/rest/layers/layer_two.json<http://wms.tidetech.org/geoserver/rest/layers/mean_sea_level_pressure.json>"
}
]
},
     *
styles:
{
        *
style:
[
           *
"null",
           *
"null"
]
},
     *
bounds:
{
        *
minx: -180.25,
        *
maxx: 179.75,
        *
miny: -90.25,
        *
maxy: 89.75,
        *
crs: "EPSG:4326"
}
}

}


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 <[email protected]>
Sent: Thursday, 1 February 2018 9:19 PM
To: Kris Powell
Cc: [email protected]
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:

1. Get the SLD file for the style you want to copy:

GET http://<HOST>/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">
    <NamedLayer>
        <Name>my_style</Name>
        <UserStyle>
            <Name>my_style</Name>
…
…
    </NamedLayer>
</StyledLayerDescriptor>


2. 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://<HOST>/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">
    <NamedLayer>
        <Name>my_style</Name>
        <UserStyle>
            <Name>my_style</Name>
            <Title>my_style</Title>
            <FeatureTypeStyle>
                <Rule>
                    <PolygonSymbolizer>
                        <Stroke>
                            <CssParameter
                name="stroke">#6E6E6E</CssParameter>
                            <CssParameter
                name="stroke-width">0.1</CssParameter>
                        </Stroke>
                    </PolygonSymbolizer>
                </Rule>
            </FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>


On successful creation the response headers will contain a Location header, 
specifying the url of the newly created style. In this case 
http://<HOST>/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 
<[email protected]<mailto:[email protected]>> 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 <[email protected]<mailto:[email protected]>>
Sent: Thursday, 1 February 2018 3:03:49 AM
To: Kris Powell
Cc: 
[email protected]<mailto:[email protected]>
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):

<layerGroup>
  <name>group_c</name>
  <mode>CONTAINER</mode>
  <title>group_c</title>
  <abstractTxt></abstractTxt>
  <workspace>
    <name>charts</name>
  </workspace>
  <publishables>
    <published type="layer">
      <name>charts:world_cities</name>
      <atom:link xmlns:atom=“http://www.w3.org/2005/Atom” rel=“alternate" 
href="http://<host>/geoserver/rest/layers/charts:world_cities.xml" 
type="application/xml" />
    </published>
    <published type="layer">
      <name>charts:usa_states</name>
      <atom:link xmlns:atom="http://www.w3.org/2005/Atom"; rel="alternate" 
href="http://<host>/geoserver/rest/layers/charts:usa_states.xml" 
type="application/xml" />
    </published>
  </publishables>
  <styles>
    <style />
    <style />
  </styles>
  <bounds>
    <minx>-124.731422</minx>
    <maxx>151.206955</maxx>
    <miny>-37.817532</miny>
    <maxy>59.916269143887</maxy>
    <crs class="projected">EPSG:4326</crs>
  </bounds>
</layerGroup>

So the published/name element should use the following format 
<workspace>:<layername>, 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 
<[email protected]<mailto:[email protected]>> 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://slashdot.org/>! 
http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this 
list:
- Earning your support instead of buying it, but Ian Turton: 
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: 
http://geoserver.org/comm/userlist-guidelines.html

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


[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/geoserver-users

------------------------------------------------------------------------------
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:
- Earning your support instead of buying it, but Ian Turton: 
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: 
http://geoserver.org/comm/userlist-guidelines.html

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


[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Reply via email to