马上搞懂 GeoJSON

用于描述地理空间信息的数据格式,语法是基于 JSON 格式的。

每一个 GeoJSON 对象都有一个 type 属性:

  • Point:点
  • MultiPoint:多点
  • LineString:线
  • MultiLineString:多线
  • Polygon:面
  • MultiPolygon:多面
  • GeometryCollection:几何体集合
  • Feature:特征
  • FeatureCollection:特征集合

分类

  • type:Point、MultiPoint、LineString、MultiLineString、Polygon、MultiPolygon

    则该对象必须有属性 coordinates,这类对象称为几何对象。

    // 点对象
    {
      'type': 'Point',
      'coordinates': [-105, 39]
    }
    // 线对象
    {
      'type': 'LineString',
      'coordinates': [[-105, 39], [-107, 38]]
    }
    // 面对象
    {
      'type': 'Polygon',
      'coordinates': [
        [[30, 0], [31, 0], [31, 5], [30, 5], [30, 0]]
      ]
    }
  • type:GeometryCollection

    则该对象必须有属性 geometries,其值是一个数组,每一项都是一个 GeoJSON 的几何对象。

    {
      'type': 'GeometryCollection',
      'geometries': [
        {
          'type': 'Point',
          'coordinates': [100, 40]
        },
        {
          'type': 'LineString',
          'coordinates': [[100, 30], [100, 35]]
        }
      ]
    }
  • type:Feature

    则该对象必须有属性 geometry,其值为一个几何对象;此外还有一个属性 properties,可以是任意 JSON 或 null

    {
      'type': 'Feature',
      'properties': {
        'name': '北京'
      },
      'geometry': {
        'type': 'Point',
        'coordinates': [116.3671875, 39.977120098439634]
      }
    }
  • type:FeatureCollection

    则该对象必须有属性 features,其值为一个数组,每一项都是一个 Feature 对象。

    {
      'type': 'FeatureCollection',
      'features': [
        {
          'type': ...,
          'properties': ...,
          'geometry': ...
        },
        ...
      ]
    }

参考

  • 《精通D3.js:交互式数据可视化高级编程》
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值