提问人:wjans 提问时间:11/21/2022 最后编辑:wjans 更新时间:11/23/2022 访问量:112
对 XYM 坐标使用 Geometry.reverse() 的结果不正确
Incorrect result using Geometry.reverse() for XYM coordinates
问:
我们将 () 与 () 一起使用,以从 PostGis () 数据库中检索具有测量尺寸的几何图形。jts-core
org.locationtech.jts:jts-core:jar:1.19.0
hibernate-spatial
org.hibernate:hibernate-spatial:jar:5.6.10.Final:compile
14.3
查询如下所示:
Geometry geometry = (Geometry) entityManager
.createNativeQuery("SELECT st_locatebetween(geom, :p1, :p2) as geom FROM GEOMS WHERE id = :id")
.setParameter("id", id)
.setParameter("p1", p1)
.setParameter("p2", p2)
.unwrap(NativeQuery.class)
.addScalar("geom", new JTSGeometryType(INSTANCE_WKB_2))
.getSingleResult();
此查询适用于检索几何图形,并返回 XYM 坐标。但是,当我们尝试使用 反转几何时,M 坐标会丢失。除中间坐标外,所有坐标的值均为 。org.locationtech.jts.geom.Geometry#reverse
NaN
m
当通过使用 的数组通过简单的单元测试尝试此操作时,这工作正常。调试查询时,它似乎正在使用 which 返回不正确的反向数组。org.locationtech.jts.geom.CoordinateXYM
org.geolatte.geom.PackedPositionSequence
我们做错了什么吗?还是这是一个错误?
如果我们尝试直接这样做,我们似乎会遇到同样的问题:org.geolatte.geom.Geometry
Geometry geometry = JTS.to(Wkt.fromWkt("LINESTRING M (1 1 1, 2 2 2, 3 3 3)"));
stream(geometry.getCoordinates()).forEach(System.out::println);
stream(geometry.reverse().getCoordinates()).forEach(System.out::println);
给出以下输出:
(1.0, 1.0 m=1.0)
(2.0, 2.0 m=2.0)
(3.0, 3.0 m=3.0)
(3.0, 3.0 m=NaN)
(2.0, 2.0 m=2.0)
(1.0, 1.0 m=NaN)
答:
这绝对是一个错误。JTS 和 .不会返回 M 坐标的正确值。reverse()
org.geolatte.geom.PackedCoordinateSequence
CoordinateSequence
我在 geolatte-geom 项目中为此创建了一个问题。
同时,您可以使用 Z 坐标设置为 0.0 的 XYZM 几何作为解决方法。然后不匹配消失,反向将正常工作。
评论
geometryFactory.createLineString(geometry.getCoordinates()).reverse()
评论