在 JTS 上处理几何端 WKBwriter 时出现的问题
我刚刚开始学习几何,但遇到了一些非常奇怪的错误。我正在尝试在我的 java 代码中使用特定的 SRID 创建 WKB。
我已经完成了:
GeometryFactory gm = new GeometryFactory(new PrecisionModel,4326)
WKBWriter w = new WKBWriter(2,ByteOrderValues.LITTLE_ENDIAN)
Geometry geom: Geometry = gm.createPoint(new Coordinate(4,5))
Array[Byte] the_geom = w.write(geom)
println(geom)
println(geom.getSRID)
println(WKBWriter.toHex(the_geom.get))
并获得了
POINT (4 5)
4326
010100000000000000000010400000000000001440
但是在我的数据库中使用postgis:
GEOMETRYFROMTEXT('Point(4 5)',4326))
导致
0101000020E610000000000000000010400000000000001440
我在这里出错了?
I've just started with geometries and I'm getting some really odd errors. I'm trying to create a WKB inside my java code with an specific SRID.
I've done:
GeometryFactory gm = new GeometryFactory(new PrecisionModel,4326)
WKBWriter w = new WKBWriter(2,ByteOrderValues.LITTLE_ENDIAN)
Geometry geom: Geometry = gm.createPoint(new Coordinate(4,5))
Array[Byte] the_geom = w.write(geom)
println(geom)
println(geom.getSRID)
println(WKBWriter.toHex(the_geom.get))
and obtained
POINT (4 5)
4326
010100000000000000000010400000000000001440
But with postgis in my DB:
GEOMETRYFROMTEXT('Point(4 5)',4326))
results in
0101000020E610000000000000000010400000000000001440
What I'm getting wrong here??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当存在 SRID 时,PostGIS 不(仅)使用 WKB 标准,它使用 EWKB 支持 3d 和 SRID 的格式,其中 WKB 规范 没有。将 WKB 视为一种轻型二进制二维数组,它是一种非常简单的格式。它不包括二进制表示形式的高程或 SRID,在 OGC 标准空间参考系统中是元数据。以下是一些交互类型,可能会帮助您了解如何使用 WKB 和 EWKB:
这为您提供:
正如您所看到的。如果您从十六进制值开始并想要添加 SRID 投影并存储为 EWKB,您可以执行以下操作的一些变体:
或:
正如您所期望的,分别产生这些结果:
其中 null
-1
默认 SRID 是与非 SRID 2d WKB 格式相同。总的来说,我认为使用 WKT、GeoJSON 和 KML 更安全,因为它们也是OGC(?)1 开放标准,并且 SQL 版本有一些需要的更新待办的。正如 PostGIS 文档所建议的:“PostGIS 扩展格式目前是 OGC 格式的超集(每个有效的 WKB/WKT 都是有效的 EWKB/EWKT),但这在未来可能会有所不同,特别是如果 OGC 推出与我们的扩展冲突的新格式因此,您不应该依赖此功能!”(1) 实际上不知道其中一半标准的状态如何,但 json、text 和 xml 似乎可能存在于任何给定应用程序的生命周期中。
PostGIS doesn't use (only) the WKB standard when an SRID is present, it uses the EWKB format that supports 3d and SRIDs, which the WKB specification does not. Think of WKB as a kind of light binary 2d array, it is a very simple format. It doesnt include elevation or an SRID in the binary representation, in the OGC standard spatial reference systems are metadata. Here are some of the kinds of interactions that might shed light on how you work with WKB and EWKB:
This gives you:
as you saw. If you start with a hex value and want to add SRID projection and store as EWKB you do some variant of:
or:
As you would expect these yield, respectively:
where the null
-1
default SRID is the same as the non-SRID 2d WKB format. In general I think it is safer to work with WKT, GeoJSON, and KML, since they are alsoOGC(?)1 open standards and the SQL version has some needed updates pending. As the PostGIS docs suggest: "PostGIS extended formats are currently superset of OGC one (every valid WKB/WKT is a valid EWKB/EWKT) but this might vary in the future, specifically if OGC comes out with a new format conflicting with our extensions. Thus you SHOULD NOT rely on this feature!"(1) Actually have no idea what the status of half these standards are, but json, text and xml seem likely to be around for the life of any given application.