地理信息数据格式.GeoJSON数据格式介绍
一、发展历史
GeoJSON 的发展历程反映了地理信息数据在 Web 时代的演进:
-
前身阶段 (2003-2007):
- 基于 XML 的 GML (Geography Markup Language) 是早期标准
- JSON 格式开始流行,但缺乏地理数据标准
-
诞生阶段 (2007-2008):
- 由一组开发者在 2007 年首次提出概念
- 2008 年正式发布初始规范 (RFC 7946 的前身)
-
标准化阶段 (2015-2016):
- 2015 年成为互联网工程任务组 (IETF) 的标准化项目
- 2016 年 8 月发布为 RFC 7946 标准
-
普及阶段 (2016 至今):
- 成为 Web 地图应用的事实标准
- 被 Leaflet、Mapbox、Google Maps 等主流地图库支持
二、数据格式字段详解
1. 根对象结构
json
复制
{"type": "FeatureCollection","bbox": [xmin, ymin, xmax, ymax],"features": [...]
}
type
(必填): 必须是 "FeatureCollection"bbox
(可选): 边界框,定义数据范围features
(必填): Feature 对象数组
2. Feature 对象
json
复制
{"type": "Feature","id": "feature-id","geometry": {...},"properties": {...},"bbox": [...]
}
type
(必填): 必须是 "Feature"id
(可选): 要素唯一标识符geometry
(必填): 几何对象properties
(可选): 属性键值对bbox
(可选): 该要素的边界框
3. Geometry 对象详解
点 (Point)
json
复制
{"type": "Point","coordinates": [x, y]
}
- 坐标顺序: [经度, 纬度]
- 高程可选: [经度, 纬度, 高程]
线 (LineString)
json
复制
{"type": "LineString","coordinates": [[x1,y1], [x2,y2], ...]
}
- 至少需要 2 个点
- 表示路径或边界
多边形 (Polygon)
json
复制
{"type": "Polygon","coordinates": [[[x1,y1], [x2,y2], ..., [x1,y1]], // 外环[[x1,y1], [x2,y2], ..., [x1,y1]] // 内环(孔洞)]
}
- 外环必须逆时针方向
- 内环(孔洞)必须顺时针方向
- 首尾坐标必须相同
多点 (MultiPoint)
json
{"type": "MultiPoint","coordinates": [[x1,y1], [x2,y2], ...]
}
多线 (MultiLineString)
json
{"type": "MultiLineString","coordinates": [[[x1,y1], [x2,y2], ...],[[x1,y1], [x2,y2], ...]]
}
多面 (MultiPolygon)
json
{"type": "MultiPolygon","coordinates": [[ /* 第一个多边形 */ ],[ /* 第二个多边形 */ ]]
}
几何集合 (GeometryCollection)
json
复制
{"type": "GeometryCollection","geometries": [{ /* 第一个几何体 */ },{ /* 第二个几何体 */ }]
}
三、应用示例详解
1. 城市地标数据
json
{"type": "FeatureCollection","features": [{"type": "Feature","properties": {"name": "东方明珠","city": "上海","height": 468},"geometry": {"type": "Point","coordinates": [121.4997, 31.2397]}},{"type": "Feature","properties": {"name": "故宫","city": "北京","built": 1420},"geometry": {"type": "Polygon","coordinates": [[[116.391, 39.916],[116.397, 39.916],[116.397, 39.924],[116.391, 39.924],[116.391, 39.916]]]}}]
}
2. 公交路线系统
json
{"type": "FeatureCollection","features": [{"type": "Feature","properties": {"name": "地铁1号线","type": "subway","color": "red"},"geometry": {"type": "MultiLineString","coordinates": [[[116.329, 39.997], [116.335, 39.991],[116.342, 39.984], [116.350, 39.977]],[[116.350, 39.977], [116.358, 39.970],[116.366, 39.963]]]}},{"type": "Feature","properties": {"name": "公交52路","type": "bus"},"geometry": {"type": "LineString","coordinates": [[116.404, 39.915], [116.408, 39.912],[116.412, 39.909], [116.416, 39.906]]}}]
}
3. 行政区划数据
json
{"type": "FeatureCollection","name": "中国省级行政区","features": [{"type": "Feature","properties": {"name": "北京市","code": "110000","capital": true},"geometry": {"type": "MultiPolygon","coordinates": [[/* 北京市主城区坐标 */],[/* 延庆区坐标 */]]}},{"type": "Feature","properties": {"name": "上海市","code": "310000"},"geometry": {"type": "Polygon","coordinates": [[/* 上海市边界坐标 */]]}}]
}
四、高级特性
1. 坐标系定义
GeoJSON 标准规定使用 WGS84 坐标系 (EPSG:4326),但可通过扩展支持其他坐标系:
json
{"type": "FeatureCollection","crs": {"type": "name","properties": {"name": "urn:ogc:def:crs:EPSG::3857"}},"features": [...]
}
2. 时态数据扩展
可通过 properties 添加时间信息:
json
{"type": "Feature","properties": {"name": "台风路径","time": "2023-08-01T12:00:00Z"},"geometry": {...}
}
3. 3D 几何体
支持包含高程数据的坐标:
json
{"type": "Point","coordinates": [116.404, 39.915, 43.5]
}
五、实际工作中的应用场景
-
Web 地图开发:
- 与 Leaflet/Mapbox/OpenLayers 等地图库交互
- 动态加载地理数据
-
数据交换:
- 不同GIS系统间的数据交换格式
- 开放数据平台的标准发布格式
-
空间分析:
- 存储分析结果(如缓冲区、相交区域)
- 可视化分析结果
-
物联网应用:
- 设备位置追踪
- 地理围栏数据定义
-
移动应用:
- 离线地图数据包
- 导航路径数据
六、验证与调试工具
-
在线验证器:
- geojson.io
- geojsonlint.com
-
命令行工具:
bash
npm install -g geojson-validation geojson-validate file.geojson
-
Python 库:
python
from geojson import validate validate(geojson_object)
通过以上详细说明,你应该对 GeoJSON 有了全面的了解。在实际应用中,建议从简单的点数据开始,逐步尝试更复杂的几何类型。