Java中使用JTS实现WKT字符串读取转换线、查找LineString的list中距离最近的线、LineString做缓冲区扩展并计算点在缓冲区内的方位角:
Java中使用JTS实现WKT字符串读取转换线、查找LineString的list中距离最近的线、LineString做缓冲区扩展并计算点在缓冲区内的方位角_jts工具类-CSDN博客
WKB(Well-Known Binary) 用二进制流 描述几何对象信息。
WKB比WKT的优势在于WKB是二进制,主要是解决传输和存储的效率问题,
所以MySQL,Postgre数据存储Geometry类型的数据,存储的值是WKB格式的
WKB 使用 1 字节无符号整数、4 字节无符号整数和 8 字节双精度数(IEEE 754 格式)。一个字节是八位。
Mysql中查询存储WKB值示例:
SELECT hex(st_asbinary(st_geomfromtext('POINT(1 2)')))
注:
博客:
霸道流氓气质_C#,架构之路,SpringBoot-CSDN博客
1、WKB相关操作api
2、WKB输出数据并转换为字符串
??????? GeometryFactory geometryFactory = new GeometryFactory();
??????? Point point1 = geometryFactory.createPoint(new Coordinate(112.11,2225.21));
??????? WKBWriter wkbWriter = new WKBWriter();
??????? byte[] write = wkbWriter.write(point1);
??????? String hex = WKBWriter.toHex(write);
??????? System.out.println(hex);
以上结果输出:
0000000001405C070A3D70A3D740A1626B851EB852
3、WKB数据读取
??????? WKBReader wkbReader = new WKBReader();
??????? Geometry geometry = null;
??????? try {
??????????? geometry = wkbReader.read(write);
??????? } catch (ParseException e) {
??????????? e.printStackTrace();
??????? }
??????? System.out.println(geometry.toText());
完整示例:
??????? //WKB输出数据
??????? GeometryFactory geometryFactory = new GeometryFactory();
??????? Point point1 = geometryFactory.createPoint(new Coordinate(112.11,2225.21));
??????? WKBWriter wkbWriter = new WKBWriter();
??????? byte[] write = wkbWriter.write(point1);
??????? String hex = WKBWriter.toHex(write);
??????? System.out.println(hex);
??????? //0000000001405C070A3D70A3D740A1626B851EB852
??????? WKBReader wkbReader = new WKBReader();
??????? Geometry geometry = null;
??????? try {
??????????? geometry = wkbReader.read(write);
??????? } catch (ParseException e) {
??????????? e.printStackTrace();
??????? }
??????? System.out.println(geometry.toText());
??????? //POINT (112.11 2225.21)