GeoServer提供了一个RESTful接口,客户端可以通过该接口获取有关实例的信息并进行配置更改。REST接口使用简单的HTTP调用,通过客户端就可以配置GeoServer,而无需使用Web管理接口。
工作区、数据源、图层、图层组以及样式之间的关系如下图所示。
可得知:
{
"workspace": {
"name": "lzugis-workspace"
}
}
{
"dataStore": {
"name": "nyc",
"connectionParameters": {
"entry": [
{"@key":"url","$":"file:/D:/data/china/capital.shp"}
]
}
}
}
{
"dataStore": {
"name": "china",
"connectionParameters": {
"entry": [
{"@key":"url","$":"file:/D:/data/china"}
]
}
}
}
{
"dataStore": {
"name": "postgres",
"connectionParameters": {
"entry": [
{"@key":"host","$":"localhost"},
{"@key":"port","$":"5432"},
{"@key":"database","$":"lzugis"},
{"@key":"user","$":"postgres"},
{"@key":"passwd","$":"passwd"},
{"@key":"dbtype","$":"postgis"}
]
}
}
}
{
"name": "layer_capital",
"nativeName": "layer_capital",
"namespace": {
"name": "lzugis",
"href": "http://localhost:8085/geoserver/rest/namespaces/lzugis.json"
},
"title": "layer_capital",
"keywords": {
"string": [
"features",
"layer_capital"
]
},
"nativeCRS": "GEOGCS[\"WGS 84\", \r\n DATUM[\"World Geodetic System 1984\", \r\n SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], \r\n AUTHORITY[\"EPSG\",\"6326\"]], \r\n PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \r\n UNIT[\"degree\", 0.017453292519943295], \r\n AXIS[\"Geodetic longitude\", EAST], \r\n AXIS[\"Geodetic latitude\", NORTH], \r\n AUTHORITY[\"EPSG\",\"4326\"]]",
"srs": "EPSG:4326",
"nativeBoundingBox": {
"minx": 87.5760726928711,
"maxx": 126.56706237792969,
"miny": 19.970149993896484,
"maxy": 45.6938591003418,
"crs": "EPSG:4326"
},
"latLonBoundingBox": {
"minx": 87.5760726928711,
"maxx": 126.56706237792969,
"miny": 19.970149993896484,
"maxy": 45.6938591003418,
"crs": "EPSG:4326"
},
"projectionPolicy": "FORCE_DECLARED",
"enabled": true,
"store": {
"@class": "dataStore",
"name": "postgres",
"href": "http://localhost:8085/geoserver/rest/workspaces/lzugis/datastores/postgres.json"
},
"serviceConfiguration": false,
"simpleConversionEnabled": false,
"internationalTitle": "",
"internationalAbstract": "",
"maxFeatures": 0,
"numDecimals": 0,
"padWithZeros": false,
"forcedDecimal": false,
"overridingServiceSRS": false,
"skipNumberMatched": false,
"circularArcPresent": false,
"attributes": {
"attribute": [{
"name": "name",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String"
},
{
"name": "geom",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "org.locationtech.jts.geom.Point"
},
{
"name": "lon",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.Double"
},
{
"name": "lat",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.Float"
}
]
}
}
application/vnd.ogc.sld+xml
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
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">
<!-- a Named Layer is the basic building block of an SLD document -->
<NamedLayer>
<Name>default_line</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
<Title>Default Line</Title>
<Abstract>A sample style that draws a line</Abstract>
<!-- FeatureTypeStyles describe how to render different features -->
<!-- A FeatureTypeStyle for rendering lines -->
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>Blue Line</Title>
<Abstract>A solid blue line with a 1 pixel width</Abstract>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#0000FF</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
由于上面的操作都需要登录Geoserver后方可,所以在进行接口调用时需要设置登录信息,如在Postman
中可进行如下设置。
如在前端代码调用,需要设置头信息Authorization
,设置方式如下:
const auth = window.btoa(`admin:geoserver`);
const url = 'http://localhost:8085/geoserver/rest/layers'
fetch(url, {
method: 'get',
headers: { 'Authorization': `Basic ${auth}`
}).then(res => res.json()).then(res => {
console.log(res)
})
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有