所以我用了两个工作日来解决这个问题。我们是自动绘制过程的地图。所有数据都是用SQL base提供的,我的工作是编写“包装器”,这样我们就可以在内部框架中实现这一点。除了一个需要的请求之外,我处理了所有的请求。该请求是POST特性类型,因为这是一种创建层的方法,以后可以呈现该层。
我有所有的要求保存在邮递员的预先测试的例子数据,由geoserver本身。我甚至无法得到状态代码201的响应,并且总是得到500个内部服务器错误。此状态被描述为系统中可能出现的语法错误。但实际上,我只是复制、粘贴、举例和使用geoserver提供的数据。
这是requst:http://127.0.0.1:8080/geoserver/rest/workspaces/tiger/datastores/nyc/featuretypes
它的身体:
{
"name": "poi",
"nativeName": "poi",
"namespace": {
"name": "tiger",
"href": "http://localhost:8080/geoserver/rest/namespaces/tiger.json"
},
"title": "Manhattan (NY) points of interest",
"abstract": "Points of interest in New York, New York (on Manhattan). One of the attributes contains the name of a file with a picture of the point of interest.",
"keywords": {
"string": [
"poi",
"Manhattan",
"DS_poi",
"points_of_interest",
"sampleKeyword\\@language=ab\\;",
"area of effect\\@language=bg\\;\\@vocabulary=technical\\;",
"Привет\\@language=ru\\;\\@vocabulary=friendly\\;"
]
},
"metadataLinks": {
"metadataLink": [
{
"type": "text/plain",
"metadataType": "FGDC",
"content": "www.google.com"
}
]
},
"dataLinks": {
"org.geoserver.catalog.impl.DataLinkInfoImpl": [
{
"type": "text/plain",
"content": "http://www.google.com"
}
]
},
"nativeCRS": "GEOGCS[\"WGS 84\", \n DATUM[\"World Geodetic System 1984\", \n SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], \n AUTHORITY[\"EPSG\",\"6326\"]], \n PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \n UNIT[\"degree\", 0.017453292519943295], \n AXIS[\"Geodetic longitude\", EAST], \n AXIS[\"Geodetic latitude\", NORTH], \n AUTHORITY[\"EPSG\",\"4326\"]]",
"srs": "EPSG:4326",
"nativeBoundingBox": {
"minx": -74.0118315772888,
"maxx": -74.00153046439813,
"miny": 40.70754683896324,
"maxy": 40.719885123828675,
"crs": "EPSG:4326"
},
"latLonBoundingBox": {
"minx": -74.0118315772888,
"maxx": -74.00857344353275,
"miny": 40.70754683896324,
"maxy": 40.711945649065406,
"crs": "EPSG:4326"
},
"projectionPolicy": "REPROJECT_TO_DECLARED",
"enabled": true,
"metadata": {
"entry": [
{
"@key": "kml.regionateStrategy",
"$": "external-sorting"
},
{
"@key": "kml.regionateFeatureLimit",
"$": "15"
},
{
"@key": "cacheAgeMax",
"$": "3000"
},
{
"@key": "cachingEnabled",
"$": "true"
},
{
"@key": "kml.regionateAttribute",
"$": "NAME"
},
{
"@key": "indexingEnabled",
"$": "false"
},
{
"@key": "dirName",
"$": "DS_poi_poi"
}
]
},
"store": {
"@class": "dataStore",
"name": "tiger:nyc",
"href": "http://localhost:8080/geoserver/rest/workspaces/tiger/datastores/nyc.json"
},
"cqlFilter": "INCLUDE",
"maxFeatures": 100,
"numDecimals": 6,
"responseSRS": {
"string": [
4326
]
},
"overridingServiceSRS": true,
"skipNumberMatched": true,
"circularArcPresent": true,
"linearizationTolerance": 10,
"attributes": {
"attribute": [
{
"name": "the_geom",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "com.vividsolutions.jts.geom.Point"
},
{},
{},
{}
]
}
}因此,这是一个示例,我无法从服务器获得任何有用的响应。我得到的代码500带有body name (json中的第一项)。类似地,在尝试使用xml (第一个标记)时,我得到了与body FeatureTypeInfo相同的代码。
我已经在Docker中的geoserver新实例中尝试了请求(更改了端口),但仍然没有成功。
我检查数据存储、工作区是否可用,以及该层"poi“是否还不存在。
下面还有一些请求日志(类似于xml主体):
2018-08-03 07:35:02,198错误com.thoughtworks.xstream.mapper.CannotResolveClassException: geoserver.rest - com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:79) at .
有没有人知道解决这个问题的办法并让它发挥作用。我使用的是GeoServer 2.13.1
发布于 2018-08-07 07:42:09
所以我仍然在寻找答案,并且使用这个帖子(https://gis.stackexchange.com/questions/12970/create-a-layer-in-geoserver-using-rest)获得了正确的内容来发布featureType,从而在GeoServer中创建了一个层。
文档不在在REST文档中。
使用上面的链接,我发现在使用JSON时,JSON中缺少一个插入。为了使API在这里工作,我们需要添加:
{featureType:
name: "...",
nativeName: "...",
.
.
.}
这样它就不会以"name“属性开头,而是包含在"featureType”中。
我也没有为XML尝试过这种方法,但我想它可能是类似的。
希望这能帮到像我这样挣扎的人。
发布于 2018-12-19 12:30:35
Blaz在这里是正确的,您需要FeatureType的外部对象,然后是配置的内部对象。是这样的;
{
"featureType": {
"name": "layer",
"nativeName": "poi",
"your config": "stuff"
}不过,我发现,使用post请求,我得到的响应非常少,如果层创建成功的话,这一点也不明显。但是您可以调用http://IP:8080/geoserver/rest/layers.json来检查您的新层是否存在。
发布于 2021-12-31 08:36:01
使用REST创建FeatureTypes需要花费大量时间。像这样使用Json真的很管用:
{
"featureType": {
"name": "layer",
"nativeName": "poi"
"otherProperties...":"values..."
}并使用下面的Json创建工作区:
{
"workspace": {
"name": "test_workspace"
}
}REST现在过时了。真令人失望。有没有人知道如何获得最新的REST文档?
https://stackoverflow.com/questions/51671250
复制相似问题