[Geoserver-users] REST API for adding new layer to existing LayerGroup

I have an existing layerGroup:
workspace: NAIP
name: NAIP-Imagery
and a new layer that I would like to add to this layerGroup:
workspace:NAIP
store: Store1
layerName: layer1

I'd like to add this layer to the layerGroup and could not find any example
for that. All examples I saw were to create new layerGroup with layers. I
assume this can be done with REST api and hope someone can show me how.

Many thanks in advance.

Regards,
Tam

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/REST-API-for-adding-new-layer-to-existing-LayerGroup-tp5137863.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Hi,

I did this some time ago… You just need to GET the description of the layergroup , via REST. (Something like: http://localhost:8080/geoserver/rest/layergroups/.[format] (I used json in format).

Then you need to add the new layer to the json, with something like this:

{
name: “layer_name”,
href: “http://localhost:8080/geoserver/rest/layers/layer_name.json
}

(This is valid only when using json)…

At last, all you need to do is POST it back to the same URL you got it.

Getting the layergroup description will show you all you can change in it…

Regards,

···

Rodrigo C. Antonialli

Rio Claro - SP - Brasil
LinkedIn: http://www.linkedin.com/in/rcantonialli
Contato: (19) 98136-2347
rcantonialli@anonymised.com
Skype: rc_antonialli

On Tue, Apr 29, 2014 at 5:29 PM, tt5430 <tt9488@anonymised.com> wrote:

I have an existing layerGroup:
workspace: NAIP
name: NAIP-Imagery
and a new layer that I would like to add to this layerGroup:
workspace:NAIP
store: Store1
layerName: layer1

I’d like to add this layer to the layerGroup and could not find any example
for that. All examples I saw were to create new layerGroup with layers. I
assume this can be done with REST api and hope someone can show me how.

Many thanks in advance.

Regards,
Tam


View this message in context: http://osgeo-org.1560.x6.nabble.com/REST-API-for-adding-new-layer-to-existing-LayerGroup-tp5137863.html
Sent from the GeoServer - User mailing list archive at Nabble.com.


“Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free.”
http://p.sf.net/sfu/SauceLabs


Geoserver-users mailing list
Geoserver-users@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Hi Rodrigo,

Thanks for your response. I followed your instructions and it did not work.
Here is what I did:

curl -u admin:geoserver -XGET \
   
http://$host:$port/geoserver/rest/workspaces/NAIP/layergroups/$layerGroupName.json
and this was what returned from the query:

{"layerGroup":{"name":"NAIP-Imagery","mode":"SINGLE","title":"Collection of
NAIP
Imagery","workspace":{"name":"NAIP"},"publishables":{"published":[{"@type":"layer","name":"Yosemite","href":"http:\/\/localhost:8081\/geoserver\/rest\/layers\/Yosemite.json"},{"@type":"layer","name":"Sioux-Falls","href":"http:\/\/localhost:8081\/geoserver\/rest\/layers\/Sioux-Falls.json"}]},"styles":{"style":[{"name":"raster","href":"http:\/\/localhost:8081\/geoserver\/rest\/styles\/raster.json"},{"name":"raster","href":"http:\/\/localhost:8081\/geoserver\/rest\/styles\/raster.json"}]},"bounds":{"minx":-1.3352069604658E7,"maxx":-1.0748569062625762E7,"miny":4499635.009236522,"maxy":5417839.565374998,"crs":{"@class":"projected","$":"EPSG:3857"}}}}

To see what you suggested works, I manually edited the json string and added
the followings:
{"@type":"layer","name":"Sioux-Falls1","href":"http:\/\/localhost:8081\/geoserver\/rest\/layers\/Sioux-Falls1.json"}
and style:
{"name":"raster","href":"http:\/\/localhost:8081\/geoserver\/rest\/styles\/raster.json"

and the modified json looks like this:
json={"layerGroup":{"name":"NAIP-Imagery","mode":"SINGLE","title":"Collection
of NAIP
Imagery","workspace":{"name":"NAIP"},"publishables":{"published":[{"@type":"layer","name":"Yosemite","href":"http:\/\/localhost:8081\geoserver\/rest\/layers\/Yosemite.json"},{"@type":"layer","name":"Sioux-Falls","href":"http:\/\/localhost:8081\/geoserver\/rest\/layers\/Sioux-Falls.json"},{"@type":"layer","name":"Sioux-Falls1","href":"http:\/\/localhost:8081\/geoserver\/rest\/layers\/Sioux-Falls1.json"}]},"styles":{"style":[{"name":"raster","href":"http:\/\/localhost:8081\/geoserver\/rest\/styles\/raster.json"},{"name":"raster","href":"http:\/\/localhost:8081\/geoserver\/rest\/styles\/raster.json"},{"name":"raster","href":"http:\/\/localhost:8081\/geoserver\/rest\/styles\/raster.json"}]},"bounds":{"minx":-1.3352069604658E7,"maxx":-1.0748569062625762E7,"miny":4499635.009236522,"maxy":5417839.565374998,"crs":{"@class":"projected","$":"EPSG:3857"}}}}

I excuted the following curl command:
curl -v -u admin:geoserver -XPOST -H "Content-type: application/json" -d
$json
http://localhost:8081/geoserver/rest/workspaces/NAIP/layergroups/$layerGroupName.json

and got this error:

< HTTP/1.1 405 Method Not Allowed
< Allow: GET, DELETE, PUT

I then changed the "XPOST" to "XPUT" and got this error:
< HTTP/1.1 500 Internal Server Error
< Transfer-Encoding: chunked
< Server: Jetty(6.1.8)
<
* Connection #0 to host localhost left intact
* Closing connection #0
: org.codehaus.jettison.json.JSONException: Expected a ',' or '}' at
character 59 of {layerGroup:{name:NAIP-Imagery,mode:SINGLE,title:Collection

Can you or someone tell me what was wrong with what I did?

Regards,
Tam

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/REST-API-for-adding-new-layer-to-existing-LayerGroup-tp5137863p5138063.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Never mind. It works. My json syntax was wrong. Now I have to figure out
how to insert the new layer from my bash script.

Thanks,
Tam

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/REST-API-for-adding-new-layer-to-existing-LayerGroup-tp5137863p5138065.html
Sent from the GeoServer - User mailing list archive at Nabble.com.