GeoJSON 是使用 JSON 编码地理数据结构的标准格式。它被地图库、GIS 工具和基于位置的服务广泛使用。
GeoJSON 结构
每个 GeoJSON 对象都有 type 属性:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [116.4074, 39.9042]
},
"properties": {
"name": "天安门",
"city": "北京"
}
}
几何类型
GeoJSON 支持七种几何类型:
Point — 单个位置:
{ "type": "Point", "coordinates": [102.0, 0.5] }
LineString — 点之间的路径:
{ "type": "LineString", "coordinates": [[102.0, 0.0], [103.0, 1.0]] }
Polygon — 有边界的区域:
{
"type": "Polygon",
"coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]
}
其他类型:MultiPoint、MultiLineString、MultiPolygon、GeometryCollection。
要素集合
组合多个要素:
{
"type": "FeatureCollection",
"features": [...]
}
坐标顺序
GeoJSON 使用 [经度, 纬度](x, y)顺序,而非 [纬度, 经度]。这是常见的错误来源。
热门库
技巧
"crs" 属性