schema.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. .. _spatialjson_schema:
  2. Opt. 1: Removing Redundant Schema Information
  3. =============================================
  4. In traditional GeoJSON, every feature in a (simple feature) feature collection has its own schema
  5. information. That is, every feature contains all its (not necessarily short) attribute names. Except
  6. the geometry name, these names are used as the keys in the ``"properties"`` map:
  7. .. code:: json
  8. {
  9. "type": "FeatureCollection",
  10. "features": [
  11. {
  12. "type": "Feature",
  13. "id": "areas.1",
  14. "geometry": {
  15. "type": "Point",
  16. "coordinates": [590529, 4914625]
  17. },
  18. "geometry_name": "the_geom",
  19. "properties": {
  20. "area_no": 12,
  21. "area_name": "Mainland",
  22. "area_description": "grassland",
  23. "area_cost_center": "0815"
  24. }
  25. },
  26. {
  27. "type": "Feature",
  28. "id": "areas.2",
  29. "geometry": {
  30. "type": "Point",
  31. "coordinates": [590215, 4913987]
  32. },
  33. "geometry_name": "the_geom",
  34. "properties": {
  35. "area_no": 17,
  36. "area_name": "South region",
  37. "area_description" : "meadow, pasture",
  38. "area_cost_center": "0812"
  39. }
  40. }
  41. ],
  42. "totalFeatures": 2,
  43. "numberMatched": 2,
  44. "numberReturned": 2,
  45. "timeStamp": "2022-10-17T08:12:45.248Z",
  46. "crs": {
  47. "type": "name",
  48. "properties": {
  49. "name": "urn:ogc:def:crs:EPSG::26713"
  50. }
  51. }
  52. }
  53. Since all features have the same schema information, SpatialJSON does not write attribute names for
  54. every feature. Instead, a single ``"schemaInformation"`` property is added to the end of the
  55. top-level ``"FeatureCollection"`` object:
  56. .. code:: json
  57. {
  58. "type": "FeatureCollection",
  59. "features": [
  60. {
  61. "type": "Feature",
  62. "id": "areas.1",
  63. "geometry": {
  64. "type": "Point",
  65. "coordinates": [590529, 4914625]
  66. },
  67. "properties": [12, "Mainland", "grassland", "0815"]
  68. },
  69. {
  70. "type": "Feature",
  71. "id": "areas.2",
  72. "geometry": {
  73. "type": "Point",
  74. "coordinates": [590215, 4913987]
  75. },
  76. "properties": [17, "South region", "meadow, pasture", "0812"]
  77. }
  78. ],
  79. "totalFeatures": 2,
  80. "numberMatched": 2,
  81. "numberReturned": 2,
  82. "timeStamp": "2022-10-17T08:14:36.521Z",
  83. "crs": {
  84. "type": "name",
  85. "properties": {
  86. "name": "urn:ogc:def:crs:EPSG::26713"
  87. }
  88. },
  89. "schemaInformation": {
  90. "propertyNames": ["area_no", "area_name", "area_description", "area_cost_center"],
  91. "geometryName": "the_geom"
  92. }
  93. }
  94. With SpatialJSON, each feature’s ``"properties"`` map becomes an *ordered list* (array) whose index
  95. corresponds to the ``"propertyNames"`` array that holds the attribute names in the new
  96. ``"schemaInformation"`` object. Additionally, the repeated property ``"geometry_name"`` is replaced
  97. by a single property named ``"geometryName"`` in the new schema information object.
  98. Evaluation
  99. ----------
  100. In the above example, without whitespaces and line breaks, savings in space are only about 5%. With
  101. much more features savings could reach almost 27% (the ratio of the sizes of a GeoJSON and a
  102. SpatialJSON feature object), that is, the size of the SpatialJSON response is only 73% of the size
  103. of a traditional GeoJSON response. More savings are possible with more attributes per feature.
  104. Savings basically depend on the ratio between schema information size and data size. In tests
  105. requesting several thousands of simple features with 200+ columns/attributes savings up to 70% have
  106. been achieved.
  107. These savings drop to between ~50% and ~3% when a compressing content encoding method (like gzip,
  108. deflate or brotli) is used on the wire. However, it’s not all about transfer size. The smaller the
  109. uncompressed JSON response, the lesser characters the client has to parse. Smaller uncompressed
  110. responses are also much more memory-friendly on both the server and the client side.