风格¶
RESTAPI允许您在geoserver中列出、创建、上载、更新和删除样式。
备注
列出所有样式¶
以JSON格式列出服务器上的所有样式:
请求
卷曲
curl -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/styles.json
响应
{"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"}]}}
以XML格式列出工作区中的所有样式:
请求
卷曲
curl -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/cite/styles.xml
响应
<styles>
<style>
<name>citerain</name>
<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"/>
</style>
</styles>
检索样式¶
下载样式的实际样式代码:
请求
卷曲
curl -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/styles/rain.sld
响应
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>rain</Name>
<UserStyle>
<Name>rain</Name>
<Title>Rain distribution</Title>
<FeatureTypeStyle>
<Rule>
<RasterSymbolizer>
<Opacity>1.0</Opacity>
<ColorMap>
<ColorMapEntry color="#FF0000" quantity="0" />
<ColorMapEntry color="#FFFFFF" quantity="100"/>
<ColorMapEntry color="#00FF00" quantity="2000"/>
<ColorMapEntry color="#0000FF" quantity="5000"/>
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
创建样式¶
您可以通过两种方式在服务器上创建新样式。首先,创建分为两个步骤:样式条目在目录中创建,然后上载样式内容。第二种方法是通过上载包含样式内容的zip,一步将样式添加到服务器:
分两步创建新样式:
请求
卷曲
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
响应
201 Created
请求
卷曲
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
响应
200 OK
单步创建新样式:
请求
卷曲
curl -u admin:geoserver -XPOST -H "Content-type: application/zip" --data-binary @roads_style.zip http://localhost:8080/geoserver/rest/styles
响应
201 Created
Create a new style in a single step using CSS:
请求
卷曲
curl -u admin:geoserver -XPOST -H "Content-type: application/vnd.geoserver.geocss+css" -d '* { stroke: red; }' http://localhost:8080/geoserver/rest/styles
响应
201 Created
此示例将在服务器上创建一个新样式,并将本地SLD文件的内容和SLD包中提供的相关图像填充到该样式中。SLD包是包含SLD样式和SLD中使用的相关图像文件的zip文件。
下面创建一个名为 roads_style
.
下面的每个代码块都包含一个可以扩展到多行的命令。
请求
卷曲
curl -u admin:geoserver -XPOST -H "Content-type: application/zip"
--data-binary @roads_style.zip
http://localhost:8080/geoserver/rest/styles
响应
201 OK
SLD本身可以通过GET请求下载:
卷曲
curl -v -u admin:geoserver -XGET
http://localhost:8080/geoserver/rest/styles/roads_style.sld
更改现有样式¶
Edit/reupload the content of an existing style on the server:
请求
卷曲
curl -u admin:geoserver -XPUT -H "Content-type: application/vnd.ogc.sld+xml" -d @roads.sld
http://localhost:8080/geoserver/rest/styles/roads_style
响应
200 OK
Edit/reupload the content of an existing style on the server when the style is in a workspace:
请求
卷曲
curl -u admin:geoserver -XPUT -H "Content-type: application/vnd.ogc.sld+xml" -d @roads.sld
http://localhost:8080/geoserver/rest/workspaces/cite/styles/roads_style
响应
200 OK
Edit/reupload the content of an existing style on the server using a ZIP file containing a shapefile:
请求
卷曲
curl -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @roads_style.zip http://localhost:8080/geoserver/rest/styles/roads_style.zip
响应
200 OK
删除样式¶
从服务器中删除样式项,保留孤立的样式内容:
请求
卷曲
curl -u admin:geoserver -XDELETE http://localhost:8080/geoserver/rest/styles/zoning
响应
200 OK
从服务器中删除样式项,删除孤立的样式内容:
请求
卷曲
curl -u admin:geoserver -XDELETE http://localhost:8080/geoserver/rest/styles/zoning?purge=true
响应
200 OK