本文介绍了在春季启动时将PostGIS地理点与休眠空间5结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,Hibernate 5支持地理类型.我进行了很多搜索,但发现几乎没有与地理位置有关的东西.

Apparently with Hibernate 5, the geography type is supported. I've searched a lot, but found close to nothing related to the geography points.

我想做的是以下事情:

  1. 在数据库表中保存经/纬度点,例如ST_GeomFromText('POINT(6.463471 52.484832)', 4326)

执行队列以检查该点是否在长/纬度矩形中,如:

Perform queues to check if the Point is in a Long/Lat rectangle like :

WHERE point && ST_MakeEnvelope (5.440433, 39.480434, 8.464680, 55.486190, 4326)

我正在使用 PostgreSQL PostGIS .

我只是找不到我必须用来获取经纬度点的冬眠列注释的类型,以及如何执行上述查询.

I just cannot find which type of column annotation for hibernate I have to use to get Long/Lat Points, and also how to perform above query.

@Type(type="org.hibernate.spatial.GeometryType")

这不是关于多头/空头的观点

Is not a point regarding Long/Lat

是否有与此相关的文档(注意:不是几何点).

Is there any documentation regarding this (note: not geometry points).

推荐答案

是的,Hibernate 5支持Spatial.

Yes, Hibernate 5 supports 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>

然后,根据您的PostgreSQL版本,您需要使用正确的方言.

Then you need to use the right dialect depending on your PostgreSQL version.

它们的列表:

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

设置正确的方言后,您可以在实体中使用Point或Polygon(无需使用@Type).它们位于 com.vividsolutions.jts.geom

After setting the correct dialect you can use Point or Polygon(there is no need to use @Type) in your entities. They come in the package com.vividsolutions.jts.geom

创建点:

GeometryFactory gf = new GeometryFactory();
Point point = gf.createPoint(new Coordinate(lat, lon));

这篇关于在春季启动时将PostGIS地理点与休眠空间5结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:13