GeoJSON 介绍
文章目录
- GeoJSON 介绍
- 1. GeoJSON 基本概念
- 2. GeoJSON 格式结构
- 3. 支持的几何类型
- Point 点
- LineString 线
- Polygon 多边形
- MultiPoint 多点
- MultiLineString 多线
- MultiPolygon 多面
- GeometryCollection 几何集合
- 4. 使用场景
- 5. 库支持
GeoJSON 介绍
-
GeoJSON 官网:https://geojson.org/
提供 GeoJSON 的规范说明、RFC 7946 标准文档及相关资源79。 -
GeoJSON 在线编辑器:http://geojson.io/
可在线编辑、预览 GeoJSON 数据。
1. GeoJSON 基本概念
GeoJSON 是一种用于对各种地理数据结构进行编码的格式。
GeoJSON 支持以下几何类型:
- 点 (Point)
- 线 (LineString)
- 面 (Polygon)
- 多点 (MultiPoint)
- 多线 (MultiLineString)
- 多面 (MultiPolygon)
- 几何集合 (GeometryCollection)
具有附加属性的几何对象是 Feature 对象。要素集包含在对象中 FeatureCollection 。
GeoJSON 默认使用 WGS84 坐标系(经度, 纬度)
2. GeoJSON 格式结构
一个基本的 GeoJSON 对象结构如下:
{"type": "FeatureCollection","features": [{"type": "Feature","geometry": {"type": "Point","coordinates": [102.0, 0.5]},"properties": {"name": "Example Point"}}]
}
主要组成部分:
type
- 标识 GeoJSON 对象的类型- 可以是 “FeatureCollection”, “Feature”, 或几何类型之一
features
(仅 FeatureCollection 有) - 包含一组 Feature 对象geometry
(仅 Feature 有) - 包含几何对象及其坐标properties
(仅 Feature 有) - 包含与几何相关的属性数据
3. 支持的几何类型
Point 点
{"type": "Feature","geometry": {"type": "Point","coordinates": [118.08804372425419, 24.48401512708469]},"properties": {"name": "Example Point"}
}
LineString 线
{"type": "Feature","geometry": {"type": "LineString","coordinates": [[118.08804372425419, 24.48401512708469],[121.44534340242714, 24.108833181868842]]},"properties": {"name": "Example LineString"}
}
Polygon 多边形
{"type": "Feature","geometry": {"type": "Polygon","coordinates": [[[115.56769883631596, 26.796759291820862],[120.24743143329276, 27.994531040608],[119.96279402305146, 20.845962507158415],[110.42921794452593, 21.9891800116634]]]},"properties": {"name": "Example Polygon"}
}
MultiPoint 多点
{"type": "Feature","geometry": {"type": "MultiPoint","coordinates": [[115.56769883631596, 26.796759291820862],[120.24743143329276, 27.994531040608],[119.96279402305146, 20.845962507158415],[110.42921794452593, 21.9891800116634]]},"properties": {"name": "Example MultiPoint"}
}
MultiLineString 多线
{"type": "Feature","geometry": {"type": "MultiLineString","coordinates": [[[115.56769883631596, 26.796759291820862],[120.24743143329276, 27.994531040608]],[[119.96279402305146, 20.845962507158415],[110.42921794452593, 21.9891800116634]]]},"properties": {"name": "Example MultiLineString"}
}
MultiPolygon 多面
{"type": "Feature","geometry": {"type": "MultiPolygon","coordinates": [[[[115.56769883631596, 26.796759291820862],[120.24743143329276, 27.994531040608],[119.96279402305146, 20.845962507158415],[110.42921794452593, 21.9891800116634]]],[[[119.96279402305146, 20.845962507158415],[110.42921794452593, 21.9891800116634],[111.1013749119565, 18.845558689105033],[121.21864864334037, 18.696822467873176]]]]},"properties": {"name": "Example MultiPolygon"}
}
GeometryCollection 几何集合
{"type": "FeatureCollection","features": [{"type": "Feature","geometry": {"type": "Point","coordinates": [102.0, 0.5]},"properties": {"name": "Example Point"}},{"type": "Feature","geometry": {"type": "LineString","coordinates": [[118.08804372425419, 24.48401512708469],[121.44534340242714, 24.108833181868842]]},"properties": {"name": "Example LineString"}}]
}
4. 使用场景
- Web 地图应用(Cesium, Mapbox GL JS 等)
- 地理空间数据交换
- 服务器与客户端之间的地理数据传输
- 地理空间数据库导出/导入
5. 库支持
- JavaScript:Turf.js