参考
介绍
GeoJSON 是一种基于 JSON,用于表示地理信息的数据格式,其文件后缀为.geojson。
举一例说明:北京地处东经 116°、北纬 39°,总面积 16410 平方千米,常住人口 2153 万人;南京地处东经 118°、北纬 32°,总面积 6587 平方千米,常住人口 850 万人。现分别使用 JSON 和 GeoJSON 表示北京和南京这两个地理要素:
// JSON: *.json
[
{
"name": "BeiJing",
"area": 16410,
"population": 2153,
"longitude": 116,
"latitude": 39
},
{
"name": "NanJing",
"area": 6587,
"population": 850,
"longitude": 118,
"latitude": 32
}
]
// GeoJSON: *.geojson
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "BeiJing",
"area": 16410,
"population": 2153.6
},
"geometry": {
"type": "Point",
"coordinates": [116, 39]
}
},
{
"type": "Feature",
"properties": {
"name": "NanJing",
"area": 6587,
"population": 850
},
"geometry": {
"type": "Point",
"coordinates": [118, 32]
}
}
]
}
可见,GeoJSON 通过geometry和properties字段将地理要素的空间特征和非空间特征区分开来,且对空间特征的格式做了规范(如南京和北京都使用点表示,且点的位置信息用一个长度为 2 的数组表示,详情参见下文),这使得地理信息的表达更加清晰。
格式
非空间特征
使用键值对表示:
{
"type": "Feature",
"properties": {
"prop1": "value1",
"prop2": "value2",
"prop3": "value3"
},
"geometry": {}
}
空间特征
点 Point
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [100.0, 0.0]
}
}
线 LineString
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[100.0, 0.0],
[101.0, 1.0]
]
}
}
多边形 Polygons
内部无洞:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
}
内部有洞:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8]
]
]
}
}
多个点 MultiPoints
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [
[100.0, 0.0],
[101.0, 1.0]
]
}
}
多条线 MultiLineStrings
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0],
[101.0, 1.0]
],
[
[102.0, 2.0],
[103.0, 3.0]
]
]
}
}
多个多边形 MultiPolygons
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
],
[
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2]
]
]
]
}
}
几何体集合 GeometryCollections
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [100.0, 0.0]
},
{
"type": "LineString",
"coordinates": [
[101.0, 0.0],
[102.0, 1.0]
]
}
]
}
}
资料
示例:在 ArcGIS API for JS 官网的沙箱中加载全国各省 GeoJSON 数据:
const layer = new GeoJSONLayer({
url: 'https://geo.datav.aliyun.com/areas_v2/bound/100000_full.json',
});
const map = new Map({
basemap: 'hybrid',
ground: 'world-elevation',
layers: [layer],
});
const view = new SceneView({
container: 'viewDiv',
map: map,
zoom: 2,
});