GeoJSON 的发展历程反映了地理信息数据在 Web 时代的演进:
前身阶段 (2003-2007):
诞生阶段 (2007-2008):
标准化阶段 (2015-2016):
普及阶段 (2016 至今):
json
复制
{
"type": "FeatureCollection",
"bbox": [xmin, ymin, xmax, ymax],
"features": [...]
}
type
(必填): 必须是 "FeatureCollection"bbox
(可选): 边界框,定义数据范围features
(必填): Feature 对象数组json
复制
{
"type": "Feature",
"id": "feature-id",
"geometry": {...},
"properties": {...},
"bbox": [...]
}
type
(必填): 必须是 "Feature"id
(可选): 要素唯一标识符geometry
(必填): 几何对象properties
(可选): 属性键值对bbox
(可选): 该要素的边界框json
复制
{
"type": "Point",
"coordinates": [x, y]
}
json
复制
{
"type": "LineString",
"coordinates": [[x1,y1], [x2,y2], ...]
}
json
复制
{
"type": "Polygon",
"coordinates": [
[[x1,y1], [x2,y2], ..., [x1,y1]], // 外环
[[x1,y1], [x2,y2], ..., [x1,y1]] // 内环(孔洞)
]
}
json
{
"type": "MultiPoint",
"coordinates": [[x1,y1], [x2,y2], ...]
}
json
{
"type": "MultiLineString",
"coordinates": [
[[x1,y1], [x2,y2], ...],
[[x1,y1], [x2,y2], ...]
]
}
json
{
"type": "MultiPolygon",
"coordinates": [
[ /* 第一个多边形 */ ],
[ /* 第二个多边形 */ ]
]
}
json
复制
{
"type": "GeometryCollection",
"geometries": [
{ /* 第一个几何体 */ },
{ /* 第二个几何体 */ }
]
}
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]
]
]
}
}
]
}
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]
]
}
}
]
}
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": [
[/* 上海市边界坐标 */]
]
}
}
]
}
GeoJSON 标准规定使用 WGS84 坐标系 (EPSG:4326),但可通过扩展支持其他坐标系:
json
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::3857"
}
},
"features": [...]
}
可通过 properties 添加时间信息:
json
{
"type": "Feature",
"properties": {
"name": "台风路径",
"time": "2023-08-01T12:00:00Z"
},
"geometry": {...}
}
支持包含高程数据的坐标:
json
{
"type": "Point",
"coordinates": [116.404, 39.915, 43.5]
}
Web 地图开发:
数据交换:
空间分析:
物联网应用:
移动应用:
在线验证器:
命令行工具:
bash
npm install -g geojson-validation
geojson-validate file.geojson
Python 库:
python
from geojson import validate
validate(geojson_object)
通过以上详细说明,你应该对 GeoJSON 有了全面的了解。在实际应用中,建议从简单的点数据开始,逐步尝试更复杂的几何类型。