前言

如果你看完文章没有得到你想要的内容,请回来点击原文链接Geojson规范,rfc7946

geojson简介

简单来说geojson是用来描述地理特征的基于 JSON 的地理空间数据交换格式。GeoJSON RFC定义了 GeoJSON 对象可以表示的 7 种几何形状“类型” 。它们是“Point”、“MultiPoint”、“LineString”、“MultiLineString”、“Polygon”、“MultiPolygon”和“GeometryCollection”。

geojson对象

Point

0维点对象,”type”为”Point”,”coordinates”为经纬度。

1
2
3
4
{
"type": "Point",
"coordinates": [100.0, 0.0]
}

MultiPoints

0维多点对象,”type”为”MultiPoints”,”coordinates”为经纬度数组。

1
2
3
4
5
6
7
{
"type": "MultiPoints",
"coordinates": [
[100.0, 0.0],
[100.0, 50.0]
]
}

LineStrings

一维线对象,”type”为”LineString”,”coordinates”为经纬度数组。线形与经纬度数组顺序相关。

1
2
3
4
5
6
7
8
{
"type": "LineStrings",
"coordinates": [
[100.0, 0.0],
[100.0, 30.0],
[100.0, 50.0]
]
}

MultiLineString

一维多线对象,”type”为”MultiLineString”,”coordinates”为”LineStrings”数组。

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0],
[101.0, 1.0]
],
[
[102.0, 2.0],
[103.0, 3.0]
]
]
}

Polygon

二维面/多边形对象,”type”为”Polygon”,”coordinates”为”linear ring”数组。面形与数组顺序相关且数组第一个点和最后一个点必须相同。

1
2
3
4
5
6
7
8
9
10
11
12
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}

MultiPolygon

二维多面对象,”type”为”MultiPolygon”,”coordinates”为”Polygon”数组。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{
"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

Geometrycollection 的”Geometr”数组中的每个元素都是上面描述的几何对象之一:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [100.0, 0.0]
},
{
"type": "LineString",
"coordinates": [
[101.0, 0.0],
[102.0, 1.0]
]
},
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
]
}

Antimeridian Cutting

他不是一种形状对象,只是在提示当你的形状要跨过180°经度的时候,需要注意基本的地理描述问题。

Feature Object

叫做特征或者要素对象,其包含了一个基本形状对象(geometry)及其基本信息(properties)。

‘properties’ 是一个普通的json对象,可以自定义形状相关的属性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
103.94760106,
30.661278365
],
//...
[
103.921334867,
30.669621744
],
[
103.94760106,
30.661278365
]
]
]
},
"properties": {
"OBJECTID": 2229,
"name": "双流区",
"adcode": "510116",
"adcode_s": "5101",
"adcode_si": "51",
"JC": 2,
"ORIG_FID": 3232,
"Shape_Leng": 1.76486274549,
"Shape_Area": 0.100061005347,
"dname": "双流区"
}
},

FeatureCollection Object

一组Feature的合集,也是通常使用较多的geojson文件内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
"name": "成都市",
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
103.55857416,
30.3350250600001
],
// ...
[
103.55216094,
30.341370645
],
[
103.55857416,
30.3350250600001
]
]
]
},
"properties": {
"OBJECTID": 2115,
"name": "蒲江县",
"adcode": "510131",
"adcode_s": "5101",
"adcode_si": "51",
"JC": 2,
"ORIG_FID": 3261,
"Shape_Leng": 1.3293374479,
"Shape_Area": 0.0543842925464,
"dname": "蒲江县"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
103.80576362,
30.524076135
],
[
103.806736421,
30.5239680460001
],
[
103.816888125,
30.522840079
],
//...
[
103.802673479,
30.5271662750001
],
[
103.80576362,
30.524076135
]
]
]
},
"properties": {
"OBJECTID": 2162,
"name": "新津区",
"adcode": "510118",
"adcode_s": "5101",
"adcode_si": "51",
"JC": 2,
"ORIG_FID": 3241,
"Shape_Leng": 0.830260507587,
"Shape_Area": 0.0306366445471,
"dname": "新津区"
}
},
]
}

后言

提供两个标准的成都市行政区区块划分和各市重心点的json文件作为参考。
chengdu-area.json
chengdu-point.json