Tim*_*son 5 java hibernate postgis
显然,Hibernate 5 支持 geography 类型。我搜索了很多,但几乎没有发现与地理点相关的任何内容。
我想要做的是以下内容:
在数据库表中保存 Long/Lat Points,例如 ST_GeomFromText('POINT(6.463471 52.484832)', 4326)
执行队列以检查 Point 是否在 Long/Lat 矩形中,例如:
WHERE point && ST_MakeEnvelope (5.440433, 39.480434, 8.464680, 55.486190, 4326)
我正在使用PostgreSQL和PostGIS。
我只是找不到我必须使用哪种类型的休眠列注释来获取长/纬度点,以及如何执行上述查询。
@Type(type="org.hibernate.spatial.GeometryType")
Run Code Online (Sandbox Code Playgroud)
不是关于 Long/Lat 的问题
是否有关于此的任何文档(注意:不是几何点)。
是的,Hibernate 5 支持 Spatial。
需要添加依赖
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.2.17.Final</version><!-- In my case was this version, needs to match with your hibernate core version-->
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后,您需要根据您的 PostgreSQL 版本使用正确的方言。
其中的一个列表:
org.hibernate.spatial.dialect.postgis.PostgisPG9Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG82Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG91Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG92Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG93Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG94Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
Run Code Online (Sandbox Code Playgroud)
设置正确的方言后,您可以在实体中使用点或多边形(无需使用@Type)。它们位于com.vividsolutions.jts.geom包中
创建一个点:
GeometryFactory gf = new GeometryFactory();
Point point = gf.createPoint(new Coordinate(lat, lon));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5145 次 |
| 最近记录: |