选择。1:删除冗余架构信息

在传统的GeoJSON中,(简单要素)要素集合中的每个要素都有自己的方案信息。也就是说,每个要素都包含其所有(不一定简短)的属性名称。除几何图形名称外,这些名称用作 "properties" 地图:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "id": "areas.1",
      "geometry": {
        "type": "Point",
        "coordinates": [590529, 4914625]
      },
      "geometry_name": "the_geom",
      "properties": {
        "area_no": 12,
        "area_name": "Mainland",
        "area_description": "grassland",
        "area_cost_center": "0815"
      }
    },
    {
      "type": "Feature",
      "id": "areas.2",
      "geometry": {
        "type": "Point",
        "coordinates": [590215, 4913987]
      },
      "geometry_name": "the_geom",
      "properties": {
        "area_no": 17,
        "area_name": "South region",
        "area_description" : "meadow, pasture",
        "area_cost_center": "0812"
      }
    }
  ],
  "totalFeatures": 2,
  "numberMatched": 2,
  "numberReturned": 2,
  "timeStamp": "2022-10-17T08:12:45.248Z",
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:EPSG::26713"
    }
  }
}

由于所有要素都具有相同的模式信息,因此SpatialJSON不会为每个要素编写属性名称。相反,一首单曲 "schemaInformation" 属性添加到顶级 "FeatureCollection" 对象:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "id": "areas.1",
      "geometry": {
        "type": "Point",
        "coordinates": [590529, 4914625]
      },
      "properties": [12, "Mainland", "grassland", "0815"]
    },
    {
      "type": "Feature",
      "id": "areas.2",
      "geometry": {
        "type": "Point",
        "coordinates": [590215, 4913987]
      },
      "properties": [17, "South region", "meadow, pasture", "0812"]
    }
  ],
  "totalFeatures": 2,
  "numberMatched": 2,
  "numberReturned": 2,
  "timeStamp": "2022-10-17T08:14:36.521Z",
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:EPSG::26713"
    }
  },
  "schemaInformation": {
    "propertyNames": ["area_no", "area_name", "area_description", "area_cost_center"],
    "geometryName": "the_geom"
  }
}

使用SpatialJSON,每个功能的 "properties" 地图成为一种 ordered list (数组),其索引与 "propertyNames" 数组,该数组保存新 "schemaInformation" 对象。此外,重复属性 "geometry_name" 替换为一个名为 "geometryName" 在新的模式信息对象中。

评估

在上面的例子中,没有空格和换行符,节省的空间只有5%左右。有了更多的功能,节省的空间几乎可以达到27%(GeoJSON和SpatialJSON Feature对象的大小之比),也就是说,SpatialJSON响应的大小只有传统GeoJSON响应的73%。每个功能的属性越多,节省的成本就越大。节省基本上取决于模式信息大小和数据大小之间的比率。在请求具有200多个列/属性的数千个简单功能的测试中,实现了高达70%的节省。

当在线路上使用压缩内容编码方法(如GZIP、DEFATE或BROTLI)时,这些节省下降到~50%到~3%之间。然而,这并不全是转账大小的问题。未压缩的JSON响应越小,客户端需要解析的字符就越少。在服务器端和客户端,较小的未压缩响应对内存也更加友好。