GeoJSON 数据简介

前言

❝

GeoJSON是一种用于编码各种地理数据结构的格式,采用JSON方式表示。在WebGIS开发中,被广泛应用于数据传输和共享交换。

1. GeoJSON数据格式

GeoJSON对象类型多样,具有Geometry类型:Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon以及GeometryCollection,要素类型Feature和要素集类型FeatureCollection共九大类 。几何对象(Geometry)加上属性信息(Properties)构成要素(Feature),要素集(Features)组成要素集合(FeatureCollection),其逻辑关系如下图。

图1几何对象组成结构图 图2几何对象包含结构图

2. GeoJSON对象结构特点

GeoJSON对象表示几何对象(Geometry)、要素对象(Feature)、以及要素类对象(Features)的集合(FeatureCollection),具有如下特征。

  • 每一个GeoJSON对象都是JSON对象
  • 每一个GeoJSON对象都具有一个type属性,其值必须是GeoJSON类型,以上九大类型之一。
  • GeoJSON对象还可能具有"bbox"属性,其值必须是边界范围数组。
  • GeoJSON对象还可能具有其他属性,如用户自定义属性。

3. GeoJSON几何对象

3.1. GeoJSON-Point

Point属性coordinates是一个数组,在投影坐标系中按[x,y]顺序显示,在地理坐标系中按经度和纬度[longitude,latitude]显示。

json 复制代码
{
   "type": "Point",
   "coordinates": [100.0, 0.0]
}

3.2. GeoJSON-LineString

LineString属性coordinates是一个数组,元素为Point数组坐标对。

csharp 复制代码
{
   "type": "LineString",
   "coordinates": [
       [100.0, 0.0],
       [101.0, 1.0]
   ]
}

3.3. GeoJSON-Polygon

Polygon属性coordinates是一个数组,元素为LineString线性环数组。数组的第一个元素表示外环,任何后续元素表示内环。无孔洞

csharp 复制代码
{
   "type": "Polygon",
   "coordinates": [
       [
           [100.0, 0.0],
           [101.0, 0.0],
           [101.0, 1.0],
           [100.0, 1.0],
           [100.0, 0.0]
       ]
   ]
}

有孔洞

csharp 复制代码
{
   "type": "Polygon",
   "coordinates": [
       // 外环
       [
           [100.0, 0.0],
           [101.0, 0.0],
           [101.0, 1.0],
           [100.0, 1.0],
           [100.0, 0.0]
       ],
       // 内环
       [
           [100.8, 0.8],
           [100.8, 0.2],
           [100.2, 0.2],
           [100.2, 0.8],
           [100.8, 0.8]
       ]
   ]
}

3.4. GeoJSON-MultiPoint

MultiPoint属性coordinates是一个LineString数组,元素为Point数组。

csharp 复制代码
{
   "type": "MultiPoint",
   "coordinates": [
       [100.0, 0.0],
       [101.0, 1.0]
   ]
}

3.5. GeoJSON-MultiLineString

MultiLineString属性coordinates是一个数组,元素为LineString数组。

csharp 复制代码
{
   "type": "MultiLineString",
   "coordinates": [
       [
           [100.0, 0.0],
           [101.0, 1.0]
       ],
       [
           [102.0, 2.0],
           [103.0, 3.0]
       ]
   ]
}

3.6. GeoJSON-MultiPolygon

MultiPolygon属性coordinates是一个数组,元素为Polygon数组。

csharp 复制代码
{
   "type": "MultiPolygon",
   "coordinates": [
       [
           [
               [102.0, 2.0],
               [103.0, 2.0],
               [103.0, 3.0],
               [102.0, 3.0],
               [102.0, 2.0]
           ]
       ],
       [
           [
               [100.0, 0.0],
               [101.0, 0.0],
               [101.0, 1.0],
               [100.0, 1.0],
               [100.0, 0.0]
           ],
           [
               [100.2, 0.2],
               [100.2, 0.8],
               [100.8, 0.8],
               [100.8, 0.2],
               [100.2, 0.2]
           ]
       ]
   ]
}

3.7. GeoJSON-GeometryCollection

GeometryCollection属性geometries是一个数组,元素为geometry对象。

csharp 复制代码
{
  "type": "GeometryCollection",
  "geometries": [
    {
      "type": "Point",
      "coordinates": [100.0, 0.0]
    }, 
    {
      "type": "LineString",
      "coordinates": [
        [101.0, 0.0],
        [102.0, 1.0]
      ]
    }
  ]
}

4. GeoJSON要素对象

要素Feature对象type属性为"Feature",由几何对象和属性信息构成。

json 复制代码
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

5. GeoJSON要素集对象

要素FeatureCollection对象type属性为"FeatureCollection",由features数组构成。元素是Feature对象。

csharp 复制代码
{
   "type": "FeatureCollection",
   "features": [{
       "type": "Feature",
       "geometry": {
           "type": "Point",
           "coordinates": [102.0, 0.5]
       },
       "properties": {
           "prop0": "value0"
       }
   }, {
       "type": "Feature",
       "geometry": {
           "type": "LineString",
           "coordinates": [
               [102.0, 0.0],
               [103.0, 1.0],
               [104.0, 0.0],
               [105.0, 1.0]
           ]
       },
       "properties": {
           "prop0": "value0",
           "prop1": 0.0
       }
   }, {
       "type": "Feature",
       "geometry": {
           "type": "Polygon",
           "coordinates": [
               [
                   [100.0, 0.0],
                   [101.0, 0.0],
                   [101.0, 1.0],
                   [100.0, 1.0],
                   [100.0, 0.0]
               ]
           ]
       },
       "properties": {
           "prop0": "value0",
           "prop1": {
               "this": "that"
           }
       }
   }]
}

6. 注意

  • GeoJSON坐标对是经度在前,纬度在后,即[longitude,latitude]
  • GeoJSON遵循右手规则,即外环为逆时针,内环为顺时针。
  • GeoJSON数据都有一个type属性,Geometry对象为对应Geometry类型值,Feature对象为"Feature",FeatureCollection对象为"FeatureCollection"
  • GeoJSON数据可能会有额外属性"bbox"或者用户自定义属性,"bbox"值为:["west", "south", "east", "north"],即[xmin,ymin,xmax,ymax]

❝

OpenLayers示例数据下载,请回复关键字:ol数据

全国信息化工程师-GIS 应用水平考试资料,请回复关键字:GIS考试
❝

【GIS之路】 已经接入了智能助手,欢迎关注,欢迎提问。

欢迎访问我的博客网站-长谈GIS :http://shanhaitalk.com

都看到这了,不要忘记点赞、收藏 + 关注 哦 !

本号不定时更新有关 GIS开发 相关内容,欢迎关注 !

相关推荐
程序员韩星11 分钟前
OpenAI 兼容接口返回 404,先查请求地址,再查模型名
前端·人工智能·http
Patrick_Wilson12 分钟前
构建通过了,为什么有些浏览器还会白屏?
前端·javascript·浏览器
其实防守也摸鱼1 小时前
用 Claude Code 重构遗留系统:从评估到落地的完整指南
前端·网络·人工智能·chrome·安全·重构
七仔啊1 小时前
CNC计算机数控加工模拟器
前端
张一凡932 小时前
你的 AGENTS.md,真的管到模型写代码了吗?
前端·后端·agent
Brookty2 小时前
CSS基础知识(一):选择器、优先级、层叠与继承、边框属性及盒模型
前端·css
颜进强2 小时前
微信小微AI-灰度与命中排查|代码全对、版本已发,为什么同事就是问不中?
前端·ai编程·全栈
verohh2 小时前
从代码组织到功能抽象:AI 时代的前端工程架构设计
前端
颜进强2 小时前
微信小微AI-评测|文档质量直接被判 0 分:小微团队评测那些没人告诉你的硬指标
前端·ai编程·全栈
Bacon2 小时前
给项目做一次"全身 CT":Agent Skills 生态里的代码体检全链路
前端·人工智能·后端