简体   繁体   English

使用JTS拓扑套件解析WKB字符串

[英]Parse WKB string using JTS Topology Suite

It's been a few days that I'm struggling with WKB strings. 几天以来,我一直在努力处理WKB字符串。 I need to be able to parse it in order to get the equivalent geometry and extract points coordinates (X,Y,Z). 我需要能够解析它以获得等效的几何图形并提取点坐标(X,Y,Z)。 I can't use PostGIS functions . 我不能使用PostGIS函数 The only java library that I found was the JTS Topology Suite, that i use as follow : 我发现的唯一Java库是JTS拓扑套件,我使用它的方式如下:

String wkb = "01ea030000020000009b4d3899fe95154153d97e8f43875941000000000000454003085bc23f9615411b4dc406578759410000000000004740"
byte[] aux = WKBReader.hexToBytes(wkb);
try {
    Geometry geom = new WKBReader().read(aux);
} catch (ParseException e) {
    e.printStackTrace();
    System.err.println("Bad WKB string.");
}

But the it gives me the following error : 但这给了我以下错误:

com.vividsolutions.jts.io.ParseException: Unknown WKB type 234 com.vividsolutions.jts.io.ParseException:未知的WKB类型234

234 is the decimal value of the hexadecimal string 'ea'. 234是十六进制字符串'ea'的十进制值。 It's like the JTS Library was only looking at the frist 2 bytes instead of looking at the 4 bytes 'ea03', that correspond to 1002 in little endian (so a LineStringZ). 就像JTS库只查看第一个2个字节,而不是查看4个字节的“ ea03”,它对应于小端序中的1002(所以是LineStringZ)。

My question is then : does the JTS Topology Suite handle LineStringZ ? 那么我的问题是:JTS拓扑套件可以处理LineStringZ吗? If not, why points can have a Z value ? 如果不是,为什么点可以具有Z值? And how can I parse it correctly ? 我如何正确解析呢?

Thanks you for reading ! 感谢您的阅读!

JTs only supports 2D geometries, it does not support a Z value. JT仅支持2D几何,不支持Z值。 Points only have X and Y in it. 点中只有X和Y。

JTS does support 3D geometries at least in reading and writing. JTS至少在读写方面确实支持3D几何。 Support may be rather 2.5D than a real 3D but Z values are still carried on in the operations. 支持可能是2.5D,而不是真实的3D,但Z值仍在操作中进行。 The problem is that there are two ways for presenting XYZ, XYM, and XYZM geometries in WKB. 问题在于,有两种方法可以在WKB中显示XYZ,XYM和XYZM几何形状。 JTS support the PostGIS EWKB variant as can be seem from the comment in the source code file https://sourceforge.net/p/jts-topo-suite/code/HEAD/tree/trunk/jts/java/src/com/vividsolutions/jts/io/WKBWriter.java 从源代码文件https://sourceforge.net/p/jts-topo-suite/code/HEAD/tree/trunk/jts/java/src/com/中的注释中可以看出,JTS支持PostGIS EWKB变体生动的解决方案/jts/io/WKBWriter.java

  • This implementation also supports the Extended WKB 此实现还支持扩展WKB
  • standard. 标准。 Extended WKB allows writing 3-dimensional coordinates 扩展的WKB允许编写3维坐标
  • and including the geometry SRID value. 并包括几何SRID值。
  • The presence of 3D coordinates is signified 表示存在3D坐标
  • by setting the high bit of the wkbType word. 通过设置wkbType字的高位。
  • The presence of an SRID is signified SRID的存在表示
  • by setting the third bit of the wkbType word. 通过设置wkbType字的第三位。
  • EWKB format is upward compatible with the original SFS WKB format. EWKB格式与原始SFS WKB格式向上兼容。

Your WKB is of the OGC variant which is defined in the OGC document http://portal.opengeospatial.org/files/?artifact_id=25355 您的WKB是OGC变体,在OGC文档http://portal.opengeospatial.org/files/?artifact_id=25355中定义

JTS don't understand the four-digit geometry type codes. JTS不了解四位数的几何类型代码。 This mail thread gives some more information https://lists.osgeo.org/pipermail/geos-devel/2013-December/006757.html . 该邮件线程提供了更多信息https://lists.osgeo.org/pipermail/geos-devel/2013-December/006757.html

JTS Topology suite supports 3D data but in EWKB format. JTS拓扑套件支持3D数据,但格式为EWKB。 ISO WKB is not supported. 不支持ISO WKB。 If just so happens that you are using postgis, it supports EWKB. 如果碰巧您正在使用postgis,则它支持EWKB。 ST_GeomFromEWKB <-> ST_AsEWKB ST_GeomFromEWKB <-> ST_AsEWKB

Also if you are writing your EWKB with WKBWriter, don't forget to specify output dimmensions : 另外,如果您正在使用WKBWriter编写EWKB,请不要忘记指定输出尺寸:

 WKBWriter wkbw = new WKBWriter(3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM