[Geoserver-users] Problem with creating LayerGroup using REST api

I got this error when I tried to create a new LayerGroup:

:Layer group within a workspace (testWS) can not contain resources from
other workspace: NAIP

Below is the command I used to create the LayerGroup:

curl -v -u $user:$password -XPOST -H "Content-type: text/xml" -d @$xmlFile
http://$host:$port/geoserver/rest/workspaces/$workspace/layergroups

Where:
$workspace=testWS
$xmlFile:
<layerGroup>
<name>Test-Imagery</name>
<mode>SINGLE</mode>
<title>Collection of Test Imagery</title>
<workspace> <name>testWS</name> </workspace>
<publishables>
<published type="layer">
      <name>Sioux-Falls</name>
      <atom:link xmlns:atom="http://www.w3.org/2005/Atom&quot; rel="alternate"
href="http://'$host:$port'/geoserver/rest/layer/Sioux-Falls.xml"
type="application/xml"/>
    </published>
</publishables>
<styles>

</styles>
</layerGroup>

I am trying to create the LayerGroup for <testWS:Sioux-Falls> layer and the
error only occurs when I also have to the layer named "NAIP:Sioux-Falls" and
the order of the "NAIP:Sioux-Falls" comes before "testWS:Sioux-Falls" layer.
I am not sure whether this is a bug or my XML is not specific enough. It
seems to me that the code only tries to find the layer name and takes
whatever it finds first without considering the workspace. Can someone let
me know how I can specify more specific so it finds the correct layers?

Many thanks.

Regards,
Tam

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-with-creating-LayerGroup-using-REST-api-tp5138216.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

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

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

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

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:///geoserver/rest/workspaces/workspace_1/styles/my_style.sld

Response body (truncated):



my_style

my_style



  1. 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:



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

···

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@anonymised.come.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

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:

{

  • layerGroup:

    {- name: “example_layergroup”,

    • mode: “NAMED”,

    • title: “Example Layergroup”,

    • abstractTxt: “Description: 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 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:

  1. 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



  1. 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