目录
简介
地理信息系统(简称GIS),以数字化的形式反映人类社会赖以生存的地球空间的现势和变迁的各种空间数据以及描述这些空间数据特征的属性,支持空间数据及其属性数据的输入/输出,存储,显示以及进行地理空间信息的查询,综合分析和辅助决策.
GIS标准简介
WKT与WKB是OGC中的简单服务标准SFS(Simple Features Interface Standard),但是GeoJSON并不是OGC中的标准。
- WKT(Well-known text)是开放地理空间联盟OGC(Open GIS Consortium )制定的一种文本标记语言,用于表示矢量几何对象、空间参照系统及空间参照系统之间的转换。
- WKB(well-known binary) 是WKT的二进制表示形式,解决了WKT表达方式冗余的问题,便于传输和在数据库中存储相同的信息
- GeoJSON 一种JSON格式的Feature信息输出格式,它便于被JavaScript等脚本语言处理,OpenLayers等地理库便是采用GeoJSON格式。此外,TopoJSON等更精简的扩展格式
No, GeoJSON is not an OGC standard:
IETF Geographic JSON Working Group
The Internet Engineering Task Force, in conjunction with the original specification authors, has formed the Geographic JSON WG to standardize the format. Work continues on GitHub at https://github.com/geojson/draft-geojson.
空间数据模型
3.1 WKT与GeoJSON
WKT与geojson分为点、线、面、几何集合四种:
- 点:Point, MultiPoint
- 线:LineString, MultiLineString
- 面:Polygon, MultiPolygon
- 几何结合:GeometryCollection可以由多种Geometry组成,如:GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10)
Type | Shape | WKT | GeoJSON |
Point | POINT (30 10) | { "type": "Point", "coordinates": [30, 10] } | |
LineString | LINESTRING (30 10, 10 30, 40 40) | { "type": "LineString", "coordinates": [ [30, 10], [10, 30], [40, 40] ] } | |
Polygon | POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)) | { "type": "Polygon", "coordinates": [ [[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]] ] } | |
POLYGON ((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]] ] } | ||
MultiPoint | MULTIPOINT ((10 40), (40 30), (20 20), (30 10)) | { "type": "MultiPoint", "coordinates": [ [10, 40], [40, 30], [20, 20], [30, 10] ] } | |
MULTIPOINT (10 40, 40 30, 20 20, 30 10) | |||
MultiLineString | MULTILINESTRING ((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]] ] } | |
MultiPolygon | MULTIPOLYGON (((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]] ] ] } | |
MULTIPOLYGON (((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还可以用来表示空间数据和属性数据的集合,下面是shp面数据转geojson,其中还包含图层信息等,而wkt并不能表示这个。
{
"type": "FeatureCollection",
"name": "a",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::3857" } },
"features": [
{ "type": "Feature", "properties": { "AREA": 0.0, "PERIMETER": 0.016, "BOU2_4M_": 914, "BOU2_4M_ID": 3089, "ADCODE93": 810000, "ADCODE99": 810000, "NAME": "棣欐腐鐗瑰埆琛屾斂鍖" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 12720007.326881121844053, 2544771.959127825684845 ], [ 12720092.256912549957633, 2545226.735669989138842 ], [ 12720510.112667175009847, 2545228.571321710944176 ], [ 12720666.383925, 2544938.081929029431194 ], [ 12720007.326881121844053, 2544771.959127825684845 ] ] ] } },
{ "type": "Feature", "properties": { "AREA": 0.0, "PERIMETER": 0.013, "BOU2_4M_": 915, "BOU2_4M_ID": 3090, "ADCODE93": 810000, "ADCODE99": 810000, "NAME": "棣欐腐鐗瑰埆琛屾斂鍖" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 12730249.039371021091938, 2544414.938326342497021 ], [ 12730198.930652478709817, 2544711.384370831772685 ], [ 12730315.28479553386569, 2544832.534102902282029 ], [ 12730576.019992018118501, 2544807.065052719321102 ], [ 12730715.30524355918169, 2544607.902998786885291 ], [ 12730353.503309676423669, 2544404.842732572928071 ], [ 12730249.039371021091938, 2544414.938326342497021 ] ] ] } }
]
}
3.2 WKB格式
WKB采用二进制进行存储,更方便于计算机处理,因此广泛运用于数据的传输与存储,以二位点Point(1 1)为例,
其WKB表达如下:
01 0100 0020 E6100000 000000000000F03F 000000000000F03F
- byteOrder
-
表示编码方式,00为使用big-endian编码(XDR),01为使用little-endian编码(NDR)。他们的不同仅限于在内存中放置字节的顺序,比如我们将0x1234abcd写入到以0×0000开始的内存中,则结果如下表:
-
Address
big-endian
little-endian
0×0000
0x12
0xcd
0×0001
0x34
0xab
0×0002
0xab
0x34
0×0003
0xcd
0x12
-
- webTypd
- 第二到第九字节对矢量数据基本信息进行了定义
-
第二与第三个字节规定了矢量数据的类型,如例子中的0100代表Point;
-
第三与第四个字节规定了矢量数据的维数,如例子中的0020代表该点是二位的;
- 第五到第九个字节规定了矢量数据的空间参考SRID,如例子中的E6100000是4326的整数十六位进制表达
-
- 第二到第九字节对矢量数据基本信息进行了定义
- srid
- 第五到第九个字节规定了矢量数据的空间参考SRID,如例子中的E6100000是4326的整数十六位进制表达
- structPoint
- 第十个字节开始,每16个字节就代表一个坐标对,如例子中的000000000000F03F是浮点型1的十六进制表达
GIS算法三方包
java是jts,python是shapely,js是turf
参考文献:
1. Java JTS & 空间数据模型 - jihite - 博客园
2. GIS算法:可视化工具JTS TestBuilder_Archie_java的博客-CSDN博客_jts testbuilder