Removed obsoleted code

git-svn-id: http://svn.osgeo.org/postgis/trunk@2207 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Sandro Santilli 2005-12-15 23:49:35 +00:00
parent b16600e141
commit c0da34f162
16 changed files with 0 additions and 1030 deletions

View file

@ -1,56 +0,0 @@
JAVAC = javac
JAVA = java
JAR = jar
PGSQL_SRC ?= ${PWD}/../../..
CLASSPATH ?= $(PGSQL_SRC)/src/interfaces/jdbc/jars/postgresql.jar:.
top_builddir:=$(PGSQL_SRC)
include $(PGSQL_SRC)/src/Makefile.global
all: ogis \
pgobjs \
test
jar: ogis pgobjs
$(JAR) -cf postgis.jar org/postgis/*.java org/postgis/*.class README
ogis:
$(JAVAC) -classpath $(CLASSPATH) \
org/postgis/Geometry.java \
org/postgis/Point.java \
org/postgis/MultiPoint.java \
org/postgis/LineString.java \
org/postgis/MultiLineString.java \
org/postgis/LinearRing.java \
org/postgis/Polygon.java \
org/postgis/MultiPolygon.java
pgobjs:
$(JAVAC) -classpath $(CLASSPATH) \
org/postgis/PGgeometry.java \
org/postgis/PGbox3d.java
install: jar installdirs
$(INSTALL_DATA) postgis.jar $(DESTDIR)
installdirs:
$(mkinstalldirs) $(DESTDIR)
uninstall:
rm -f $(DESTDIR)/postgis.jar
test:
$(JAVAC) -classpath $(CLASSPATH) examples/Test.java
$(JAVA) -classpath $(CLASSPATH) examples/Test
jtest:
$(JAVAC) -classpath $(CLASSPATH) examples/TestServer.java
$(JAVA) -classpath $(CLASSPATH) examples/TestServer
clean:
rm -f postgis.jar
rm -f org/postgis/*.class
rm -f examples/*.class

View file

@ -1,15 +0,0 @@
To use the PostGIS types, you must:
- have the postgis.jar in your CLASSPATH
- have a PostgreSQL JDBC Connection instance
Connection conn = new Connection();
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
To build the examples:
- put the jar file containing the PostgreSQL JDBC under
postgis/original/jars/postgresql.jar
The file might be named jdbc7.1-1.2.jar originally
- edit the file TestServer.java to adjust the connection information, run
the test with 'make jtest'

View file

@ -1,60 +0,0 @@
package examples;
import org.postgis.*;
public class Test
{
public static void main(String[] args)
{
String mlng_str = "MULTILINESTRING ((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))";
String mplg_str = "MULTIPOLYGON (((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)),((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)))";
String plg_str = "POLYGON ((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))";
String lng_str = "LINESTRING (10 10 20,20 20 20, 50 50 50, 34 34 34)";
String ptg_str = "POINT(10 10 20)";
String pt_str = "10 10 20";
String lr_str = "(10 10 20,34 34 34, 23 19 23 , 10 10 11)";
try {
System.out.println("LinearRing Test:");
System.out.println(lr_str);
LinearRing lr = new LinearRing(lr_str);
System.out.println(lr.toString());
System.out.println("Point Test:");
System.out.println(ptg_str);
Point ptg = new Point(ptg_str);
System.out.println(ptg.toString());
System.out.println("LineString Test:");
System.out.println(lng_str);
LineString lng = new LineString(lng_str);
System.out.println(lng.toString());
System.out.println("Polygon Test:");
System.out.println(plg_str);
Polygon plg = new Polygon(plg_str);
System.out.println(plg.toString());
System.out.println("MultiPolygon Test:");
System.out.println(mplg_str);
MultiPolygon mplg = new MultiPolygon(mplg_str);
System.out.println(mplg.toString());
System.out.println("MultiLineString Test:");
System.out.println(mlng_str);
MultiLineString mlng = new MultiLineString(mlng_str);
System.out.println(mlng.toString());
System.out.println("PG Test:");
System.out.println(mlng_str);
PGgeometry pgf = new PGgeometry(mlng_str);
System.out.println(pgf.toString());
}
catch(Exception e) {
e.printStackTrace();
}
}
}

View file

@ -1,73 +0,0 @@
package examples;
import java.sql.*;
import java.util.*;
import java.lang.*;
import org.postgis.*;
public class TestServer
{
public static void main(String[] args)
{
Connection conn;
String dbname = "tb";
String dbuser = "dblasby";
String dbpass = "";
String dbhost = "ox";
String dbport = "5555";
String dbtable = "jdbc_test";
String dropSQL = "drop table " + dbtable;
String createSQL = "create table " + dbtable + " (geom geometry, id int4)";
String insertPointSQL = "insert into " + dbtable + " values ('POINT (10 10 10)',1)";
String insertPolygonSQL = "insert into " + dbtable + " values ('POLYGON ((0 0 0,0 10 0,10 10 0,10 0 0,0 0 0))',2)";
try {
System.out.println("Creating JDBC connection...");
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://" + dbhost + ":" + dbport + "/" + dbname;
conn = DriverManager.getConnection(url, dbuser, dbpass);
System.out.println("Adding geometric type entries...");
((org.postgresql.PGConnection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.PGConnection)conn).addDataType("box3d","org.postgis.PGbox3d");
Statement s = conn.createStatement();
System.out.println("Creating table with geometric types...");
//table might not yet exist
try {
s.execute(dropSQL);
} catch(Exception e) {
e.printStackTrace();
}
s.execute(createSQL);
System.out.println("Inserting point...");
s.execute(insertPointSQL);
System.out.println("Inserting polygon...");
s.execute(insertPolygonSQL);
System.out.println("Done.");
s = conn.createStatement();
System.out.println("Querying table...");
ResultSet r = s.executeQuery("select asText(geom),id from " + dbtable);
while( r.next() )
{
Object obj = r.getObject(1);
int id = r.getInt(2);
System.out.println("Row " + id + ":");
System.out.println(obj.toString());
}
s.close();
conn.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
}

View file

@ -1,67 +0,0 @@
package org.postgis;
public class Geometry
{
/**
* The dimensionality of this feature (2,3)
*/
public int dimension;
/**
* The OGIS geometry type of this feature.
*/
public int type;
/**
* The OGIS geometry type number for points.
*/
public static final int POINT = 1;
/**
* The OGIS geometry type number for lines.
*/
public static final int LINESTRING = 2;
/**
* The OGIS geometry type number for polygons.
*/
public static final int POLYGON = 3;
/**
* The OGIS geometry type number for aggregate points.
*/
public static final int MULTIPOINT = 4;
/**
* The OGIS geometry type number for aggregate lines.
*/
public static final int MULTILINESTRING = 5;
/**
* The OGIS geometry type number for aggregate polygons.
*/
public static final int MULTIPOLYGON = 6;
/**
* The OGIS geometry type number for feature collections.
* Feature collections are not currently supported by the
* backend.
*/
public static final int GEOMETRYCOLLECTION = 7;
/**
* @return The OGIS geometry type number of this geometry.
*/
public int getType() {
return type;
}
/**
* @return The dimensionality (eg, 2D or 3D) of this geometry.
*/
public int getDimension() {
return dimension;
}
}

View file

@ -1,12 +0,0 @@
package org.postgis;
public class GeometryFactory {
public static byte[] Geometry2WKB(Geometry geom) {}
public static Geometry WKB2Geometry(byte[] wkb) {}
public static Geometry WKS2Geometry(String wks) {}
}

View file

@ -1,75 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
import java.util.*;
public class LineString extends Geometry
{
Point[] points;
public LineString()
{
type = LINESTRING;
}
public LineString(Point[] points)
{
this();
this.points = points;
dimension = points[0].dimension;
}
public LineString(String value) throws SQLException
{
this();
value = value.trim();
if ( value.indexOf("LINESTRING") == 0 )
{
value = value.substring(10).trim();
}
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value),',');
int npoints = t.getSize();
points = new Point[npoints];
for( int p = 0; p < npoints; p++)
{
points[p] = new Point(t.getToken(p));
}
dimension = points[0].dimension;
}
public String toString()
{
return "LINESTRING " + getValue();
}
public String getValue()
{
StringBuffer b = new StringBuffer("(");
for( int p = 0; p < points.length; p++ )
{
if( p > 0 ) b.append(",");
b.append(points[p].getValue());
}
b.append(")");
return b.toString();
}
public int numPoints()
{
return points.length;
}
public Point getPoint(int idx)
{
if ( idx >= 0 & idx < points.length ) {
return points[idx];
}
else {
return null;
}
}
}

View file

@ -1,82 +0,0 @@
package org.postgis;
import java.io.*;
import java.sql.*;
import org.postgresql.util.*;
/**
* This represents the LinearRing GIS datatype. This type is used to
* construct the polygon types, but is not
* stored or retrieved directly from the database.
*/
public class LinearRing extends Geometry
{
/**
* The points in the ring.
*/
public Point[] points;
public LinearRing(Point[] points)
{
this.points = points;
dimension = points[0].dimension;
}
/**
* This is called to construct a LinearRing from the
* PostGIS string representation of a ring.
*
* @param value Definition of this ring in the PostGIS
* string format.
*/
public LinearRing(String value) throws SQLException
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.trim()),',');
int npoints = t.getSize();
points = new Point[npoints];
for( int p = 0; p < npoints; p++ ) {
points[p] = new Point(t.getToken(p));
}
dimension = points[0].dimension;
}
/**
* @return the LinearRing in the syntax expected by PostGIS
*/
public String toString()
{
StringBuffer b = new StringBuffer("(");
for ( int p = 0; p < points.length; p++ )
{
if( p > 0 ) b.append(",");
b.append(points[p].getValue());
}
b.append(")");
return b.toString();
}
/**
* @return the LinearRing in the string syntax expected by PostGIS
*/
public String getValue()
{
return toString();
}
public int numPoints()
{
return points.length;
}
public Point getPoint(int idx)
{
if ( idx >= 0 & idx < points.length ) {
return points[idx];
}
else {
return null;
}
}
}

View file

@ -1,76 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
import java.util.*;
public class MultiLineString extends Geometry
{
LineString[] lines;
public MultiLineString()
{
type = MULTILINESTRING;
}
public MultiLineString(LineString[] lines)
{
this();
this.lines = lines;
dimension = lines[0].dimension;
}
public MultiLineString(String value) throws SQLException
{
this();
value = value.trim();
if ( value.indexOf("MULTILINESTRING") == 0 )
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(15).trim()),',');
int nlines = t.getSize();
lines = new LineString[nlines];
for( int p = 0; p < nlines; p++)
{
lines[p] = new LineString(t.getToken(p));
}
dimension = lines[0].dimension;
} else {
throw new SQLException("postgis.multilinestringgeometry");
}
}
public String toString()
{
return "MULTILINESTRING " + getValue();
}
public String getValue()
{
StringBuffer b = new StringBuffer("(");
for( int p = 0; p < lines.length; p++ )
{
if( p > 0 ) b.append(",");
b.append(lines[p].getValue());
}
b.append(")");
return b.toString();
}
public int numLines()
{
return lines.length;
}
public LineString getLine(int idx)
{
if( idx >= 0 & idx < lines.length ) {
return lines[idx];
}
else {
return null;
}
}
}

View file

@ -1,77 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
import java.util.*;
public class MultiPoint extends Geometry
{
Point[] points;
public MultiPoint()
{
type = MULTIPOINT;
}
public MultiPoint(Point[] points)
{
this();
this.points = points;
dimension = points[0].dimension;
}
public MultiPoint(String value) throws SQLException
{
this();
value = value.trim();
if ( value.indexOf("MULTIPOINT") == 0 )
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(10).trim()),',');
int npoints = t.getSize();
points = new Point[npoints];
for( int p = 0; p < npoints; p++)
{
points[p] = new Point(t.getToken(p));
}
dimension = points[0].dimension;
} else {
throw new SQLException("postgis.multipointgeometry");
}
}
public String toString()
{
return "MULTIPOINT " + getValue();
}
public String getValue()
{
StringBuffer b = new StringBuffer("(");
for( int p = 0; p < points.length; p++ )
{
if( p > 0 ) b.append(",");
b.append(points[p].getValue());
}
b.append(")");
return b.toString();
}
public int numPoints()
{
return points.length;
}
public Point getPoint(int idx)
{
if ( idx >= 0 & idx < points.length ) {
return points[idx];
}
else {
return null;
}
}
}

View file

@ -1,76 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
import java.util.*;
public class MultiPolygon extends Geometry
{
Polygon[] polygons;
public MultiPolygon()
{
type = MULTIPOLYGON;
}
public MultiPolygon(Polygon[] polygons)
{
this();
this.polygons = polygons;
dimension = polygons[0].dimension;
}
public MultiPolygon(String value) throws SQLException
{
this();
value = value.trim();
if ( value.indexOf("MULTIPOLYGON") == 0 )
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(12).trim()),',');
int npolygons = t.getSize();
polygons = new Polygon[npolygons];
for( int p = 0; p < npolygons; p++)
{
polygons[p] = new Polygon(t.getToken(p));
}
dimension = polygons[0].dimension;
} else {
throw new SQLException("postgis.multipolygongeometry");
}
}
public String toString()
{
return "MULTIPOLYGON " + getValue();
}
public String getValue()
{
StringBuffer b = new StringBuffer("(");
for( int p = 0; p < polygons.length; p++ )
{
if( p > 0 ) b.append(",");
b.append(polygons[p].getValue());
}
b.append(")");
return b.toString();
}
public int numPolygons()
{
return polygons.length;
}
public Polygon getPolygon(int idx)
{
if ( idx >= 0 & idx < polygons.length ) {
return polygons[idx];
}
else {
return null;
}
}
}

View file

@ -1,73 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
/*
* Updates Oct 2002
* - data members made private
* - getLLB() and getURT() methods added
*/
public class PGbox3d extends PGobject
{
/**
* The lower left bottom corner of the box.
*/
private Point llb;
/**
* The upper right top corner of the box.
*/
private Point urt;
public PGbox3d() {}
public PGbox3d(Point llb, Point urt) {
this.llb = llb;
this.urt = urt;
}
public PGbox3d(String value) throws SQLException
{
setValue(value);
}
public void setValue(String value) throws SQLException
{
value = value.trim();
if( value.startsWith("BOX3D") ) {
value = value.substring(5);
}
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.trim()),',');
llb = new Point(t.getToken(0));
urt = new Point(t.getToken(1));
}
public String getValue() {
return "BOX3D (" + llb.getValue() + "," + urt.getValue() + ")";
}
public String toString() {
return getValue();
}
public Object clone() {
PGbox3d obj = new PGbox3d(llb,urt);
obj.setType(type);
return obj;
}
/**Returns the lower left bottom corner of the box as a Point object*/
public Point getLLB() {
return llb;
}
/**Returns the upper right top corner of the box as a Point object*/
public Point getURT() {
return urt;
}
}

View file

@ -1,78 +0,0 @@
package org.postgis;
import org.postgresql.util.PGobject;
import org.postgresql.util.PGtokenizer;
import java.sql.*;
/*
* Updates Oct 2002
* - setValue() method now cheaks if the geometry has a SRID. If present,
* it is removed and only the wkt is used to create the new geometry
*/
public class PGgeometry extends PGobject
{
Geometry geom;
public PGgeometry() { }
public PGgeometry(Geometry geom) {
this.geom = geom;
}
public PGgeometry(String value) throws SQLException
{
setValue(value);
}
public void setValue(String value) throws SQLException
{
value = value.trim();
if( value.startsWith("SRID")) {
//break up geometry into srid and wkt
PGtokenizer t = new PGtokenizer(value,';');
value = t.getToken(1);
}
if( value.startsWith("MULTIPOLYGON")) {
geom = new MultiPolygon(value);
} else if( value.startsWith("MULTILINESTRING")) {
geom = new MultiLineString(value);
} else if( value.startsWith("MULTIPOINT")) {
geom = new MultiPoint(value);
} else if( value.startsWith("POLYGON")) {
geom = new Polygon(value);
} else if( value.startsWith("LINESTRING")) {
geom = new LineString(value);
} else if( value.startsWith("POINT")) {
geom = new Point(value);
} else {
throw new SQLException("Unknown type: " + value);
}
}
public Geometry getGeometry() {
return geom;
}
public int getGeoType() {
return geom.type;
}
public String toString() {
return geom.toString();
}
public String getValue() {
return geom.toString();
}
public Object clone()
{
PGgeometry obj = new PGgeometry(geom);
obj.setType(type);
return obj;
}
}

View file

@ -1,136 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
import java.util.*;
public class Point extends Geometry
{
/**
* The X coordinate of the point.
*/
public double x;
/**
* The Y coordinate of the point.
*/
public double y;
/**
* The Z coordinate of the point.
*/
public double z;
public Point()
{
type = POINT;
}
public Point(double x, double y, double z)
{
this();
this.x = x;
this.y = y;
this.z = z;
dimension = 3;
}
public Point(double x, double y)
{
this();
this.x = x;
this.y = y;
this.z = 0.0;
dimension = 2;
}
public Point(String value) throws SQLException
{
this();
value = value.trim();
if ( value.indexOf("POINT") == 0 )
{
value = value.substring(5).trim();
}
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value),' ');
try {
if ( t.getSize() == 3 ) {
x = Double.valueOf(t.getToken(0)).doubleValue();
y = Double.valueOf(t.getToken(1)).doubleValue();
z = Double.valueOf(t.getToken(2)).doubleValue();
dimension = 3;
} else {
x = Double.valueOf(t.getToken(0)).doubleValue();
y = Double.valueOf(t.getToken(1)).doubleValue();
z = 0.0;
dimension = 2;
}
}
catch(NumberFormatException e) {
throw new SQLException("postgis.Point: " + e.toString());
}
}
public String toString()
{
return "POINT (" + getValue() + ")";
}
public String getValue()
{
if ( dimension == 3 )
{
return x+" "+y+" "+z;
} else {
return x+" "+y;
}
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
public double getZ()
{
return z;
}
public void setX(double x)
{
this.x = x;
}
public void setY(double y)
{
this.y = y;
}
public void setZ(double z)
{
this.z = z;
}
public void setX(int x)
{
this.x = (double)x;
}
public void setY(int y)
{
this.y = (double)y;
}
public void setZ(int z)
{
this.z = (double)z;
}
}

View file

@ -1,74 +0,0 @@
package org.postgis;
import org.postgresql.util.*;
import java.sql.*;
import java.util.*;
public class Polygon extends Geometry
{
LinearRing[] rings;
public Polygon()
{
type = POLYGON;
}
public Polygon(LinearRing[] rings)
{
this();
this.rings = rings;
dimension = rings[0].dimension;
}
public Polygon(String value) throws SQLException
{
this();
value = value.trim();
if ( value.indexOf("POLYGON") == 0 )
{
value = value.substring(7).trim();
}
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value),',');
int nrings = t.getSize();
rings = new LinearRing[nrings];
for( int r = 0; r < nrings; r++)
{
rings[r] = new LinearRing(t.getToken(r));
}
dimension = rings[0].dimension;
}
public String toString()
{
return "POLYGON " + getValue();
}
public String getValue()
{
StringBuffer b = new StringBuffer("(");
for( int r = 0; r < rings.length; r++ )
{
if( r > 0 ) b.append(",");
b.append(rings[r].toString());
}
b.append(")");
return b.toString();
}
public int numRings()
{
return rings.length;
}
public LinearRing getRing(int idx)
{
if( idx >= 0 & idx < rings.length ) {
return rings[idx];
}
else {
return null;
}
}
}