当输入字节流包含SRID时,如何使用JTS WKBReader读取WKB?

时间:2015-12-03 21:28:58

标签: jts

WKBReader的documentation说:

  

它还部分处理PostGIS使用的扩展WKB格式(by   读取SRID值)

但是当我将前4个字节中具有SRID的字节数组传递给WKBReader时,我从WKBReader获得了异常。 This链接也会遇到同样的问题,并在将字节流传递给WKBReader之前跳过前4个字节。查看WKBReader的代码本身:

private Geometry readGeometry() throws IOException, ParseException {
        byte byteOrderWKB = this.dis.readByte();
        int byteOrder = byteOrderWKB == 1?2:1;
        this.dis.setOrder(byteOrder);
        int typeInt = this.dis.readInt();
        int geometryType = typeInt & 255;
        boolean hasZ = (typeInt & -2147483648) != 0;
        this.inputDimension = hasZ?3:2;
        this.hasSRID = (typeInt & 536870912) != 0;
        int SRID = 0;
        if(this.hasSRID) {
            SRID = this.dis.readInt();
        }

它看起来不正确,因为它不会将前4个字节解码为SRID。我也尝试过:

g = some JTS Geometry
g.setSRID(4326);
new WKBReader().read(new WKBWriter().write(g)).getSRID()

返回0而不是预期的4326。我的问题是,来自JTS的任何人都可以确认这确实是一个错误吗?如果没有,有什么不对?把它修好会很好。

1 个答案:

答案 0 :(得分:0)

回答我自己的问题:这不是一个错误。 WKBReader支持WKBWriter格式的SRID。

new WKBReader().read(new WKBWriter(2, true).write(g)).getSRID();

返回预期答案。此方法签名不存在于官方docs中,但存在here