提问人:JavDevHar 提问时间:1/10/2023 最后编辑:JGHJavDevHar 更新时间:1/10/2023 访问量:144
PostGis 使用ST_GeomFromText时几何无效
PostGis invalid geometry when using ST_GeomFromText
问:
我正在将 Postgis 与 Spring Boot Hibernate JPA 一起使用。
存储库中的代码:
@Query(value = "select {h-schema}ref_plz_geom.plz from {h-schema}ref_plz_geom WHERE ST_Contains(geom, ST_Transform(ST_GeomFromText('POINT(:userLongitude :userLatitude)',4647),4326))", nativeQuery=true)
String getPlz(Double userLongitude, Double userLatitude);
我收到以下错误:
2023-01-10 14:44:08,479 ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: parse error - invalid geometry
Hint: "POINT(:u" <-- parse error at position 8 within geometry
当我在postgres中运行相同的查询时,我得到pincode:
select
pincode
from
pin_code_table
WHERE
ST_Contains(geom, ST_Transform(ST_GeomFromText('POINT(32528808.761501245 5471624.355)',4647),4326))
但是当我运行 sring 启动应用程序时,我收到上述错误。请指教。
答:
0赞
JGH
1/10/2023
#1
您需要声明参数名称:
String getPlz(@Param("userLongitude") Double userLongitude, @Param("userLatitude") Double userLatitude);
评论
0赞
JavDevHar
1/10/2023
我已经试过了,但这不是问题
评论
st_point
从坐标创建点,无需先转换为文本(而且速度更快)。