我正在使用Java中的oracle spatial开发一个位置应用程序.我正在为orm层使用hibernate 4.0空间.我是空间新手,我无法找到休眠空间的最佳实践.我的数据库模型如下;
CREATE TABLE SYSTEM.POI ( POI_ID INTEGER, SERVICE_ID INTEGER, POI_NAME VARCHAR2(255 CHAR), DESCRIPTION VARCHAR2(1023 CHAR), CATEGORY VARCHAR2(127 CHAR), ADDRESS VARCHAR2(4000 CHAR), MOBILE_PHONE VARCHAR2(15 CHAR), FIXED_PHONE VARCHAR2(15 CHAR), BUSINESS_HOURS VARCHAR2(1023 CHAR), SHAPE SDO_GEOMETRY )
insert语句如下;
INSERT INTO SYSTEM.POI (SERVICE_ID, POI_NAME, DESCRIPTION, CATEGORY, ADDRESS, MOBILE_PHONE, FIXED_PHONE, BUSINESS_HOURS, SHAPE) VALUES( '1320', 'PO-Kral Petrol Ürünleri San ve Tic. Ltd. ?ti.', 'Camilerimiz', 'CAMI', '?SL?CE MAHALLES? DERE SOKAK NO:5', '2762151093', '5552552343', 'Hafta içi 09:00 - 17:00, haftasonu 09:00 - 13:00 aç?k', SDO_GEOMETRY( 2001, 3785, SDO_POINT_TYPE(28.90762, 41.1521, NULL), NULL, NULL ) );
实体模型跟随我只分享sdo_geometry对象;
import com.vividsolutions.jts.geom.Geometry; ... @Column(name="SHAPE") @Type(type = "org.hibernatespatial.GeometryUserType") private Geometry shape; public Geometry getShape() { return shape; } public void setShape(Geometry shape) { this.shape = shape; }
如何用动态参数填充此spahe对象.例如;
SDO_GEOMETRY( 2001, --> sdo_gtype 3785, --> sdo_srid SDO_POINT_TYPE(28.90762, 41.1521, NULL), --> sdo_point NULL, --> sdo_elem_info NULL --> sdo_ordinates )
如何动态地将sdo_gtype,sdo_srid,sdo_point_type参数传递给几何对象?
您可以创建如下所示.
com.vividsolutions.jts.geom.Point p = new GeometryFactory().createPoint(new Coordinate(12.34343, 12.232424)); System.out.println(p);
在里面 GeonmetryFactory
构造函数中,您可以传递precision model,srid和CoordinateReferenceSystem.
然而,有一个空间包装器JTS
被调用geolatte
,它随Hibernate Spatial一起提供(自动下载maven中的jar).您可以Point
使用Geolatte
如下所示创建.
org.geolatte.geom.Pointpoint = Geometries.mkPoint(new G2D(12.34343, 12.232424), CoordinateReferenceSystems.WGS84); System.out.println(point);
有实用类从对等转换JTS
到Geolatte
,反之亦然.并附加程序的输出.
org.geolatte.geom.Pointpoint = Geometries.mkPoint(new G2D(12.34343, 12.232424), CoordinateReferenceSystems.WGS84); System.out.println(point); com.vividsolutions.jts.geom.Point p = new GeometryFactory(new PrecisionModel(), 4326).createPoint(new Coordinate(12.34343, 12.232424)); System.out.println(p); System.out.println(JTS.to(point)); System.out.println(JTS.from(p));
输出:
SRID=4326;POINT(12.34343 12.232424) POINT (12.34343 12.232424) POINT (12.34343 12.232424) SRID=4326;POINT(12.34343 12.232424)
UPDATE
您正在寻找的投影得到支持Geolatte
,这里有SRID支持Geolatte
,因为您使用的是Project CS,所以需要使用C2D(笛卡尔2D)
这是要创建的代码示例
System.out.println(CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(3785).getName()); org.geolatte.geom.Pointpoint1 = Geometries.mkPoint(new C2D(12.34343, 12.232424), CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(3785)); System.out.println(point1);
输出:
Popular Visualisation CRS / Mercator (deprecated) SRID=3785;POINT(12.34343 12.232424)