我正在用Java在oracle space中开发一个定位应用程序。我正在使用休眠4.0空间的orm层。我是空间领域的新手,我找不到休眠空间的最佳实践。我的数据库模型如下;

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 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构造函数中,您可以传递精度模型,srid和CoordinateReferenceSystem。
但是,Hibernate Spatial附带了称为JTSgeolatte周围的空间包装器(在maven中自动下载jars)。您可以使用Point创建Geolatte,如下所示。
        org.geolatte.geom.Point<G2D> point = Geometries.mkPoint(new G2D(12.34343, 12.232424), CoordinateReferenceSystems.WGS84);
        System.out.println(point);

有一些实用程序类,可以从JTS转换为Geolatte,反之亦然。并附加程序的输出。
        org.geolatte.geom.Point<G2D> point = 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)

更新
Geolatte支持您要寻找的投影,Geolatte支持here SRID,因为您使用的是Project CS,所以需要使用C2D(笛卡尔2D)

这是要创建的代码示例
        System.out.println(CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(3785).getName());
        org.geolatte.geom.Point<C2D> point1 = 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)

07-24 09:32