我正在构建一个具有属性boundary
的JSON模式。我指的是可以正常工作的GeoJson模式。现在,我想将边界限制为Polygon
类型,这是GeoJson模式中的enum
。
该怎么做?
这是我的架构的相关部分:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"plot": {
"type": "object",
"properties": {
"boundary": {
"description": "The boundary of the plot",
"title": "Plot boundary",
"additionalProperties": false,
"required": [
"type",
"coordinates",
"crs"
],
"TODO": "Restrict to (multi)polygons only.",
"$ref": "http://json.schemastore.org/geojson"
}
}
}
}
}
这是我的验证json:
{
"plot":
{
"boundary": {
"crs": {
"type": "name",
"properties": {
"name": "EPSG:3857"
}
},
"coordinates": [],
"type": "MultiPolygon"
}
}
}
答案 0 :(得分:0)
似乎我使用了错误的geojson。 我更改了代码,现在它可以按预期运行,并且新架构也为草案7。 这是我更新的代码:
"boundary": {
"title": "The boundary of the plot",
"anyOf": [
{
"$ref": "http://geojson.org/schema/MultiPolygon.json"
},
{
"$ref": "http://geojson.org/schema/Polygon.json"
}
],
"additionalProperties": false
和
"geoLocation": {
"title": "Front door geolocation",
"$ref": "http://geojson.org/schema/Point.json",
"additionalProperties": false
},
JSON可以是:
"boundary":
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],
[100.0, 0.0]
]
]
}
和
"geoLocation": {
"coordinates": [125.25, 135.255],
"type": "Point"
}