【问题标题】:Can not create new layer (featuretype) in GeoServer using REST API无法使用 REST API 在 GeoServer 中创建新图层(要素类型)
【发布时间】:2018-08-03 11:06:42
【问题描述】:

所以我只用了 2 个工作日来解决这个问题。我们是地图的自动渲染过程。所有数据都在 SQL 库中给出,我的工作是编写“包装器”,以便我们可以在内部框架中实现它。除了一个需要的请求外,我管理了所有请求。 该请求是 POST 特征类型,因为这是一种创建稍后可以渲染的层的方式。

我已将所有请求保存在邮递员中,用于对 geoserver 本身提供的示例数据进行预测试。我什至无法得到状态码 201 的响应,并且总是收到 500 内部服务器错误。此状态在 sytax 中被描述为可能的语法错误。但实际上我只是复制并粘贴了示例并使用了 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"
      },
      {},
      {},
      {}
    ]
  }
}

所以这是示例案例,我无法从服务器获得任何有用的响应。我得到带有正文 name 的代码 500(json 中的第一项)。同样,在尝试使用 xml 正文(第一个标签)时,我得到与正文 FeatureTypeInfo 相同的代码。

我已经在 Docker 的新地理服务器实例中尝试了请求(更改了端口),但仍然没有成功。

我检查数据存储区、工作区是否可用,并且该层“poi”尚不存在。

这里还有一些请求日志(xml body类似):

2018-08-03 07:35:02,198 错误 [geoserver.rest] - com.thoughtworks.xstream.mapper.CannotResolveClassException:名称在 com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:79) 在.....

有谁知道这个问题的解决方案并让它工作。我正在使用 GeoServer 2.13.1

【问题讨论】:

    标签: rest request geoserver


    【解决方案1】:

    所以我仍在寻找答案并使用这篇文章 (https://gis.stackexchange.com/questions/12970/create-a-layer-in-geoserver-using-rest) 找到正确的内容来发布 featureType 并因此在 GeoServer 中创建一个层。

    文档已关闭in REST API docs

    使用上面的链接,我发现在使用 JSON 时,JSON 中缺少插入。为了让 API 在这里工作,我们需要添加:

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

    所以它不以“name”属性开头,而是包含在“featureType”中。

    我也没有为 XML 尝试过,但我想它可能是相似的。

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

    【讨论】:

      【解决方案2】:

      Blaz 在这里是正确的,您需要一个 FeatureType 的外部对象,然后是一个带有配置的内部对象。所以;

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

      我发现,虽然使用发布请求,我得到的响应很少,而且如果图层创建有效,这并不明显。但是您可以致电http://IP:8080/geoserver/rest/layers.json 来检查您的新图层是否存在。

      【讨论】:

        【解决方案3】:

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

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

        并使用下面的 Json 创建 Workspace:

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

        REST API 现在已经过时了。这很令人失望。有谁知道如何获取最新的 REST API 文档?

        【讨论】:

          猜你喜欢
          • 2023-03-05
          • 1970-01-01
          • 2023-04-02
          • 2019-03-23
          • 2015-09-08
          • 1970-01-01
          • 2019-06-03
          • 2015-08-28
          • 1970-01-01
          相关资源
          最近更新 更多