2

I'm automating the publishing of layers in Geoserver 2.9. I've had good luck with getting my GeoTIFFs to publish nicely, despite having garbage for incoming SRS info.

With the GeoTIFFs, I POST a coverageStore definition and then POST a coverage definition. It works great.

export t="American_Redstart_100_1_abund_aut.tif"
export sp=American_Redstart_100_1
export dataStoreName=${t%.*}

curl -v -u admin:geoserver -XPOST -H 'Content-Type: text/xml' 
-d "<coverageStore>
      <name>${dataStoreName}</name>
      <enabled>true</enabled>
      <type>GeoTIFF</type>
      <url>file:///my_directory/data/species/${sp}/${t}</url>
      <workspace>stemlt</workspace>
    </coverageStore>" 
"http://localhost:8080/geoserver/rest/workspaces/stemlt/coveragestores?configure=all"

curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' 
-d "<coverage>
      <name>${dataStoreName}</name>
      <title>${dataStoreName}</title>
      <nativeCRS>UNKNOWN</nativeCRS>
      <srs>EPSG:3857</srs>
      <projectionPolicy>FORCE_DECLARED</projectionPolicy>
      <latLonBoundingBox>
        <minx>-20051271</minx>
        <maxx>20055048</maxx>
        <miny>-2722745</miny>
        <maxy>20268684</maxy>
        <crs>EPSG:3857</crs>
      </latLonBoundingBox></coverage>" 
"http://localhost:8080/geoserver/rest/workspaces/stemlt/coveragestores/${dataStoreName}/coverages"

However, I want to do something similar with a directory of shapefiles, but can't find the API parameters to do it. I'd like to be able to point to a directory of shapefiles and set the nativeCRS, srs, projectionPolicy, and latLonBoundingBox as they go in.

Currently, I am using PUT and external.shp?configure=all to load the directory of shapefiles, but then I have to manually update the projection information.

sp=American_Redstart_100_1

curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain" 
-d "file:///my_directory/data/species/${sp}/" 
"http://localhost:8080/geoserver/rest/workspaces/stemlt/datastores/${sp}_grids/external.shp?configure=all"

How do I pass along projection information as I PUT or POST the directory of Shapefiles? I'm also okay with looping through loaded shapefiles, but can't find the right function for operating on those either.

2

That information is stored in the FeatureType - for example http://localhost:8080/geoserver/rest/workspaces/topp/datastores/states_shapefile/featuretypes/states.xml

<nativeCRS>
GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Longitude", EAST], AXIS["Latitude", NORTH]]
</nativeCRS>
<srs>EPSG:4326</srs>
<nativeBoundingBox>
<minx>-134.731422</minx>
<maxx>-66.969849</maxx>
<miny>24.955967</miny>
<maxy>49.371735</maxy>
<crs>EPSG:4326</crs>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>-134.731422</minx>
<maxx>-66.969849</maxx>
<miny>24.955967</miny>
<maxy>49.371735</maxy>
<crs>
GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]
</crs>
</latLonBoundingBox>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
<enabled>true</enabled>
<advertised>true</advertised>

So for each shapefile you can GET the feature type, make whatever changes and then PUT it back to GeoServer.

I can't help thinking it would be easier to fix the shapefiles before uploading by dropping a correct .prj file into them.

  • Thanks, Ian! This works for me. It is probably easier to change the .prj file on the shapefiles, but I figured since I was already doing a bunch of similar work with REST API to load layers, that doing it with the shapefiles wasn't much more work. – the_skua Aug 2 '16 at 14:18

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.