layers.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. .. _gwc_rest_layers:
  2. Managing Layers
  3. ===============
  4. The GeoWebCache REST API provides a RESTful interface through which users can add, modify, or remove cached layers.
  5. .. note:: JSON is not recommended for managing layers as the JSON library has a number of issues with multi-valued properties such as "parameterFilters".
  6. Layer list
  7. ----------
  8. URL: ``/gwc/rest/layers.xml``
  9. .. list-table::
  10. :header-rows: 1
  11. * - Method
  12. - Action
  13. - Return Code
  14. - Formats
  15. * - GET
  16. - Return the list of available layers
  17. - 200
  18. - XML
  19. * - POST
  20. -
  21. - 400
  22. -
  23. * - PUT
  24. -
  25. - 400
  26. -
  27. * - DELETE
  28. -
  29. - 400
  30. -
  31. The following example will request a full list of layers:
  32. .. code-block:: xml
  33. curl -u admin:geoserver "http://localhost:8080/geoserver/gwc/rest/layers"
  34. .. code-block:: xml
  35. <layers>
  36. <layer>
  37. <name>img states</name>
  38. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/gwc/rest/layers/img+states.xml" type="text/xml"/>
  39. </layer>
  40. <layer>
  41. <name>raster test layer</name>
  42. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/gwc/rest/layers/raster+test+layer.xml" type="text/xml"/>
  43. </layer>
  44. <layer>
  45. <name>topp:states</name>
  46. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/gwc/rest/layers/topp%3Astates.xml" type="text/xml"/>
  47. </layer>
  48. </layers>
  49. Layer Operations
  50. ----------------
  51. URL: ``/gwc/rest/layers/<layer>.xml``
  52. .. note:: JSON is not recommended for managing layers as the JSON library has a number of issues with multi-valued properties such as "parameterFilters".
  53. .. list-table::
  54. :header-rows: 1
  55. * - Method
  56. - Action
  57. - Return Code
  58. - Formats
  59. * - GET
  60. - Return the XML representation of the layer
  61. - 200
  62. - XML
  63. * - POST
  64. - Modify the definition/configuration of the layer
  65. - 200
  66. - XML
  67. * - PUT
  68. - Add a new layer
  69. - 200
  70. - XML
  71. * - DELETE
  72. - Delete the layer
  73. - 200
  74. -
  75. .. note:: There are two different representations for cached layers, depending on whether the tile layer is created from the GeoServer WMS layer or layer group (``GeoServerLayer``), or is configured in ``geowebcache.xml`` as a regular GWC layer (``wmsLayer``). A GeoServer layer is referred to as a ``GeoServerLayer`` and contains no image data source information such as origin WMS URL.
  76. **Representations**:
  77. * GeoWebCache (``wmsLayer``) :download:`XML minimal <representations/wmslayer_minimal.xml.txt>`
  78. * GeoWebCache (``wmsLayer``) :download:`XML <representations/wmslayer.xml.txt>`
  79. * GeoServer (``GeoServerLayer``) :download:`XML minimal <representations/geoserverlayer_minimal.xml.txt>`
  80. * GeoServer (``GeoServerLayer``) :download:`XML <representations/geoserverlayer.xml.txt>`
  81. The examples below use the `cURL <http://curl.haxx.se/>`_ tool, though the examples apply to any HTTP-capable tool or library.
  82. Adding a GeoWebCache layer
  83. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  84. The following example will add a new layer to GeoWebCache:
  85. .. code-block:: console
  86. curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml" -d @layer.xml "http://localhost:8080/geoserver/gwc/rest/layers/newlayer.xml"
  87. The :file:`layer.xml` file is defined as the following:
  88. .. code-block:: xml
  89. <wmsLayer>
  90. <name>newlayer</name>
  91. <mimeFormats>
  92. <string>image/png</string>
  93. </mimeFormats>
  94. <gridSubsets>
  95. <gridSubset>
  96. <gridSetName>EPSG:900913</gridSetName>
  97. </gridSubset>
  98. </gridSubsets>
  99. <wmsUrl>
  100. <string>http://localhost:8080/geoserver/wms</string>
  101. </wmsUrl>
  102. <wmsLayers>topp:states</wmsLayers>
  103. </wmsLayer>
  104. .. note:: The addressed resource (``newlayer`` in this example) must match the name of the layer in the XML representation.
  105. Adding a GeoServer layer
  106. ~~~~~~~~~~~~~~~~~~~~~~~~
  107. The following example will add a new layer to both GeoServer and GeoWebCache:
  108. .. code-block:: console
  109. curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml" -d @poi.xml "http://localhost:8080/geoserver/gwc/rest/layers/tiger:poi.xml"
  110. The :file:`poi.xml` file is defined as the following:
  111. .. code-block:: xml
  112. <GeoServerLayer>
  113. <id>LayerInfoImpl--570ae188:124761b8d78:-7fd0</id>
  114. <enabled>true</enabled>
  115. <name>tiger:poi</name>
  116. <mimeFormats>
  117. <string>image/png8</string>
  118. </mimeFormats>
  119. <gridSubsets>
  120. <gridSubset>
  121. <gridSetName>GoogleCRS84Quad</gridSetName>
  122. <zoomStart>0</zoomStart>
  123. <zoomStop>14</zoomStop>
  124. <minCachedLevel>1</minCachedLevel>
  125. <maxCachedLevel>9</maxCachedLevel>
  126. </gridSubset>
  127. </gridSubsets>
  128. <metaWidthHeight>
  129. <int>4</int>
  130. <int>4</int>
  131. </metaWidthHeight>
  132. <gutter>50</gutter>
  133. <autoCacheStyles>true</autoCacheStyles>
  134. </GeoServerLayer>
  135. .. note:: The addressed resource ( ``tiger:poi`` in this example) must match the name of the layer in the XML representation, as well as the name of an *existing* GeoServer layer or layer group.
  136. Modifying a layer
  137. ~~~~~~~~~~~~~~~~~
  138. This example modifies the layer definition via the :file:`layer.xml` file. The request adds a parameter filter and a grid subset to the existing ``tiger:poi`` tile layer:
  139. .. code-block:: xml
  140. <GeoServerLayer>
  141. <enabled>true</enabled>
  142. <name>tiger:poi</name>
  143. <mimeFormats>
  144. <string>image/png8</string>
  145. </mimeFormats>
  146. <gridSubsets>
  147. <gridSubset>
  148. <gridSetName>GoogleCRS84Quad</gridSetName>
  149. <zoomStart>0</zoomStart>
  150. <zoomStop>14</zoomStop>
  151. <minCachedLevel>1</minCachedLevel>
  152. <maxCachedLevel>9</maxCachedLevel>
  153. </gridSubset>
  154. <gridSubset>
  155. <gridSetName>EPSG:900913</gridSetName>
  156. <extent>
  157. <coords>
  158. <double>-8238959.403861314</double>
  159. <double>4969300.121476209</double>
  160. <double>-8237812.689219721</double>
  161. <double>4971112.167757057</double>
  162. </coords>
  163. </extent>
  164. </gridSubset>
  165. </gridSubsets>
  166. <metaWidthHeight>
  167. <int>4</int>
  168. <int>4</int>
  169. </metaWidthHeight>
  170. <parameterFilters>
  171. <floatParameterFilter>
  172. <key>ELEVATION</key>
  173. <defaultValue>0.0</defaultValue>
  174. <values>
  175. <float>0.0</float>
  176. <float>1.0</float>
  177. <float>2.0</float>
  178. <float>3.0</float>
  179. <float>4.0</float>
  180. </values>
  181. <threshold>1.0E-3</threshold>
  182. </floatParameterFilter>
  183. </parameterFilters>
  184. <gutter>50</gutter>
  185. <autoCacheStyles>true</autoCacheStyles>
  186. </GeoServerLayer>
  187. Instead of PUT, use the HTTP POST method instead:
  188. .. code-block:: console
  189. curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d @poi.xml "http://localhost:8080/geoserver/gwc/rest/layers/tiger:poi.xml"
  190. Deleting a layer
  191. ~~~~~~~~~~~~~~~~
  192. Deleting a GeoWebCache tile layer deletes the layer configuration *as well as the layer's disk cache*. No tile images will remain in the cache directory after deleting a tile layer.
  193. To delete a layer, use the HTTP DELETE method against the layer resource:
  194. .. code-block:: console
  195. curl -v -u admin:geoserver -XDELETE "http://localhost:8080/geoserver/gwc/rest/layers/newlayer.xml"
  196. .. note::
  197. If trying to delete a tile layer that is an integrated ``GeoServerLayer``, only the GeoWebCache layer definition will be deleted; the GeoServer definition is left untouched. To delete a layer in GeoServer, use the GeoServer :ref:`rest` to manipulate GeoServer resources.
  198. On the other hand, deleting a GeoServer layer via the GeoServer REST API *will* automatically delete the associated tile layer.