WKT、WKB、GeoJSON
WKT(Well-known text)与WKB(well-known binary)是OGC(Open GIS Consortium )中的简单服务标准SFS(Simple Features Interface Standard),但是GeoJSON并不是OGC中的标准。
WKT是一种文本标记语言, 以文本形式描述, 用于表示矢量几何对象
WKB是WKT的二进制表示形式,便于传输和在数据库中存储相同的信息。
GeoJSON 一种JSON格式的Feature信息输出格式,它便于被JavaScript等脚本语言处理,OpenLayers等地理库便是采用GeoJSON格式。
WKT与GeoJSON
WKT与GeoJSON,点、线、面、几何集合对比
- Point, MultiPoint
- LineString, MultiLineString
- Polygon, MultiPolygon
- GeometryCollection
Point
- WKT
- POINT (30 30)
- GeoJSON
- {“type”:“Point”,“coordinates”:[30,30]}
LineString
- WKT
- LINESTRING (30 30, 20 20, 10 10)
- GeoJSON
- {“type”:“LineString”,“coordinates”:[[30,30],[20,20],[10,10]]}
Polygon
- WKT
- POLYGON ((30 30, 20 20, 10 10, 30 30))
- POLYGON ((30 30, 20 20, 10 10, 30 30),(9 9, 8 8, 7 7, 9 9))
- GeoJSON
- {“type”:“Polygon”,“coordinates”:[[[30,30],[20,20],[10,10],[30,30]]]}
- {“type”:“Polygon”,“coordinates”:[[[30,30],[20,20],[10,10],[30,30]],[[9,9],[8,8],[7,7],[9,9]]]}
MultiPoint
- WKT
- MULTIPOINT ((30 30), (20 20), (10 10))
- MULTIPOINT (30 30, 20 20, 10 10)
- GeoJSON
- {“type”:“MultiPoint”,“coordinates”:[[30,30],[20,20],[10,10]]}
MultiLineString
- WKT
- MULTILINESTRING ((30 30, 20 20, 10 10),(40 40, 50 50, 60 60, 70 70))
- GeoJSON
- {“type”:“MultiLineString”,“coordinates”:[[[30,30],[20,20],[10,10]],[[40,40],[50,50],[60,60],[70,70]]]}
MultiPolygon
- WKT
- MULTIPOLYGON (((40 40, 50 50, 60 60, 70 70, 40 40)),((30 30, 20 20, 10 10, 30 30)))
- MULTIPOLYGON (((40 40, 50 50, 60 60, 70 70, 40 40)),((30 30, 20 20, 10 10, 30 30),(9 9, 8 8, 7 7, 9 9)))
- GeoJSON
- {“type”:“MultiPolygon”,“coordinates”:[[[[40,40],[50,50],[60,60],[70,70],[40,40]]],[[[30,30],[20,20],[10,10],[30,30]]]]}
- {“type”:“MultiPolygon”,“coordinates”:[[[[40,40],[50,50],[60,60],[70,70],[40,40]]],[[[30,30],[20,20],[10,10],[30,30]],[[9,9],[8,8],[7,7],[9,9]]]]}
区别
WKT与GeoJSON的主要区别是WKT是单独用来表示空间点线面数据的,而GeoJSON还可以用来表示空间数据和属性数据的集合
// Feature(要素)
{
"type": "Feature",
"id":"feature-0",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "test point"
}
}