- early return from force_collection
- segfault fix in geom_accum()
- consistency check fix in SnapToGrid()
+ - jdbc2: code cleanups, Makefile improvements
PostGIS 1.0.0RC3
2005/02/24
top_makefile:=$(PGSQL_SRC)/src/Makefile.global
-include $(top_makefile)
-# Make sure you CLASSPATH environmental variable includes your postgresql.jar
-# We set a reasonable default for un*xoid systems here. Note that some JREs
-# (e. G. sablevm on debian woody) seem to need their own system classes
-# to be included in the classpath, because they do not adhere to the standard
-# concept of -classpath and -bootclasspath. SUN jdk, IBM jdk, Blackdown JDK,
-# gij and kaffe are known to work fine.
+# Make sure our classpath includes your postgresql.jar. This is somehow
+# difficult because some JREs (e. G. those on debian woody or sablevm) seem
+# to forget their own system classes (aka bootclasspath) as soon as _any_
+# classpath is set, either via environment or via command line. They do not
+# implement the concept of distinct classpath and bootclasspath settings,
+# as most current java implementations do. This makes it necessary to either
+# explicitly include the system classes in the set classpath, or use
+# non-standard options line --addclasspath to add both the postgresql.jar
+# and our own classes. We also cannot set an unset CLASSPATH variable here
+# for this reason. Current (Jan 2005) implementations from SUN, IBM,
+# Blackdown, gij and kaffe are known to work fine.
+
+# If you set POSTGIS_BUILD_CLASSPATH via Environment (even to an empty string), we
+# simply use it and do not try to guess anything. If POSTGIS_CLASSPATH is
+# not set, we use the contents of CLASSPATH. If CLASSPATH is empty or not
+# set, we try to guess a default location that works on most unixoid systems.
+
+ifeq (${CLASSPATH},)
+ TEMP=/usr/share/java/postgresql.jar
+else
+ TEMP=${CLASSPATH}
+endif
+
+POSTGIS_BUILD_CLASSPATH?=$(TEMP)
-CLASSPATH?=/usr/share/java/postgresql.jar
+# Set those to --addclasspath for sablevm, to avoid overriding the
+# BOOTCLASSPATH, the first one is for the compiler, the second one for JRE.
+COMP_ADDCP?=-classpath
+EXEC_ADDCP?=-classpath
# This are used for the online regression tests, override via environment
-# as applicable.
+# as applicable. The jtest needs table creation privilege in current_schema(),
+# the others only call self contained SELECTs that do not access any tables.
PGHOST?=localhost
PGPORT?=5432
PGDATABASE?=jdbc_test
SRCDIR=src
EXAMPLES=examples
BUILD=bin
-RUNCP=$(CLASSPATH):postgis.jar
-BUILDCP=$(STUBBUILD):$(SRCDIR):$(CLASSPATH)
+RUNCP=$(POSTGIS_BUILD_CLASSPATH):postgis.jar
+BUILDCP=$(STUBBUILD):$(POSTGIS_BUILD_CLASSPATH)
# All the java files to compile
SRC= $(SRCDIR)/examples/Test.java \
touch stubcompile
compile: stubcompile $(BUILD) $(SRC)
- $(JAVAC) -classpath "$(BUILDCP)" -d $(BUILD) $(SRC)
+ $(JAVAC) $(COMP_ADDCP) "$(BUILDCP)" -d $(BUILD) $(SRC)
touch compile
test: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/Test
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/Test
jtest: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestServer jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestServer jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
ptestoffline: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestParser offline
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestParser offline
ptest: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestParser jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestParser jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
boxtestoffline: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestBoxes offline
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestBoxes offline
boxtest: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestBoxes jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestBoxes jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
autoregistertest: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestAutoregister jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestAutoregister jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
offlinetests: boxtestoffline ptestoffline test
# Print all available versions
versions: postgis.jar
- $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/VersionPrinter jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+ $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/VersionPrinter jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
# boxtest and ptest include boxtestoffline and ptestoffline, so we only need
# to run test in addition to the onlinetests
jtscompile: compile stubcompile $(JTSBUILD) $(JTSSRC)
- $(JAVAC) -classpath "$(BUILD):$(CP)" -d $(JTSBUILD) $(JTSSRC)
+ $(JAVAC) $(COMP_ADDCP) "$(BUILD):$(CP)" -d $(JTSBUILD) $(JTSSRC)
touch jtscompile
jtstestoffline: jtscompile
- $(JAVA) -classpath "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser offline
+ $(JAVA) $(EXEC_ADDCP) "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser offline
jtstest: jtscompile
- $(JAVA) -classpath "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser jdbc:postgres_jts://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+ $(JAVA) -$(EXEC_ADDCP) "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser jdbc:postgres_jts://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
postgis_jts.jar: jtscompile $(SRCDIR)/org/postgresql/driverconfig.properties
$(JAR) -cf postgis_jts.jar -C $(BUILD) . \
package org.postgis;
+import org.postgresql.util.PGtokenizer;
+
+import java.sql.SQLException;
import java.util.Iterator;
/**
}
}
+ protected ComposedGeom(int type, String value, boolean haveM) throws SQLException {
+ super(type);
+ value = value.trim();
+ String typestring = getTypeString();
+ if (value.indexOf(typestring) == 0) {
+ int pfxlen = typestring.length();
+ if (value.charAt(pfxlen) == 'M') {
+ pfxlen += 1;
+ haveM = true;
+ }
+ value = value.substring(pfxlen).trim();
+ } else if (value.charAt(0) != '(') {
+ // we are neigher inner nor outer rep.
+ throw new SQLException("Error parsing a " + typestring + " out of " + value);
+ }
+ if (value.equals("(EMPTY)")) {
+ // Special case for PostGIS 0.X style empty geometry collections
+ // (which are not OpenGIS compliant)
+ return;
+ }
+ PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
+ int subgeomcount = t.getSize();
+ subgeoms = createSubGeomArray(subgeomcount);
+ for (int p = 0; p < subgeomcount; p++) {
+ subgeoms[p] = createSubGeomInstance(t.getToken(p), haveM);
+ }
+ dimension = subgeoms[0].dimension;
+ // fetch haveMeasure from subpoint because haveM does only work with
+ // 2d+M, not with 3d+M geometries
+ haveMeasure = subgeoms[0].haveMeasure;
+ }
+
+ /**
+ * Return the appropriate instance of the subgeometry - this encapsulates
+ * subclass specific constructor calls
+ */
+ protected abstract Geometry createSubGeomInstance(String token, boolean haveM)
+ throws SQLException;
+
+ /**
+ * Return the appropriate instance of the subgeometry array - this
+ * encapsulates subclass specific array instantiation
+ */
+ protected abstract Geometry[] createSubGeomArray(int size);
+
protected boolean equalsintern(Geometry other) {
// Can be assumed to be the same subclass of Geometry, so it must be a
// ComposedGeom, too.
*/
public final int type;
- /**
- * The string rep of the current type
- */
- public final String typestring;
-
/**
* The spacial reference system id of this geometry, default (no srid) is -1
*/
*/
protected Geometry(int type) {
this.type = type;
- this.typestring = getTypeString(type);
}
/**
* StringBuffer.
*/
public void outerWKT(StringBuffer sb, boolean putM) {
- sb.append(typestring);
+ sb.append(getTypeString());
if (putM && haveMeasure && dimension == 2) {
sb.append('M');
}
package org.postgis;
-import org.postgresql.util.PGtokenizer;
-
import java.sql.SQLException;
/**
*/
public class GeometryCollection extends ComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
+
public static final String GeoCollID = "GEOMETRYCOLLECTION";
- public static final String EmptyColl = GeoCollID + "(EMPTY)";
public GeometryCollection() {
super(GEOMETRYCOLLECTION);
}
public GeometryCollection(String value, boolean haveM) throws SQLException {
- this();
- value = value.trim();
- if (value.equals(EmptyColl)) {
- //Do nothing
- } else if (value.startsWith(GeoCollID)) {
- int pfxlen = typestring.length();
- if (value.charAt(pfxlen) == 'M') {
- pfxlen += 1;
- haveM = true;
- }
- value = value.substring(pfxlen).trim();
+ super(GEOMETRYCOLLECTION, value, haveM);
+ }
- PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
- int ngeoms = t.getSize();
- subgeoms = new Geometry[ngeoms];
- for (int p = 0; p < ngeoms; p++) {
- subgeoms[p] = PGgeometry.geomFromString(t.getToken(p), haveM);
- }
- dimension = subgeoms[0].dimension;
- haveMeasure = subgeoms[0].haveMeasure;
- } else {
- throw new SQLException("postgis.geocollection");
- }
+ protected Geometry[] createSubGeomArray(int ngeoms) {
+ return new Geometry[ngeoms];
+ }
+
+ protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException {
+ return PGgeometry.geomFromString(token, haveM);
}
protected void innerWKT(StringBuffer SB) {
import java.sql.SQLException;
public class LineString extends PointComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
double len = -1.;
* the polygon types, but is not stored or retrieved directly from the database.
*/
public class LinearRing extends PointComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
public LinearRing(Point[] points) {
super(LINEARRING, points);
package org.postgis;
-import org.postgresql.util.PGtokenizer;
-
import java.sql.SQLException;
public class MultiLineString extends ComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
double len = -1;
public MultiLineString(String value) throws SQLException {
this(value, false);
}
-
- protected MultiLineString(String value, boolean haveM) throws SQLException {
- this();
- value = value.trim();
- if (value.indexOf(typestring) == 0) {
- int pfxlen = typestring.length();
- if (value.charAt(pfxlen) == 'M') {
- pfxlen += 1;
- haveM = true;
- }
- value = value.substring(pfxlen).trim();
- PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
- int nlines = t.getSize();
- subgeoms = new LineString[nlines];
- for (int p = 0; p < nlines; p++) {
- subgeoms[p] = new LineString(t.getToken(p), haveM);
- }
- dimension = subgeoms[0].dimension;
- haveMeasure = subgeoms[0].haveMeasure;
- } else {
- throw new SQLException("postgis.multilinestringgeometry");
- }
+
+ public MultiLineString(String value, boolean haveM) throws SQLException {
+ super(MULTILINESTRING, value, haveM);
+ }
+
+ protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException {
+ return new LineString(token, haveM);
+ }
+
+ protected Geometry[] createSubGeomArray(int nlines) {
+ return new LineString[nlines];
}
public int numLines() {
import java.sql.SQLException;
public class MultiPoint extends PointComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
public MultiPoint() {
super(MULTIPOINT);
package org.postgis;
-import org.postgresql.util.PGtokenizer;
-
import java.sql.SQLException;
public class MultiPolygon extends ComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
public MultiPolygon() {
super(MULTIPOLYGON);
}
protected MultiPolygon(String value, boolean haveM) throws SQLException {
- this();
- value = value.trim();
- if (value.indexOf("MULTIPOLYGON") == 0) {
- int pfxlen = typestring.length();
- if (value.charAt(pfxlen) == 'M') {
- pfxlen += 1;
- haveM = true;
- }
- value = value.substring(pfxlen).trim();
- PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
- int npolygons = t.getSize();
- subgeoms = new Polygon[npolygons];
- for (int p = 0; p < npolygons; p++) {
- subgeoms[p] = new Polygon(t.getToken(p), haveM);
- }
- dimension = subgeoms[0].dimension;
- // fetch haveMeasure from subpoint because haveM does only work with
- // 2d+M, not with 3d+M geometries
- this.haveMeasure = subgeoms[0].haveMeasure;
- } else {
- throw new SQLException("postgis.multipolygongeometry");
- }
+ super(MULTIPOLYGON, value, haveM);
+ }
+
+ protected Geometry[] createSubGeomArray(int npolygons) {
+ return new Polygon[npolygons];
+ }
+
+ protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException {
+ return new Polygon(token, haveM);
}
public int numPolygons() {
return null;
}
}
-
}
\ No newline at end of file
import java.sql.SQLException;
public class PGbox2d extends PGboxbase {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
public PGbox2d() {
super();
import java.sql.SQLException;
public class PGbox3d extends PGboxbase {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
+
public PGbox3d() {
super();
}
import java.sql.SQLException;
public class PGgeometry extends PGobject {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
Geometry geom;
BinaryParser bp = new BinaryParser();
int srid = -1;
if (value.startsWith(SRIDPREFIX)) {
- //break up geometry into srid and wkt
+ // break up geometry into srid and wkt
String[] parts = PGgeometry.splitSRID(value);
value = parts[1].trim();
srid = Integer.parseInt(parts[0].substring(5));
import java.sql.SQLException;
public class Point extends Geometry {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
public static final boolean CUTINTS = true;
m = Double.valueOf(t.getToken(dimension)).doubleValue();
}
} catch (NumberFormatException e) {
- throw new SQLException("postgis.Point" + e.toString());
+ throw new SQLException("Error parsing Point: " + e.toString());
}
haveMeasure = haveM;
}
*/
package org.postgis;
-import org.postgresql.util.PGtokenizer;
-
import java.sql.SQLException;
/**
public PointComposedGeom(int type, String value) throws SQLException {
this(type, value, false);
}
+
public PointComposedGeom(int type, String value, boolean haveM) throws SQLException {
- this(type);
- value = value.trim();
- if (value.indexOf(typestring) == 0) {
- int pfxlen = typestring.length();
- if (value.charAt(pfxlen)=='M') {
- pfxlen += 1;
- haveM=true;
- }
- value = value.substring(pfxlen).trim();
- }
- if (value.charAt(0) == '(') {
- PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
- int npoints = t.getSize();
- subgeoms = new Point[npoints];
- for (int p = 0; p < npoints; p++) {
- subgeoms[p] = new Point(t.getToken(p), haveM);
- }
- dimension = subgeoms[0].dimension;
- haveM |= subgeoms[0].haveMeasure;
- } else {
- throw new SQLException("postgis.multipointgeometry");
- }
- this.haveMeasure = haveM;
+ super(type, value, haveM);
+ }
+
+ protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException {
+ return new Point(token, haveM);
+ }
+
+ protected Geometry[] createSubGeomArray(int pointcount) {
+ return new Point[pointcount];
}
protected void innerWKT(StringBuffer sb) {
package org.postgis;
-import org.postgresql.util.PGtokenizer;
-
import java.sql.SQLException;
public class Polygon extends ComposedGeom {
+ /* JDK 1.5 Serialization */
+ private static final long serialVersionUID = 0x100;
public Polygon() {
super(POLYGON);
public Polygon(String value) throws SQLException {
this(value, false);
}
-
- public Polygon(String value, boolean haveM) throws SQLException{
- this();
- value = value.trim();
- if (value.indexOf(typestring) == 0) {
- int pfxlen = typestring.length();
- if (value.charAt(pfxlen) == 'M') {
- pfxlen += 1;
- haveM = true;
- }
- value = value.substring(pfxlen).trim();
- }
- PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
- int nrings = t.getSize();
- subgeoms = new LinearRing[nrings];
- for (int r = 0; r < nrings; r++) {
- subgeoms[r] = new LinearRing(t.getToken(r), haveM);
- }
- dimension = subgeoms[0].dimension;
- // fetch haveMeasure from subpoint because haveM does only work with
- // 2d+M, not with 3d+M geometries
- this.haveMeasure = subgeoms[0].haveMeasure;
+
+ public Polygon(String value, boolean haveM) throws SQLException {
+ super(POLYGON, value, haveM);
+ }
+
+ protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException {
+ return new LinearRing(token, haveM);
+ }
+
+ protected Geometry[] createSubGeomArray(int ringcount) {
+ return new LinearRing[ringcount];
}
public int numRings() {