org.geotools.data.oracle.sdo
Class GeometryConverter

java.lang.Object
  extended byorg.geotools.data.oracle.sdo.GeometryConverter

public class GeometryConverter
extends java.lang.Object

Sample use of SDO class for simple JTS Geometry.

If needed I can make a LRSGeometryConverter that allows JTS Geometries with additional ordinates beyond xyz.

Author:
jgarnett

Field Summary
protected  oracle.jdbc.OracleConnection connection
           
static java.lang.String DATATYPE
           
 
Constructor Summary
GeometryConverter(oracle.jdbc.OracleConnection connection)
           
GeometryConverter(oracle.jdbc.OracleConnection connection, com.vividsolutions.jts.geom.GeometryFactory geometryFactory)
           
 
Method Summary
protected  double asDouble(oracle.sql.Datum datum, double DEFAULT)
          Presents datum as a double
protected  double[] asDoubleArray(oracle.sql.ARRAY array, double DEFAULT)
          Presents array as a double[]
protected  double[] asDoubleArray(oracle.sql.Datum[] data, double DEFAULT)
          Presents Datum[] as a double[]
protected  double[] asDoubleArray(oracle.sql.STRUCT struct, double DEFAULT)
          Presents struct as a double[]
protected  oracle.sql.STRUCT asEmptyDataType()
          Representation of null as an Empty SDO_GEOMETRY.
 com.vividsolutions.jts.geom.Geometry asGeometry(oracle.sql.STRUCT sdoGeometry)
          Convert provided SDO_GEOMETRY to JTS Geometry.
protected  int[] asIntArray(oracle.sql.ARRAY array, int DEFAULT)
           
protected  int[] asIntArray(oracle.sql.Datum[] data, int DEFAULT)
          Presents Datum[] as a int[]
protected  int asInteger(oracle.sql.Datum datum, int DEFAULT)
          Presents datum as an int
 java.lang.String getDataTypeName()
          Used to handle MDSYS.SDO_GEOMETRY.
 boolean isCapable(com.vividsolutions.jts.geom.Geometry geom)
          Ensure that obj is a JTS Geometry (2D or 3D) with no LRS measures.
protected  oracle.sql.ARRAY toARRAY(double[] doubles, java.lang.String dataType)
          Convience method for ARRAY construction.
protected  oracle.sql.ARRAY toARRAY(int[] ints, java.lang.String dataType)
          Convience method for ARRAY construction.
protected  oracle.sql.ARRAY toATTRIBUTE(double[] ords, java.lang.String desc)
           
protected  oracle.sql.CHAR toCHAR(java.lang.String s)
          Convience method for CHAR construction
protected  oracle.sql.NUMBER toNUMBER(double number)
          Convience method for NUMBER construction.
protected  oracle.sql.NUMBER toNUMBER(int number)
          Convience method for NUMBER construction
protected  oracle.sql.ARRAY toORDINATE(com.vividsolutions.jts.geom.CoordinateList list, double[][] measures, int D)
          Convience method for ARRAY construction.
protected  oracle.sql.ARRAY toORDINATE(double[] ords)
           
 oracle.sql.STRUCT toSDO(com.vividsolutions.jts.geom.Geometry geom)
          Used to convert double[] to SDO_ODINATE_ARRAY.
protected  oracle.sql.STRUCT toSTRUCT(oracle.sql.Datum[] attributes, java.lang.String dataType)
          Convience method for STRUCT construction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected oracle.jdbc.OracleConnection connection

DATATYPE

public static final java.lang.String DATATYPE
See Also:
Constant Field Values
Constructor Detail

GeometryConverter

public GeometryConverter(oracle.jdbc.OracleConnection connection)

GeometryConverter

public GeometryConverter(oracle.jdbc.OracleConnection connection,
                         com.vividsolutions.jts.geom.GeometryFactory geometryFactory)
Method Detail

getDataTypeName

public java.lang.String getDataTypeName()
Used to handle MDSYS.SDO_GEOMETRY.

Returns:
MDSYS.SDO_GEOMETRY
See Also:
net.refractions.jspatial.Converter#getDataType()

isCapable

public boolean isCapable(com.vividsolutions.jts.geom.Geometry geom)
Ensure that obj is a JTS Geometry (2D or 3D) with no LRS measures.

This Converter does not support SpatialCoordinates

Returns:
true if obj is a JTS Geometry
See Also:
net.refractions.jspatial.Converter#isCapable(java.lang.Object)

asGeometry

public com.vividsolutions.jts.geom.Geometry asGeometry(oracle.sql.STRUCT sdoGeometry)
                                                throws java.sql.SQLException
Convert provided SDO_GEOMETRY to JTS Geometry.

Will return null as null.

Returns:
JTS Geometry representing the provided datum
Throws:
java.sql.SQLException
See Also:
net.refractions.jspatial.Converter#toObject(oracle.sql.STRUCT)

toSDO

public oracle.sql.STRUCT toSDO(com.vividsolutions.jts.geom.Geometry geom)
                        throws java.sql.SQLException
Used to convert double[] to SDO_ODINATE_ARRAY.

Will return null as an empty SDO_GEOMETRY

Returns:
STRUCT representing provided Map
Throws:
java.sql.SQLException
See Also:
net.refractions.jspatial.Converter#toDataType(java.lang.Object)

asEmptyDataType

protected oracle.sql.STRUCT asEmptyDataType()
                                     throws java.sql.SQLException
Representation of null as an Empty SDO_GEOMETRY.

Returns:
null as a SDO_GEOMETRY
Throws:
java.sql.SQLException

toSTRUCT

protected final oracle.sql.STRUCT toSTRUCT(oracle.sql.Datum[] attributes,
                                           java.lang.String dataType)
                                    throws java.sql.SQLException
Convience method for STRUCT construction.

Throws:
java.sql.SQLException

toARRAY

protected final oracle.sql.ARRAY toARRAY(double[] doubles,
                                         java.lang.String dataType)
                                  throws java.sql.SQLException
Convience method for ARRAY construction.

Compare and contrast with toORDINATE - which treats Double.NaN asNULL

Throws:
java.sql.SQLException

toORDINATE

protected final oracle.sql.ARRAY toORDINATE(com.vividsolutions.jts.geom.CoordinateList list,
                                            double[][] measures,
                                            int D)
                                     throws java.sql.SQLException
Convience method for ARRAY construction.

Forced to burn memory here - only way to actually place NULL numbers in the ordinate stream.

The alternative is to construct the array from a array of doubles, which does not record NULL NUMBERs.

The results is an "MDSYS.SDO_ORDINATE_ARRAY"

 list     = c1(1,2,0), c2(3,4,Double.NaN)
 measures = {{5,6},{7,8}
 
 toORDINATE( list, measures, 2 )
 = (1,2,5,7, 3,4,6,8)
 
 toORDINATE( list, measures, 3 )
 = (1,2,0,5,7, 3,4,NULL,6,8)
 
 toORDINATE( list, null, 2 )
 = (1,2, 3,4)
 

Parameters:
list - CoordinateList to be represented
measures - Per Coordiante Measures, null if not required
D - Dimension of Coordinates (limited to 2d, 3d)
Throws:
java.sql.SQLException

toORDINATE

protected final oracle.sql.ARRAY toORDINATE(double[] ords)
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

toATTRIBUTE

protected final oracle.sql.ARRAY toATTRIBUTE(double[] ords,
                                             java.lang.String desc)
                                      throws java.sql.SQLException
Throws:
java.sql.SQLException

toNUMBER

protected final oracle.sql.NUMBER toNUMBER(double number)
                                    throws java.sql.SQLException
Convience method for NUMBER construction.

Double.NaN is represented as NULL to agree with JTS use.

Throws:
java.sql.SQLException

toARRAY

protected final oracle.sql.ARRAY toARRAY(int[] ints,
                                         java.lang.String dataType)
                                  throws java.sql.SQLException
Convience method for ARRAY construction.

Throws:
java.sql.SQLException

toNUMBER

protected final oracle.sql.NUMBER toNUMBER(int number)
Convience method for NUMBER construction


toCHAR

protected final oracle.sql.CHAR toCHAR(java.lang.String s)
Convience method for CHAR construction


asInteger

protected int asInteger(oracle.sql.Datum datum,
                        int DEFAULT)
                 throws java.sql.SQLException
Presents datum as an int

Throws:
java.sql.SQLException

asDouble

protected double asDouble(oracle.sql.Datum datum,
                          double DEFAULT)
                   throws java.sql.SQLException
Presents datum as a double

Throws:
java.sql.SQLException

asDoubleArray

protected double[] asDoubleArray(oracle.sql.STRUCT struct,
                                 double DEFAULT)
                          throws java.sql.SQLException
Presents struct as a double[]

Throws:
java.sql.SQLException

asDoubleArray

protected double[] asDoubleArray(oracle.sql.ARRAY array,
                                 double DEFAULT)
                          throws java.sql.SQLException
Presents array as a double[]

Throws:
java.sql.SQLException

asDoubleArray

protected double[] asDoubleArray(oracle.sql.Datum[] data,
                                 double DEFAULT)
                          throws java.sql.SQLException
Presents Datum[] as a double[]

Throws:
java.sql.SQLException

asIntArray

protected int[] asIntArray(oracle.sql.ARRAY array,
                           int DEFAULT)
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

asIntArray

protected int[] asIntArray(oracle.sql.Datum[] data,
                           int DEFAULT)
                    throws java.sql.SQLException
Presents Datum[] as a int[]

Throws:
java.sql.SQLException


Copyright © GeoTools. All Rights Reserved.