styles.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. .. _rest_styles:
  2. Styles
  3. ======
  4. The REST API allows you to list, create, upload, update, and delete styles in GeoServer.
  5. .. note:: Read the :api:`API reference for /styles <styles.yaml>`.
  6. Listing all styles
  7. ------------------
  8. **List all styles on the server, in JSON format:**
  9. *Request*
  10. .. admonition:: curl
  11. ::
  12. curl -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/styles.json
  13. *Response*
  14. .. code-block:: json
  15. {"styles":{"style":[{"name":"burg","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/burg.json"},{"name":"capitals","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/capitals.json"},{"name":"dem","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/dem.json"},{"name":"generic","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/generic.json"},{"name":"giant_polygon","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/giant_polygon.json"},{"name":"grass","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/grass.json"},{"name":"green","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/green.json"},{"name":"line","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/line.json"},{"name":"poi","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/poi.json"},{"name":"point","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/point.json"},{"name":"polygon","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/polygon.json"},{"name":"poly_landmarks","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/poly_landmarks.json"},{"name":"pophatch","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/pophatch.json"},{"name":"population","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/population.json"},{"name":"rain","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/rain.json"},{"name":"raster","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/raster.json"},{"name":"restricted","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/restricted.json"},{"name":"simple_roads","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/simple_roads.json"},{"name":"simple_streams","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/simple_streams.json"},{"name":"tiger_roads","href":"http:\/\/localhost:8080\/geoserver\/rest\/styles\/tiger_roads.json"}]}}
  16. **List all styles in a workspace, in XML format:**
  17. *Request*
  18. .. admonition:: curl
  19. ::
  20. curl -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/cite/styles.xml
  21. *Response*
  22. .. code-block:: xml
  23. <styles>
  24. <style>
  25. <name>citerain</name>
  26. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/cite/styles/citerain.xml" type="application/xml"/>
  27. </style>
  28. </styles>
  29. Retrieve a style
  30. ----------------
  31. **Download the actual style code for a style:**
  32. *Request*
  33. .. admonition:: curl
  34. ::
  35. curl -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/styles/rain.sld
  36. *Response*
  37. .. code-block:: xml
  38. <StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  39. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  40. xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  41. <NamedLayer>
  42. <Name>rain</Name>
  43. <UserStyle>
  44. <Name>rain</Name>
  45. <Title>Rain distribution</Title>
  46. <FeatureTypeStyle>
  47. <Rule>
  48. <RasterSymbolizer>
  49. <Opacity>1.0</Opacity>
  50. <ColorMap>
  51. <ColorMapEntry color="#FF0000" quantity="0" />
  52. <ColorMapEntry color="#FFFFFF" quantity="100"/>
  53. <ColorMapEntry color="#00FF00" quantity="2000"/>
  54. <ColorMapEntry color="#0000FF" quantity="5000"/>
  55. </ColorMap>
  56. </RasterSymbolizer>
  57. </Rule>
  58. </FeatureTypeStyle>
  59. </UserStyle>
  60. </NamedLayer>
  61. </StyledLayerDescriptor>
  62. Creating a style
  63. ----------------
  64. You can create a new style on the server in two ways. In the first way, the creation is done in two steps: the style entry is created in the catalog, and then the style content is uploaded. The second way can add the style to the server in a single step by uploading a ZIP containing the style content:
  65. **Create a new style in two steps:**
  66. *Request*
  67. .. admonition:: curl
  68. ::
  69. curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<style><name>roads_style</name><filename>roads.sld</filename></style>" http://localhost:8080/geoserver/rest/styles
  70. *Response*
  71. ::
  72. 201 Created
  73. *Request*
  74. .. admonition:: curl
  75. ::
  76. curl -v -u admin:geoserver -XPUT -H "Content-type: application/vnd.ogc.sld+xml" -d @roads.sld http://localhost:8080/geoserver/rest/styles/roads_style
  77. *Response*
  78. ::
  79. 200 OK
  80. **Create a new style in a single step:**
  81. *Request*
  82. .. admonition:: curl
  83. ::
  84. curl -u admin:geoserver -XPOST -H "Content-type: application/zip" --data-binary @roads_style.zip http://localhost:8080/geoserver/rest/styles
  85. *Response*
  86. ::
  87. 201 Created
  88. **Create a new style in a single step using CSS:**
  89. *Request*
  90. .. admonition:: curl
  91. ::
  92. curl -u admin:geoserver -XPOST -H "Content-type: application/vnd.geoserver.geocss+css" -d '* { stroke: red; }' http://localhost:8080/geoserver/rest/styles
  93. *Response*
  94. ::
  95. 201 Created
  96. This example will create a new style on the server and populate it the contents of a local SLD file and related images provided in a SLD package.
  97. A SLD package is a zip file containing the SLD style and related image files used in the SLD.
  98. The following creates a new style named ``roads_style``.
  99. Each code block below contains a single command that may be extended over multiple lines.
  100. *Request*
  101. .. admonition:: curl
  102. ::
  103. curl -u admin:geoserver -XPOST -H "Content-type: application/zip"
  104. --data-binary @roads_style.zip
  105. http://localhost:8080/geoserver/rest/styles
  106. *Response*
  107. ::
  108. 201 OK
  109. The SLD itself can be downloaded through a a GET request:
  110. .. admonition:: curl
  111. ::
  112. curl -v -u admin:geoserver -XGET
  113. http://localhost:8080/geoserver/rest/styles/roads_style.sld
  114. Changing an existing style
  115. --------------------------
  116. **Edit/reupload the content of an existing style on the server:**
  117. *Request*
  118. .. admonition:: curl
  119. ::
  120. curl -u admin:geoserver -XPUT -H "Content-type: application/vnd.ogc.sld+xml" -d @roads.sld
  121. http://localhost:8080/geoserver/rest/styles/roads_style
  122. *Response*
  123. ::
  124. 200 OK
  125. **Edit/reupload the content of an existing style on the server when the style is in a workspace:**
  126. *Request*
  127. .. admonition:: curl
  128. ::
  129. curl -u admin:geoserver -XPUT -H "Content-type: application/vnd.ogc.sld+xml" -d @roads.sld
  130. http://localhost:8080/geoserver/rest/workspaces/cite/styles/roads_style
  131. *Response*
  132. ::
  133. 200 OK
  134. **Edit/reupload the content of an existing style on the server using a ZIP file containing a shapefile:**
  135. *Request*
  136. .. admonition:: curl
  137. ::
  138. curl -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @roads_style.zip http://localhost:8080/geoserver/rest/styles/roads_style.zip
  139. *Response*
  140. ::
  141. 200 OK
  142. Deleting a style
  143. ----------------
  144. **Remove a style entry from the server, retaining the orphaned style content:**
  145. *Request*
  146. .. admonition:: curl
  147. ::
  148. curl -u admin:geoserver -XDELETE http://localhost:8080/geoserver/rest/styles/zoning
  149. *Response*
  150. ::
  151. 200 OK
  152. **Remove a style entry from the server, deleting the orphaned style content:**
  153. *Request*
  154. .. admonition:: curl
  155. ::
  156. curl -u admin:geoserver -XDELETE http://localhost:8080/geoserver/rest/styles/zoning?purge=true
  157. *Response*
  158. ::
  159. 200 OK