使用REST API在GeoServer中无法创建新的图层(要素类型)

4
所以我花了两个工作日来解决这个问题。我们是地图的自动渲染过程。所有数据都是基于SQL的,我的任务是编写“包装器”,以便我们可以在内部框架中实现这一点。我已经完成了除一个必要请求之外的所有请求。这个请求是 POST featuretype ,因为这是创建一个稍后可以呈现的图层的方法。
我在postman中保存了所有请求,用geoserver提供的示例数据进行预测试。我甚至无法获得状态码201的响应,总是得到500个内部服务器错误。这个状态被描述为可能是语法错误。但实际上,我只是复制和粘贴了示例,并使用了geoserver提供的数据。
这是请求: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"
      },
      {},
      {},
      {}
    ]
  }
}

所以这是一个例子,我无法从服务器中获取任何有用的响应。当使用json body时,我得到带有name的500代码(json中的第一项)。同样,当使用xml body时,我会得到带有FeatureTypeInfo的相同代码(第一个标签)。
我已经在Docker的geoserver新实例中尝试了该请求(更改了端口),但仍然没有成功。
我检查了数据存储、工作空间是否可用,并且那个"poi"图层还不存在。
以下是一些请求的日志(xml body类似):

2018-08-03 07:35:02,198 ERROR [geoserver.rest] - com.thoughtworks.xstream.mapper.CannotResolveClassException: name at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:79) at .....

有谁知道解决方法并让它工作?我正在使用GeoServer 2.13.1。
3个回答

2
所以我一直在寻找答案,并使用此帖子 (https://gis.stackexchange.com/questions/12970/create-a-layer-in-geoserver-using-rest) 找到了正确的内容来POST featureType,从而在GeoServer中创建图层。
文档在REST API文档中有误 使用上面的链接,我发现当使用JSON时,JSON中缺少插入。为了使API在这里起作用,我们需要添加:

{featureType:
  name: "...",
  nativeName: "...",
  .
  .
  .}

为了让它不以"name"属性开始,而是包含在"featureType"中。

我没有尝试过XML,但我猜它可能是类似的。

希望这能帮助像我一样挣扎的人。


1

使用 REST API 创建 FeatureTypes 花费了我很多时间。像这样使用 Json 真的很有效:

{
"featureType": {
    "name": "layer",
    "nativeName": "poi"
    "otherProperties...":"values..."
}

以下是使用 Json 创建 Workspace 的步骤:

{
    "workspace": {
        "name": "test_workspace"
    }
}

现在的REST API已经过时了,这让人感到失望。有没有人知道如何获取最新的REST API文档?


1

Blaz是正确的,你需要一个FeatureType的外部对象,然后是一个包含你的配置的内部对象。因此;

{
"featureType": {
    "name": "layer",
    "nativeName": "poi",
    "your config": "stuff"
}

我发现使用POST请求几乎没有响应,而且不明显是否图层创建成功。但是您可以调用http://IP:8080/geoserver/rest/layers.json来检查您的新图层是否存在。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接