4
* PostGIS extension for PostgreSQL JDBC driver - bounding box model
7
* (C) 2004 Paul Ramsey, pramsey@refractions.net
9
* (C) 2005 Markus Schaber, markus@schabi.de
11
* This library is free software; you can redistribute it and/or modify it under
12
* the terms of the GNU Lesser General Public License as published by the Free
13
* Software Foundation, either version 2.1 of the License.
15
* This library is distributed in the hope that it will be useful, but WITHOUT
16
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this library; if not, write to the Free Software Foundation, Inc.,
22
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
25
* $Id: PGboxbase.java,v 1.6 2005/03/30 15:24:40 mschaber Exp $
30
import org.postgresql.util.PGobject;
31
import org.postgresql.util.PGtokenizer;
33
import java.sql.SQLException;
36
* Updates Oct 2002 - data members made private - getLLB() and getURT() methods
40
public abstract class PGboxbase extends PGobject {
43
* The lower left bottom corner of the box.
48
* The upper right top corner of the box.
53
* The Prefix we have in WKT rep.
55
* I use an abstract method here so we do not need to replicate the String
56
* object in every instance.
59
public abstract String getPrefix();
62
* The Postgres type we have (same construct as getPrefix())
64
public abstract String getPGtype();
67
this.setType(getPGtype());
70
public PGboxbase(Point llb, Point urt) {
76
public PGboxbase(String value) throws SQLException {
81
public void setValue(String value) throws SQLException {
84
if (value.startsWith("SRID=")) {
85
String[] temp = PGgeometry.splitSRID(value);
86
value = temp[1].trim();
87
srid = Integer.parseInt(temp[0].substring(5));
89
String myPrefix = getPrefix();
90
if (value.startsWith(myPrefix)) {
91
value = value.substring(myPrefix.length()).trim();
93
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
94
llb = new Point(t.getToken(0));
95
urt = new Point(t.getToken(1));
102
public String getValue() {
103
StringBuffer sb = new StringBuffer();
105
return sb.toString();
108
private void outerWKT(StringBuffer sb) {
109
sb.append(getPrefix());
118
* Unlike geometries, toString() does _not_ contain the srid, as server-side
119
* PostGIS cannot parse this.
121
public String toString() {
125
/** Returns the lower left bottom corner of the box as a Point object */
126
public Point getLLB() {
130
/** Returns the upper right top corner of the box as a Point object */
131
public Point getURT() {
135
public boolean equals(Object other) {
136
if (other instanceof PGboxbase) {
137
PGboxbase otherbox = (PGboxbase) other;
138
return (compareLazyDim(this.llb, otherbox.llb) && compareLazyDim(this.urt, otherbox.urt));
144
* Compare two coordinates with lazy dimension checking.
146
* As the Server always returns Box3D with three dimensions, z==0 equals
150
protected static boolean compareLazyDim(Point first, Point second) {
151
return first.x == second.x
152
&& first.y == second.y
153
&& (((first.dimension == 2 || first.z == 0.0) && (second.dimension == 2 || second.z == 0)) || (first.z == second.z));
156
public Object clone() {
157
PGboxbase obj = newInstance();
165
* We could have used this.getClass().newInstance() here, but this forces us
166
* dealing with InstantiationException and IllegalAccessException. Due to
167
* the PGObject.clone() brokennes that does not allow clone() to throw
168
* CloneNotSupportedException, we cannot even pass this exceptions down to
169
* callers in a sane way.
171
protected abstract PGboxbase newInstance();
b'\\ No newline at end of file'