0

有人可以解释如何使用 APIC 工具包创建 API 吗?

我想使用此 API 与 IBM Bluemix 上的 Cloudant DB 或本地 CouchDB 一起使用,以创建、读取和更新 geoJSON 数据。

下面是存储兴趣点名称和坐标的典型数据的简单示例。

[{
    "type": "Feature",
    "properties": {
        "name": "Nice Place 1"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [16.45961, 48.23896]
    } 
}, {
    "type": "Feature",
    "properties": {
        "name": "Nice Place 2"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [16.34561, 49.89612]
    }
}]
4

2 回答 2

1

LoopBack 支持 GeoPoint(即 GeoJSON 中的点)数据类型。考虑到您的典型示例,假设您有一个名为:Feature 的模型,然后要使用 GeoPoint,您Feature.json应该如下所示:

{
  "name": "Feature",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string"
    },
    "geometry": {
      "type": "geopoint"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

现在,这个以 PersistedModel 为基础的 Feature 模型将具有公开为 REST 端点的通用 CRUD 方法,并且您可以存储数据,例如,使用 CURL:

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
  \"name\": \"Nice Place 1\",
  \"geometry\": {
    \"lat\": 16.20,
    \"lng\": 48.23
  }
}" "http://0.0.0.0:3000/api/Features"

希望有助于创建支持 GeoPoint 的 API。

回复:Cloudant db,我不确定它是否支持开箱即用的地理空间数据,但似乎支持它:https ://cloudant.com/product/cloudant-features/geospatial/

于 2016-10-11T14:01:19.827 回答
1

我尝试使用环回应用程序(使用 cloudant 作为 ds)上面的模型,它是资源管理器:

使用示例数据创建:

{ "name": "string", "geometry": { "lat": 12, "lng": 13 } }

并从 GET/myGeoModels 成功获取:

[ { "name": "string", "geometry": { "lat": 12, "lng": 13 }, "id": "f08301abe833ad427c9c61ffd30df8ef" } ]

APIC 应该具有相同的环回行为。

于 2016-10-11T14:21:34.560 回答