17

I have a directory of raster imagery that will be updated continually. From this imagery, I am making Image Pyramids using the Geotool's PyramidBuilder utility. I need to setup a cron job to automatically add raster datastores and layers to Geoserver without using the UI.

After looking at the REST section of the Geoserver manual I was able to add my workspace, "testWS", but trying the create an ImagePyramid datastore did not work.

Since I have access to the datastore, I expanded on the shapefile example and tried to

curl -u admin:geoserver -XPUT -H 'Content-type: text/plain' \ 
   -d '/opt/geoserver_data_dir/2.0.2/data/test_pyramid.pyr' \
    "http://localhost:8080/geoserver/rest/workspaces/testWS/datastores/test_pyramid.pyr/external.imagepyramid?configure=all"

Where test_pyramid.pyr is the base of my ImagePyramid at this location.

This gave me an error of "No such datastore: test_pyramid"

Is there a better way to add a new datastore and layer to Geoserver without manually adding each one via the UI? I need help in crafting the proper REST statement that will add an extisting ImagePyramid as a datastore and layer.

Is there some Java code that could do this? I looked at the Geoserver python extensions but they did not have this either.

9
  • This post from Jan mail-archive.com/[email protected]/… describes almost the exact same problem. No resolution there. Commented Feb 24, 2011 at 0:28
  • 1
    The geoserver docs at docs.geoserver.org/stable/en/user/restconfig/… imply that the only datastores you can configure using this method are a file in the case of a Shapefile, a database in the case of PostGIS, or a server in the case of a remote Web Feature Service, but the docs may simply be incomplete. Commented Feb 24, 2011 at 0:51
  • can you add what is actually in the file you are POSTing to the server?
    – Ian Turton
    Commented Feb 24, 2011 at 16:47
  • But you have to construct an XML file that contains that information.
    – Ian Turton
    Commented Feb 25, 2011 at 1:24
  • what I am trying to post is the path to the datastore I want Geoserver to create. This path is an external set of raster files (imagepyramid) in a single directory. All I wanted is for Geoserver to create the datastore and layer for an imagepyramid at this location (on the same filesystem as geoserver.)
    – rbrister
    Commented Feb 25, 2011 at 1:25

2 Answers 2

22

You can create a workspace, datastore and layer (coveragestore) for a GeoTiff with curl and xml from outside the UI like so:

  1. Create the workspace.

    curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' \
         -d '<workspace><name>wsgeotiff</name></workspace>' \
         http://localhost:8080/geoserver/rest/workspaces
    
  2. Then create the datastore.

    curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' \
         -d '<coverageStore>
             <name>wsgeotiff_imageGeoTiffWGS84_1298678792699</name>
             <workspace>wsgeotiff</workspace>
             <enabled>true</enabled>
             <type>GeoTIFF</type>
             <url>/home/gis/image_wgs84.tif</url>
             </coverageStore>' \
         "http://localhost:8080/geoserver/rest/workspaces/wsgeotiff/coveragestores?configure=all"
    
  3. Then create the Layer.

     curl -u admin:geoserver -v -XPOST -H 'Content-type: text/xml' \
          -d '<coverage>
              <name>imageGeoTiffWGS84</name>
              <title>imageGeoTiffWGS84</title>
              <nativeCRS>GEOGCS[&quot;WGS 84&quot;,DATUM[&quot;World Geodetic System 1984&quot;,SPHEROID[&quot;WGS 84&quot;,6378137.0, 298.257223563, AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;, 0.0, AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNIT[&quot;degree&quot;, 0.017453292519943295],AXIS[&quot;Geodetic longitude&quot;, EAST],AXIS[&quot;Geodetic latitude&quot;, NORTH],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]</nativeCRS>
              <srs>EPSG:4326</srs>
              <latLonBoundingBox><minx>-179.958</minx><maxx>-105.002</maxx><miny>-65.007</miny><maxy>65.007</maxy><crs>EPSG:4326</crs></latLonBoundingBox>
              </coverage>' \
          "http://localhost:8080/geoserver/rest/workspaces/wsgeotiff/coveragestores/wsgeotiff_imageGeoTiffWGS84_1298678792699/coverages"
    

When all this is done you have a datastore pointing to the external image 'image_wgs84.tif' and a WMS layer to display the coverage in.

What I don't know is whether this technique will translate directly into a technique for creating an image pyramid type datastore or not.

Good luck.

6
  • I have the same exact problem as the question above. Thanks for putting it nicely, most solutions out there are confusing. I have one question here though. In your answer the Bounding Boxes of the raster need to be given as input. Now I understand that if I am putting the above solution in a script, i could use gdalinfo to find the bounding box. But thats just added work (parsing etc.). My question is can we make geoserver calculate the bounding boxes automatically? We know it can do so , because when we add a raster from UI it calculates Bounding Box!
    – Shaunak
    Commented Sep 30, 2011 at 7:19
  • 3
    On my GeoServer 2.2 you don't need to specify the Bounding Box (and SRS etc) explicitly. It detects them automatically from the file upon layer creation (tested for GeoTIFF and ImageMosaic). You can additionally set ?recalculate=nativebbox to have the native bounding box recalculated when the projection or projection policy is changed. See docs.geoserver.org/stable/en/user/rest/api/… Commented Jul 30, 2013 at 7:29
  • This is a great explanation. I want to implement a similar approach but the geotiff will be updated daily by another cronjob, I have tested manually and seems it does not updates as I visually see the first geotiff used to create the layer. Is there a way to achieve this or this is not a use case for Geoserver ?
    – neavilag
    Commented Oct 23, 2021 at 23:55
  • @neavilag - AFAIK each geotiff is a separate store with a corresponding layer in geoserver. If the images are updated daily, you should use the cron job as the trigger in an image processing pipeline - after the image is updated, create a coverage store and layer. Even if you try to "slip a new image" in the same location as the original, you may run afoul of goeservers internal caching which could return the outdated image version. Commented Oct 26, 2021 at 13:47
  • 1
    @neavilag - Depending on your GeoServer version, yes. Try checking out docs.geoserver.org/latest/en/api/#1.0.0/coveragestores.yaml The 2.20 GeoServer REST API has has PUT implemented for modifying existing coverage stores. Links to all the REST API docs can be accessed here: docs.geoserver.org/stable/en/user/rest/index.html - including the geowebcache 'layers' API, which has a PUT verb to update an existing layer. Commented Oct 28, 2021 at 13:36
5

You'll need a coverage store and coverages.

A coverage store is a source of spatial data that is raster based.

The data stores you tried to use are only for vector data.

Have you checked How to use curl to upload Coverage through the Geoserver rest?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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