JTS

地理空间系列知识(一)WKT、WKB、GeoJSON简介

1.WKT、WKB、GeoJSON

WKT(Well-known text)是开放地理空间联盟OGC(Open GIS Consortium )制定的一种文本标记语言,用于表示矢量几何对象、空间参照系统及空间参照系统之间的转换。

WKB(well-known binary) 是WKT的二进制表示形式,解决了WKT表达方式冗余的问题,便于传输和在数据库中存储相同的信息。

GeoJSON 一种JSON格式的Feature信息输出格式,它便于被JavaScript等脚本语言处理,OpenLayers等地理库便是采用GeoJSON格式。此外,TopoJSON等更精简的扩展格式。

2. WKT与GeoJSON

WKT与geojson分为点、线、面、几何集合四种:

1、Point, MultiPoint

2、LineString, MultiLineString

3、Polygon, MultiPolygon

4、GeometryCollection

可以由多种Geometry组成,如:GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))

TypeWKTGeoJSON
PointPOINT (30 10){ “type”: “Point”, “coordinates”: [30, 10] }
LineStringLINESTRING (30 10, 10 30, 40 40){ “type”: “LineString”, “coordinates”: [ [30, 10], [10, 30], [40, 40] ] }
PolygonPOLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)){ “type”: “Polygon”, “coordinates”: [ [[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]] ] }
PolygonPOLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),
(20 30, 35 35, 30 20, 20 30))
{ “type”: “Polygon”, “coordinates”: [ [[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], [[20, 30], [35, 35], [30, 20], [20, 30]] ] }
MultiPointMULTIPOINT ((10 40), (40 30), (20 20), (30 10)){ “type”: “MultiPoint”, “coordinates”: [ [10, 40], [40, 30], [20, 20], [30, 10] ] }
MultiPointMULTIPOINT (10 40, 40 30, 20 20, 30 10){ “type”: “MultiPoint”, “coordinates”: [ [10, 40], [40, 30], [20, 20], [30, 10] ] }
MultiLineStringMULTILINESTRING ((10 10, 20 20, 10 40),
(40 40, 30 30, 40 20, 30 10))
{ “type”: “MultiLineString”, “coordinates”: [ [[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]] ] }
MultiPolygonMULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),
((15 5, 40 10, 10 20, 5 10, 15 5)))
{ “type”: “MultiPolygon”, “coordinates”: [ [ [[30, 20], [45, 40], [10, 40], [30, 20]] ], [ [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]] ] ] }
MultiPolygonMULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),
(30 20, 20 15, 20 25, 30 20)))
{ “type”: “MultiPolygon”, “coordinates”: [ [ [[40, 40], [20, 45], [45, 30], [40, 40]] ], [ [[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], [[30, 20], [20, 15], [20, 25], [30, 20]] ] ] }
WKT与geojson的主要区别是wkt是单独用来表示空间点线面数据的,而geojson还可以用来表示空间数据和属性数据的集合;WKB是采用二进制存储表示点线面。