.. _rest_stores:
Stores
======
Uploading a shapefile
---------------------
**Create a new store "roads" by uploading a shapefile "roads.zip"**
*Request*
.. admonition:: curl
::
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
.. admonition:: python
TBD
.. admonition:: java
TBD
*Response*
::
201 Created
Listing store details
---------------------
*Retrieve information about a specific store**
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XGET
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads.xml
.. admonition:: python
TBD
.. admonition:: java
TBD
*Response*
.. code-block:: xml
roads
Shapefile
true
acme
file:/C:/path/to/data_dir/data/acme/roads/
http://acme
<__default>false
*Request*
.. note:: The XML response only provides details about the store itself, so you can use HTML to see the contents of the store.
.. code-block:: console
curl -v -u admin:geoserver -XGET
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads.html
Listing featuretype details
---------------------------
.. note:: By default when a shapefile is uploaded, a featuretype is automatically created.
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XGET
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/featuretypes/roads.xml
.. admonition:: python
TBD
.. admonition:: java
TBD
*Response*
.. code-block:: xml
roads
roads
acme
...
Adding an existing shapefile
----------------------------
**Publish a shapefile "rivers.shp" that already exists on the server without needing to be uploaded**
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain"
-d "file:///data/shapefiles/rivers/rivers.shp"
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/rivers/external.shp
.. note:: The ``external.shp`` part of the request URI indicates that the file is coming from outside the catalog.
*Response*
::
201 Created
Adding a directory of existing shapefiles
-----------------------------------------
**Create a store containing a directory of shapefiles that already exists on the server without needing to be uploaded**
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain"
-d "file:///data/shapefiles/"
"http://localhost:8080/geoserver/rest/workspaces/acme/datastores/shapefiles/external.shp?configure=all"
.. note:: The ``configure=all`` query string parameter sets each shapefile in the directory to be loaded and published.
*Response*
::
201 Created
Adding a PostGIS database store
-------------------------------
**Add an existing PostGIS database named "nyc" as a new store**
.. note:: This example assumes that a PostGIS database named ``nyc`` is present on the local system and is accessible by the user ``bob``.
Given the following content saved as :file:`nycDataStore.xml`:
.. code-block:: xml
nyc
localhost
5432
nyc
bob
postgres
postgis
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XPOST -T nycDataStore.xml -H "Content-type: text/xml"
http://localhost:8080/geoserver/rest/workspaces/acme/datastores
*Response*
::
201 Created
Listing a PostGIS database store details
----------------------------------------
**Retrieve information about a PostGIS store**
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc.xml
*Response*
.. code-block:: xml
nyc
PostGIS
true
acme
5432
postgis
localhost
bob
nyc
http://acme
<__default>false
Publishing a table from an existing PostGIS store
-------------------------------------------------
**Publish a new featuretype from a PostGIS store table "buildings"**
.. note:: This example assumes the table has already been created.
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml"
-d "buildings"
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
.. note::
This layer can viewed with a WMS GetMap request::
http://localhost:8080/geoserver/wms/reflect?layers=acme:buildings
Creating a PostGIS table
------------------------
**Create a new featuretype in GeoServer and simultaneously create a table in PostGIS**
Given the following content saved as :file:`annotations.xml`:
.. code-block:: xml
annotations
annotations
Annotations
EPSG:4326
the_geom
com.vividsolutions.jts.geom.Point
description
java.lang.String
timestamp
java.util.Date
*Request*
.. admonition:: curl
::
curl -v -u admin:geoserver -XPOST -T annotations.xml -H "Content-type: text/xml"
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
.. note:: The NYC store must be a PostGIS store for this to succeed.
*Response*
::
201 Created
A new and empty table named "annotations" in the "nyc" database will be created as well.