GeoJSON是一種對各種地理數據結構進行編碼的格式,基於Javascript對象表示法的地理空間信息數據交換格式。
中文翻譯: https://www.oschina.net/trans...
GeoJSON對象
GeoJSON對象必須由一個名字爲"type"的成員。
type成員的值必須是下面之一:"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", 或者 "FeatureCollection"。
GeoJSON對象分爲三種:幾何對象、特徵對象、特徵集合對象
note: 下面的代碼都可以在 http://geojson.io 查看效果,如下:
幾何對象
GeoJSON支持以下幾何類型:Point,MultiPoint,LineString,MultiLineString,Polygon,和MultiPolygon。
除了“GeometryCollection”外的其他任何類型的GeoJSON幾何對象必須由一個名字爲"coordinates"的成員。coordinates成員的值總是數組。這個數組裏的元素的結構由幾何類型來確定。
點(Point)
{ "type": "Point", "coordinates": [100.0, 0.0] }
多點(MultiPoint)
{
"type": "MultiPoint",
"coordinates": [
[ 100, 0 ],
[ 101, 1 ]
]
}
線 (LineString)
{
"type": "LineString",
"coordinates": [
[ 100, 0 ],
[ 101, 1 ]
]
}
多線 (MultiLineString)
{
"type": "MultiLineString",
"coordinates": [
[ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ]
]
}
多邊 (Polygon)
沒有孔的:
{
"type": "Polygon",
"coordinates": [
[
[ 100, 0 ],
[ 101, 0 ],
[ 101, 1 ],
[ 100, 1 ],
[ 100, 0 ]
]
]
}
有孔的:
{
"type": "Polygon",
"coordinates": [
[
[ 100, 0 ],
[ 101, 0 ],
[ 101, 1 ],
[ 100, 1 ],
[ 100, 0 ]
],
[
[ 100.2, 0.2 ],
[ 100.8, 0.2 ],
[ 100.8, 0.8 ],
[ 100.2, 0.8 ],
[ 100.2, 0.2 ]
]
]
}
多多邊(和MultiPolygon)
{
"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.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]
]
]
]
}
幾何集合
{ "type": "GeometryCollection",
"geometries": [
{ "type": "Point",
"coordinates": [100.0, 0.0]
},
{ "type": "LineString",
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
}
]
}
特徵對象
類型爲"Feature"的GeoJSON對象是特徵對象。
特徵對象必須由一個名字爲"geometry"的成員,這個幾何成員的值是上面定義的幾何對象或者JSON的null值。
特徵對戲那個必須有一個名字爲“properties"的成員,這個屬性成員的值是一個對象(任何JSON對象或者JSON的null值)。
如果特徵是常用的標識符,那麼這個標識符應當包含名字爲“id”的特徵對象成員。
{
"type":"Feature",
"properties":{},
"geometry":{ "type": "Point", "coordinates": [100.0, 0.0] }
}
特徵集合對象
特徵集合對象type爲FeatureCollection。
類型爲"FeatureCollection"的對象必須由一個名字爲"features"的成員。與“features"相對應的值是一個數組。這個數組中的每個元素都是上面定義的特徵對象。
{
"type": "FeatureCollection",
"features": []
}
座標參考系統對象
GeoJSON對象的座標參考系統(CRS)是由它的"crs"成員(指的是下面的CRS對象)來確定的。如果對象沒有crs成員,那麼它的父對象或者祖父對象的crs成員可能被獲取作爲它的crs。如果這樣還沒有獲得crs成員,那麼默認的CRS將應用到GeoJSON對象。
邊界框
GeoJSON對象可能有一個名字爲"bbox的成員。bbox成員的值必須是2*n數組,這兒n是所包含幾何對象的維數,並且所有座標軸的最低值後面跟着最高者值。