当前位置:  开发笔记 > 编程语言 > 正文

Hibernate Spatial创建几何对象

如何解决《HibernateSpatial创建几何对象》经验,为你挑选了1个好方法。

我正在使用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参数传递给几何对象?



1> Karthik Pras..:

您可以创建如下所示.

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.Point point = Geometries.mkPoint(new G2D(12.34343, 12.232424), CoordinateReferenceSystems.WGS84);
        System.out.println(point);

有实用类从对等转换JTSGeolatte,反之亦然.并附加程序的输出.

        org.geolatte.geom.Point 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)

UPDATE

您正在寻找的投影得到支持Geolatte,这里有SRID支持Geolatte,因为您使用的是Project CS,所以需要使用C2D(笛卡尔2D)

这是要创建的代码示例

        System.out.println(CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(3785).getName());
        org.geolatte.geom.Point 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)

推荐阅读
echo7111436
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有