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>

curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' 
-d "<coverage>

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.


curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain" 
-d "file:///my_directory/data/species/${sp}/" 

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.


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

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]]
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]]

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.