GeoJSON 是什麼?快速上手指南
GeoJSON 是一種以 JSON 表示地理空間資料(geometry + properties)的標準格式,廣泛用於網頁地圖、GIS 與資料交換。GeoJSON 使用 WGS84(經度、緯度)座標系統,座標陣列的順序為 [lon, lat](注意不是 [lat, lon])。
info
Longitude and latitude 的中文是經度和緯度
本文重點
- 介紹 GeoJSON 的核心結構與常用 Geometry 類型
- 提供可直接使用的範例(Point、Polygon、FeatureCollection)
- 展示如何在 Leaflet 與 Mapbox GL JS 中載入 GeoJSON
- 列出常見陷阱與最佳實務
核心概念
- Geometry 類型:
Point,MultiPoint,LineString,MultiLineString,Polygon,MultiPolygon,GeometryCollection。 - Feature:一個帶有
geometry與properties的資料記錄,結構包含type: "Feature"。 - FeatureCollection:多個
Feature的集合,type: "FeatureCollection",features為陣列。 - 座標順序:GeoJSON 使用
[longitude, latitude](經度在前)。 - CRS(座標參考系):根據 RFC 7946,GeoJSON 預設並且只使用 WGS84,不再支援自訂 CRS 字段。
簡單範例(FeatureCollection)
下面是一個包含 Point 與 Polygon 的最小 GeoJSON:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "name": "台北 101", "type": "landmark" },
"geometry": {
"type": "Point",
"coordinates": [121.5654, 25.033]
}
},
{
"type": "Feature",
"properties": { "name": "範例範圍", "type": "area" },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[121.56, 25.03],
[121.57, 25.03],
[121.57, 25.04],
[121.56, 25.04],
[121.56, 25.03]
]
]
}
}
]
}
Download geojson https://r2.datahub.io/clvyjaryy0000la0cxieg4o8o/main/raw/data/countries.geojson