当输入字节流中包含 SRID 时,如何使用 JTS WKBReader 读取 WKB?
How to read WKB using JTS WKBReader when input bytestream contains SRID in it?
WKBReader 的 documentation 说:
It also partiually handles the Extended WKB format used by PostGIS (by
reading SRID values)
但是当我将前 4 个字节中有 SRID 的字节数组传递给 WKBReader
时,我从 WKBReader
中得到一个异常。 This link 也遇到同样的问题并在将字节流传递给 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()
returns 0
而不是预期的 4326
。我的问题是 JTS 的任何人都可以确认这确实是一个错误吗?如果不是,有什么问题?修好了就好了。
WKBReader 的 documentation 说:
It also partiually handles the Extended WKB format used by PostGIS (by reading SRID values)
但是当我将前 4 个字节中有 SRID 的字节数组传递给 WKBReader
时,我从 WKBReader
中得到一个异常。 This link 也遇到同样的问题并在将字节流传递给 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()
returns 0
而不是预期的 4326
。我的问题是 JTS 的任何人都可以确认这确实是一个错误吗?如果不是,有什么问题?修好了就好了。