01: /*
02: * This file is part of the GeOxygene project source files.
03: *
04: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
05: * the development and deployment of geographic (GIS) applications. It is a open source
06: * contribution of the COGIT laboratory at the Institut Géographique National (the French
07: * National Mapping Agency).
08: *
09: * See: http://oxygene-project.sourceforge.net
10: *
11: * Copyright (C) 2005 Institut Géographique National
12: *
13: * This library is free software; you can redistribute it and/or modify it under the terms
14: * of the GNU Lesser General Public License as published by the Free Software Foundation;
15: * either version 2.1 of the License, or any later version.
16: *
17: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser General Public License along with
22: * this library (see file LICENSE if present); if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: *
25: */
26:
27: package fr.ign.cogit.geoxygene.datatools.oracle;
28:
29: import java.sql.Connection;
30:
31: import oracle.jdbc.driver.OracleConnection;
32: import oracle.sdoapi.OraSpatialManager;
33: import oracle.sdoapi.adapter.SDOGeometry;
34: import oracle.sdoapi.adapter.SDOTemplateFactory;
35: import oracle.sdoapi.adapter.SDOTemplateFactoryImpl;
36: import oracle.sdoapi.geom.Geometry;
37: import oracle.sdoapi.geom.GeometryFactory;
38: import oracle.sdoapi.sref.SRManager;
39: import oracle.sql.STRUCT;
40:
41: import org.apache.ojb.broker.util.batch.BatchConnection;
42:
43: import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
44:
45: /**
46: * Conversion dans les 2 sens entre une SDO_GEOMETRY (format sql.STRUCT) et un GM_Object
47: *
48: * @author Thierry Badard & Arnaud Braun
49: * @version 1.1
50: */
51:
52: public class GeometryConvertor {
53:
54: /////////////////////////////////////////////////////////////////////////////////////
55: public static Object Sdo2GM_Object(Object object) {
56: try {
57: GeometryFactory gf = OraSpatialManager.getGeometryFactory();
58: SRManager srm = OraSpatialManager
59: .getSpatialReferenceManager();
60: Geometry sdoGeom = SDOGeometry.STRUCTtoGeometry(
61: (STRUCT) object, gf, srm);
62: GM_Object isoGeom = IsoAndSdo.sdoapi2iso(sdoGeom);
63: return isoGeom;
64: } catch (Exception e) {
65: e.printStackTrace();
66: return null;
67: }
68: }
69:
70: /////////////////////////////////////////////////////////////////////////////////////
71: public static Object GM_Object2Sdo(Object object, Connection conn) {
72: try {
73: GeometryFactory gf = OraSpatialManager.getGeometryFactory();
74: Geometry sdoGeom = IsoAndSdo.iso2sdoapi(gf,
75: (GM_Object) object);
76: SDOTemplateFactory sdoTF;
77: if (conn instanceof BatchConnection) {// ceci est pour OJB
78: OracleConnection oConn = (OracleConnection) ((BatchConnection) conn)
79: .getDelegate();
80: sdoTF = new SDOTemplateFactoryImpl(oConn);
81: } else
82: sdoTF = new SDOTemplateFactoryImpl(
83: (OracleConnection) conn);
84:
85: STRUCT str = SDOGeometry.geometryToSTRUCT(sdoGeom, sdoTF);
86: return str;
87: } catch (Exception e) {
88: e.printStackTrace();
89: return null;
90: }
91: }
92:
93: }
|