GeoJSON - 存储各种地理数据结构的标准格式

336 阅读1分钟

GeoJSON 是一种基于 JSON 的用于存储地理信息的数据格式。其可以表示几何特征或者特征集合,支持点、线、面、多点、多线、多面以及几何集合

GeoJSON 里的特征包含一个 几何对象扩展对象,特征集合表示一系列特征

GeoJson.png

特征对象

  • 表示 Point 单个点
    {
      "type": "Feature", 
      "properties": {},
      "geometry": {
        "type": "Point", "coordinates": [125.6, 10.1],
      }
    }
    
  • 表示 LineString 单条线
    {
      "type": "Feature", 
      "properties": {},
      "geometry": {
        "type": "LineString", "coordinates": [
          [30, 10], [10, 30], [40, 40]
        ],
      }
    }
    
  • 表示 Polygon 单个面
    {
      "type": "Feature", 
      "properties": {},
      "geometry": {
        "type": "Polygon", "coordinates": [
          [
            [-67.13734, 45.13745], [-66.96466, 44.8097],
            [-68.03252, 44.3252], [-69.06, 43.98],
            [-70.11617, 43.68405], [-70.64573, 43.09008],
            [-70.75102, 43.08003], [-70.79761, 43.21973],
            [-70.98176, 43.36789], [-70.94416, 43.46633],
            [-71.08482, 45.30524], [-70.66002, 45.46022],
            [-70.30495, 45.91479], [-70.00014, 46.69317],
            [-69.23708, 47.44777], [-68.90478, 47.18479],
            [-68.2343, 47.35462], [-67.79035, 47.06624],
            [-67.79141, 45.70258], [-67.13734, 45.13745]
          ]
        ],
      }
    }
    
  • 表示 MultiPoint 多个点
    {
      "type": "Feature", 
      "properties": {},
      "geometry": {
        "type": "MultiPoint", "coordinates": [
          [-121.415061, 40.506229],
          [-121.354465, 40.488737]
        ],
      }
    }
    
  • 表示 MultiLineString 多条线
    {
      "type": "Feature", 
      "properties": {},
      "geometry": {
        "type": "MultiLineString", "coordinates": [
          [[10, 10], [20, 20], [10, 40]], 
          [[40, 40], [30, 30], [40, 20], [30, 10]] 
        ],
      }
    }
    
  • 表示 MultiPolygon 多个面
    {
      "type": "Feature", 
      "properties": {},
      "geometry": {
        "type": "MultiPolygon", "coordinates": [
          [
            [-67.13734, 45.13745], [-66.96466, 44.8097],
            [-68.03252, 44.3252], [-69.06, 43.98],
            [-70.11617, 43.68405], [-70.64573, 43.09008],
            [-70.75102, 43.08003], [-70.79761, 43.21973],
          ],
          [
            [-70.30495, 45.91479], [-70.00014, 46.69317],
            [-69.23708, 47.44777], [-68.90478, 47.18479],
            [-68.2343, 47.35462], [-67.79035, 47.06624],
            [-67.79141, 45.70258], [-67.13734, 45.13745]
          ]
        ],
      }
    }
    
    通过 properties 扩展对象可以设置自定义数据,便于业务处理

特征集合

  • 集合描述

    示例:表示包含一个面和两个点的特征集合

  • 数据结构

    {
      "type": "FeatureCollection", 
      "properties": {},
      "features": [
        {
          "type": "Feature",
          "geometry": {
            "type": "Polygon", "coordinates": [
              [
                [-121.353637, 40.584978], [-121.284551, 40.584758],
                [-121.275349, 40.541646], [-121.246768, 40.541017],
                [-121.251343, 40.423383], [-121.32687, 40.423768],
                [-121.360619, 40.43479],  [-121.363694, 40.409124],
                [-121.439713, 40.409197],  [-121.439711, 40.423791],
                [-121.572133, 40.423548],  [-121.577415, 40.550766],
                [-121.539486, 40.558107], [-121.520284, 40.572459],
                [-121.487219, 40.550822], [-121.446951, 40.56319],
                [-121.370644, 40.563267],  [-121.353637, 40.584978]
               ]
             ]
          }
        },
        {
          "type": "Feature", "properties": {},
          "geometry": {
            "type": "Point", "coordinates": [-121.415061, 40.506229]
          }
        },
        {
          "type": "Feature", "properties": {},
          "geometry": {
            "type": "Point", "coordinates": [-121.505184, 40.488084]
          }
        }
      ]
    }
    

数据生成工具