[GIS] Geoserver Datastore Property Update via REST API

geoservergeoserver-rest-api

I am trying to change the properties of an existing Geoserver data store via the REST API. I have created the data store from an existing folder of shapefiles. However, I need to change the "charset" and "Create spatial index if missing/outdated" properties but I cannot for the life of me figure out how to do it.

I have tried sending the following XML as a PUT request to the data store but it doesn't work:

<DataStore>
  <parameters>
    <Parameter>
      <name>create spatial index</name>
      <value>true</value>
    </Parameter>
    <Parameter>
      <name>charset</name>
      <value>ISO-8859-1</value>
    </Parameter>
  </parameters>
</DataStore>

REST:

http://localhost/geoserver/rest/workspaces/uk/datastores/roads.xml
PUT /geoserver/rest/workspaces/uk/datastores/roads.xml

Anyone have any ideas?

Thanks

Best Answer

I was testing with GeoServer 2.6-RC1. Version 2.4.x is very soon out of maintenance so I did not feel like playing with it. I apologize it you can't update yet.

First thing that I learned is that you must PUT the whole datastore configuration file and not only the changed parts. Second lesson was that the configuration file does not look the same in GeoServer 2.6 than in this document http://docs.geoserver.org/stable/en/user/data/app-schema/data-stores.html. I finally studied the datastore config file by changing some settings with the GUI admin utility.

With this command I created a new datastore from directory of shapefiles:

C:\data\states>curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain" -d "file:///data/states/" "http://localhost:8080/geoserver/rest/workspaces/topp/datastores/shapefiles/external.shp?configure=all"

The config file can now be reached from

http://localhost:8080/geoserver/rest/workspaces/topp/datastores/shapefiles/datastore.xml

For making the changes which you want the datastore.xml file should be edited like this:

<dataStore>
  <id>DataStoreInfoImpl--17f899d6:1483b8b6f12:-8000</id>
  <name>shapefiles</name>
  <type>Shapefile</type>
  <enabled>true</enabled>
  <workspace>
    <id>WorkspaceInfoImpl--570ae188:124761b8d78:-7ffd</id>
  </workspace>
  <connectionParameters>
    <entry key="memory mapped buffer">false</entry>
    <entry key="create spatial index">true</entry>
    <entry key="charset">ISO-8859-1</entry>
    <entry key="cache and reuse memory maps">false</entry>
    <entry key="url">file:/c:/data/states/</entry>
    <entry key="namespace">http://www.openplans.org/topp</entry>
  </connectionParameters>
  <__default>false</__default>
</dataStore>

Save the edited file as "put.xml" and PUT it

C:\data\states>curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml" -d @put.xml http://localhost:8080/geoserver/
rest/workspaces/topp/datastores/shapefiles/datastore.xml

This works for me.

Related Question