PostgreSQL™ has a set of data types that can store geometric features into a table. These include single points, lines, and polygons. We support these types in Java with the org.postgresql.geometric package. It contains classes that extend the org.postgresql.util.PGobject class. Refer to that class for details on how to implement your own data type handlers.
Class org.postgresql.geometric.PGbox
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGbox
public class PGbox extends PGobject implements Serializable,
Cloneable
This represents the box data type within PostgreSQL™.
Variables
public PGpoint point[]
These are the two corner points of the box.
Constructors
public PGbox(double x1,
double y1,
double x2,
double y2)
Parameters:
x1 - first x coordinate
y1 - first y coordinate
x2 - second x coordinate
y2 - second y coordinate
public PGbox(PGpoint p1,
PGpoint p2)
Parameters:
p1 - first point
p2 - second point
public PGbox(String s) throws SQLException
Parameters:
s - Box definition in PostgreSQL™ syntax
Throws: SQLException
if definition is invalid
public PGbox()
Required constructor
Methods
public void setValue(String value) throws SQLException
This method sets the value of this object. It should be
overridden, but still called by subclasses.
Parameters:
value - a string representation of the value of the
object
Throws: SQLException
thrown if value is invalid for this type
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two boxes are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
Returns:
the PGbox in the syntax expected by PostgreSQL™
Overrides:
getValue in class PGobject
Class org.postgresql.geometric.PGcircle
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGcircle
public class PGcircle extends PGobject implements Serializable,
Cloneable
This represents PostgreSQL™'s circle data type, consisting of a point
and a radius
Variables
public PGpoint center
This is the center point
double radius
This is the radius
Constructors
public PGcircle(double x,
double y,
double r)
Parameters:
x - coordinate of center
y - coordinate of center
r - radius of circle
public PGcircle(PGpoint c,
double r)
Parameters:
c - PGpoint describing the circle's center
r - radius of circle
public PGcircle(String s) throws SQLException
Parameters:
s - definition of the circle in PostgreSQL™'s syntax.
Throws: SQLException
on conversion failure
public PGcircle()
This constructor is used by the driver.
Methods
public void setValue(String s) throws SQLException
Parameters:
s - definition of the circle in PostgreSQL™'s syntax.
Throws: SQLException
on conversion failure
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two circles are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
Returns:
the PGcircle in the syntax expected by PostgreSQL™
Overrides:
getValue in class PGobject
Class org.postgresql.geometric.PGline
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGline
public class PGline extends PGobject implements Serializable,
Cloneable
This implements a line consisting of two points. Currently line is
not yet implemented in the server, but this class ensures that when
it's done were ready for it.
Variables
public PGpoint point[]
These are the two points.
Constructors
public PGline(double x1,
double y1,
double x2,
double y2)
Parameters:
x1 - coordinate for first point
y1 - coordinate for first point
x2 - coordinate for second point
y2 - coordinate for second point
public PGline(PGpoint p1,
PGpoint p2)
Parameters:
p1 - first point
p2 - second point
public PGline(String s) throws SQLException
Parameters:
s - definition of the line in PostgreSQL™'s syntax.
Throws: SQLException
on conversion failure
public PGline()
required by the driver
Methods
public void setValue(String s) throws SQLException
Parameters:
s - Definition of the line segment in PostgreSQL™'s
syntax
Throws: SQLException
on conversion failure
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two lines are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
Returns:
the PGline in the syntax expected by PostgreSQL™
Overrides:
getValue in class PGobject
Class org.postgresql.geometric.PGlseg
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGlseg
public class PGlseg extends PGobject implements Serializable,
Cloneable
This implements a lseg (line segment) consisting of two points
Variables
public PGpoint point[]
These are the two points.
Constructors
public PGlseg(double x1,
double y1,
double x2,
double y2)
Parameters:
x1 - coordinate for first point
y1 - coordinate for first point
x2 - coordinate for second point
y2 - coordinate for second point
public PGlseg(PGpoint p1,
PGpoint p2)
Parameters:
p1 - first point
p2 - second point
public PGlseg(String s) throws SQLException
Parameters:
s - Definition of the line segment in PostgreSQL™'s syntax.
Throws: SQLException
on conversion failure
public PGlseg()
required by the driver
Methods
public void setValue(String s) throws SQLException
Parameters:
s - Definition of the line segment in PostgreSQL™'s
syntax
Throws: SQLException
on conversion failure
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two line segments are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
Returns:
the PGlseg in the syntax expected by PostgreSQL™
Overrides:
getValue in class PGobject
Class org.postgresql.geometric.PGpath
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGpath
public class PGpath extends PGobject implements Serializable,
Cloneable
This implements a path (a multiply segmented line, which may be
closed)
Variables
public boolean open
True if the path is open, false if closed
public PGpoint points[]
The points defining this path
Constructors
public PGpath(PGpoint points[],
boolean open)
Parameters:
points - the PGpoints that define the path
open - True if the path is open, false if closed
public PGpath()
Required by the driver
public PGpath(String s) throws SQLException
Parameters:
s - definition of the path in PostgreSQL™'s syntax.
Throws: SQLException
on conversion failure
Methods
public void setValue(String s) throws SQLException
Parameters:
s - Definition of the path in PostgreSQL™'s syntax
Throws: SQLException
on conversion failure
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two pathes are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
This returns the path in the syntax expected by
PostgreSQL™
Overrides:
getValue in class PGobject
public boolean isOpen()
This returns true if the path is open
public boolean isClosed()
This returns true if the path is closed
public void closePath()
Marks the path as closed
public void openPath()
Marks the path as open
Class org.postgresql.geometric.PGpoint
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGpoint
public class PGpoint extends PGobject implements Serializable,
Cloneable
This implements a version of java.awt.Point, except it uses double
to represent the coordinates.
It maps to the point data type in PostgreSQL™.
Variables
public double x
The X coordinate of the point
public double y
The Y coordinate of the point
Constructors
public PGpoint(double x,
double y)
Parameters:
x - coordinate
y - coordinate
public PGpoint(String value) throws SQLException
This is called mainly from the other geometric types, when a
point is embedded within their definition.
Parameters:
value - Definition of this point in PostgreSQL™'s
syntax
public PGpoint()
Required by the driver
Methods
public void setValue(String s) throws SQLException
Parameters:
s - Definition of this point in PostgreSQL™'s syntax
Throws: SQLException
on conversion failure
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two points are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
Returns:
the PGpoint in the syntax expected by PostgreSQL™
Overrides:
getValue in class PGobject
public void translate(int x,
int y)
Translate the point with the supplied amount.
Parameters:
x - integer amount to add on the x axis
y - integer amount to add on the y axis
public void translate(double x,
double y)
Translate the point with the supplied amount.
Parameters:
x - double amount to add on the x axis
y - double amount to add on the y axis
public void move(int x,
int y)
Moves the point to the supplied coordinates.
Parameters:
x - integer coordinate
y - integer coordinate
public void move(double x,
double y)
Moves the point to the supplied coordinates.
Parameters:
x - double coordinate
y - double coordinate
public void setLocation(int x,
int y)
Moves the point to the supplied coordinates. refer to
java.awt.Point for description of this
Parameters:
x - integer coordinate
y - integer coordinate
See Also:
Point
public void setLocation(Point p)
Moves the point to the supplied java.awt.Point refer to
java.awt.Point for description of this
Parameters:
p - Point to move to
See Also:
Point
Class org.postgresql.geometric.PGpolygon
java.lang.Object
|
+----org.postgresql.util.PGobject
|
+----org.postgresql.geometric.PGpolygon
public class PGpolygon extends PGobject implements Serializable,
Cloneable
This implements the polygon data type within PostgreSQL™.
Variables
public PGpoint points[]
The points defining the polygon
Constructors
public PGpolygon(PGpoint points[])
Creates a polygon using an array of PGpoints
Parameters:
points - the points defining the polygon
public PGpolygon(String s) throws SQLException
Parameters:
s - definition of the polygon in PostgreSQL™'s syntax.
Throws: SQLException
on conversion failure
public PGpolygon()
Required by the driver
Methods
public void setValue(String s) throws SQLException
Parameters:
s - Definition of the polygon in PostgreSQL™'s syntax
Throws: SQLException
on conversion failure
Overrides:
setValue in class PGobject
public boolean equals(Object obj)
Parameters:
obj - Object to compare with
Returns:
true if the two polygons are identical
Overrides:
equals in class PGobject
public Object clone()
This must be overridden to allow the object to be cloned
Overrides:
clone in class PGobject
public String getValue()
Returns:
the PGpolygon in the syntax expected by PostgreSQL™
Overrides:
getValue in class PGobject