stores.rst 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. .. _rest_stores:
  2. Stores
  3. ======
  4. Uploading a shapefile
  5. ---------------------
  6. **Create a new store "roads" by uploading a shapefile "roads.zip"**
  7. *Request*
  8. .. admonition:: curl
  9. ::
  10. curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip"
  11. --data-binary @roads.zip
  12. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/file.shp
  13. *Response*
  14. ::
  15. 201 Created
  16. Listing store details
  17. ---------------------
  18. *Retrieve information about a specific store**
  19. *Request*
  20. .. admonition:: curl
  21. ::
  22. curl -v -u admin:geoserver -XGET
  23. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads.xml
  24. .. admonition:: python
  25. TBD
  26. .. admonition:: java
  27. TBD
  28. *Response*
  29. .. code-block:: xml
  30. <dataStore>
  31. <name>roads</name>
  32. <type>Shapefile</type>
  33. <enabled>true</enabled>
  34. <workspace>
  35. <name>acme</name>
  36. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
  37. href="http://localhost:8080/geoserver/rest/workspaces/acme.xml" type="application/xml"/>
  38. </workspace>
  39. <connectionParameters>
  40. <entry key="url">file:/C:/path/to/data_dir/data/acme/roads/</entry>
  41. <entry key="namespace">http://acme</entry>
  42. </connectionParameters>
  43. <__default>false</__default>
  44. <featureTypes>
  45. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
  46. href="http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/featuretypes.xml"
  47. type="application/xml"/>
  48. </featureTypes>
  49. </dataStore>
  50. *Request*
  51. .. note:: The XML response only provides details about the store itself, so you can use HTML to see the contents of the store.
  52. .. code-block:: console
  53. curl -v -u admin:geoserver -XGET
  54. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads.html
  55. Listing featuretype details
  56. ---------------------------
  57. .. note:: By default when a shapefile is uploaded, a featuretype is automatically created.
  58. *Request*
  59. .. admonition:: curl
  60. ::
  61. curl -v -u admin:geoserver -XGET
  62. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/featuretypes/roads.xml
  63. .. admonition:: python
  64. TBD
  65. .. admonition:: java
  66. TBD
  67. *Response*
  68. .. code-block:: xml
  69. <featureType>
  70. <name>roads</name>
  71. <nativeName>roads</nativeName>
  72. <namespace>
  73. <name>acme</name>
  74. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
  75. href="http://localhost:8080/geoserver/rest/namespaces/acme.xml" type="application/xml"/>
  76. </namespace>
  77. ...
  78. </featureType>
  79. Adding an existing shapefile
  80. ----------------------------
  81. **Publish a shapefile "rivers.shp" that already exists on the server without needing to be uploaded**
  82. *Request*
  83. .. admonition:: curl
  84. ::
  85. curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain"
  86. -d "file:///data/shapefiles/rivers/rivers.shp"
  87. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/rivers/external.shp
  88. .. note:: The ``external.shp`` part of the request URI indicates that the file is coming from outside the catalog.
  89. *Response*
  90. ::
  91. 201 Created
  92. Adding a directory of existing shapefiles
  93. -----------------------------------------
  94. **Create a store containing a directory of shapefiles that already exists on the server without needing to be uploaded**
  95. *Request*
  96. .. admonition:: curl
  97. ::
  98. curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain"
  99. -d "file:///data/shapefiles/"
  100. "http://localhost:8080/geoserver/rest/workspaces/acme/datastores/shapefiles/external.shp?configure=all"
  101. .. note:: The ``configure=all`` query string parameter sets each shapefile in the directory to be loaded and published.
  102. *Response*
  103. ::
  104. 201 Created
  105. Adding a PostGIS database store
  106. -------------------------------
  107. **Add an existing PostGIS database named "nyc" as a new store**
  108. .. note:: This example assumes that a PostGIS database named ``nyc`` is present on the local system and is accessible by the user ``bob``.
  109. Given the following content saved as :file:`nycDataStore.xml`:
  110. .. code-block:: xml
  111. <dataStore>
  112. <name>nyc</name>
  113. <connectionParameters>
  114. <host>localhost</host>
  115. <port>5432</port>
  116. <database>nyc</database>
  117. <user>bob</user>
  118. <passwd>postgres</passwd>
  119. <dbtype>postgis</dbtype>
  120. </connectionParameters>
  121. </dataStore>
  122. *Request*
  123. .. admonition:: curl
  124. ::
  125. curl -v -u admin:geoserver -XPOST -T nycDataStore.xml -H "Content-type: text/xml"
  126. http://localhost:8080/geoserver/rest/workspaces/acme/datastores
  127. *Response*
  128. ::
  129. 201 Created
  130. Listing a PostGIS database store details
  131. ----------------------------------------
  132. **Retrieve information about a PostGIS store**
  133. *Request*
  134. .. admonition:: curl
  135. ::
  136. curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc.xml
  137. *Response*
  138. .. code-block:: xml
  139. <dataStore>
  140. <name>nyc</name>
  141. <type>PostGIS</type>
  142. <enabled>true</enabled>
  143. <workspace>
  144. <name>acme</name>
  145. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
  146. href="http://localhost:8080/geoserver/rest/workspaces/acme.xml" type="application/xml"/>
  147. </workspace>
  148. <connectionParameters>
  149. <entry key="port">5432</entry>
  150. <entry key="dbtype">postgis</entry>
  151. <entry key="host">localhost</entry>
  152. <entry key="user">bob</entry>
  153. <entry key="database">nyc</entry>
  154. <entry key="namespace">http://acme</entry>
  155. </connectionParameters>
  156. <__default>false</__default>
  157. <featureTypes>
  158. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
  159. href="http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes.xml"
  160. type="application/xml"/>
  161. </featureTypes>
  162. </dataStore>
  163. Publishing a table from an existing PostGIS store
  164. -------------------------------------------------
  165. **Publish a new featuretype from a PostGIS store table "buildings"**
  166. .. note:: This example assumes the table has already been created.
  167. *Request*
  168. .. admonition:: curl
  169. ::
  170. curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml"
  171. -d "<featureType><name>buildings</name></featureType>"
  172. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
  173. .. note::
  174. This layer can viewed with a WMS GetMap request::
  175. http://localhost:8080/geoserver/wms/reflect?layers=acme:buildings
  176. Creating a PostGIS table
  177. ------------------------
  178. **Create a new featuretype in GeoServer and simultaneously create a table in PostGIS**
  179. Given the following content saved as :file:`annotations.xml`:
  180. .. code-block:: xml
  181. <featureType>
  182. <name>annotations</name>
  183. <nativeName>annotations</nativeName>
  184. <title>Annotations</title>
  185. <srs>EPSG:4326</srs>
  186. <attributes>
  187. <attribute>
  188. <name>the_geom</name>
  189. <binding>org.locationtech.jts.geom.Point</binding>
  190. </attribute>
  191. <attribute>
  192. <name>description</name>
  193. <binding>java.lang.String</binding>
  194. </attribute>
  195. <attribute>
  196. <name>timestamp</name>
  197. <binding>java.util.Date</binding>
  198. </attribute>
  199. </attributes>
  200. </featureType>
  201. *Request*
  202. .. admonition:: curl
  203. ::
  204. curl -v -u admin:geoserver -XPOST -T annotations.xml -H "Content-type: text/xml"
  205. http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
  206. .. note:: The NYC store must be a PostGIS store for this to succeed.
  207. *Response*
  208. ::
  209. 201 Created
  210. A new and empty table named "annotations" in the "nyc" database will be created as well.
  211. Adding an external WMTS Store
  212. -----------------------------
  213. **Create a new WMTS store "Basemap-Nat-Geo-Datastore"**
  214. *Request*
  215. .. admonition:: curl
  216. ::
  217. curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml"
  218. -d "<wmtsStore><name>basemap-nat-geo-datastore</name><description>esri-street-map</description><capabilitiesURL>https://services.arcgisonline.com/arcgis/rest/services/NatGeo_World_Map/MapServer/WMTS/1.0.0/WMTSCapabilities.xml</capabilitiesURL><type>WMTS</type></wmtsStore>"
  219. http://localhost:8080/geoserver/rest/workspaces/acme/wmtsstores
  220. *Response*
  221. ::
  222. 201 Created
  223. Adding an external WMTS Layer
  224. -----------------------------
  225. **Publish a new WMTS Layer "NatGeo_World_Map" from the WMTS store "Basemap-Nat-Geo-Datastore"**
  226. *Request*
  227. .. admonition:: curl
  228. ::
  229. curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml"
  230. -d "<wmtsLayer><name>NatGeo_World_Map</name></wmtsLayer>"
  231. http://localhost:8080/geoserver/rest/workspaces/acme/wmtsstores/Basemap-Nat-Geo-Datastore/layers
  232. *Response*
  233. ::
  234. 201 Created