com.mizar.persistence.jpa.utils
Class JGeometryUtils

java.lang.Object
  extended by com.mizar.persistence.jpa.utils.JGeometryUtils

public class JGeometryUtils
extends java.lang.Object


Field Summary
static int geographicWGS84
           
 
Constructor Summary
protected JGeometryUtils()
           
 
Method Summary
static oracle.spatial.geometry.JGeometry convertTo2D(oracle.spatial.geometry.JGeometry geom)
           
static oracle.spatial.geometry.JGeometry createRectangle(double[] range, int srid)
           
static oracle.spatial.geometry.JGeometry equalEndPoints(oracle.spatial.geometry.JGeometry geom1, oracle.spatial.geometry.JGeometry geom2, double tolerance)
           
static GeometryBean findIn(javax.persistence.EntityManager em, double[] xy, int srid, java.lang.String primaryFilter, java.lang.String alias, java.lang.Class beanClass, java.lang.String geomProperty)
          Does a SDO_RELATE with MASK=CONTAINS+COVERS
static java.util.List<GeometryBean> findIn(javax.persistence.EntityManager em, double[] xy, int srid, java.lang.String primaryFilter, java.lang.String alias, java.lang.Class beanClass, java.lang.String geomProperty, int count)
          Does a SDO_RELATE with MASK=CONTAINS+COVERS
static GeometryBean findNearest(javax.persistence.EntityManager em, double[] xy, int srid, java.lang.String primaryFilter, java.lang.String alias, java.lang.Class beanClass, java.lang.String geomProperty)
           
static GeometryBean findNearest(javax.persistence.EntityManager em, double[] xy, int srid, java.lang.String primaryFilter, java.lang.String alias, java.lang.Class beanClass, java.lang.String geomProperty, double maxDistance)
           
static java.util.List<GeometryBean> findNearest(javax.persistence.EntityManager em, double[] xy, int srid, java.lang.String primaryFilter, java.lang.String alias, java.lang.Class beanClass, java.lang.String geomProperty, int count)
          Does a SDO_NN with rownum <= count
static double[][] findNearestPoints(oracle.spatial.geometry.JGeometry geom, double[] newPoint)
           
static java.util.List<GeometryBean> findSdoRelate(javax.persistence.EntityManager em, oracle.spatial.geometry.JGeometry geom, java.lang.String primaryFilter, java.lang.String alias, java.lang.Class beanClass, java.lang.String geomProperty, int maxRows)
           
static double getAngle(oracle.spatial.geometry.JGeometry geom)
           
static double getArea(oracle.spatial.geometry.JGeometry geom)
           
static java.awt.geom.Point2D getCenter(double[] range)
           
static java.awt.geom.Point2D getCenter(oracle.spatial.geometry.JGeometry geom)
           
static java.awt.geom.Point2D getCentroid(oracle.spatial.geometry.JGeometry geom)
           
static java.awt.geom.Point2D getFirstPoint(oracle.spatial.geometry.JGeometry geom)
           
static java.lang.String getGeographicDescription(oracle.spatial.geometry.JGeometry geom)
           
static double[] getGeographicPoint(oracle.spatial.geometry.JGeometry geom)
           
static java.awt.geom.Point2D getLastPoint(oracle.spatial.geometry.JGeometry geom)
           
static double getLength(oracle.spatial.geometry.JGeometry geom)
           
static double getLengthAlong(oracle.spatial.geometry.JGeometry geom, double[] point)
           
static java.util.List<GeometryBean> getListSQL(javax.persistence.EntityManager em, javax.persistence.Query query, int maxRows)
           
static java.util.List<GeometryBean> getListSQL(javax.persistence.EntityManager em, java.lang.String sql, java.lang.Class resultClass, int maxRows)
           
static double[] getMidPoint(oracle.spatial.geometry.JGeometry geom)
           
static double[] getOrdinateArray(oracle.spatial.geometry.JGeometry geom)
          This calls JGeometry getOrdinatesArray() and if that is empty it then calls Jgeometry.getPoint();
static double[] getOrdinateArray2D(oracle.spatial.geometry.JGeometry geom)
          BUG BUG -- this does not work for annotated points This calls JGeometryUtils.getOrdinatesArray() but only returns the XY ordinates
static double[] getOrdinates(java.awt.geom.Point2D point)
           
static double[] getOrdinates(java.awt.geom.Point2D[] points)
           
static double[] getPoint(oracle.spatial.geometry.JGeometry geom)
          This checks JGeometry.getPoint() and if a point does not exist then it calls JGeometry.getFirstPoint();
static double[] getPointAlong(oracle.spatial.geometry.JGeometry geom, double distance)
           
static double[] getRange(java.util.ArrayList<oracle.spatial.geometry.JGeometry> geoms)
           
static double[] getRange(java.util.ArrayList<oracle.spatial.geometry.JGeometry> geoms, double[] currentRange)
           
static double[] getRange(oracle.spatial.geometry.JGeometry geom)
           
static double[] getRange(oracle.spatial.geometry.JGeometry geom, double[] currentRange)
           
static java.lang.String getWKT(double[] ordinates2d, double precision)
           
static java.lang.String getWKT(double[] ordinates2d, double precision, int maxFractionDigits)
          Allows you to specify the number of fractional digits in the WKT
static java.lang.String getWKT(oracle.spatial.geometry.JGeometry geom, double precision)
           
static java.lang.String getWKT(oracle.spatial.geometry.JGeometry geom, double precision, int maxFractionDigits)
          Allows you to specify the number of fractional digits in the WKT
static java.lang.String getWKT(oracle.spatial.geometry.JGeometry geom, int maxFractionDigits)
           
static java.lang.String getWKTLinestring(double[] ordinates2d, int maxFractionDigits)
           
static java.lang.String getWKTPoint(double[] ordinates2d, int maxFractionDigits)
           
static java.lang.String getWKTPoint(oracle.spatial.geometry.JGeometry geom, double precision)
           
static java.lang.String getWKTPolygon(double[] ordinates2d, double precision)
           
static java.lang.String getWKTPolygon(double[] ordinates2d, int maxFractionDigits)
           
static java.lang.String getWKTPolyline(double[] ordinates2d, int maxFractionDigits)
           
static java.lang.String getWKTPolyline(oracle.spatial.geometry.JGeometry geom, double precision)
           
static double getZ(double[] xy, double[] triangle)
          The method computes the elevation of an XY location projected onto a plane described by a three-dimensional triangle.
static oracle.spatial.geometry.JGeometry insertPoint(oracle.spatial.geometry.JGeometry geom, double[] beforePoint, double[] afterPoint, double[] newPoint)
           
static boolean isGeographic(int srid)
           
static boolean isPointInsidePolygon(double[] polygon, oracle.spatial.geometry.JGeometry point)
           
static boolean isPointInsidePolygon(oracle.spatial.geometry.JGeometry polygon, double[] point)
           
static boolean isPointInsidePolygon(oracle.spatial.geometry.JGeometry polygon, oracle.spatial.geometry.JGeometry point)
          If there are more than 20 vertices the method will compute the MBR of the polygon to enable quick rejection
static boolean isUTM(int srid)
           
static boolean matches(oracle.spatial.geometry.JGeometry geom1, oracle.spatial.geometry.JGeometry geom2)
          Compares two geometries for identical characteristics.
static oracle.spatial.geometry.JGeometry removePoint(oracle.spatial.geometry.JGeometry geom, double[] oldPoint)
           
static oracle.spatial.geometry.JGeometry replacePoint(oracle.spatial.geometry.JGeometry geom, double[] oldPoint, double[] newPoint)
           
static oracle.spatial.geometry.JGeometry reverse(oracle.spatial.geometry.JGeometry geom)
           
static oracle.spatial.geometry.JGeometry transform(oracle.spatial.geometry.JGeometry fromGeom, int toSrid, javax.persistence.EntityManager em)
           
static oracle.spatial.geometry.JGeometry transform(oracle.spatial.geometry.JGeometry geom, int toSrid, java.lang.String managedDatasource)
           
static oracle.spatial.geometry.JGeometry transformPoint(oracle.spatial.geometry.JGeometry point, int toSrid, javax.persistence.EntityManager em)
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

geographicWGS84

public static final int geographicWGS84
See Also:
Constant Field Values
Constructor Detail

JGeometryUtils

protected JGeometryUtils()
Method Detail

isGeographic

public static boolean isGeographic(int srid)
Parameters:
srid -
Returns:

isUTM

public static boolean isUTM(int srid)
Parameters:
srid -
Returns:

getPoint

public static double[] getPoint(oracle.spatial.geometry.JGeometry geom)
                         throws java.sql.SQLException
This checks JGeometry.getPoint() and if a point does not exist then it calls JGeometry.getFirstPoint();

Parameters:
geom -
Returns:
Throws:
java.sql.SQLException

getOrdinateArray

public static double[] getOrdinateArray(oracle.spatial.geometry.JGeometry geom)
                                 throws java.sql.SQLException
This calls JGeometry getOrdinatesArray() and if that is empty it then calls Jgeometry.getPoint();

Parameters:
geom -
Returns:
Throws:
java.sql.SQLException

convertTo2D

public static oracle.spatial.geometry.JGeometry convertTo2D(oracle.spatial.geometry.JGeometry geom)

getOrdinateArray2D

public static double[] getOrdinateArray2D(oracle.spatial.geometry.JGeometry geom)
BUG BUG -- this does not work for annotated points This calls JGeometryUtils.getOrdinatesArray() but only returns the XY ordinates

Parameters:
geom -
Returns:
See Also:
getOrdinateArray(JGeometry)

matches

public static boolean matches(oracle.spatial.geometry.JGeometry geom1,
                              oracle.spatial.geometry.JGeometry geom2)
                       throws GeometryException
Compares two geometries for identical characteristics.

Parameters:
geom1 -
geom2 -
Returns:
true if the geometries match for dimensions, srid, type, elementInfo, and coordinates; or if both are null
Throws:
GeometryException

equalEndPoints

public static oracle.spatial.geometry.JGeometry equalEndPoints(oracle.spatial.geometry.JGeometry geom1,
                                                               oracle.spatial.geometry.JGeometry geom2,
                                                               double tolerance)
                                                        throws GeometryException
Throws:
GeometryException

getWKTPolygon

public static java.lang.String getWKTPolygon(double[] ordinates2d,
                                             double precision)
Parameters:
ordinates2d - an array of XY (2d) ordinates that form a closed polygon
precision -
Returns:
a Well Known Text (WKT) POLYGON
See Also:
getWKTPolygon(double[],int)

getWKTPolygon

public static java.lang.String getWKTPolygon(double[] ordinates2d,
                                             int maxFractionDigits)
Parameters:
ordinates2d - an array of XY (2d) ordinates that form a closed polygon
maxFractionDigits - the number of significant decimal places
Returns:
a Well Known Text (WKT) POLYGON
See Also:
getWKTPolygon(double[],double)

getWKTPolyline

public static java.lang.String getWKTPolyline(oracle.spatial.geometry.JGeometry geom,
                                              double precision)

getWKTPolyline

public static java.lang.String getWKTPolyline(double[] ordinates2d,
                                              int maxFractionDigits)
Parameters:
ordinates2d - an array of XY (2d) ordinates describing a linestring
maxFractionDigits - the number of significant decimal places
Returns:
a Well Known Text (WKT) LINESTRING

getWKTLinestring

public static java.lang.String getWKTLinestring(double[] ordinates2d,
                                                int maxFractionDigits)

getWKTPoint

public static java.lang.String getWKTPoint(oracle.spatial.geometry.JGeometry geom,
                                           double precision)

getWKTPoint

public static java.lang.String getWKTPoint(double[] ordinates2d,
                                           int maxFractionDigits)
Parameters:
ordinates2d - a double[2] array of XY ordinates describing a point
maxFractionDigits - the number of significant decimal places
Returns:
a Well Known Text (WKT) POINT

getWKT

public static java.lang.String getWKT(oracle.spatial.geometry.JGeometry geom,
                                      double precision,
                                      int maxFractionDigits)
Allows you to specify the number of fractional digits in the WKT

Parameters:
geom -
precision -
maxFractionDigits - Maximum fraction digits, -1 for all digits possible
Returns:

getWKT

public static java.lang.String getWKT(oracle.spatial.geometry.JGeometry geom,
                                      double precision)

getWKT

public static java.lang.String getWKT(double[] ordinates2d,
                                      double precision,
                                      int maxFractionDigits)
Allows you to specify the number of fractional digits in the WKT

Parameters:
geom -
precision -
maxFractionDigits - Maximum fraction digits, -1 for all digits possible
Returns:

getWKT

public static java.lang.String getWKT(double[] ordinates2d,
                                      double precision)

getWKT

public static java.lang.String getWKT(oracle.spatial.geometry.JGeometry geom,
                                      int maxFractionDigits)

createRectangle

public static oracle.spatial.geometry.JGeometry createRectangle(double[] range,
                                                                int srid)

getRange

public static double[] getRange(oracle.spatial.geometry.JGeometry geom)

getRange

public static double[] getRange(oracle.spatial.geometry.JGeometry geom,
                                double[] currentRange)

getRange

public static double[] getRange(java.util.ArrayList<oracle.spatial.geometry.JGeometry> geoms,
                                double[] currentRange)

getRange

public static double[] getRange(java.util.ArrayList<oracle.spatial.geometry.JGeometry> geoms)

getOrdinates

public static double[] getOrdinates(java.awt.geom.Point2D point)

getOrdinates

public static double[] getOrdinates(java.awt.geom.Point2D[] points)

getCenter

public static java.awt.geom.Point2D getCenter(oracle.spatial.geometry.JGeometry geom)
Parameters:
geom -
Returns:
the center of the MBR of geom

getCentroid

public static java.awt.geom.Point2D getCentroid(oracle.spatial.geometry.JGeometry geom)
Parameters:
geom -
Returns:
the centroid of geom

getCenter

public static java.awt.geom.Point2D getCenter(double[] range)

getFirstPoint

public static java.awt.geom.Point2D getFirstPoint(oracle.spatial.geometry.JGeometry geom)

getLastPoint

public static java.awt.geom.Point2D getLastPoint(oracle.spatial.geometry.JGeometry geom)

getAngle

public static double getAngle(oracle.spatial.geometry.JGeometry geom)
                       throws GeometryException
Throws:
GeometryException

getLength

public static double getLength(oracle.spatial.geometry.JGeometry geom)
                        throws GeometryException
Throws:
GeometryException

getLengthAlong

public static double getLengthAlong(oracle.spatial.geometry.JGeometry geom,
                                    double[] point)
                             throws GeometryException
Throws:
GeometryException

getPointAlong

public static double[] getPointAlong(oracle.spatial.geometry.JGeometry geom,
                                     double distance)
                              throws GeometryException
Throws:
GeometryException

getMidPoint

public static double[] getMidPoint(oracle.spatial.geometry.JGeometry geom)
                            throws GeometryException
Throws:
GeometryException

getZ

public static double getZ(double[] xy,
                          double[] triangle)
The method computes the elevation of an XY location projected onto a plane described by a three-dimensional triangle.

Parameters:
xy - a two dimensional double array describing an XY location. xy is not required to lie inside triangle
triangle - an array of 9 doubles describing a triangle in 3 dimensions {x1,y1,z1,x2,y2,z2,x3,y3,z3}
Returns:
the Z value of xy such that xyz lies on the plane described by triangle

getGeographicDescription

public static java.lang.String getGeographicDescription(oracle.spatial.geometry.JGeometry geom)

getGeographicPoint

public static double[] getGeographicPoint(oracle.spatial.geometry.JGeometry geom)

findNearest

public static GeometryBean findNearest(javax.persistence.EntityManager em,
                                       double[] xy,
                                       int srid,
                                       java.lang.String primaryFilter,
                                       java.lang.String alias,
                                       java.lang.Class beanClass,
                                       java.lang.String geomProperty,
                                       double maxDistance)
                                throws java.sql.SQLException,
                                       GeometryException
Parameters:
em -
xy - a 2-dimensional XY coordinate
srid - the Oracle spatial reference identifier
primaryFilter - an SQL clause to prepend to the computed where clause (do not include the word WHERE)
alias - an alias (may be optional unless used in the primaryFilter)
beanClass - the class of the bean to return
geomProperty - the name of the geometry property, defaults to "geom"
maxDistance - the maximum distance the returned GeometryBean may be from xy. If the nearest bean found is beyond this distance it will be ignored.
Returns:
an instance of a GeometryBean
Throws:
java.sql.SQLException
GeometryException

findNearest

public static GeometryBean findNearest(javax.persistence.EntityManager em,
                                       double[] xy,
                                       int srid,
                                       java.lang.String primaryFilter,
                                       java.lang.String alias,
                                       java.lang.Class beanClass,
                                       java.lang.String geomProperty)
Parameters:
em -
xy - a 2-dimensional XY coordinate
srid - the Oracle spatial reference identifier
primaryFilter - an SQL clause to prepend to the computed where clause (do not include the word WHERE)
alias - an alias (may be optional unless used in the primaryFilter)
beanClass - the class of the bean to return
geomProperty - the name of the geometry property, defaults to "geom"
Returns:
an instance of a GeometryBean

findNearest

public static java.util.List<GeometryBean> findNearest(javax.persistence.EntityManager em,
                                                       double[] xy,
                                                       int srid,
                                                       java.lang.String primaryFilter,
                                                       java.lang.String alias,
                                                       java.lang.Class beanClass,
                                                       java.lang.String geomProperty,
                                                       int count)
Does a SDO_NN with rownum <= count

Parameters:
em -
xy - a 2-dimensional XY coordinate
srid - the Oracle spatial reference identifier
primaryFilter - an SQL clause to prepend to the computed where clause (do not include the word WHERE)
alias - an alias (may be optional unless used in the primaryFilter)
beanClass - the class of the bean to return
geomProperty - the name of the geometry property, defaults to "geom"
count - the maximum number of GeometryBeans to return.
Returns:
a List of GeometryBeans

findSdoRelate

public static java.util.List<GeometryBean> findSdoRelate(javax.persistence.EntityManager em,
                                                         oracle.spatial.geometry.JGeometry geom,
                                                         java.lang.String primaryFilter,
                                                         java.lang.String alias,
                                                         java.lang.Class beanClass,
                                                         java.lang.String geomProperty,
                                                         int maxRows)

findIn

public static java.util.List<GeometryBean> findIn(javax.persistence.EntityManager em,
                                                  double[] xy,
                                                  int srid,
                                                  java.lang.String primaryFilter,
                                                  java.lang.String alias,
                                                  java.lang.Class beanClass,
                                                  java.lang.String geomProperty,
                                                  int count)
Does a SDO_RELATE with MASK=CONTAINS+COVERS

Parameters:
em -
xy - a 2-dimensional XY coordinate
srid - the Oracle spatial reference identifier
primaryFilter - an SQL clause to prepend to the computed where clause (do not include the word WHERE)
alias - an alias (may be optional unless used in the primaryFilter)
beanClass - the class of the bean to return
geomProperty - the name of the geometry property, defaults to "geom"
count - the maximum number of GeometryBeans to return.
Returns:
a List of GeometryBeans

findIn

public static GeometryBean findIn(javax.persistence.EntityManager em,
                                  double[] xy,
                                  int srid,
                                  java.lang.String primaryFilter,
                                  java.lang.String alias,
                                  java.lang.Class beanClass,
                                  java.lang.String geomProperty)
Does a SDO_RELATE with MASK=CONTAINS+COVERS

Parameters:
em -
xy - a 2-dimensional XY coordinate
srid - the Oracle spatial reference identifier
primaryFilter - an SQL clause to prepend to the computed where clause (do not include the word WHERE)
alias - an alias (may be optional unless used in the primaryFilter)
beanClass - the class of the bean to return
geomProperty - the name of the geometry property, defaults to "geom"
Returns:
an instance of a GeometryBean

transformPoint

@Deprecated
public static oracle.spatial.geometry.JGeometry transformPoint(oracle.spatial.geometry.JGeometry point,
                                                                          int toSrid,
                                                                          javax.persistence.EntityManager em)
                                                        throws java.sql.SQLException,
                                                               javax.naming.NamingException
Deprecated. 

Throws:
java.sql.SQLException
javax.naming.NamingException
See Also:
transform(JGeometry,int,EntityManager)

transform

public static oracle.spatial.geometry.JGeometry transform(oracle.spatial.geometry.JGeometry fromGeom,
                                                          int toSrid,
                                                          javax.persistence.EntityManager em)
                                                   throws java.sql.SQLException,
                                                          javax.naming.NamingException
Parameters:
fromGeom -
toSrid -
em -
Returns:
Throws:
java.sql.SQLException
javax.naming.NamingException

transform

public static oracle.spatial.geometry.JGeometry transform(oracle.spatial.geometry.JGeometry geom,
                                                          int toSrid,
                                                          java.lang.String managedDatasource)
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getListSQL

public static java.util.List<GeometryBean> getListSQL(javax.persistence.EntityManager em,
                                                      java.lang.String sql,
                                                      java.lang.Class resultClass,
                                                      int maxRows)
Parameters:
em -
sql -
resultClass -
Returns:

getListSQL

public static java.util.List<GeometryBean> getListSQL(javax.persistence.EntityManager em,
                                                      javax.persistence.Query query,
                                                      int maxRows)
Parameters:
em - an open EntityManager
query - a valid Query
maxRows - the maximum number of rows to return
Returns:
a list of GeometryBeans

getArea

public static double getArea(oracle.spatial.geometry.JGeometry geom)

reverse

public static oracle.spatial.geometry.JGeometry reverse(oracle.spatial.geometry.JGeometry geom)
                                                 throws GeometryException
Throws:
GeometryException

findNearestPoints

public static double[][] findNearestPoints(oracle.spatial.geometry.JGeometry geom,
                                           double[] newPoint)

insertPoint

public static oracle.spatial.geometry.JGeometry insertPoint(oracle.spatial.geometry.JGeometry geom,
                                                            double[] beforePoint,
                                                            double[] afterPoint,
                                                            double[] newPoint)

removePoint

public static oracle.spatial.geometry.JGeometry removePoint(oracle.spatial.geometry.JGeometry geom,
                                                            double[] oldPoint)

replacePoint

public static oracle.spatial.geometry.JGeometry replacePoint(oracle.spatial.geometry.JGeometry geom,
                                                             double[] oldPoint,
                                                             double[] newPoint)

isPointInsidePolygon

public static boolean isPointInsidePolygon(oracle.spatial.geometry.JGeometry polygon,
                                           oracle.spatial.geometry.JGeometry point)
                                    throws GeometryException
If there are more than 20 vertices the method will compute the MBR of the polygon to enable quick rejection

Parameters:
polygon - this must be a simple 2D polygon without holes or islands
point - this must be a point geometry
Returns:
Throws:
GeometryException
See Also:
Polygon.isPointInsidePolygon(double[] polygon, double[] point), Polygon.isPointInsidePolygon(double[] mbr, double[] polygon, double[] point)

isPointInsidePolygon

public static boolean isPointInsidePolygon(double[] polygon,
                                           oracle.spatial.geometry.JGeometry point)
                                    throws GeometryException
Parameters:
polygon - this must be a simple 2D polygon without holes or islands
point - this must be a point geometry
Returns:
Throws:
GeometryException
See Also:
Polygon.isPointInsidePolygon(double[] polygon, double[] point), Polygon.isPointInsidePolygon(double[] mbr, double[] polygon, double[] point)

isPointInsidePolygon

public static boolean isPointInsidePolygon(oracle.spatial.geometry.JGeometry polygon,
                                           double[] point)
Parameters:
polygon - this must be a simple 2D polygon without holes or islands
point - this must be a point geometry
Returns:
See Also:
Polygon.isPointInsidePolygon(double[] polygon, double[] point), Polygon.isPointInsidePolygon(double[] mbr, double[] polygon, double[] point)