9

So, simple thing as it seems but I can't seem to make it work! I'm trying to add a raster data file (GeoTIFF) to geoserver via REST API, using curl on linux. REST API is working, since I created a new workspace using it:

curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' \
 -d '<workspace><name>restProba</name></workspace>' \
 http://localhost:8080/geoserver/rest/workspaces

It's correctly created as shown by Geoserver's admin ui, but when I try to add a coveragestore to that workspace by executing

curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' -d
'<coverageStore><name>int_dec</name><enabled>true</enabled>
<type>GeoTIFF</type> <url>$home/int_dec.tif</url></coverageStore>'     
"http://localhost:8080/geoserver/rest/workspaces/restProba/coveragestores?configure=all"

even though it is correctly loaded, it goes directly into the default workspace, which is not the one I want it in. Is there any way of defining which workspace i want it in? I thought it'd enough by mentioning it in the URL where I point to restProba's workspace URI but it seems to be omiting it.

Thanks for your help :-)

pd: newbie with geoserver, I've tried searching for this but either i'm not using the correct search criteria, im a fool or it's just too simple for anyone to ask that i'm even fooler for asking it :p

5

Maybe you can try this after creating the workspace:

curl -u admin:geoserver -v -XPOST -H 'Content-Type: application/xml' \
     -d '<coverageStore><name>int_dec</name><workspace>restProba</workspace>  
         <enabled>true</enabled></coverageStore>' \
         http://localhost:8080/geoserver/rest/workspaces/restProba/coveragestores

It should create a coveragestore called int_dec in the restProba workspace::

You can then reference the GeoTIFF file:

curl -u admin:geoserver -v -XPUT -H 'Content-type: text/plain' \
     -d 'file:/$home/int_dec.tif' \
      http://localhost:8080/geoserver/rest/workspaces/restProba/coveragestores/int_dec/external.geotiff?configure=first\&coverageName=int_dec

I think your problem is the missing '

Your request was:

curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' -d
<coverageStore><name>int_dec</name><enabled>true</enabled>
<type>GeoTIFF</type> <url>$home/int_dec.tif</url></coverageStore>'     
"http://localhost:8080/geoserver/rest/workspaces/restProba/coveragestores?configure=all"

It should've been:

curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' -d
'<coverageStore><name>int_dec</name><enabled>true</enabled>
<type>GeoTIFF</type> <url>$home/int_dec.tif</url></coverageStore>'     
"http://localhost:8080/geoserver/rest/workspaces/restProba/coveragestores?configure=all"

  • Checked it and nope, I did the request properly. Good catch tho, I'll correct the question :) (im kind of relieved it wasn't that, I'd be humiliated!) – Mikel G. Gainza Oct 29 '12 at 13:43
  • 1
    At least your problem will be solved ;-) Updated my answer. I hope it will work now. – R.K. Oct 29 '12 at 14:32
1

To add a GeoTIFF store and a layer of the same name in one step you can execute:

$ curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain"
       -d "file:///path_to_directory/int_dec.tif"
       http://localhost:8080/geoserver/rest/workspaces/restProba/coveragestores/int_dec/external.geotiff

More details in the "REST configuration examples: Adding an existing shapefile".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.