- Web viewNote: Oracle JDBC drivers cache array and structure descriptors. ... Projects ageometry...
Transcript of - Web viewNote: Oracle JDBC drivers cache array and structure descriptors. ... Projects ageometry...
Informācijas sistēma ar grafikas izmantošanu.Objektu transformēšanas nepieciešamība
SQL objekts
Datu bāzes sistēma
Datu bāze
Datu bāzes
vadības sistēma
SDO_GEOMETRY
Lietojums
JDBC interfeiss
Java objekts
JDBC DBS draiveris
1
Datu bāzes SDO_GEOMETRY tipa ģeometriju objektu transformēšana (attēlošana) programmēšanas valodas Java objektos
JGeometry klase1
MDSYS.SDO_GEOMETRY JGeometry
java.lang.Object oracle.spatial.geometry.JGeometry
A Java class that maps Oracle Spatial's SQL type MDSYS.SDO_GEOMETRY. Provides basic access functions to the geomeries stroed in Oracle Spatial database.
Packagesoracle.spatial.geometry
Provides support for the Spatial SQL SDO_GEOMETRY data type.
oracle.spatial.network Provides support for the Oracle Spatial network data model.
oracle.spatial.topo Provides support for the Oracle Spatial topology data model.
oracle.spatial.util Provides classes that perform miscellaneous operations.
1 http://docs.oracle.com/cd/B19306_01/appdev.102/b14373/oracle/spatial/geometry/JGeometry.html
2
Grafiskās datu bāzes datu vizualizācija izmantojot Java klasi JGEOMETRY
Datu bāzes sistēma
Datu bāze
Datu bāzes
vadības sistēma
SDO_GEOMETRY
Lietojums
JDBC interfeiss
JGEOMETRY
Java2D(vizualizācija)
3
Datu bāzes objektu transformēšana Java objektos
1. Vāji tipizētās noklusētās Java klases (weakly typed default Java class) Struct (Java) vai STRUCT (Oracle) izmantošana objektu transformēšanai. Šis variants ir efektīvāks un vienkāršāks.
2. Stipri tipizētas pašveidotās Java klases (strongly typed custom Java classe) izveidošana Oracle objektiem.
Literatūra
1. R. M. Menon. Expert Oracle JDBC Programming. Apress, 2005, 744. Lpp.
2.Kuassi Mensah. Oracle Database programming using Java and Web Services. Elsevier Digital Press publications, 2006.
Programmēšanas Java objekti
Relāciju-objektu datu bāzes objekti
Javas objekts
SQL objekts
JDBC SQLData interfeiss
Objekta tipu transformāciju apraksti
JDBC
Struct (Java)STRUCT (Oracle)
4
Telpas datu datu bāzes lietojuma izveidošana izmantojot IDE rīku NetBeans
Lietojums
IDE NetBeans 7.3.1
Datu bāzes sistēma
JDBC interfeiss
JDK 7
SQL Developer
DBVS
Grafikas datu bāze
Bibliotēkas
5
Klases java.sql.Struct izmantošana datu bāzes un Java objektu savstarpējai transformēšanai
ResultSet rs= stmt.executeQuery( "SELECT * FROM TABULA");java.sql.Struct jdbcStruct = (java.sql.Struct)rs.getObject(1);
java.sql.Struct instance and use the following standard methods:1) getAttributes(map). This method retrieves the values of the
attributes, using entries in the specified type map to determine the Java classes to use in materializing any attribute that is a structured object type. The Java types for other attribute values would be the same as for a getObject call on data of the underlying SQL type.
2) getAttributes. This method is the same as the preceding getAttributes(map) method, except it uses the default type map for the connection.
3) getSQLTypeName. This method returns a Java String that represents the fully qualified name of the Oracle object type that this Struct represents.
You can use standard JDBC functionality, such as getObject, to retrieve an Oracle object from the database as an instance of java.sql.Struct. Because getObject returns a java.lang.Object, you must cast the output of the method to Struct. For example:
Struktūra:java.sql.Struct
Datu bāzes sistēma
Struktūrasjava.sql.Struct
metodes:1) getAttributes(map)2) get Attributes3) getSQLTypeName
Izveidoša
6
Klases oracle.sql.STRUCT izmantošana datu bāzes un Java objektu savstarpējai transformēšanai
oracle.sql.Datum[] attrs = oracleSTRUCT.getOracleAttributes();
oracle.sql.Datum[] attrs = ((oracle.sql.STRUCT)jdbcStruct).getOracleAttributes();
Object[] attrs = jdbcStruct.getAttributes();
You can select data from the database into STRUCT objects and create STRUCT objects for inserting data into the database. STRUCT objects completely preserve data, because they maintain the data in SQL format. Using STRUCT objects is more efficient and more precise in situations where you do not need the information in an application specific form.If you want to take advantage of the extended functionality offered by Oracle-defined methods, then use an oracle.sql.STRUCT instance.The oracle.sql.STRUCT class implements the java.sql.Struct interface and provides extended functionality beyond the JDBC 2.0 standard.The STRUCT class includes the following methods in addition to standard Struct functionality:
1) getOracleAttributes. Retrieves the values of the values array as oracle.sql.* objects2) getDescriptor. Returns the StructDescriptor object for the SQL type that corresponds to this
STRUCT object.3) getJavaSQLConnection. Returns the current connection instance.4) toJdbc. Consults the default type map of the connection to determine what class to map to and,
then, uses toClass.5) toJdbc(map). Consults the specified type map to determine what class to map to, and then uses
toClassIf you want to retrieve Oracle object attributes from a STRUCT or Struct instance as oracle.sql types, then use the getOracleAttributes method of the oracle.sql.STRUCT class, as follows:
oracle.sql.Datum[] attrs = oracleSTRUCT.getOracleAttributes();or:oracle.sql.Datum[] attrs = ((oracle.sql.STRUCT)jdbcStruct).getOracleAttributes();
Struktūra:oracle.sql.STRUCT Datu bāzes
sistēma
Struktūrasoracle.sql.STRUCT
metodes:1) getOracleAttributes2) getDescriptor3) getJavaSQLConnection4) toJdbc5) toJdbc(map)
Izveidošana
7
If you want to retrieve Oracle object attributes as standard Java types from a STRUCT or Struct instance, use the standard getAttributes method:
Object[] attrs = jdbcStruct.getAttributes();
Note: Oracle JDBC drivers cache array and structure descriptors. This provides enormous performance benefits. However, it means that if you change the underlying type definition of a structure type in the database, the cached descriptor for that structure type will become stale and your application will receive a SQLException exception.
8
oracle.spatial.geometry.JGeometry klase
Nodrošina:1) SDO_GEOMETRY tipa objektu nolasīšana un ievade datu bāzē;2) SDO_GEOMETRY tipa objektu pārbaude;3) jaunu SDO_GEOMETRY tipa objektu izveidošana;4) SDO_GEOMETRY tipa objektu transformāciju veikšana.
SDO_GEOMETRY SELECT JDBC
oracle.sql.STRUCT objekts JGeometry
JGeometry INSERT JDBC UPDATE
oracle.sql.STRUCT objekts SDO_GEOMETRY
9
oracle.sql.STRUCT objekts JGeometry objekts
1. variants load()oracle.sql.STRUCT oracle.spatial.JGeometry objekts objekts store()
// SDO_GEOMETRY tipa objekta nolasīšana no datu bāzes.// Tabula VALSTIS, SDO_GEOMETRY tipa kolona GEOMETRIJA.ResultSet rs = statement.executeQuery("select GEOMETRIJA from VALSTIS where NOSAUKUMS = 'Latvija'");//SDO_GEOMETRY tipa objekta transformēšana JGeometry tipa objektā.STRUCT st = (oracle.sql.STRUCT) rs.getObject(1);JGeometry j_geom = JGeometry.load(st);
// SDO_GEOMETRY tipa objekta ierakstīšanas datu bāzē komandas// definēšana.PreparedStatement ps = connection.prepareStatement("update VALSTIS set GEOMETRIJA =? where NOSAUKUMS = 'Latvija'");//JGeometry tipa objekta transformēšana SDO_GEOMETRY tipa objektāSTRUCT obj = JGeometry.store(j_geom, connection);ps.setObject(1, obj);ps.execute();
Prasības:1) Oracle JDBC driver ver. 8.1.7 or higher;2) JDK 1.2 or higher (for Java2D support).
10
oracle.sql.STRUCT objekts JGeometry objekts
2. variants (pickling, unpicling)
1. variants load()SDO_GEOMETRY byte[] oracle.spatial. objekts masīvs JGeometry store()
// SDO_GEOMETRY tipa objekta nolasīšana no datu bāzes.// Tabula VALSTIS, SDO_GEOMETRY tipa kolona GEOMETRIJA.ResultSet rs = statement.executeQuery("select GEOMETRIJA from VALSTIS where NOSAUKUMS = 'Latvija'");byte[] image = ((OracleResultSet)rs).getBytes(1);//convert image into a JGeometry object using the SDO picklerJGeometry j_geom = JGeometry.load(image);
// SDO_GEOMETRY tipa objekta ierakstīšanas datu bāzē komandas// definēšanaPreparedStatement ps = connection.prepareStatement("update VALSTIS set GEOMETRIJA =? where NOSAUKUMS = 'Latvija'");//JGeometry tipa objekta transformēšana SDO_GEOMETRY tipa objektāSTRUCT obj = JGeometry.store(connection, j_geom);ps.setObject(1, obj);ps.execute();
11
The following is an example. First use the getObject() method of the result set to extract the geometry object for each row into a STRUCT and then use the static load() method of JGeometry to convert it into a JGeometry object.
STRUCT dbObject = (STRUCT) rs.getObject(1);JGeometry geom = JGeometry.load(dbObject);
To use the optimized unpickler, first use the getBytes() method of the result set to extract the geometry into a byte array. Then again use the static load() method of JGeometry to convert it to a JGeometry object.
byte[] image = rs. getBytes (1);JGeometry geom = JGeometry.load(image);
12
You can use one of the many get() methods to extract information from the geometry object. Table summarizes the main methods. The additional is() methods detail the nature of the geometry.
Method Information Returned getType() Type of geometry (1 for apoint, 2 for aline, and so on). getDimensions() Dimensionality.getSRID() Spatial reference system ID.getNumPoints() Number of points in the geometry.getPoint() Coordinates of the point object (if the geometry is apoint).getFirstPoint() First point of the geometry.getLastPoint() Last point of the geometry.getMBR() MBR of the geometry. getElemInfo() Content of the SDO_ELEM_INFO array.getOrdinatesArray() Content of the SDO_ORDINATES array.getLabelPoint() Returns the coordinates of the SDO_POINT structure. When filled for aline or polygon geometry, this is often used as alabeling point. getJavaPoint() For asingle-point object, returns the coordinates of the point as a java.awt.geom. Point2D object. getJavaPoints() For amultipoint object, returns an array of java.awt.geom. Point2D objects. getElements() Gets an array of JGeometry objects, each representing one element of the geometry. getElementAt() Extracts one element of the geometry as a JGeometry. createShape() Converts the geometry into ajava.awt.Shape object, ready for use by the drawing and manipulation facilities of the java.awt package.isPoint() Is this apoint?isOrientedPoint() Is this an oriented point?isCircle() Is this acircle? isGeodeticMBR() Is this ageodetic MBR?isMultiPoint() Is this amultipoint? isRectangle() Is this arectangle?hasCircularArcs() Does the geometry contain any arcs?isLRSGeometry() Is this a“linear referenced” geometry?
Two of the methods getElements() and getElementAt() allow you to inspect the structure of complex geometries: they allow you to extract individual elements as separate JGeometry objects. The first method returns all elements into an array of separate JGeometry objects. The second returns one specific element identified by its position in the geometry.
Decoding and constructing STRUCTs is rather complex, and the main goal of the Oracle Spatial Java API (the JGeometry class) is to make that task easy.
13
Creating Geometries
Writing a geometry to the database (in an INSERT or UPDATE statement) requires that you create anew JGeometry object, convert it into a STRUCT using the static JGeometry.store() method, and then pass the STRUCT to an INSERT or UPDATE statement. Just like for the load() method, you can also use the faster spatial pickler. The following is an example of both approaches. First use the static store() method of JGeometryto convert it to a STRUCT, and then use the setObject() method to set it into the prepared SQL statement.
STRUCT dbObject = JGeometry.store (geom, dbConnection);stmt.setObject (1,dbObject);
Using the optimized pickler is very much the same except that the order of the arguments to the store() method is reversed: first specify the database connection object and then the JGeometry object!
STRUCT dbObject = JGeometry.store (dbConnection, geom);stmt.setObject (1,dbObject);
14
There are two ways you can construct new JGeometry objects. One way is to use one of the constructors. The other way is to use one of the static methods that create various geometries.
JGeometry Constructors Constructor Purpose JGeometry (double x, double y, int srid) Constructs apoint JGeometry (double x, double y, double z, int srid) Constructs a three-dimensional point JGeometry (double minX, double minY, double maxX, double maxY, int srid) Creates arectangle JGeometry (int gtype, int srid, int[] elemInfo, double[] ordinates)Constructs ageneric geometry
Static JGeometry Creation Methods Creation Method Purpose createPoint(double[] coord, int dim, int srid) Creates a pointcreateLinearLineString(double[] coords, int dim, int srid) Creates a simple line string createLinearPolygon(double[] coords, int dim, int srid) Creates asimple polygoncreateMultiPoint(java.lang.Object[] coords, int dim, int srid) Creates a multipoint objectcreateLinearMultiLineString(java.lang.Object[] coords, int dim, int srid) Creates amultiline string object createLinearPolygon(java.lang.Object[] coords, int dim, int srid) Creates amultipolygon createCircle(double x1, double y1, double x2, double y2, double x3, double y3, int srid) Creates acircle using three points on its circumferencecreateCircle(double x, double y, double radius, int srid) Creates acircleusing acenter and radius
15
Modifying Existing Geometries
The JGeometry class doesnot provide any method that lets you modify ageometry. For example, there is no method to remove apoint from aline or to add one more point to aline. To perform those updates, you need to extract the list of points using amethod such as getOrdinatesArray(), then update the resulting Java arrays, and then create anew JGeometry object with the results. To write the modified geometries to the database, proceed as discussed previously: convert the JGeometry object into a STRUCT using the store() method, and then pass the STRUCT to your SQL INSERT or UPDATE statement.
16
Processing Geometries
The Java API alsoprovides you with anumber of methods that perform various transformations on geometries. Table7-6 lists the main ones. They take aJGeometry object as input and generate anew geometry as aresult. Note that most of those functions are also provided via PL/SQL calls in the database that will be discussed in detail in Chapter 9.Table 7-6. Geometry-Processing Functions Method Purpose buffer(double bufferWidth) Generates abuffer around ageometry simplify(double threshold) Simplifies ageometry densifyArcs(double arc_tolerance) Densifies all arcs in ageometry clone() Duplicates ageometry affineTransforms(...) Applies affine transformations on the input geometry based on the parameters supplied: translation, scaling, rotation, shear, reflection projectToLTP(double smax, double flat) Projects ageometry from longitude/latitude to alocal tangent plane projectFromLTP() Projects ageometry from alocal tangent plane to longitude/latitudeThe API also provides some helper methods, summarized in Table7-7. Those functions (except for equals) do not deal with JGeometryobjects but are provided to help certain processing tasks. The equals() method compares two JGeometry objects and determines whether they are the same. However, the comparison is based on the internal encoding of the geometry: two geometries willbe considered as equal if the coordinates of all their points are the same and in the same sequence. The method does not perform atrue geometric comparison involving tolerance.Table 7-7. Geometry Helper Functions Method Purpose equals() Determines whether two geometries are identical computeArc(double x1, Computes the center, radius, and angles for this arc from the double y1, double x2, three coordinate points double y2, double x3, double y3) linearizeArc(double x1, Converts an arc into an array of 2D line segments double y1, double x2, double y2, double x3, double y3) reFormulateArc(double[] d) Reformulates an arc by recomputing the angles expandCircle(double x1, Linearizes the circle by converting it into an array of 2D segments double y1, double x2, double y2, double x3, double y3) monoMeasure(double[] coords, Determines whether a line has increasing or decreasing measures int dim ()
17
JGeometry tipa objekta konstruktora metodes
JGeometry(double x, double y, int srid)Objekta veidošana punktam (2D)
JGeometry(double minX, double minY, double maxX, double maxY, int srid)Objekta veidošana taisnstūrim
JGeometry(int gtype, int srid, double x, double y, double z, int[] elemInfo, double[] ordinates)Objekta veidošana vispārējai ģeometrijai
JGeometry(int gtype, int srid, int[] elemInfo, double[] ordinates)Objekta veidošana vispārējai ģeometrijai
18
public JGeometry(int gtype, int srid, double x, double y, double z, int[] elemInfo, double[] ordinates)
Parameters:gtype - the geometry typesrid - the SRS id; if 0 is used then the MDSYS.SDO_GEOMETRY.SDO_SRID will be set to null when converted into DB format.x - x ordinate of a label pointy - y ordinate of a label pointz - z ordinate of a label pointelemInfo - geometry element info arrayordinates - geometry ordinates array
public JGeometry(int gtype, int srid, int[] elemInfo, double[] ordinates)
Parameters:gtype - the geometry typesrid - the SRS id; if 0 is used then the MDSYS.SDO_GEOMETRY.SDO_SRID will be set to null when converted into DB format.elemInfo - geometry element info arrayordinates - geometry ordinates array
public JGeometry(double x, double y, int srid)
Parameters:x - x ordinate of a label pointy - y ordinate of a label pointsrid - the SRS id; if 0 is used then the MDSYS.SDO_GEOMETRY.SDO_SRID will be set to null when converted into DB format.
public JGeometry(double x, double y, double z, int srid)
Parameters:x - x ordinate of a label pointy - y ordinate of a label pointz - z ordinate of a label pointsrid - the SRS id; if 0 is used then the MDSYS.SDO_GEOMETRY.SDO_SRID will be set to null when converted into DB format.
public JGeometry(double minX, double minY, double maxX,
19
double maxY, int srid)
Parameters:minX - the minimum x ordinate of the rectangleminY - the minimum y ordinate of the rectanglemaxX - the maximum x ordinate of the rectanglemaxY - the maximum y ordinate of the rectanglesrid - the SRS id. if 0 is used then the MDSYS.SDO_GEOMETRY.SDO_SRID will be set to null when converted into DB format.
20
Klases JGeometry metodes
Kāda ģeometrija ir objektā noskaidrošana
int getType()Gets the geometry type.
boolean hasCircularArcs()Checks if this geometry is a compound one.
boolean isCircle()Checks if this geometry represents a circle.
boolean isMultiPoint()Checks if this geometry is of Multi-Point type.
boolean isPoint()Checks if this geometry is of point type.
boolean isRectangle()Checks if this geometry represents a rectangle.
21
Klases JGeometry metodes
Ģeometrijas datu no objekta iegūšana
java.lang.Object clone() Constructs an instance that is a clone of this JGeometry.
static double[] computeArc(double x1, double y1, double x2, double y2, double x3, double y3)Helper method to compute center, radius, and angles for this arc from the three coordinate
points. static JGeometry createCircle(double x1, double y1, double x2, double y2, double x3, double y3, int srid)Creates a JGeometry that is a 2D Circle.
static JGeometry createCircle(double x, double y, double radius, int srid)Creates a JGeometry that is a Circle with provided radius and center.
static JGeometry createLinearLineString(double[] coords, int dim, int srid)Creates a JGeometry that is a single linear Line String.
static JGeometry createLinearMultiLineString(java.lang.Object[] coords, int dim, int srid)Creates a JGeometry that is a linear multi-linestring.
static JGeometry createLinearPolygon(double[] coords, int dim, int srid)Creates a JGeometry that is a simple linear Polygon without holes.
static JGeometry createLinearPolygon(java.lang.Object[] coords, int dim, int srid)Creates a JGeometry that is a linear polygon which may have holes.
static JGeometry createMultiPoint(java.lang.Object[] coords, int dim, int srid)Creates a JGeometry that is a multi-point geometry.
static JGeometry createPoint(double[] coord, int dim, int srid)int getDimensions()Gets the dimensionality of this geometry.
int[] getElemInfo()Gets the reference to the element infomation array of this JGeometry.
double[] getFirstPoint()Gets the first coordinate for this geometry.
java.awt.geom.Point2D getJavaPoint()Gets the java2D point rerepsentation of this geometry.
java.awt.geom.Point2D[] getJavaPoints()Gets the java2D points rerepsentation of this geometry.
java.awt.geom.Point2D getLabelPoint()Gets the SDO_GEOMETRY.sdo_point as a label point.
22
double[] getLastPoint()Gets the last coordinate of the geometry.
int getNumPoints()Gets the number of points or verticies in this geometry.
double[] getOrdinatesArray()Gets the reference to the ordinate array of this JGeometry.
java.lang.Object[] getOrdinatesOfElements()Gets an array of the (top-level) elements in this geometry.
double[] getPoint()Gets the coordinate of this point geometry.
long getSize()Gets an estimated size of the geometry in bytes.
int getSRID()Gets the geometry SRID.
int getType()Gets the geometry type.
static JGeometry load(STRUCT st)Creates a JGeometry instance from a STRUCT object representing a geometry column in a JDBC result set. static int monoMeasure(double[] coords, int dim)Edited version of PL/SQL monotonic_measure() monoMeasure() determines whether a line is monotonically increasing or decreasing Returns: 1 if increasing or all measures null; -1 if decreasing; 0 if measures are inconsistent Note: Repeated measures are not flagged as inconsistent (but are not valid in LRS); assumes measure is in the last position: X,Y,M or X,Y,Z,M
void setSRID(int srid)Sets the srid for this geometry.
void setType(int gt)Sets the geometry type for this geometry.
static STRUCT store(JGeometry geom, java.sql.Connection conn)Convert the given geometry object into an Oracle JDBC STRUCT object.
23
clonepublic java.lang.Object clone()
constructs an instance that is a clone of this JGeometry. All the fields of this object is deep-copied over to the clone.Overrides:clone in class java.lang.Object
createPointpublic static JGeometry createPoint(double[] coord, int dim, int srid)
createLRSPointpublic static JGeometry createLRSPoint(double[] coord, int LRSdim, int srid)
Parameters:LRSdim - LRS dimensionality: X,Y,M=2D; X,Y,Z,M=3D
createCirclepublic static JGeometry createCircle(double x, double y, double radius, int srid)
Creates a JGeometry that is a Circle with provided radius and center.Parameters:x - the x ordinate of the circle's centery - the y ordinate of the circle's centerradius - the radius of the circlesrid - the srid of the circle
createCirclepublic static JGeometry createCircle(double x1, double y1, double x2, double y2, double x3, double y3, int srid)
Creates a JGeometry that is a 2D Circle. The three supplied coordinates form the circumference of the circle.Parameters:x1 - x ordinate of point 1y1 - y ordinate of point 1x2 - x ordinate of point 2y2 - y ordinate of point 2
24
x3 - x ordinate of point 3y3 - y ordinate of point 3srid - srs id for the circle
createLinearLineStringpublic static JGeometry createLinearLineString(double[] coords, int dim, int srid)
Creates a JGeometry that is a single linear Line String.Parameters:coords - the coordinates of the linear line stringdim - the dimensionality of the line string.srid - the srid of the linear line stringReturns:a JGeometry object that is a linear line string
createLRSLinearLineStringpublic static JGeometry createLRSLinearLineString(double[] coords, int LRSdim, int srid)
Creates a JGeometry that is a single LRS linear Line String.Parameters:coords - the coordinates of the LRS linear line stringLRSdim - the LRS dimensionality of the line string: X,Y,M=2D; X,Y,Z,M=3Dsrid - the srid of the linear line stringReturns:a JGeometry object that is a LRS linear line string
createLinearMultiLineStringpublic static JGeometry createLinearMultiLineString(java.lang.Object[] coords, int dim, int srid)
Creates a JGeometry that is a linear multi-linestring.Parameters:coords - an array of all the linestrings' coordinatesdim - the dimensionality of the linestringsrid - the srid of the multi-linestring
createLRSLinearMultiLineStringpublic static JGeometry createLRSLinearMultiLineString(java.lang.Object[] coords, int LRSdim, int srid)
Creates a JGeometry that is a LRS linear multi-linestring.Parameters:coords - an array of all the LRS linestrings' coordinatesLRSdim - the LRS dimensionality of the linestring: X,Y,M=2D; X,Y,Z,M=3Dsrid - the srid of the multi-linestring
25
createMultiPointpublic static JGeometry createMultiPoint(java.lang.Object[] coords, int dim, int srid)
Creates a JGeometry that is a multi-point geometry.Parameters:coords - the array of double-typed arrays each containing one pointdim - the dimensionality of each pointsrid - the srid for the geometry.
createLinearPolygonpublic static JGeometry createLinearPolygon(double[] coords, int dim, int srid)
Creates a JGeometry that is a simple linear Polygon without holes. Note that if the supplied coordinate array does not close itslef, meaning the last coordinate is not the same as the first, a new coordinate will be appended to the end of the input coordinates array. the new coordinate repeats the first one.Parameters:coords - the coordinates of the linear polygondim - the dimensionality of the polygonsrid - the srid of the polygon
createLinearPolygonpublic static JGeometry createLinearPolygon(java.lang.Object[] coords, int dim, int srid)
Creates a JGeometry that is a linear polygon which may have holes. Each array in the double array parameter represents a single ring of the polygon. The outer ring must be the first in the double array. Note that for each ring, if its coordinate array does not close itslef, meaning the last coordinate is not the same as the first, a new coordinate will be appended to the end of that ring's coordinates array. The new coordinate repeats the first one for the said ring.Parameters:coords - an array of double-typed arrays that contains all the rings' coordinatesdim - the dimensionality of the polygonsrid - the srid of the polygon
createLRSLinearPolygonpublic static JGeometry createLRSLinearPolygon(double[] coords, int LRSdim, int srid)
Creates a JGeometry that is a simple LRS linear Polygon without holes. Note that if the supplied coordinate array does not close itslef, meaning the last coordinate is not the same as the first, a new coordinate will be appended to the end of the input coordinates array. the new coordinate repeats the first one.Parameters:
26
coords - the coordinates of the LRS linear polygonLRSdim - the LRS dimensionality of the polygon: X,Y,M=2D; X,Y,Z,M=3Dsrid - the srid of the polygon
createLRSLinearPolygonpublic static JGeometry createLRSLinearPolygon(java.lang.Object[] coords, int LRSdim, int srid)
Creates a JGeometry that is a linear LRS polygon which may have holes. Each array in the double array parameter represents a single ring of the polygon. The outer ring must be the first in the double array. Note that for each ring, if its coordinate array does not close itslef, meaning the last coordinate is not the same as the first, a new coordinate will be appended to the end of that ring's coordinates array. The new coordinate repeats the first one for the said ring.Parameters:coords - an array of double-typed arrays that contains all the rings' coordinatesLRSdim - the LRS dimensionality of the polygon: X,Y,M=2D; X,Y,Z,M=3Dsrid - the srid of the polygon
monoMeasurepublic static int monoMeasure(double[] coords, int dim)
Edited version of PL/SQL monotonic_measure() monoMeasure() determines whether a line is monotonically increasing or decreasing Returns: 1 if increasing or all measures null; -1 if decreasing; 0 if measures are inconsistent Note: Repeated measures are not flagged as inconsistent (but are not valid in LRS); assumes measure is in the last position: X,Y,M or X,Y,Z,MParameters:coords - an array of double that contains all coordinatesdim - the dimensionality of the feature: X,Y,M=3D; X,Y,Z,M=4D
getTypepublic int getType()
Gets the geometry type.
Known geom types (1st digit from right):
GTYPE_POINT = 1; GTYPE_CURVE = 2; GTYPE_POLYGON = 3; GTYPE_COLLECTION = 4; GTYPE_MULTIPOINT = 5; GTYPE_MULTICURVE = 6; GTYPE_MULTIPOLYGON = 7;
27
Returns:the geometry type
setTypepublic void setType(int gt)
Sets the geometry type for this geometry.Parameters:gt - the geometry type
getSRIDpublic int getSRID()
Gets the geometry SRID.
setSRIDpublic void setSRID(int srid)
Sets the srid for this geometry.Parameters:srid - the srid
getLabelPointpublic java.awt.geom.Point2D getLabelPoint()
Gets the SDO_GEOMETRY.sdo_point as a label point.
getPointpublic double[] getPoint()
Gets the coordinate of this point geometry. Retruns null if this geometry is not of point type.Returns:a double array which stores the oridnates of this point; null if this geometry is not a point
getJavaPointpublic java.awt.geom.Point2D getJavaPoint()
Gets the java2D point rerepsentation of this geometry. Returns null if this geometry is not of point type.Returns:a java Point2D.Double instance if this is a point geometry.
getJavaPointspublic java.awt.geom.Point2D[] getJavaPoints()
Gets the java2D points rerepsentation of this geometry. Returns null if this geometry is not of 2D multipoint type.Returns:an array of java Point2D.Double instances if this is a 2D multipoint geometry.
28
isPointpublic final boolean isPoint()
Checks if this geometry is of point type.Returns:true if this geometry is a point
isMultiPointpublic final boolean isMultiPoint()
Checks if this geometry is of Multi-Point type.Returns:true if this geometry is a multi-point; otherwise false.
isRectanglepublic final boolean isRectangle()
Checks if this geometry represents a rectangle.Returns:true if this geometry is a rectangle.
isCirclepublic final boolean isCircle()
Checks if this geometry represents a circle.Returns:true if this geometry is a circle.
isGeodeticMBRpublic final boolean isGeodeticMBR()
Checks if this geometry represents a geodetic MBR.Returns:true if this geometry is a geodetic MBR.
isLRSGeometrypublic final boolean isLRSGeometry()
Checks if this is a LRS (Linear Reference System) geometry.Returns:true if this is a LRS geometry; otherwise false
hasCircularArcspublic final boolean hasCircularArcs()
Checks if this geometry is a compound one. A compound geometry has circular arcs as part of its boundary.
getDimensionspublic int getDimensions()
29
Gets the dimensionality of this geometry.Returns:the dimensions of this geoemtry.
getOrdinatesArraypublic double[] getOrdinatesArray()
Gets the reference to the ordinate array of this JGeometry. Unless you know what you are doing, you should not modify the values in the returned array.Returns:the ordinates array corresponding to the server side MDSYS.SDO_GEOMETRY.SDO_ORDINATE_ARRAY. Null will be returned if this geometry is a point with optimal storage (i.e., the coordinate is stored in the SDO_GEOM.SDO_POINT field).
getElemInfopublic int[] getElemInfo()
Gets the reference to the element infomation array of this JGeometry. Unless you know what you are doing, you should not modify the values in the returned array.Returns:the element information array corresponding to the server side MDSYS.SDO_GEOMETRY.SDO_ELEM_INFO_ARRAY.
getNumPointspublic final int getNumPoints()
Gets the number of points or verticies in this geometry. Not to be confused with the number of ordinates or double values in the ordinates array.Returns:the number of points (including all parts) in this geometry.
getFirstPointpublic double[] getFirstPoint()
Gets the first coordinate for this geometry. If the geometry is a point, the point's coordinate will be returned. If anything else, the first coordinate in the geometry's ordinates array (MDSYS.SDO_GEOMETRY.SDO_ORDINATES) will be returned.Returns:the first point of the geometry in an array that stores the ordinates. The size of the result array is the same as the dimension of the geometry.
getLastPointpublic double[] getLastPoint()
Gets the last coordinate of the geometry. If the geometry is a point its coordinate will be returned. For any other geometry types the last coordinate in the ordinates array (MDSYS.SDO_GEOMETRY.SDO_ORDINATES) will be returned. Note that this method does not take into account the logica separation that may exist for the ordinates array (such as that of a multi-polygon geometry). It merely picks the last coordinate in the array.Returns:
30
the last point of the geometry in an array that stores the ordinates. The size of the result array is the same as the dimension of the geometry.
getMBRpublic double[] getMBR()
Gets the MBR of this geometry. When a JSDOGeoemtry is first instantiated from a db geometry STRUCT, no MBR is computed. The MBR exists only after the first call to this method. The MBR will be recalucated only when the geoemtry's structure has been modified.Returns:a double array containing the minX,minY, maxX,maxY value of the MBR
getOrdinatesOfElementspublic java.lang.Object[] getOrdinatesOfElements()
Gets an array of the (top-level) elements in this geometry. Each array element in the result array is itself an array of all the ordinates for a geometry element. In other words, if this geometry has three elements, each with 10,20 and 30 ordinates, then the result Object[] array will have three elements, each being double[10], double[20] and double[30].
Note: applicable only to linear geometries without compound elements.
Returns:an array of ordinates arrays
createShapepublic final java.awt.Shape createShape()
Creates a Java2D shape object from this JGeometry Note: for point geometry this method returns null. You should call getJavaPoint() for point or getJavaPoints() for multi-points.Returns:a Java2D shape representation of this geometry; NULL if the geometry is of Point or Multi-point type.
loadpublic static final JGeometry load(STRUCT st) throws java.sql.SQLException
Creates a JGeometry instance from a STRUCT object representing a geometry column in a JDBC result set.Parameters:st - the STRUCT object from an oracle result set.Returns:a JGeometry instance if successful; otherwise null is returned.Throws:java.sql.SQLException
storepublic static STRUCT store(JGeometry geom, java.sql.Connection conn)
31
throws java.sql.SQLExceptionConvert the given geometry object into an Oracle JDBC STRUCT object. You can then bind the STRUCT object to a SQL statment that inserts or updates the geometry in the database. Usage note: Do not bind the STRUCT object of a JGeometry of the geodetic MBR type to an SQL DML statement that inserts or updates the geometry in the database. a database, you are not allowed to use this method to convert it into a STRUCT object.Parameters:geom - the JGeometry instance to be converted.conn - the connection to use.Returns:a Oracle STRUCT object when successful; otherwise nullThrows:java.sql.SQLException
computeArcpublic static final double[] computeArc(double x1, double y1, double x2, double y2, double x3, double y3)
Helper method to compute center, radius, and angles for this arc from the three coordinate points.Returns:an array if an arc can be computed; null if the three points overlap or are co-linear. The array contains the following (in radians): centerX, centerY, radius, startAngle, midAngle, endAngle;
linearizeArcpublic static double[] linearizeArc(double x1, double y1, double x2, double y2, double x3, double y3, int numPoints)
returns a linearized array of 2D line segments for an ARC given in three points.Returns:an double array in the form of (x1,y1,x2,y2....xn,yn)
linearizeArcpublic static double[] linearizeArc(double x1, double y1, double x2, double y2, double x3, double y3, double tolerance)
32
For a given arc, returns a linearized array of 2D line segments.Returns:an double array in the form of (x1,y1,x2,y2....xn,yn)
linearizeArcpublic static double[] linearizeArc(double x1, double y1, double x2, double y2, double x3, double y3)
For a given arc, returns a linearized array of 2D line segments. This will use a default tolerance value that is 1% of the arc radius.Returns:an double array in the form of (x1,y1,x2,y2....xn,yn)
getSizepublic long getSize()
Gets an estimated size of the geometry in bytes.Returns:size of this geometry in bytes.
toStringpublic java.lang.String toString()
Overrides:toString in class java.lang.Object
equalspublic boolean equals(java.lang.Object otherObj)
Deprecated. This function has been moved to oracle.spatial.util.GML. public static JGeometry fromNodeToGeometry(Node nd) throws DataException { return GML.fromNodeToGeometry(nd); }Overrides:equals in class java.lang.Object
33