Class SDO
- Object
-
- SDO
-
public final class SDO extends Object
Oracle Spatial Data Object utilities functions.Provide utility functions for working with JTS Geometries in terms Oracle Spatial Data Objects
This class can be used for normal JTS Geometry persistence with little fuss and bother - please see GeometryConverter for an example of this.
With a little fuss and bother LRS information can also be handled. Although it is very rare that JTS makes use of such things.
- Author:
- Jody Garnett, Refractions Reasearch Inc.
- See Also:
- Spatial
User's Guide (10.1),
net.refractions.jspatial.jts
-
-
Field Summary
Fields Modifier and Type Field Description static int
SRID_NULL
-
Constructor Summary
Constructors Constructor Description SDO()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Coordinate[]
asCoordinates(double[] ordinates)
Coordinates from(x,y,x2,y2,...)
ordinates.static Coordinate[]
asCoordinates(double[] ordinates, int d)
Coordinates from a(x,y,i3..
static CoordinateSequence
coordiantes(CoordinateSequenceFactory f, AttributeList x, AttributeList y, AttributeList z)
Construct CoordinateSequence with no LRS measures.static CoordinateSequence
coordiantes(CoordinateSequenceFactory f, OrdinateList x, OrdinateList y, OrdinateList z)
Construct CoordinateSequence with no LRS measures.static CoordinateSequence
coordiantes(CoordinateSequenceFactory f, OrdinateList x, OrdinateList y, OrdinateList z, OrdinateList m)
bugfix 20121231-BK: added: TODO org.geotools.geometry.jts.CoordinateSequenceFactory does not support 4 dimensions!static void
coordinates(List<double[]> list, Geometry geom)
Encode Geometry as described by GTYPE and ELEM_INFOstatic CoordinateSequence
coordinates(CoordinateSequenceFactory f, int GTYPE, double[] ordinates)
Construct CoordinateList as described by GTYPE.static CoordinateSequence
counterClockWise(CoordinateSequenceFactory factory, CoordinateSequence ring)
Ensure Ring of Coordinates are in a counter Orientationwise order.static Geometry
create(GeometryFactory gf, int GTYPE, int SRID, double[] point, int[] elemInfo, double[] ordinates)
Decode geometry from provided SDO encoded information.static Geometry
create(GeometryFactory gf, int GTYPE, int SRID, int[] elemInfo, int triplet, CoordinateSequence coords, int N)
Consturct geometry with SDO encoded information over a CoordinateList.static int
D(int GTYPE)
Access D (for dimension) as encoded in GTYPEstatic int
D(Geometry geom)
Return D as defined by SDO_GTYPE (either 2,3 or 4).static int[]
elemInfo(Geometry geom)
Return SDO_ELEM_INFO array for geometrystatic int[]
elemInfo(Geometry geom, int GTYPE)
protected static int
elemInfoEType(Geometry geom)
ProduceSDO_ETYPE
for geometry description as stored in theSDO_ELEM_INFO
.static int
elemInfoInterpretation(Geometry geom)
ProduceSDO_INTERPRETATION
for geometry description as stored in theSDO_ELEM_INFO
.static int
elemInfoInterpretation(Geometry geom, int etype)
Allows specification ofINTERPRETATION
used to interpretgeom
.static int
elemInfoStartingOffset(Geometry geom)
Starting offset used by SDO_ORDINATES as stored in the SDO_ELEM_INFO array.static CoordinateSequence
getCS(Geometry geom)
static int
gType(Geometry geom)
Produce SDO_GTYPE representing provided Geometry.static int
L(int GTYPE)
Access L (for LRS) as encoded in GTYPEstatic int
L(Geometry geom)
Return L as defined by SDO_GTYPE (either 3,4 or 0).static double[]
ordinateArray(List list, int ordinate)
static double[]
ordinateArray(Coordinate[] array, int ordinate)
Ordinate access.static double[]
ordinateArray(CoordinateSequence coords, int ordinate)
Package up array of requested ordinate, regardless of geometrystatic double[]
ordinates(List list, Geometry geom)
Package uparray
in correct manner forgeom
.static double[]
ordinates(Geometry geom)
ProduceSDO_ORDINATES
for geometry.static double[]
ordinates2d(List list)
Ordinates (x,y,x1,y1,...) from coordiante list.static double[]
ordinates2d(List list, int L)
Ordinates (x,y,...id,x2,y2,...) from coordiante[] List.static double[]
ordinates3d(List list)
Ordinates (x,y,z,x2,y2,z2...) from coordiante[] array.static double[]
ordinates3d(List list, int L)
Ordinates (x,y,z,...id,x2,y2,z2...) from coordiante[] array.static double[]
point(Geometry geom)
Return SDO_POINT_TYPE for geometrystatic int
SRID(Geometry geom)
Returns geometry SRID.static int
TT(int GTYPE)
Access TT (for geometry type) as encoded in GTYPEstatic int
TT(Geometry geom)
Return TT as defined by SDO_GTYPE (represents geometry type).
-
-
-
Field Detail
-
SRID_NULL
public static final int SRID_NULL
- See Also:
- Constant Field Values
-
-
Method Detail
-
gType
public static int gType(Geometry geom)
Produce SDO_GTYPE representing provided Geometry.Encoding of Geometry type and dimension.
SDO_GTYPE defined as for digits
[d][l][tt]
:d
: number of dimensions (limited to 2,3, or 4)l
: measure representation (ordinate 3 or 4) or 0 to represent none/lasttt:
See the TT. constants defined in this class
Definition provided by Oracle Spatial User�s Guide and Reference.
-
D
public static int D(Geometry geom)
Return D as defined by SDO_GTYPE (either 2,3 or 4).For normal JTS Geometry this will be 2 or 3 depending if geom.getCoordinate.z is Double.NaN.
Subclasses may override as required.
- Returns:
3
-
L
public static int L(Geometry geom)
Return L as defined by SDO_GTYPE (either 3,4 or 0).L represents support for LRS (Liniar Referencing System?). JTS Geometry objects do not support LRS so this will be 0.
Subclasses may override as required.
- Returns:
0
-
TT
public static int TT(Geometry geom)
Return TT as defined by SDO_GTYPE (represents geometry type).TT is used to represent the type of the JTS Geometry:
Value Geometry Type JTS Geometry 00 UNKNOWN_GEOMETRY null 01 POINT Point 02 LINE LineString CURVE not supported 03 POLYGON Polygon 04 COLLECTION GeometryCollection 05 MULTIPOINT MultiPoint 06 MULTILINE MultiLineString MULTICURVE not supported 07 MULTIPOLYGON MultiPolygon
- Returns:
TT
representinggeom
- Throws:
IllegalArgumentException
- If SDO_GTYPE can not be represetned by JTS
-
SRID
public static int SRID(Geometry geom)
Returns geometry SRID.SRID code representing Spatial Reference System. SRID number used must be defined in the Oracle MDSYS.CS_SRS table.
SRID_NULL
represents lack of coordinate system.- Parameters:
geom
- Geometry SRID Number (JTS14 uses GeometryFactor.getSRID() )- Returns:
SRID
for provided geom
-
point
public static double[] point(Geometry geom)
Return SDO_POINT_TYPE for geometryWill return non null for Point objects.
null
is returned for all non point objects.You cannot use this with LRS Coordinates
Subclasses may wish to repress this method and force Points to be represented using SDO_ORDINATES.
-
elemInfo
public static int[] elemInfo(Geometry geom)
Return SDO_ELEM_INFO array for geometryDescribes how to use Ordinates to represent Geometry.
# Name Meaning 0 SDO_STARTING_OFFSET Offsets start at one 1 SDO_ETYPE Describes how ordinates are ordered 2 SDO_INTERPRETATION SDO_ETYPE: 4, 1005, or 2005 Number of triplets involved in compound geometry SDO_ETYPE: 1, 2, 1003, or 2003 Describes ordering of ordinates in geometry
For compound elements (SDO_ETYPE values 4 and 5) the last element of one is the first element of the next.
- Parameters:
geom
- Geometry being represented- Returns:
- Descriptionof Ordinates representation
-
elemInfo
public static int[] elemInfo(Geometry geom, int GTYPE)
-
elemInfoStartingOffset
public static int elemInfoStartingOffset(Geometry geom)
Starting offset used by SDO_ORDINATES as stored in the SDO_ELEM_INFO array.Starting offsets start from one.
Describes ordinates as part of
SDO_ELEM_INFO
data type.- Returns:
1
for non nestedgeom
-
elemInfoEType
protected static int elemInfoEType(Geometry geom)
ProduceSDO_ETYPE
for geometry description as stored in theSDO_ELEM_INFO
.Describes how Ordinates are ordered:
Value Elements Meaning 0 Custom Geometry (like spline) 1 simple Point (or Points) 2 simple Line (or Lines) 3 polygon ring of unknown order (discouraged update to 1003 or 2003) 1003 simple polygon ring (1 exterior counterOrientationwise order) 2003 simple polygon ring (2 interior Orientationwise order) 4 compound series defines a linestring 5 compound series defines a polygon ring of unknown order (discouraged) 1005 compound series defines exterior polygon ring (counterOrientationwise order) 2005 compound series defines interior polygon ring (Orientationwise order)
Keep in mind:
simple
elements are defined by a single triplet entry in theSDO_ELEM_INFO
arraycompound
elements are defined by a header triplet, and a series of triplets for the parts. Elements in a compound element share first and last points.- We are not allowed to mix 1 digit and 4 digit values for ETYPE and GTYPE in a single geometry
This whole mess describes ordinates as part of
SDO_ELEM_INFO
array. data type.- Parameters:
geom
- Geometry being represented- Returns:
- Descriptionof Ordinates representation
-
elemInfoInterpretation
public static int elemInfoInterpretation(Geometry geom)
ProduceSDO_INTERPRETATION
for geometry description as stored in theSDO_ELEM_INFO
.Describes ordinates as part of
SDO_ELEM_INFO
array.compound
element:(SDO_ETYPE 4, 1005, or 2005)
Number of subsequent triplets are part of compound elementsimple
element:(SDE_ELEM 1, 2, 1003, or 2003)
Code defines how ordinates are interpreted (lines or curves)
SDO_INTERPRETAION Values: (from Table 2-2 in reference docs)
SDO_ETYPE Value Meaning 0 anything Custom Geometry 1 1 Point 1 N > 1 N points 2 1 LineString of straight lines 2 2 LineString connected by circ arcs (start,any,end pt) 1003/2003 1 Polygon Edged with straight lines 1003/2003 2 Polygon Edged with circ arcs (start, any, end pt) 1003/2003 3 Non SRID rectangle defined by (bottomleft,topright pt) 1003/2003 4 Circle defined by three points on circumference 4 N > 1 Compound Line String made of N (ETYPE=2) lines and arcs 1005/2005 N > 1 Polygon defined by (ETYPE=2) lines and arcs
When playing with circular arcs (SDO_INTERPRETATION==2) arcs are defined by three points. A start point, any point on the arc and the end point. The last point of an arc is the start point of the next. When used to describe a polygon (SDO_ETYPE==1003 or 2003) the first and last point must be the same.
-
elemInfoInterpretation
public static int elemInfoInterpretation(Geometry geom, int etype)
Allows specification ofINTERPRETATION
used to interpretgeom
.Provides the INTERPRETATION value for the ELEM_INFO triplet of (STARTING_OFFSET, ETYPE, INTERPRETATION).
- Parameters:
geom
- Geometry to encodeetype
- ETYPE value requiring an INTERPREATION- Returns:
- INTERPRETATION ELEM_INFO entry for geom given etype
- Throws:
IllegalArgumentException
- If asked to encode a curve
-
ordinates
public static double[] ordinates(Geometry geom)
ProduceSDO_ORDINATES
for geometry.Please see SDO_ETYPE, SDO_INTERPRETATION and SDO_GTYPE for description of how these ordinates are to be interpreted.
Ordinates are ordered by Dimension are non null:
-
Two Dimensional: {x1,y1,x2,y2,...}
-
Three Dimensional: {x1,y1,z1,x2,y2,z2,...}
Spatial will siliently detect and ignore the following:
- d001 point/d005 multipoint elements that are not SDO_ETYPE==1 points
- d002 lines or curve/d006 multilines or multicurve elements that are not SDO_ETYPE==2 lines or SDO_ETYPE==4 arcs
- d003 polygon/d007 multipolygon elements that are not SDO_ETYPE==3 unordered polygon lines or SDO_ETYPE==5 unorderd compound polygon ring are ignored
While Oracle is silient on these errors - all other errors will not be detected!
-
-
getCS
public static CoordinateSequence getCS(Geometry geom)
-
coordinates
public static void coordinates(List<double[]> list, Geometry geom)
Encode Geometry as described by GTYPE and ELEM_INFOCoordinateSequence & CoordinateAccess wil be used to determine the dimension, and the number of ordinates added.
- Parameters:
list
- Flat list of Doublegeom
- Geometry- Throws:
IllegalArgumentException
- If geometry cannot be encoded
-
ordinateArray
public static double[] ordinateArray(CoordinateSequence coords, int ordinate)
Package up array of requested ordinate, regardless of geometryExample numbering: for (x y g m) dimension==2, measure==2
- 0: x ordinate array
- 1: y ordinate array
- 2: g ordinate array
- 3: m ordinate array
-
ordinateArray
public static double[] ordinateArray(Coordinate[] array, int ordinate)
Ordinate access.CoordinateAccess is required for additional ordinates.
Ordinate limitied to:
- 0: x ordinate array
- 1: y ordinate array
- 2: z ordinate array
- 3: empty ordinate array
-
ordinateArray
public static double[] ordinateArray(List list, int ordinate)
-
ordinates
public static double[] ordinates(List list, Geometry geom)
Package uparray
in correct manner forgeom
.Ordinates are placed into an array based on:
- geometryGTypeD - chooses between 2d and 3d representation
- geometryGTypeL - number of LRS measures
-
ordinates2d
public static double[] ordinates2d(List list)
Ordinates (x,y,x1,y1,...) from coordiante list.No assumptions are made about the order
- Parameters:
list
- coordinate list- Returns:
- ordinate array
-
ordinates3d
public static double[] ordinates3d(List list)
Ordinates (x,y,z,x2,y2,z2...) from coordiante[] array.- Parameters:
list
- List of coordiante- Returns:
- ordinate array
-
ordinates2d
public static double[] ordinates2d(List list, int L)
Ordinates (x,y,...id,x2,y2,...) from coordiante[] List.- Parameters:
list
- coordiante listL
- Dimension of ordinates required for representation- Returns:
- ordinate array
-
ordinates3d
public static double[] ordinates3d(List list, int L)
Ordinates (x,y,z,...id,x2,y2,z2...) from coordiante[] array.- Parameters:
list
- coordinate array to be represented as ordinatesL
- Dimension of ordinates required for representation- Returns:
- ordinate array
-
counterClockWise
public static CoordinateSequence counterClockWise(CoordinateSequenceFactory factory, CoordinateSequence ring)
Ensure Ring of Coordinates are in a counter Orientationwise order.If the Coordinate need to be reversed a copy will be returned.
- Parameters:
factory
- Factory to used to reverse CoordinateSequencering
- Ring of Coordinates- Returns:
- coords in a CCW order
-
D
public static int D(int GTYPE)
Access D (for dimension) as encoded in GTYPE
-
L
public static int L(int GTYPE)
Access L (for LRS) as encoded in GTYPE
-
TT
public static int TT(int GTYPE)
Access TT (for geometry type) as encoded in GTYPE
-
asCoordinates
public static Coordinate[] asCoordinates(double[] ordinates)
Coordinates from(x,y,x2,y2,...)
ordinates.
-
asCoordinates
public static Coordinate[] asCoordinates(double[] ordinates, int d)
Coordinates from a(x,y,i3..,id,x2,y2...)
ordinates.
-
coordinates
public static CoordinateSequence coordinates(CoordinateSequenceFactory f, int GTYPE, double[] ordinates)
Construct CoordinateList as described by GTYPE.GTYPE encodes the following information:
- D: Dimension of ordinates
- L: Ordinate that represents the LRS measure
The number of ordinates per coordinate are taken to be D, and the number of ordinates should be a multiple of this value.
In the Special case of GTYPE 2001 and a three ordinates are interpreted as a single Coordinate rather than an error.
For 3-dimensional coordinates we assume z to be the third ordinate. If the LRS measure value is stored in the third ordinate (L=3) we assume a 2-dimensional coordinate.
- Parameters:
f
- CoordinateSequenceFactory used to encode ordiantes for JTSGTYPE
- Encoding of Dimension, LRS and TType
-
coordiantes
public static CoordinateSequence coordiantes(CoordinateSequenceFactory f, OrdinateList x, OrdinateList y, OrdinateList z)
Construct CoordinateSequence with no LRS measures.To produce two dimension Coordinates pass in
null
for z
-
coordiantes
public static CoordinateSequence coordiantes(CoordinateSequenceFactory f, AttributeList x, AttributeList y, AttributeList z)
Construct CoordinateSequence with no LRS measures.To produce two dimension Coordinates pass in
null
for z
-
coordiantes
public static CoordinateSequence coordiantes(CoordinateSequenceFactory f, OrdinateList x, OrdinateList y, OrdinateList z, OrdinateList m)
bugfix 20121231-BK: added: TODO org.geotools.geometry.jts.CoordinateSequenceFactory does not support 4 dimensions! Construct CoordinateSequence with LRS measures.To produce three dimension Coordinates pass in
null
for z- Parameters:
f
-CoordinateSequenceFactory
x
- x-ordinatesy
- y-ordinatesz
- z-ordinates,null
for 2Dm
- m-ordinates- Returns:
CoordinateSequence
-
create
public static Geometry create(GeometryFactory gf, int GTYPE, int SRID, double[] point, int[] elemInfo, double[] ordinates)
Decode geometry from provided SDO encoded information.- Parameters:
gf
- Used to construct returned GeometryGTYPE
- SDO_GTYPE represents dimension, LRS, and geometry typeSRID
- SDO_SRID represents Spatial Reference System- Returns:
- Geometry as encoded
-
create
public static Geometry create(GeometryFactory gf, int GTYPE, int SRID, int[] elemInfo, int triplet, CoordinateSequence coords, int N)
Consturct geometry with SDO encoded information over a CoordinateList.Helpful when dealing construction Geometries with your own Coordinate Types. The dimensionality specified in GTYPE will be used to interpret the offsets in elemInfo.
- Parameters:
GTYPE
- Encoding of Dimension, LRS and TTypeN
- Number of triplets (-1 for unknown/don't care)- Returns:
- Geometry as encoded, or null w/ log if it cannot be represented via JTS
-
-