2

I'm building a PHP class to interact with my GeoServer. I'm following the limited Documentation, this GeoServer REST API with PHP post and also this great advice. I've successfully created/deleted a Workspace.

But when I try to upload a Shapefile it fails because no dataStore endpoint exists in my Workspace (I get a 404 response from cURL). So, I guess I should create a Store before trying to upload a Shapefile.

I've failed at finding any information regarding this issue (both here at GIS SE or Googling) but I've successfully created a Store with some RevEng:

I've checked the JSON for my GeoServer's default Store:

{
  "dataStore": {
    "name": "cntry_shp",
    "type": "Directory of spatial files (shapefiles)",
    "enabled": true,
    "workspace": {
      "name": "opengeo",
      "href": "http:\/\/0.0.0.0:8080\/geoserver\/rest\/workspaces\/opengeo.json"
    },
    "connectionParameters": {
      "entry": [
        {
          "@key": "memory mapped buffer",
          "$": "false"
        },
        {
          "@key": "timezone",
          "$": "America\/Vancouver"
        },
        {
          "@key": "fstype",
          "$": "shape-ng"
        },
        {
          "@key": "create spatial index",
          "$": "true"
        },
        {
          "@key": "charset",
          "$": "ISO-8859-1"
        },
        {
          "@key": "filetype",
          "$": "shapefile"
        },
        {
          "@key": "cache and reuse memory maps",
          "$": "true"
        },
        {
          "@key": "enable spatial index",
          "$": "true"
        },
        {
          "@key": "url",
          "$": "file:workspaces\/opengeo\/data"
        },
        {
          "@key": "namespace",
          "$": "http:\/\/opengeo.org"
        }
      ]
    },
    "_default": false,
    "featureTypes": "http:\/\/0.0.0.0:8080\/geoserver\/rest\/workspaces\/opengeo\/datastores\/cntry_shp\/featuretypes.json"
  }
}

I copied it, replacing its name and workspace, and inserted it in my system with a cURL call at the endpoint:

 rest/workspaces/MY_WORKSPACE/datastores

Then I tried to upload a Shapefile to it, and it failed. Anyway, I don't think this is the right way to do this.

Do you know which is the right way or, at least, do you know some examples or documentation?

2

The GeoServer REST manual has a section on creating DataStores that should show how its done. Basically you make a POST of the file to /workspaces/<ws>/datastores[.<format>].

curl -v -u admin:geoserver -XPOST -T nycDataStore.xml -H "Content-type: text/xml"
  http://localhost:8080/geoserver/rest/workspaces/acme/datastores

But GeoServer will create a DataStore for you when you PUT a new ShapeFile:

curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip"
  --data-binary @roads.zip
  http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/file.shp

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.