【发布时间】:2012-01-14 07:14:27
【问题描述】:
我正在尝试将休眠空间与 JPA 集成以进行地理搜索。我一直在官方网站上引用tutorial(我与hibernatespatial无关)。
不幸的是,本教程没有介绍如何从纬度/经度对创建 Point 实例。我正在尝试在这里执行此操作,但我仍然不确定这是否是将纬度/经度对转换为 JTS Point 实例的正确方法:
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.hibernate.annotations.Type;
import javax.persistence.*;
@Entity
public class Location {
private Double latitude;
private Double longitude;
@Type(type = "org.hibernatespatial.GeometryUserType")
private Point coordinates;
private final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
@PrePersist
@PreUpdate
public void updateCoordinate() {
if (this.latitude == null || this.longitude == null) {
this.coordinates = null;
} else {
this.coordinates = geometryFactory.createPoint(new Coordinate(latitude, longitude));
}
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
}
【问题讨论】:
-
我不知道;您可能会在Geographic Information Systems 获得更多关注。另外,请尽量不要在每个帖子中提出一个以上的问题;这里的第一点已经够复杂了!
-
不幸的是,该问题的教程链接现已失效。
标签: java hibernate jpa geolocation geospatial