[DebianGIS-dev] r561 - in packages/postgis/upstream: . doc doc/html extras/WFS_locks extras/ogc_test_suite extras/wkb_reader java java/ejb2 java/ejb2/lib java/ejb2/resources java/ejb2/resources/jndi java/ejb2/src java/ejb2/src/com java/ejb2/src/com/geodetix java/ejb2/src/com/geodetix/geo java/ejb2/src/com/geodetix/geo/client java/ejb2/src/com/geodetix/geo/dao java/ejb2/src/com/geodetix/geo/ejb java/ejb2/src/com/geodetix/geo/exception java/ejb3 java/ejb3/.settings java/ejb3/jboss java/ejb3/src java/ejb3/src/META-INF java/ejb3/src/org java/ejb3/src/org/postgis java/ejb3/src/org/postgis/ejb java/ejb3/src/org/postgis/ejb/mdb java/ejb3/src/org/postgis/hibernate java/jdbc java/jdbc/jtssrc java/jdbc/jtssrc/examples java/jdbc/jtssrc/org java/jdbc/jtssrc/org/postgis java/jdbc/jtssrc/org/postgis/jts java/jdbc/src java/jdbc/src/examples java/jdbc/src/org java/jdbc/src/org/postgis java/jdbc/src/org/postgis/binary java/jdbc/src/org/postgis/java2d java/jdbc/src/org/postgresql java/jdbc/stubs java/jdbc/stubs/org java/jdbc/stubs/org/postgresql loader lwgeom regress regress/loader topology topology/ER topology/test utils

Fabio Tranchitella kobold at costa.debian.org
Fri Oct 6 08:43:13 UTC 2006


Author: kobold
Date: 2006-10-06 08:43:11 +0000 (Fri, 06 Oct 2006)
New Revision: 561

Added:
   packages/postgis/upstream/doc/html/postgis.html
   packages/postgis/upstream/java/
   packages/postgis/upstream/java/ejb2/
   packages/postgis/upstream/java/ejb2/CHANGES
   packages/postgis/upstream/java/ejb2/COPYING
   packages/postgis/upstream/java/ejb2/COPYING_LGPL
   packages/postgis/upstream/java/ejb2/README
   packages/postgis/upstream/java/ejb2/build.xml
   packages/postgis/upstream/java/ejb2/lib/
   packages/postgis/upstream/java/ejb2/lib/commonlib/
   packages/postgis/upstream/java/ejb2/lib/compiletimelib/
   packages/postgis/upstream/java/ejb2/lib/xdocletlib/
   packages/postgis/upstream/java/ejb2/prepare-jboss.xml
   packages/postgis/upstream/java/ejb2/resources/
   packages/postgis/upstream/java/ejb2/resources/application.xml
   packages/postgis/upstream/java/ejb2/resources/build.properties
   packages/postgis/upstream/java/ejb2/resources/jndi/
   packages/postgis/upstream/java/ejb2/resources/jndi/jndi.properties
   packages/postgis/upstream/java/ejb2/resources/postgis-ejb2-ds.xml
   packages/postgis/upstream/java/ejb2/src/
   packages/postgis/upstream/java/ejb2/src/com/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/client/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/client/Client.java
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAO.java
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAOImpl.java
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryBean.java
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryFacadeBean.java
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/exception/
   packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/exception/ApplicationGeoLayerException.java
   packages/postgis/upstream/java/ejb3/
   packages/postgis/upstream/java/ejb3/.classpath
   packages/postgis/upstream/java/ejb3/.project
   packages/postgis/upstream/java/ejb3/.settings/
   packages/postgis/upstream/java/ejb3/.settings/org.eclipse.jdt.core.prefs
   packages/postgis/upstream/java/ejb3/README.txt
   packages/postgis/upstream/java/ejb3/build.xml
   packages/postgis/upstream/java/ejb3/ejb3spatial.pdf
   packages/postgis/upstream/java/ejb3/jboss/
   packages/postgis/upstream/java/ejb3/jboss/geodata-ds.xml
   packages/postgis/upstream/java/ejb3/jboss/ingest-service.xml
   packages/postgis/upstream/java/ejb3/lib/
   packages/postgis/upstream/java/ejb3/src/
   packages/postgis/upstream/java/ejb3/src/META-INF/
   packages/postgis/upstream/java/ejb3/src/META-INF/persistence.xml
   packages/postgis/upstream/java/ejb3/src/jndi.properties
   packages/postgis/upstream/java/ejb3/src/org/
   packages/postgis/upstream/java/ejb3/src/org/postgis/
   packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/
   packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/PersonEntity.java
   packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBean.java
   packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBeanRemote.java
   packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/mdb/
   packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/mdb/IngestMDB.java
   packages/postgis/upstream/java/ejb3/src/org/postgis/hibernate/
   packages/postgis/upstream/java/ejb3/src/org/postgis/hibernate/GeometryType.java
   packages/postgis/upstream/java/jdbc/
   packages/postgis/upstream/java/jdbc/COPYING_LGPL
   packages/postgis/upstream/java/jdbc/Makefile
   packages/postgis/upstream/java/jdbc/README
   packages/postgis/upstream/java/jdbc/jtssrc/
   packages/postgis/upstream/java/jdbc/jtssrc/examples/
   packages/postgis/upstream/java/jdbc/jtssrc/examples/JtsTestParser.java
   packages/postgis/upstream/java/jdbc/jtssrc/org/
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryParser.java
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryWriter.java
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGeometry.java
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGisWrapper.java
   packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsWrapper.java
   packages/postgis/upstream/java/jdbc/src/
   packages/postgis/upstream/java/jdbc/src/examples/
   packages/postgis/upstream/java/jdbc/src/examples/Test.java
   packages/postgis/upstream/java/jdbc/src/examples/TestAutoregister.java
   packages/postgis/upstream/java/jdbc/src/examples/TestBoxes.java
   packages/postgis/upstream/java/jdbc/src/examples/TestJava2d.java
   packages/postgis/upstream/java/jdbc/src/examples/TestParser.java
   packages/postgis/upstream/java/jdbc/src/examples/TestServer.java
   packages/postgis/upstream/java/jdbc/src/examples/VersionPrinter.java
   packages/postgis/upstream/java/jdbc/src/org/
   packages/postgis/upstream/java/jdbc/src/org/postgis/
   packages/postgis/upstream/java/jdbc/src/org/postgis/ComposedGeom.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapper.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperAutoprobe.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperLW.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/Geometry.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/GeometryCollection.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/LineString.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/LinearRing.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/MultiLineString.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPoint.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPolygon.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox2d.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox3d.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/PGboxbase.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometry.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometryLW.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/Point.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/PointComposedGeom.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/Polygon.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/Version.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryParser.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryWriter.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteGetter.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteSetter.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueGetter.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueSetter.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/
   packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/Java2DWrapper.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/PGShapeGeometry.java
   packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/ShapeBinaryParser.java
   packages/postgis/upstream/java/jdbc/src/org/postgresql/
   packages/postgis/upstream/java/jdbc/src/org/postgresql/driverconfig.properties
   packages/postgis/upstream/java/jdbc/stubs/
   packages/postgis/upstream/java/jdbc/stubs/LICENSE
   packages/postgis/upstream/java/jdbc/stubs/org/
   packages/postgis/upstream/java/jdbc/stubs/org/postgresql/
   packages/postgis/upstream/java/jdbc/stubs/org/postgresql/Connection.java
   packages/postgis/upstream/java/jdbc/stubs/org/postgresql/PGConnection.java
   packages/postgis/upstream/java/jdbc/todo.txt
   packages/postgis/upstream/regress/ctors.sql
   packages/postgis/upstream/regress/ctors_expected
Removed:
   packages/postgis/upstream/.cvsignore
   packages/postgis/upstream/autom4te.cache/
   packages/postgis/upstream/doc/.cvsignore
   packages/postgis/upstream/doc/html/.cvsignore
   packages/postgis/upstream/doc/html/apa.html
   packages/postgis/upstream/doc/html/ch01.html
   packages/postgis/upstream/doc/html/ch02.html
   packages/postgis/upstream/doc/html/ch03.html
   packages/postgis/upstream/doc/html/ch04.html
   packages/postgis/upstream/doc/html/ch05.html
   packages/postgis/upstream/doc/html/ch06.html
   packages/postgis/upstream/doc/html/ch07.html
   packages/postgis/upstream/doc/html/index.html
   packages/postgis/upstream/extras/ogc_test_suite/.cvsignore
   packages/postgis/upstream/extras/wkb_reader/.cvsignore
   packages/postgis/upstream/loader/.cvsignore
   packages/postgis/upstream/lwgeom/.cvsignore
   packages/postgis/upstream/topology/.cvsignore
   packages/postgis/upstream/topology/ER/.cvsignore
   packages/postgis/upstream/topology/test/.cvsignore
Modified:
   packages/postgis/upstream/CHANGES
   packages/postgis/upstream/Version.config
   packages/postgis/upstream/doc/postgis.xml
   packages/postgis/upstream/extras/WFS_locks/WFS_locks.sql.in
   packages/postgis/upstream/extras/ogc_test_suite/1_schema.sql
   packages/postgis/upstream/extras/ogc_test_suite/2_queries.sql
   packages/postgis/upstream/loader/dbfopen.c
   packages/postgis/upstream/loader/pgsql2shp.c
   packages/postgis/upstream/loader/shapefil.h
   packages/postgis/upstream/loader/shp2pgsql.c
   packages/postgis/upstream/loader/shpopen.c
   packages/postgis/upstream/lwgeom/lex.yy.c
   packages/postgis/upstream/lwgeom/long_xact.sql
   packages/postgis/upstream/lwgeom/lwcollection.c
   packages/postgis/upstream/lwgeom/lwgeom.c
   packages/postgis/upstream/lwgeom/lwgeom_box2dfloat4.c
   packages/postgis/upstream/lwgeom/lwgeom_box3d.c
   packages/postgis/upstream/lwgeom/lwgeom_btree.c
   packages/postgis/upstream/lwgeom/lwgeom_chip.c
   packages/postgis/upstream/lwgeom/lwgeom_dump.c
   packages/postgis/upstream/lwgeom/lwgeom_estimate.c
   packages/postgis/upstream/lwgeom/lwgeom_functions_analytic.c
   packages/postgis/upstream/lwgeom/lwgeom_functions_basic.c
   packages/postgis/upstream/lwgeom/lwgeom_functions_lrs.c
   packages/postgis/upstream/lwgeom/lwgeom_gist.c
   packages/postgis/upstream/lwgeom/lwgeom_gml.c
   packages/postgis/upstream/lwgeom/lwgeom_ogc.c
   packages/postgis/upstream/lwgeom/lwgeom_spheroid.c
   packages/postgis/upstream/lwgeom/lwgeom_svg.c
   packages/postgis/upstream/lwgeom/lwgeom_transform.c
   packages/postgis/upstream/lwgeom/lwline.c
   packages/postgis/upstream/lwgeom/lwmline.c
   packages/postgis/upstream/lwgeom/lwmpoint.c
   packages/postgis/upstream/lwgeom/lwmpoly.c
   packages/postgis/upstream/lwgeom/lwpoint.c
   packages/postgis/upstream/lwgeom/lwpoly.c
   packages/postgis/upstream/lwgeom/lwpostgis.sql.in
   packages/postgis/upstream/lwgeom/measures.c
   packages/postgis/upstream/lwgeom/ptarray.c
   packages/postgis/upstream/lwgeom/stringBuffer.h
   packages/postgis/upstream/lwgeom/wktparse.h
   packages/postgis/upstream/lwgeom/wktunparse.c
   packages/postgis/upstream/regress/Makefile
   packages/postgis/upstream/regress/loader/Arc.dbf
   packages/postgis/upstream/regress/loader/ArcM.dbf
   packages/postgis/upstream/regress/loader/MultiPoint.dbf
   packages/postgis/upstream/regress/loader/MultiPointM.dbf
   packages/postgis/upstream/regress/loader/MultiPointZ.dbf
   packages/postgis/upstream/regress/loader/Point.dbf
   packages/postgis/upstream/regress/loader/PointM.dbf
   packages/postgis/upstream/regress/loader/PointZ.dbf
   packages/postgis/upstream/regress/loader/Polygon.dbf
   packages/postgis/upstream/regress/loader/PolygonM.dbf
   packages/postgis/upstream/regress/loader/PolygonZ.dbf
   packages/postgis/upstream/regress/regress_index.sql
   packages/postgis/upstream/regress/regress_ogc.sql
   packages/postgis/upstream/regress/regress_ogc_expected
   packages/postgis/upstream/topology/topology.sql.in
   packages/postgis/upstream/utils/profile_intersects.pl
   packages/postgis/upstream/utils/test_estimation.pl
   packages/postgis/upstream/utils/test_joinestimation.pl
Log:
Import new upstream release (postgis 1.1.4) into upstream.


Deleted: packages/postgis/upstream/.cvsignore
===================================================================
--- packages/postgis/upstream/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,15 +0,0 @@
-Makefile.config
-libpostgis.so.0.8
-postgis.sql
-postgis_undef.sql
-postgis_old.sql
-lwpostgis.sql
-lwpostgis_upgrade.sql
-.classpath
-.project
-config.log
-config.status
-configure
-autom4te.cache
-config.h
-eclipsebin

Modified: packages/postgis/upstream/CHANGES
===================================================================
--- packages/postgis/upstream/CHANGES	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/CHANGES	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,3 +1,21 @@
+PostGIS 1.1.4
+
+	- Fixed support for PostgreSQL 8.2
+	- Fixed bug in collect() function discarding SRID of
+	  input
+	- Added SRID match check in MakeBox2d and MakeBox3d
+	- Fixed regress tests to pass with GEOS-3.0.0
+	- Improved pgsql2shp run concurrency.
+	- Java:
+		- reworked JTS support to reflect new upstream
+		  JTS developers' attitude to SRID handling.
+		  Simplifies code and drops build depend on GNU trove.
+		- Added EJB2 support generously donated by the
+		  "Geodetix s.r.l. Company" http://www.geodetix.it/
+		- Added EJB3 tutorial / examples donated by
+		  Norman Barker <nbarker at ittvis.com>
+		- Reorganized java directory layout a little.
+
 PostGIS 1.1.3
 2006/06/30
 

Modified: packages/postgis/upstream/Version.config
===================================================================
--- packages/postgis/upstream/Version.config	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/Version.config	2006-10-06 08:43:11 UTC (rev 561)
@@ -4,7 +4,7 @@
 # shared library / release version
 SO_MAJOR_VERSION=1
 SO_MINOR_VERSION=1
-SO_MICRO_VERSION=3
+SO_MICRO_VERSION=4
 
 # JDBC code version
 JDBC_MAJOR_VERSION=1

Deleted: packages/postgis/upstream/doc/.cvsignore
===================================================================
--- packages/postgis/upstream/doc/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,3 +0,0 @@
-postgis-out.xml
-postgis.fo
-postgis.pdf

Deleted: packages/postgis/upstream/doc/html/.cvsignore
===================================================================
--- packages/postgis/upstream/doc/html/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1 +0,0 @@
-*.html

Deleted: packages/postgis/upstream/doc/html/apa.html
===================================================================
--- packages/postgis/upstream/doc/html/apa.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/apa.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,239 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Appendix A. Appendix</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch07.html" title="Chapter 7. Reporting Bugs"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Appendix A. Appendix</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="release_notes"></a>Appendix A. Appendix</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="apa.html#id2530726">A.1. Release Notes</a></span></dt><dd><dl><dt><span class="sect2"><a href="apa.html#id2530732">A.1.1. Release 1.1.3</a></span></dt><dt><span class="sect2"><a href="apa.html#id2530900">A.1.2. Release 1.1.2</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531032">A.1.3. Release 1.1.1</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531325">A.1.4. Release 1.1.0</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531650">A.1.5. Release 1.0.6</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531758">A.1.6. Release 1.0.5</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531890">A.1.7. Release 1.0.4</a></span></dt><dt><span class="sect2"><a href="apa.html#rel_1.0.3_upgrading">A.1.8. Release 1.0.3</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532137">A.1.9. Release 1.0.2</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532216">A.1.10. Release 1.0.1</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532315">A.1.11. Release 1.0.0</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532414">A.1.12. Release 1.0.0RC6</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532488">A.1.13. Release 1.0.0RC5</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532560">A.1.14. Release 1.0.0RC4</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532685">A.1.15. Release 1.0.0RC3</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532857">A.1.16. Release 1.0.0RC2</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532955">A.1.17. Release 1.0.0RC1</a></span></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2530726"></a>A.1. Release Notes</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2530732"></a>A.1.1. Release 1.1.3</h3></div></div><div></div></div><p>Release date: 2006/06/30</p><p>
-This is an bugfix release including also some new functionalities (most notably long transaction support) and portability enhancements.
-Upgrade is <span class="emphasis"><em>encouraged</em></span>.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530751"></a>A.1.1.1. Upgrading</h4></div></div><div></div></div><p>
-If you are upgrading from release 1.0.3 or later follow the
-<a href="ch02.html#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
-				</p><p>
-If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
-1.0.2</em></span> (inclusive) and really want a live upgrade read the
-<a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade section</a> of the 1.0.3
-release notes chapter.
-				</p><p>
-Upgrade from any release prior to 1.0.0RC6 requires an
-<a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530800"></a>A.1.1.2. Bug fixes / correctness</h4></div></div><div></div></div><p> BUGFIX in distance(poly,poly) giving wrong results. </p><p> BUGFIX in pgsql2shp successful return code. </p><p> BUGFIX in shp2pgsql handling of MultiLine WKT. </p><p> BUGFIX in affine() failing to update bounding box. </p><p> WKT parser: forbidden construction of multigeometries with 
-	  EMPTY elements (still supported for GEOMETRYCOLLECTION). </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530829"></a>A.1.1.3. New functionalities</h4></div></div><div></div></div><p> NEW Long Transactions support. </p><p> NEW DumpRings() function. </p><p> NEW AsHEXEWKB(geom, XDR|NDR) function. </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530847"></a>A.1.1.4. JDBC changes</h4></div></div><div></div></div><p> Improved regression tests: MultiPoint and scientific ordinates </p><p> Fixed some minor bugs in jdbc code </p><p>
-Added proper accessor functions for all fields in preparation of 
-making those fields private later
-</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530868"></a>A.1.1.5. Other changes</h4></div></div><div></div></div><p> NEW regress test support for loader/dumper. </p><p> Added --with-proj-libdir and --with-geos-libdir configure switches. </p><p> Support for build Tru64 build. </p><p> Use Jade for generating documentation. </p><p> Don't link pgsql2shp to more libs then required. </p><p> Initial support for PostgreSQL 8.2. </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2530900"></a>A.1.2. Release 1.1.2</h3></div></div><div></div></div><p>Release date: 2006/03/30</p><p>
-This is an bugfix release including some new functions and portability enhancements.
-Upgrade is <span class="emphasis"><em>encouraged</em></span>.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530918"></a>A.1.2.1. Upgrading</h4></div></div><div></div></div><p>
-If you are upgrading from release 1.0.3 or later follow the
-<a href="ch02.html#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
-				</p><p>
-If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
-1.0.2</em></span> (inclusive) and really want a live upgrade read the
-<a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade section</a> of the 1.0.3
-release notes chapter.
-				</p><p>
-Upgrade from any release prior to 1.0.0RC6 requires an
-<a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530965"></a>A.1.2.2. Bug fixes</h4></div></div><div></div></div><p>BUGFIX in SnapToGrid() computation of output bounding box</p><p>BUGFIX in EnforceRHR() </p><p>jdbc2 SRID handling fixes in JTS code</p><p>Fixed support for 64bit archs</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2530988"></a>A.1.2.3. New functionalities</h4></div></div><div></div></div><p>Regress tests can now be run *before* postgis intallation</p><p>New affine() matrix transformation functions</p><p>New rotate{,X,Y,Z}() function </p><p>Old translating and scaling functions now use affine() internally</p><p>Embedded access control in estimated_extent() for builds against pgsql &gt;= 8.0.0</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531016"></a>A.1.2.4. Other changes</h4></div></div><div></div></div><p>More portable ./configure script</p><p>Changed ./run_test script to have more sane default behaviour</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2531032"></a>A.1.3. Release 1.1.1</h3></div></div><div></div></div><p>Release date: 2006/01/23</p><p>
-This is an important Bugfix release, upgrade is <span class="emphasis"><em>highly
-recommended</em></span>.
-Previous version contained a bug in postgis_restore.pl preventing
-<a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a> procedure to complete
-and a bug in GEOS-2.2+ connector preventing GeometryCollection objects
-to be used in topological operations.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531060"></a>A.1.3.1. Upgrading</h4></div></div><div></div></div><p>
-If you are upgrading from release 1.0.3 or later follow the
-<a href="ch02.html#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
-				</p><p>
-If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
-1.0.2</em></span> (inclusive) and really want a live upgrade read the
-<a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade section</a> of the 1.0.3
-release notes chapter.
-				</p><p>
-Upgrade from any release prior to 1.0.0RC6 requires an
-<a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531269"></a>A.1.3.2. Bug fixes</h4></div></div><div></div></div><p>Fixed a premature exit in postgis_restore.pl </p><p>BUGFIX in geometrycollection handling of GEOS-CAPI connector</p><p>Solaris 2.7 and MingW support improvements</p><p>BUGFIX in line_locate_point()</p><p>Fixed handling of postgresql paths</p><p>BUGFIX in line_substring()</p><p>Added support for localized cluster in regress tester</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531304"></a>A.1.3.3. New functionalities</h4></div></div><div></div></div><p>New Z and M interpolation in line_substring()</p><p>New Z and M interpolation in line_interpolate_point()</p><p>added NumInteriorRing() alias due to OpenGIS ambiguity</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2531325"></a>A.1.4. Release 1.1.0</h3></div></div><div></div></div><p>Release date: 2005/12/21</p><p>
-This is a Minor release, containing many improvements and new things.
-Most notably: build procedure greatly simplified; transform() performance
-drastically improved; more stable GEOS connectivity (CAPI support);
-lots of new functions; draft topology support.
-			</p><p>
-It is <span class="emphasis"><em>highly recommended</em></span> that you upgrade to GEOS-2.2.x
-before installing PostGIS, this will ensure future GEOS upgrades won't
-require a rebuild of the PostGIS library.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531352"></a>A.1.4.1. Credits</h4></div></div><div></div></div><p>
-This release includes code from Mark Cave Ayland for caching of proj4
-objects. Markus Schaber added many improvements in his JDBC2 code.
-Alex Bodnaru helped with PostgreSQL source dependency relief and
-provided Debian specfiles.  Michael Fuhr tested new things on Solaris arch.
-David Techer and Gerald Fenoy helped testing GEOS C-API connector.
-Hartmut Tschauner provided code for the azimuth() function. 
-Devrim GUNDUZ provided RPM specfiles. Carl Anderson helped with
-the new area building functions.
-See the <a href="ch01.html#credits" title="1.1. Credits">credits</a> section for more names.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531378"></a>A.1.4.2. Upgrading</h4></div></div><div></div></div><p>
-If you are upgrading from release 1.0.3 or later you <span class="emphasis"><em>DO
-NOT</em></span> need a dump/reload.
-Simply sourcing the new lwpostgis_upgrade.sql script in all your
-existing databases will work.
-See the <a href="ch02.html#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> chapter
-for more informations.
-				</p><p>
-If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
-1.0.2</em></span> (inclusive) and really want a live upgrade read the
-<a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade section</a> of the 1.0.3
-release notes chapter.
-				</p><p>
-Upgrade from any release prior to 1.0.0RC6 requires an
-<a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531431"></a>A.1.4.3. New functions</h4></div></div><div></div></div><p>scale() and transscale() companion methods to translate()</p><p>line_substring() </p><p>line_locate_point()</p><p>M(point) </p><p>LineMerge(geometry) </p><p>shift_longitude(geometry) </p><p>azimuth(geometry) </p><p>locate_along_measure(geometry, float8) </p><p>locate_between_measures(geometry, float8, float8) </p><p>SnapToGrid by point offset (up to 4d support)</p><p>BuildArea(any_geometry) </p><p>OGC BdPolyFromText(linestring_wkt, srid) </p><p>OGC BdMPolyFromText(linestring_wkt, srid)</p><p>RemovePoint(linestring, offset)</p><p>ReplacePoint(linestring, offset, point)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531496"></a>A.1.4.4. Bug fixes</h4></div></div><div></div></div><p>Fixed memory leak in polygonize()</p><p>Fixed bug in lwgeom_as_anytype cast funcions</p><p>
-Fixed USE_GEOS, USE_PROJ and USE_STATS elements of postgis_version()
-output to always reflect library state.
-</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531516"></a>A.1.4.5. Function semantic changes</h4></div></div><div></div></div><p>SnapToGrid doesn't discard higher dimensions</p><p>Changed Z() function to return NULL if requested dimension is not available</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531531"></a>A.1.4.6. Performance improvements</h4></div></div><div></div></div><p>
-Much faster transform() function, caching proj4 objects
-</p><p>
-Removed automatic call to fix_geometry_columns() in
-AddGeometryColumns() and update_geometry_stats()
-</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531548"></a>A.1.4.7. JDBC2 works</h4></div></div><div></div></div><p>Makefile improvements</p><p>JTS support improvements</p><p>Improved regression test system</p><p>Basic consistency check method for geometry collections</p><p>Support for (Hex)(E)wkb</p><p>Autoprobing DriverWrapper for HexWKB / EWKT switching</p><p>fix compile problems in ValueSetter for ancient jdk releases.</p><p>fix EWKT constructors to accept SRID=4711; representation</p><p>added preliminary read-only support for java2d geometries</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531591"></a>A.1.4.8. Other new things</h4></div></div><div></div></div><p>
-Full autoconf-based configuration, with PostgreSQL source dependency relief
-</p><p>GEOS C-API support (2.2.0 and higher)</p><p>Initial support for topology modelling</p><p>Debian and RPM specfiles</p><p>New lwpostgis_upgrade.sql script</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531618"></a>A.1.4.9. Other changes</h4></div></div><div></div></div><p>JTS support improvements</p><p>Stricter mapping between DBF and SQL integer and string attributes</p><p>Wider and cleaner regression test suite</p><p>old jdbc code removed from release</p><p>obsoleted direct use of postgis_proc_upgrade.pl</p><p>scripts version unified with release version</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2531650"></a>A.1.5. Release 1.0.6</h3></div></div><div></div></div><p>Release date: 2005/12/06</p><p>
-Contains a few bug fixes and improvements.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531664"></a>A.1.5.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.3 or later you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.
-				</p><p>If you are upgrading from
-				a release <span class="emphasis"><em>between 1.0.0RC6 and
-				1.0.2</em></span> (inclusive) and really want
-				a live upgrade read the <a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade
-				section</a> of the 1.0.3 release notes
-				chapter.
-				</p><p>
-				Upgrade from any release prior to 1.0.0RC6
-				requires an <a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard
-				upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531707"></a>A.1.5.2. Bug fixes</h4></div></div><div></div></div><p>Fixed palloc(0) call in collection deserializer (only gives problem with --enable-cassert)</p><p>Fixed bbox cache handling bugs</p><p>Fixed geom_accum(NULL, NULL) segfault</p><p>Fixed segfault in addPoint()</p><p>Fixed short-allocation in lwcollection_clone()</p><p>Fixed bug in segmentize()</p><p>Fixed bbox computation of SnapToGrid output</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531742"></a>A.1.5.3. Improvements</h4></div></div><div></div></div><p>Initial support for postgresql 8.2</p><p>Added missing SRID mismatch checks in GEOS ops</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2531758"></a>A.1.6. Release 1.0.5</h3></div></div><div></div></div><p>Release date: 2005/11/25</p><p>
-Contains memory-alignment fixes in the library, a segfault fix in loader's
-handling of UTF8 attributes and a few improvements and cleanups.
-			</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-Return code of shp2pgsl changed from previous releases to conform to unix
-standards (return 0 on success).
-			</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531780"></a>A.1.6.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.3 or later you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.
-				</p><p>If you are upgrading from
-				a release <span class="emphasis"><em>between 1.0.0RC6 and
-				1.0.2</em></span> (inclusive) and really want
-				a live upgrade read the <a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade
-				section</a> of the 1.0.3 release notes
-				chapter.
-				</p><p>
-				Upgrade from any release prior to 1.0.0RC6
-				requires an <a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard
-				upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531823"></a>A.1.6.2. Library changes</h4></div></div><div></div></div><p>Fixed memory alignment problems</p><p>Fixed computation of null values fraction in analyzer</p><p>Fixed a small bug in the getPoint4d_p() low-level function</p><p>Speedup of serializer functions</p><p>Fixed a bug in force_3dm(), force_3dz() and force_4d()</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531850"></a>A.1.6.3. Loader changes</h4></div></div><div></div></div><p>Fixed return code of shp2pgsql</p><p>Fixed back-compatibility issue in loader (load of null shapefiles)</p><p>Fixed handling of trailing dots in dbf numerical attributes</p><p>Segfault fix in shp2pgsql (utf8 encoding)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531874"></a>A.1.6.4. Other changes</h4></div></div><div></div></div><p>Schema aware postgis_proc_upgrade.pl, support for pgsql 7.2+</p><p>New "Reporting Bugs" chapter in manual</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2531890"></a>A.1.7. Release 1.0.4</h3></div></div><div></div></div><p>Release date: 2005/09/09</p><p>
-Contains important bug fixes and a few improvements. In particular, it
-fixes a memory leak preventing successful build of GiST indexes
-for large spatial tables.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531906"></a>A.1.7.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.3 you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.
-				</p><p>If you are upgrading from
-				a release <span class="emphasis"><em>between 1.0.0RC6 and
-				1.0.2</em></span> (inclusive) and really want
-				a live upgrade read the <a href="apa.html#rel_1.0.3_upgrading" title="A.1.8. Release 1.0.3">upgrade
-				section</a> of the 1.0.3 release notes
-				chapter.
-				</p><p>
-				Upgrade from any release prior to 1.0.0RC6
-				requires an <a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard
-				upgrade</a>.
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531949"></a>A.1.7.2. Bug fixes</h4></div></div><div></div></div><p>Memory leak plugged in GiST indexing</p><p>Segfault fix in transform() handling of proj4 errors</p><p>Fixed some proj4 texts in spatial_ref_sys (missing +proj)</p><p>Loader: fixed string functions usage, reworked NULL objects check, fixed segfault on MULTILINESTRING input.</p><p>Fixed bug in MakeLine dimension handling</p><p>Fixed bug in translate() corrupting output bounding box</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2531982"></a>A.1.7.3. Improvements</h4></div></div><div></div></div><p>Documentation improvements</p><p>More robust selectivity estimator </p><p>Minor speedup in distance()</p><p>Minor cleanups </p><p>GiST indexing cleanup</p><p>Looser syntax acceptance in box3d parser</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="rel_1.0.3_upgrading"></a>A.1.8. Release 1.0.3</h3></div></div><div></div></div><p>Release date: 2005/08/08</p><p>
-Contains some bug fixes - <span class="emphasis"><em>including a severe one affecting
-correctness of stored geometries</em></span> - and a few improvements.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532034"></a>A.1.8.1. Upgrading</h4></div></div><div></div></div><p>
-Due to a bug in a bounding box computation routine, the upgrade procedure
-requires special attention, as bounding boxes cached in the database could
-be incorrect.
-				</p><p>
-An <a href="ch02.html#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a> procedure (dump/reload)
-will force recomputation of all bounding boxes (not included in dumps).
-This is <span class="emphasis"><em>required</em></span> if upgrading from releases prior
-to 1.0.0RC6.
-				</p><p>
-If you are upgrading from versions 1.0.0RC6 or up, this release includes a
-perl script (utils/rebuild_bbox_caches.pl) to force recomputation of
-geometries' bounding boxes and invoke all operations required to propagate
-eventual changes in them (geometry statistics update, reindexing).
-Invoke the script after a make install (run with no args for syntax help).
-Optionally run utils/postgis_proc_upgrade.pl to refresh postgis procedures
-and functions signatures (see <a href="ch02.html#soft_upgrade" title="2.2.1.1. Soft upgrade">Soft upgrade</a>).
-				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532082"></a>A.1.8.2. Bug fixes</h4></div></div><div></div></div><p>Severe bugfix in lwgeom's 2d bounding box computation</p><p>Bugfix in WKT (-w) POINT handling in loader</p><p>Bugfix in dumper on 64bit machines</p><p>Bugfix in dumper handling of user-defined queries </p><p>Bugfix in create_undef.pl script</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532109"></a>A.1.8.3. Improvements</h4></div></div><div></div></div><p>Small performance improvement in canonical input function</p><p>Minor cleanups in loader</p><p>Support for multibyte field names in loader</p><p>Improvement in the postgis_restore.pl script</p><p>New rebuild_bbox_caches.pl util script</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532137"></a>A.1.9. Release 1.0.2</h3></div></div><div></div></div><p>Release date: 2005/07/04</p><p>
-			Contains a few bug fixes and improvements.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532151"></a>A.1.9.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.0RC6 or up you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.</p><p>Upgrading from older releases
-				requires a dump/reload. 
-				See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532177"></a>A.1.9.2. Bug fixes</h4></div></div><div></div></div><p>Fault tolerant btree ops</p><p>Memory leak plugged in pg_error</p><p>Rtree index fix</p><p>Cleaner build scripts (avoided mix of CFLAGS and CXXFLAGS)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532200"></a>A.1.9.3. Improvements</h4></div></div><div></div></div><p>New index creation capabilities in loader (-I switch)</p><p>Initial support for postgresql 8.1dev</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532216"></a>A.1.10. Release 1.0.1</h3></div></div><div></div></div><p>Release date: 2005/05/24</p><p>
-			Contains a few bug fixes and some improvements.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532229"></a>A.1.10.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.0RC6 or up you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.</p><p>Upgrading from older releases
-				requires a dump/reload. 
-				See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532256"></a>A.1.10.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in 3d computation of lenght_spheroid()</p><p>BUGFIX in join selectivity estimator</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532271"></a>A.1.10.3. Other changes/additions</h4></div></div><div></div></div><p>BUGFIX in shp2pgql escape functions</p><p>better support for concurrent postgis in multiple schemas</p><p>documentation fixes</p><p>jdbc2: compile with "-target 1.2 -source 1.2" by default</p><p>NEW -k switch for pgsql2shp</p><p>NEW support for custom createdb options in postgis_restore.pl</p><p>BUGFIX in pgsql2shp attribute names unicity enforcement</p><p>BUGFIX in Paris projections definitions</p><p>postgis_restore.pl cleanups</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532315"></a>A.1.11. Release 1.0.0</h3></div></div><div></div></div><p>Release date: 2005/04/19</p><p>Final 1.0.0 release.
-			Contains a few bug fixes, some improvements
-			in the loader (most notably support for older
-			postgis versions), and more docs.
-			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532331"></a>A.1.11.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.0RC6 you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.</p><p>Upgrading from any other precedent
-				release requires a dump/reload. 
-				See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532358"></a>A.1.11.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in transform() releasing random memory address</p><p>BUGFIX in force_3dm() allocating less memory then required</p><p>BUGFIX in join selectivity estimator (defaults, leaks, tuplecount, sd)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532378"></a>A.1.11.3. Other changes/additions</h4></div></div><div></div></div><p>BUGFIX in shp2pgsql escape of values starting with tab or single-quote</p><p>NEW manual pages for loader/dumper</p><p>NEW shp2pgsql support for old (HWGEOM) postgis versions</p><p>NEW -p (prepare) flag for shp2pgsql</p><p>NEW manual chapter about OGC compliancy enforcement</p><p>NEW autoconf support for JTS lib</p><p>BUGFIX in estimator testers (support for LWGEOM and schema parsing)</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532414"></a>A.1.12. Release 1.0.0RC6</h3></div></div><div></div></div><p>Release date: 2005/03/30</p><p>Sixth release candidate for 1.0.0.
-			Contains a few bug fixes and cleanups.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532429"></a>A.1.12.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
-				from precedent releases. See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532447"></a>A.1.12.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in multi()</p><p>early return [when noop] from multi()</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532462"></a>A.1.12.3. Scripts changes</h4></div></div><div></div></div><p>dropped {x,y}{min,max}(box2d) functions</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532472"></a>A.1.12.4. Other changes</h4></div></div><div></div></div><p>BUGFIX in postgis_restore.pl scrip</p><p>BUGFIX in dumper's 64bit support</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532488"></a>A.1.13. Release 1.0.0RC5</h3></div></div><div></div></div><p>Release date: 2005/03/25</p><p>Fifth release candidate for 1.0.0.
-			Contains a few bug fixes and a improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532502"></a>A.1.13.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
-				release 1.0.0RC4 you <span class="emphasis"><em>DO
-				NOT</em></span> need a dump/reload.</p><p>Upgrading from any other precedent
-				release requires a dump/reload. 
-				See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532529"></a>A.1.13.2. Library changes</h4></div></div><div></div></div><p>BUGFIX (segfaulting) in box3d computation (yes, another!).</p><p>BUGFIX (segfaulting) in estimated_extent().</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532544"></a>A.1.13.3. Other changes</h4></div></div><div></div></div><p>Small build scripts and utilities refinements.</p><p>Additional performance tips documented.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532560"></a>A.1.14. Release 1.0.0RC4</h3></div></div><div></div></div><p>Release date: 2005/03/18</p><p>Fourth release candidate for 1.0.0.
-			Contains bug fixes and a few improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532574"></a>A.1.14.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
-				from precedent releases. See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532593"></a>A.1.14.2. Library changes</h4></div></div><div></div></div><p>BUGFIX (segfaulting) in geom_accum().</p><p>BUGFIX in 64bit architectures support.</p><p>BUGFIX in box3d computation function with collections.</p><p>NEW subselects support in selectivity estimator.</p><p>Early return from force_collection.</p><p>Consistency check fix in SnapToGrid().</p><p>Box2d output changed back to 15 significant digits.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532628"></a>A.1.14.3. Scripts changes</h4></div></div><div></div></div><p>NEW distance_sphere() function.</p><p>Changed get_proj4_from_srid implementation to use PL/PGSQL instead of SQL.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532643"></a>A.1.14.4. Other changes</h4></div></div><div></div></div><p>BUGFIX in loader and dumper handling of MultiLine shapes</p><p>BUGFIX in loader, skipping all but first hole of polygons.</p><p>jdbc2: code cleanups, Makefile improvements</p><p>FLEX and YACC variables set *after* pgsql Makefile.global is included and only if the pgsql *stripped* version evaulates to the empty string</p><p>Added already generated parser in release</p><p>Build scripts refinements</p><p>improved version handling, central Version.config</p><p>improvements in postgis_restore.pl</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532685"></a>A.1.15. Release 1.0.0RC3</h3></div></div><div></div></div><p>Release date: 2005/02/24</p><p>Third release candidate for 1.0.0.
-			Contains many bug fixes and improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532699"></a>A.1.15.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
-				from precedent releases. See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532718"></a>A.1.15.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in transform(): missing SRID, better error handling.</p><p>BUGFIX in memory alignment handling</p><p>BUGFIX in force_collection() causing mapserver connector failures on simple (single) geometry types.</p><p>BUGFIX in GeometryFromText() missing to add a bbox cache.</p><p>reduced precision of box2d output.</p><p>prefixed DEBUG macros with PGIS_ to avoid clash with pgsql one</p><p>plugged a leak in GEOS2POSTGIS converter</p><p>Reduced memory usage by early releasing query-context palloced one.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532759"></a>A.1.15.3. Scripts changes</h4></div></div><div></div></div><p>BUGFIX in 72 index bindings.</p><p>BUGFIX in probe_geometry_columns() to work with PG72 and support multiple geometry columns in a single table</p><p>NEW bool::text cast</p><p>Some functions made IMMUTABLE from STABLE, for performance
-	improvement.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532783"></a>A.1.15.4. JDBC changes</h4></div></div><div></div></div><p>jdbc2: small patches, box2d/3d tests, revised docs and license.</p><p>jdbc2: bug fix and testcase in for pgjdbc 8.0 type autoregistration</p><p>jdbc2: Removed use of jdk1.4 only features to enable build with older jdk releases.</p><p>jdbc2: Added support for building against pg72jdbc2.jar</p><p>jdbc2: updated and cleaned makefile</p><p>jdbc2: added BETA support for jts geometry classes</p><p>jdbc2: Skip known-to-fail tests against older PostGIS servers.</p><p>jdbc2: Fixed handling of measured geometries in EWKT.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532824"></a>A.1.15.5. Other changes</h4></div></div><div></div></div><p>new performance tips chapter in manual</p><p>documentation updates: pgsql72 requirement, lwpostgis.sql</p><p>few changes in autoconf </p><p>BUILDDATE extraction made more portable</p><p>fixed spatial_ref_sys.sql to avoid vacuuming the whole
-	database.</p><p>spatial_ref_sys: changed Paris entries to match the ones
-	distributed with 0.x.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532857"></a>A.1.16. Release 1.0.0RC2</h3></div></div><div></div></div><p>Release date: 2005/01/26</p><p>Second release candidate for 1.0.0
-			containing bug fixes and a few improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532871"></a>A.1.16.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
-				from precedent releases. See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532889"></a>A.1.16.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in pointarray box3d computation</p><p>BUGFIX in distance_spheroid definition</p><p>BUGFIX in transform() missing to update bbox cache</p><p>NEW jdbc driver (jdbc2)</p><p>GEOMETRYCOLLECTION(EMPTY) syntax support for backward compatibility</p><p>Faster binary outputs</p><p>Stricter OGC WKB/WKT constructors</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532924"></a>A.1.16.3. Scripts changes</h4></div></div><div></div></div><p>More correct STABLE, IMMUTABLE, STRICT uses in lwpostgis.sql</p><p>stricter OGC WKB/WKT constructors</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532939"></a>A.1.16.4. Other changes</h4></div></div><div></div></div><p>Faster and more robust loader (both i18n and not)</p><p>Initial autoconf script</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2532955"></a>A.1.17. Release 1.0.0RC1</h3></div></div><div></div></div><p>Release date: 2005/01/13</p><p>This is the first candidate of a
-			major postgis release, with internal
-			storage of postgis types redesigned to be smaller
-			and faster on indexed queries.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532970"></a>A.1.17.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
-				from precedent releases. See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">upgrading</a>
-				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2532989"></a>A.1.17.2. Changes</h4></div></div><div></div></div><p>
-				Faster canonical input parsing.
-				</p><p>
-				Lossless canonical output.
-				</p><p>
-				EWKB Canonical binary IO with PG&gt;73.
-				</p><p>
-				Support for up to 4d coordinates, providing
-				lossless shapefile-&gt;postgis-&gt;shapefile
-				conversion.
-				</p><p>
-				New function: UpdateGeometrySRID(), AsGML(),
-				SnapToGrid(), ForceRHR(), estimated_extent(),
-				accum().
-				</p><p>
-				Vertical positioning indexed operators.
-				</p><p>
-				JOIN selectivity function.
-				</p><p>
-				More geometry constructors / editors.
-				</p><p>
-				Postgis extension API.
-				</p><p>
-				UTF8 support in loader.
-				</p></div></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. Reporting Bugs </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch01.html
===================================================================
--- packages/postgis/upstream/doc/html/ch01.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch01.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,37 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 1. Introduction</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="index.html" title="PostGIS Manual"><link rel="next" href="ch02.html" title="Chapter 2. Installation"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 1. Introduction</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2454821"></a>Chapter 1. Introduction</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch01.html#credits">1.1. Credits</a></span></dt><dt><span class="sect1"><a href="ch01.html#id2454630">1.2. More Information</a></span></dt></dl></div><p>PostGIS is developed by Refractions Research Inc, as a spatial
-    database technology research project. Refractions is a GIS and database
-    consulting company in Victoria, British Columbia, Canada, specializing in
-    data integration and custom software development. We plan on supporting
-    and developing PostGIS to support a range of important GIS functionality,
-    including full OpenGIS support, advanced topological constructs
-    (coverages, surfaces, networks), desktop user interface tools for viewing
-    and editing GIS data, and web-based access tools.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="credits"></a>1.1. Credits</h2></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Sandro Santilli &lt;strk at refractions.net&gt;</span></dt><dd><p>Coordinates all bug fixing and maintainance effort,
-            integration of new GEOS functionality, and new function
-            enhancements.</p></dd><dt><span class="term">Chris Hodgson &lt;chodgson at refractions.net&gt;</span></dt><dd><p>Maintains new functions and the 7.2 index bindings.</p></dd><dt><span class="term">Paul Ramsey &lt;pramsey at refractions.net&gt;</span></dt><dd><p>Keeps track of the
-            documentation and packaging.</p></dd><dt><span class="term">Jeff Lounsbury &lt;jeffloun at refractions.net&gt;</span></dt><dd><p>Original development of the Shape file loader/dumper.</p></dd><dt><span class="term">Dave Blasby &lt;dblasby at gmail.com&gt;</span></dt><dd><p>The original developer of PostGIS. Dave wrote the server
-            side objects, index bindings, and many of the server side
-            analytical functions.</p></dd><dt><span class="term">Other contributors</span></dt><dd><p>
-		In alphabetical order: 
-		Alex Bodnaru, Alex Mayrhofer, Bruce Rindahl,
-		Bernhard Reiter, 
-		Bruno Wolff III, Carl Anderson, Charlie Savage,
-		David Skea, David Techer, 
-		IIDA Tetsushi, Geographic Data BC, Gerald Fenoy,
-		Gino Lucrezi, Klaus Foerster, Kris Jurka, Mark Cave-Ayland,
-		Mark Sondheim, Markus Schaber, Michael Fuhr, Nikita Shulga,
-		Norman Vine, Olivier Courtin, Ralph Mason, Steffen Macke.
-            </p></dd><dt><span class="term">Important Support Libraries</span></dt><dd><p>The <a href="http://geos.refractions.net" target="_top">GEOS</a>
-            geometry operations library, and the algorithmic work of 
-            Martin Davis &lt;mbdavis at vividsolutions.com&gt; of Vivid Solutions
-            in making it all work.</p><p>The <a href="http://proj4.maptools.org" target="_top">Proj4</a>
-            cartographic projection library, and the work of Gerald Evenden
-            and Frank Warmerdam in creating and maintaining it.</p></dd></dl></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2454630"></a>1.2. More Information</h2></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><p>The latest software, documentation and news items are
-          available at the PostGIS web site, <a href="http://postgis.refractions.net" target="_top">http://postgis.refractions.net</a>.</p></li><li><p>More information about the GEOS geometry operations library is
-          available at<a href="http://geos.refractions.net" target="_top">
-          http://geos.refractions.net</a>.</p></li><li><p>More information about the Proj4 reprojection library is
-          available at <a href="http://www.remotesensing.org/proj" target="_top">http://www.remotesensing.org/proj</a>.</p></li><li><p>More information about the PostgreSQL database server is
-          available at the PostgreSQL main site <a href="http://www.postgresql.org" target="_top">http://www.postgresql.org</a>.</p></li><li><p>More information about GiST indexing is available at the
-          PostgreSQL GiST development site, <a href="http://www.sai.msu.su/~megera/postgres/gist" target="_top">http://www.sai.msu.su/~megera/postgres/gist</a>.</p></li><li><p>More information about Mapserver internet map server is
-          available at <a href="http://mapserver.gis.umn.edu/" target="_top">http://mapserver.gis.umn.edu</a>.</p></li><li><p>The "<a href="http://www.opengis.org/docs/99-049.pdf" target="_top">Simple Features
-          for Specification for SQL</a>" is available at the OpenGIS
-          Consortium web site: <a href="http://www.opengis.org" target="_top">http://www.opengis.org</a>.</p></li></ul></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">PostGIS Manual </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. Installation</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch02.html
===================================================================
--- packages/postgis/upstream/doc/html/ch02.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch02.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,171 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 2. Installation</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch01.html" title="Chapter 1. Introduction"><link rel="next" href="ch03.html" title="Chapter 3. Frequently Asked Questions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. Installation</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch01.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch03.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2481874"></a>Chapter 2. Installation</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch02.html#id2481880">2.1. Requirements</a></span></dt><dt><span class="sect1"><a href="ch02.html#PGInstall">2.2. PostGIS</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02.html#upgrading">2.2.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="ch02.html#id2453863">2.2.2. Common Problems</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02.html#id2522143">2.3. JDBC</a></span></dt><dt><span class="sect1"><a href="ch02.html#id2522219">2.4. Loader/Dumper</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2481880"></a>2.1. Requirements</h2></div></div><div></div></div><p>PostGIS has the following requirements for building and
-      usage:</p><div class="itemizedlist"><ul type="disc"><li><p>
-	  A complete installation of PostgreSQL (including server headers).
-          PostgreSQL is available from <a href="http://www.postgresql.org" target="_top">http://www.postgresql.org</a>.
-	  Version 7.2 or higher is required.
-	  </p></li><li><p>GNU C compiler (<tt class="filename">gcc</tt>). Some other ANSI C
-          compilers can be used to compile PostGIS, but we find far fewer
-          problems when compiling with <tt class="filename">gcc</tt>.</p></li><li><p>GNU Make (<tt class="filename">gmake</tt> or
-          <tt class="filename">make</tt>). For many systems, GNU
-          <tt class="filename">make</tt> is the default version of make. Check the
-          version by invoking <tt class="filename">make -v</tt>. Other versions of
-          <tt class="filename">make</tt> may not process the PostGIS
-          <tt class="filename">Makefile</tt> properly.</p></li><li><p>(Recommended) Proj4 reprojection library. The Proj4 library is
-          used to provide coordinate reprojection support within PostGIS.
-          Proj4 is available for download from <a href="http://www.remotesensing.org/proj" target="_top">http://www.remotesensing.org/proj</a>.</p></li><li><p>(Recommended) GEOS geometry library. The GEOS library is used
-          to provide geometry tests (Touches(), Contains(), Intersects()) and
-          operations (Buffer(), GeomUnion(), Difference()) within PostGIS.
-          GEOS is available for download from <a href="http://geos.refractions.net" target="_top">http://geos.refractions.net</a>.</p></li></ul></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="PGInstall"></a>2.2. PostGIS</h2></div></div><div></div></div><p>The PostGIS module is a extension to the PostgreSQL backend
-      server. As such, PostGIS 1.1.3
-      <span class="emphasis"><em>requires</em></span> full PostgreSQL server headers access
-      in order to compile. The PostgreSQL source code is available at <a href="http://www.postgresql.org" target="_top">http://www.postgresql.org</a>.</p><p>PostGIS 1.1.3 can be built against PostgreSQL
-      versions 7.2.0 or higher. Earlier versions of PostgreSQL are
-      <span class="emphasis"><em>not</em></span> supported.</p><div class="orderedlist"><ol type="1"><li><p>Before you can compile the PostGIS server modules, you must
-          compile and install the PostgreSQL package.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you plan to use GEOS functionality you might need to
-            explicitly link PostgreSQL against the standard C++
-            library:</p><pre class="programlisting">LDFLAGS=-lstdc++ ./configure [YOUR OPTIONS HERE]</pre><p>This is a workaround for bogus C++ exceptions interaction
-            with older development tools. If you experience weird problems
-            (backend unexpectedly closed or similar things) try this trick.
-            This will require recompiling your PostgreSQL from scratch, of
-            course.</p></div></li><li><p>Retrieve the PostGIS source archive from <a href="http://postgis.refractions.net/postgis-1.1.3.tar.gz" target="_top">http://postgis.refractions.net/postgis-1.1.3.tar.gz</a>.
-          Uncompress and untar the archive.
-	  </p><pre class="programlisting"># gzip -d -c postgis-1.1.3.tar.gz | tar xvf -</pre></li><li><p>Enter the postgis-1.1.3 directory, and run:
-</p><pre class="programlisting"># ./configure</pre><p>
-	  </p><div class="itemizedlist"><ul type="disc"><li><p>
-		If you want support for coordinate reprojection, you must have
-		the Proj4 library installed. If ./configure didn't find
-		it, try using <tt class="code">--with-proj=PATH</tt>
-		switch specify a specific Proj4 installation directory.
-		</p></li><li><p>
-		If you want to use GEOS functionality, you must have the GEOS
-		library installed. If ./configure didn't find it, try
-		using <tt class="code">--with-geos=PATH</tt> to specify the full 
-                path to the geos-config program full path.
-		</p></li></ul></div></li><li><p>Run the compile and install commands.</p><pre class="programlisting"># make 
-# make install</pre><p>All files are installed using information provided
-	  by <tt class="filename">pg_config</tt></p><div class="itemizedlist"><ul type="disc"><li><p>Libraries are installed
-              <tt class="filename">[pkglibdir]/lib/contrib</tt>.</p></li><li><p>Important support files such as
-              <tt class="filename">lwpostgis.sql</tt> are installed in
-              <tt class="filename">[prefix]/share/contrib</tt>.</p></li><li><p>Loader and dumper binaries are installed in
-              <tt class="filename">[bindir]/</tt>.</p></li></ul></div></li><li><p>PostGIS requires the PL/pgSQL procedural language extension.
-          Before loading the <tt class="filename">lwpostgis.sql</tt> file, you must
-          first enable PL/pgSQL. You should use the
-          <tt class="filename">createlang</tt> command. The PostgreSQL 
-          Programmer's Guide has the details if you want to this manually for
-          some reason.</p><pre class="programlisting"># createlang plpgsql [yourdatabase]</pre></li><li><p>Now load the PostGIS object and function definitions into your
-          database by loading the <tt class="filename">lwpostgis.sql</tt> definitions
-          file.</p><pre class="programlisting"># psql -d [yourdatabase] -f lwpostgis.sql</pre><p>The PostGIS server extensions are now loaded and ready to
-          use.</p></li><li><p>For a complete set of EPSG coordinate system definition
-          identifiers, you can also load the
-          <tt class="filename">spatial_ref_sys.sql</tt> definitions file and
-          populate the <tt class="varname">SPATIAL_REF_SYS</tt> table.</p><pre class="programlisting"># psql -d [yourdatabase] -f spatial_ref_sys.sql</pre></li></ol></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="upgrading"></a>2.2.1. Upgrading</h3></div></div><div></div></div><p>
-Upgrading existing spatial databases can be tricky as it requires
-replacement or introduction of new PostGIS object definitions.
-</p><p>
-Unfortunately not all definitions can be easily replaced in 
-a live database, so sometimes your best bet is a dump/reload
-process. 
-</p><p>
-PostGIS provides a SOFT UPGRADE procedure for minor or bugfix
-releases, and an HARD UPGRADE procedure for major releases.
-</p><p>
-Before attempting to upgrade postgis, it is always worth to backup
-your data. If you use the -Fc flag to pg_dump you will always be able
-to restore the dump with an HARD UPGRADE.
-	</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="soft_upgrade"></a>2.2.1.1. Soft upgrade</h4></div></div><div></div></div><p>
-Soft upgrade consists of sourcing the lwpostgis_upgrade.sql
-script in your spatial database:
-</p><pre class="programlisting">psql -f lwpostgis_upgrade.sql -d your_spatial_database</pre><p>
-If a soft upgrade is not possible the script will abort and 
-you will be warned about HARD UPGRADE being required,
-so do not hesitate to try a soft upgrade first.
-</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-If you can't find the <tt class="filename">lwpostgis_upgrade.sql</tt> file
-you are probably using a version prior to 1.1 and must generate that
-file by yourself. This is done with the following command:
-</p><pre class="programlisting">utils/postgis_proc_upgrade.pl lwpostgis.sql &gt; lwpostgis_upgrade.sql</pre></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="hard_upgrade"></a>2.2.1.2. Hard upgrade</h4></div></div><div></div></div><p>
-By HARD UPGRADE we intend full dump/reload of postgis-enabled databases.
-You need an HARD UPGRADE when postgis objects' internal storage
-changes or when SOFT UPGRADE is not possible.
-The <a href="apa.html" title="Appendix A. Appendix">Release Notes</a> appendix reports for each version wheter you need a
-dump/reload (HARD UPGRADE) to upgrade.
-	</p><p>
-PostGIS provides an utility script to restore a dump
-produced with the pg_dump -Fc command. It is experimental so redirecting
-its output to a file will help in case of problems. The procedure is
-as follow:
-	</p><pre class="programlisting">
-	# Create a "custom-format" dump of the database you want
-	# to upgrade (let's call it "olddb")
-	$ pg_dump -Fc olddb &gt; olddb.dump
-
-	# Restore the dump contextually upgrading postgis into
-	# a new database. The new database doesn't have to exist.
-	# Let's call it "newdb"
-	$ sh utils/postgis_restore.pl lwpostgis.sql newdb olddb.dump &gt; restore.log
-
-	# Check that all restored dump objects really had to be restored from dump
-	# and do not conflict with the ones defined in lwpostgis.sql
-	$ grep ^KEEPING restore.log | less
-
-	# If upgrading from PostgreSQL &lt; 8.0 to &gt;= 8.0 you might want to 
-	# drop the attrelid, varattnum and stats columns in the geometry_columns
-	# table, which are no-more needed. Keeping them won't hurt.
-	# !!! DROPPING THEM WHEN REALLY NEEDED WILL DO HURT !!!!
-	$ psql newdb -c "ALTER TABLE geometry_columns DROP attrelid"
-	$ psql newdb -c "ALTER TABLE geometry_columns DROP varattnum"
-	$ psql newdb -c "ALTER TABLE geometry_columns DROP stats"
-
-	# spatial_ref_sys table is restore from the dump, to ensure your custom
-	# additions are kept, but the distributed one might contain modification
-	# so you should backup your entries, drop the table and source the new one.
-	# If you did make additions we assume you know how to backup them before
-	# upgrading the table. Replace of it with the new one is done like this:
-	$ psql newdb
-	newdb=&gt; delete from spatial_ref_sys; 
-	DROP
-	newdb=&gt; \i spatial_ref_sys.sql
-	</pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2453863"></a>2.2.2. Common Problems</h3></div></div><div></div></div><p>There are several things to check when your installation or
-        upgrade doesn't go as you expected.</p><div class="orderedlist"><ol type="1"><li><p>It is easiest if you untar the PostGIS distribution into the
-            contrib directory under the PostgreSQL source tree. However, if
-            this is not possible for some reason, you can set the
-            <tt class="varname">PGSQL_SRC</tt> environment variable to the path to
-            the PostgreSQL source directory. This will allow you to compile
-            PostGIS, but the <span><b class="command">make install</b></span> may not work, so
-            be prepared to copy the PostGIS library and executable files to
-            the appropriate locations yourself.</p></li><li><p>Check that you you have installed PostgreSQL 7.2 or newer,
-            and that you are compiling against the same version of the
-            PostgreSQL source as the version of PostgreSQL that is running.
-            Mix-ups can occur when your (Linux) distrubution has already
-            installed PostgreSQL, or you have otherwise installed PostgreSQL
-            before and forgotten about it. PostGIS will only work with
-            PostgreSQL 7.2 or newer, and strange, unexpected error messages
-            will result if you use an older version. To check the version of
-            PostgreSQL which is running, connect to the database using psql
-            and run this query:</p><pre class="programlisting">SELECT version();</pre><p>If you are running an RPM based distribution, you can check
-            for the existence of pre-installed packages using the
-            <span><b class="command">rpm</b></span> command as follows: <span><b class="command">rpm -qa | grep
-            postgresql</b></span></p></li></ol></div><p>Also check that you have made any necessary changes to the top
-        of the Makefile.config. This includes:</p><div class="orderedlist"><ol type="1"><li><p>If you want to be able to do coordinate reprojections, you
-            must install the Proj4 library on your system, set the
-            <tt class="varname">USE_PROJ</tt> variable to 1 and the
-            <tt class="varname">PROJ_DIR</tt> to your installation prefix in the
-            Makefile.config.</p></li><li><p>If you want to be able to use GEOS functions you must
-            install the GEOS library on your system, and set the
-            <tt class="varname">USE_GEOS</tt> to 1 and the
-            <tt class="varname">GEOS_DIR</tt> to your installation prefix in the
-            Makefile.config</p></li></ol></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2522143"></a>2.3. JDBC</h2></div></div><div></div></div><p>The JDBC extensions provide Java objects corresponding to the
-      internal PostGIS types. These objects can be used to write Java clients
-      which query the PostGIS database and draw or do calculations on the GIS
-      data in PostGIS.</p><div class="orderedlist"><ol type="1"><li><p>Enter the <tt class="filename">jdbc</tt> sub-directory of the
-          PostGIS distribution.</p></li><li><p>Edit the <tt class="filename">Makefile</tt> to provide the correct
-          paths of your java compiler (<tt class="varname">JAVAC</tt>) and
-          interpreter (<tt class="varname">JAVA</tt>).</p></li><li><p>Run the <tt class="filename">make</tt> command. Copy the
-          <tt class="filename">postgis.jar</tt> file to wherever you keep your java
-          libraries.</p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2522219"></a>2.4. Loader/Dumper</h2></div></div><div></div></div><p>The data loader and dumper are built and installed automatically
-      as part of the PostGIS build. To build and install them manually:</p><pre class="programlisting"># cd postgis-1.1.3/loader 
-# make
-# make install</pre><p>The loader is called <tt class="filename">shp2pgsql</tt> and converts
-      ESRI Shape files into SQL suitable for loading in PostGIS/PostgreSQL.
-      The dumper is called <tt class="filename">pgsql2shp</tt> and converts PostGIS
-      tables (or queries) into ESRI Shape files.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch01.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 1. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 3. Frequently Asked Questions</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch03.html
===================================================================
--- packages/postgis/upstream/doc/html/ch03.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch03.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,92 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 3. Frequently Asked Questions</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch02.html" title="Chapter 2. Installation"><link rel="next" href="ch04.html" title="Chapter 4. Using PostGIS"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 3. Frequently Asked Questions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch04.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2522258"></a>Chapter 3. Frequently Asked Questions</h2></div></div><div></div></div><div class="qandaset"><dl><dt>3.1. <a href="ch03.html#id2522266">What kind of geometric objects can I store?</a></dt><dt>3.2. <a href="ch03.html#id2522286">How do I insert a GIS object into the database?</a></dt><dt>3.3. <a href="ch03.html#id2522382">How do I construct a spatial query?</a></dt><dt>3.4. <a href="ch03.html#id2522447">How do I speed up spatial queries on large tables?</a></dt><dt>3.5. <a href="ch03.html#id2522529">Why aren't PostgreSQL R-Tree indexes supported?</a></dt><dt>3.6. <a href="ch03.html#id2522581">Why should I use the AddGeometryColumn()
-          function and all the other OpenGIS stuff?</a></dt><dt>3.7. <a href="ch03.html#id2522629">What is the best way to find all objects within a radius of
-          another object?</a></dt><dt>3.8. <a href="ch03.html#id2522681">How do I perform a coordinate reprojection as part of a
-          query?</a></dt></dl><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="question"><td align="left" valign="top"><a name="id2522266"></a><a name="id2522268"></a><b>3.1.</b></td><td align="left" valign="top"><p>What kind of geometric objects can I store?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>You can store point, line, polygon, multipoint, multiline,
-          multipolygon, and geometrycollections. These are specified in the
-          Open GIS Well Known Text Format (with XYZ,XYM,XYZM extentions).</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522286"></a><a name="id2522288"></a><b>3.2.</b></td><td align="left" valign="top"><p>How do I insert a GIS object into the database?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>First, you need to create a table with a column of type
-          "geometry" to hold your GIS data. Connect to your database with
-          <tt class="filename">psql</tt> and try the following SQL:</p><pre class="programlisting">CREATE TABLE gtest ( ID int4, NAME varchar(20) );
-SELECT AddGeometryColumn('', 'gtest','geom',-1,'LINESTRING',2);</pre><p>If the geometry column addition fails, you probably have not
-          loaded the PostGIS functions and objects into this database. See the
-          <a href="ch02.html#PGInstall" title="2.2. PostGIS">installation instructions</a>.</p><p>Then, you can insert a geometry into the table using a SQL
-          insert statement. The GIS object itself is formatted using the
-          OpenGIS Consortium "well-known text" format:</p><pre class="programlisting">INSERT INTO gtest (ID, NAME, GEOM) VALUES (1, 'First Geometry', GeomFromText('LINESTRING(2 3,4 5,6 5,7 8)', -1));</pre><p>For more information about other GIS objects, see the <a href="ch04.html#RefObject" title="4.1. GIS Objects">object reference</a>.</p><p>To view your GIS data in the table:</p><pre class="programlisting">SELECT id, name, AsText(geom) AS geom FROM gtest;</pre><p>The return value should look something like this:</p><pre class="programlisting"> id | name           | geom
-----+----------------+-----------------------------
-  1 | First Geometry | LINESTRING(2 3,4 5,6 5,7 8) 
-(1 row)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522382"></a><a name="id2522384"></a><b>3.3.</b></td><td align="left" valign="top"><p>How do I construct a spatial query?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>The same way you construct any other database query, as an SQL
-          combination of return values, functions, and boolean tests.</p><p>For spatial queries, there are two issues that are important
-          to keep in mind while constructing your query: is there a spatial
-          index you can make use of; and, are you doing expensive calculations
-          on a large number of geometries.</p><p>In general, you will want to use the "intersects operator"
-          (&amp;&amp;) which tests whether the bounding boxes of features
-          intersect. The reason the &amp;&amp; operator is useful is because
-          if a spatial index is available to speed up the test, the &amp;&amp;
-          operator will make use of this. This can make queries much much
-          faster.</p><p>You will also make use of spatial functions, such as
-          Distance(), Intersects(), Contains() and Within(), among others, to
-          narrow down the results of your search. Most spatial queries include
-          both an indexed test and a spatial function test. The index test
-          serves to limit the number of return tuples to only tuples that
-          <span class="emphasis"><em>might</em></span> meet the condition of interest. The
-          spatial functions are then use to test the condition exactly.</p><pre class="programlisting">SELECT id, the_geom FROM thetable
-WHERE
-  the_geom &amp;&amp; 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'
-AND
-  Contains(the_geom,'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))';</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522447"></a><a name="id2522449"></a><b>3.4.</b></td><td align="left" valign="top"><p>How do I speed up spatial queries on large tables?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Fast queries on large tables is the <span class="emphasis"><em>raison
-          d'etre</em></span> of spatial databases (along with transaction
-          support) so having a good index is important.</p><p>To build a spatial index on a table with a
-          <tt class="varname">geometry</tt> column, use the "CREATE INDEX" function
-          as follows:</p><pre class="programlisting">CREATE INDEX [indexname] ON [tablename]  
-  USING GIST ( [geometrycolumn] );</pre><p>The "USING GIST" option tells the server to use a GiST
-          (Generalized Search Tree) index.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-            GiST indexes are assumed to be lossy.
-	    Lossy indexes uses a proxy object (in the spatial case,
-	    a bounding box) for building the index.</p></div><p>You should also ensure that the PostgreSQL query planner has
-          enough information about your index to make rational decisions about
-          when to use it. To do this, you have to "gather statistics" on your
-          geometry tables.</p><p>For PostgreSQL 8.0.x and greater, just run the <span><b class="command">VACUUM
-          ANALYZE</b></span> command.</p><p>For PostgreSQL 7.4.x and below, run the <span><b class="command">SELECT
-          UPDATE_GEOMETRY_STATS()</b></span> command.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522529"></a><a name="id2522531"></a><b>3.5.</b></td><td align="left" valign="top"><p>Why aren't PostgreSQL R-Tree indexes supported?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Early versions of PostGIS used the PostgreSQL R-Tree indexes.
-          However, PostgreSQL R-Trees have been completely discarded since
-          version 0.6, and spatial indexing is provided with an
-          R-Tree-over-GiST scheme.</p><p>Our tests have shown search speed for native R-Tree and GiST
-          to be comparable. Native PostgreSQL R-Trees have two limitations
-          which make them undesirable for use with GIS features (note that
-          these limitations are due to the current PostgreSQL native R-Tree
-          implementation, not the R-Tree concept in general):</p><div class="itemizedlist"><ul type="disc"><li><p>R-Tree indexes in PostgreSQL cannot handle features which
-              are larger than 8K in size. GiST indexes can, using the "lossy"
-              trick of substituting the bounding box for the feature
-              itself.</p></li><li><p>R-Tree indexes in PostgreSQL are not "null safe", so
-              building an index on a geometry column which contains null
-              geometries will fail.</p></li></ul></div></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522581"></a><a name="id2522584"></a><b>3.6.</b></td><td align="left" valign="top"><p>Why should I use the <tt class="varname">AddGeometryColumn()</tt>
-          function and all the other OpenGIS stuff?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>If you do not want to use the OpenGIS support functions, you
-          do not have to. Simply create tables as in older versions, defining
-          your geometry columns in the CREATE statement. All your geometries
-          will have SRIDs of -1, and the OpenGIS meta-data tables will
-          <span class="emphasis"><em>not</em></span> be filled in properly. However, this will
-          cause most applications based on PostGIS to fail, and it is
-          generally suggested that you do use
-          <tt class="varname">AddGeometryColumn()</tt> to create geometry
-          tables.</p><p>Mapserver is one application which makes use of the
-          <tt class="varname">geometry_columns</tt> meta-data. Specifically,
-          Mapserver can use the SRID of the geometry column to do on-the-fly
-          reprojection of features into the correct map projection.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522629"></a><a name="id2522631"></a><b>3.7.</b></td><td align="left" valign="top"><p>What is the best way to find all objects within a radius of
-          another object?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>To use the database most efficiently, it is best to do radius
-          queries which combine the radius test with a bounding box test: the
-          bounding box test uses the spatial index, giving fast access to a
-          subset of data which the radius test is then applied to.</p><p>The <tt class="varname">Expand()</tt> function is a handy way of
-          enlarging a bounding box to allow an index search of a region of
-          interest. The combination of a fast access index clause and a slower
-          accurate distance test provides the best combination of speed and
-          precision for this query.</p><p>For example, to find all objects with 100 meters of POINT(1000
-          1000) the following query would work well:</p><pre class="programlisting">SELECT * 
-FROM GEOTABLE 
-WHERE 
-  GEOCOLUMN &amp;&amp; Expand(GeomFromText('POINT(1000 1000)',-1),100)
-AND
-  Distance(GeomFromText('POINT(1000 1000)',-1),GEOCOLUMN) &lt; 100;</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2522681"></a><a name="id2522683"></a><b>3.8.</b></td><td align="left" valign="top"><p>How do I perform a coordinate reprojection as part of a
-          query?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>To perform a reprojection, both the source and destination
-          coordinate systems must be defined in the SPATIAL_REF_SYS table, and
-          the geometries being reprojected must already have an SRID set on
-          them. Once that is done, a reprojection is as simple as referring to
-          the desired destination SRID.</p><pre class="programlisting">SELECT Transform(GEOM,4269) FROM GEOTABLE;</pre></td></tr></tbody></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. Installation </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 4. Using PostGIS</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch04.html
===================================================================
--- packages/postgis/upstream/doc/html/ch04.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch04.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,782 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 4. Using PostGIS</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch03.html" title="Chapter 3. Frequently Asked Questions"><link rel="next" href="ch05.html" title="Chapter 5. Performance tips"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. Using PostGIS</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch05.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2522713"></a>Chapter 4. Using PostGIS</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch04.html#RefObject">4.1. GIS Objects</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2522740">4.1.1. OpenGIS WKB and WKT</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2522847">4.1.2. PostGIS EWKB, EWKT and Canonical Forms</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2523004">4.2. Using OpenGIS Standards</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2523037">4.2.1. The SPATIAL_REF_SYS Table</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523246">4.2.2. The GEOMETRY_COLUMNS Table</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523380">4.2.3. Creating a Spatial Table</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523486">4.2.4. Ensuring OpenGIS compliancy of geometries</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2523576">4.3. Loading GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2523590">4.3.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523645">4.3.2. Using the Loader</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2523875">4.4. Retrieving GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2523888">4.4.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2524054">4.4.2. Using the Dumper</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2524232">4.5. Building Indexes</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2524285">4.5.1. GiST Indexes</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2524354">4.5.2. Using Indexes</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2524472">4.6. Complex Queries</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2524491">4.6.1. Taking Advantage of Indexes</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2524587">4.6.2. Examples of Spatial SQL</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2524902">4.7. Using Mapserver</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2524945">4.7.1. Basic Usage</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2525193">4.7.2. Frequently Asked Questions</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2525360">4.7.3. Advanced Usage</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2453149">4.7.4. Examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2453247">4.8. Java Clients (JDBC)</a></span></dt><dt><span class="sect1"><a href="ch04.html#id2525835">4.9. C Clients (libpq)</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2525844">4.9.1. Text Cursors</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2525854">4.9.2. Binary Cursors</a></span></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="RefObject"></a>4.1. GIS Objects</h2></div></div><div></div></div><p>The GIS objects supported by PostGIS are a superset of
-      the "Simple Features" defined by the OpenGIS Consortium (OGC).
-      As of version 0.9, PostGIS supports all the objects and functions
-      specified in the OGC "Simple Features for SQL" specification.</p><p>PostGIS extends the standard with support for 3DZ,3DM and 4D
-      coordinates.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522740"></a>4.1.1. OpenGIS WKB and WKT</h3></div></div><div></div></div><p>The OpenGIS specification defines two standard ways of
-        expressing spatial objects: the Well-Known Text (WKT) form and
-	the Well-Known Binary (WKB) form. Both WKT and WKB include
-	information about the type of the object and the
-        coordinates which form the object.</p><p>Examples of the text representations (WKT) of the spatial
-      objects of the features are as follows:</p><div class="itemizedlist"><ul type="disc"><li><p>POINT(0 0)</p></li><li><p>LINESTRING(0 0,1 1,1 2)</p></li><li><p>POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))</p></li><li><p>MULTIPOINT(0 0,1 2)</p></li><li><p>MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))</p></li><li><p>MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)),
-	  ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))</p></li><li><p>GEOMETRYCOLLECTION(POINT(2 3),LINESTRING((2 3,3 4)))</p></li></ul></div><p>The OpenGIS specification also requires that the
-        internal storage format of spatial objects include a spatial
-        referencing system identifier (SRID). The SRID is required when
-        creating spatial objects for insertion into the database.</p><p>
-Input/Output of these formats are available using the following
-interfaces:
-</p><pre class="programlisting">
-	bytea WKB = asBinary(geometry);
-	text WKT = asText(geometry);
-	geometry = GeomFromWKB(bytea WKB, SRID); 
-	geometry = GeometryFromText(text WKT, SRID);
-	</pre><p> For example, a valid insert statement to create and insert an OGC spatial object would be:</p><pre class="programlisting">
-	INSERT INTO SPATIALTABLE ( 
-		  THE_GEOM, 
-		  THE_NAME 
-	) 
-	VALUES ( 
-		  GeomFromText('POINT(-126.4 45.32)', 312), 
-		  'A Place' 
-	)</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2522847"></a>4.1.2. PostGIS EWKB, EWKT and Canonical Forms</h3></div></div><div></div></div><p>
-OGC formats only support 2d geometries, and the associated SRID
-is *never* embedded in the input/output representations.
-</p><p>
-Postgis extended formats are currently superset of OGC one (every
-valid WKB/WKT is a valid EWKB/EWKT) but this might vary in the
-future, specifically if OGC comes out with a new format conflicting
-with our extensions. Thus you SHOULD NOT rely on this feature!
-</p><p>
-Postgis EWKB/EWKT add 3dm,3dz,4d coordinates support and embedded
-SRID information.
-</p><p>Examples of the text representations (EWKT) of the
-      extended spatial objects of the features are as follows:</p><div class="itemizedlist"><ul type="disc"><li><p>POINT(0 0 0) -- XYZ</p></li><li><p>SRID=32632;POINT(0 0) -- XY with SRID</p></li><li><p>POINTM(0 0 0) -- XYM</p></li><li><p>POINT(0 0 0 0) -- XYZM</p></li><li><p>SRID=4326;MULTIPOINTM(0 0 0,1 2 1) -- XYM with SRID</p></li><li><p>MULTILINESTRING((0 0 0,1 1 0,1 2 1),(2 3 1,3 2 1,5 4
-          1))</p></li><li><p>POLYGON((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2 0,1 2
-          0,1 1 0))</p></li><li><p>MULTIPOLYGON(((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2
-          0,1 2 0,1 1 0)),((-1 -1 0,-1 -2 0,-2 -2 0,-2 -1 0,-1 -1 0)))</p></li><li><p>GEOMETRYCOLLECTIONM(POINTM(2 3 9),LINESTRINGM((2 3 4,3 4
-          5)))</p></li></ul></div><p>
-Input/Output of these formats are available using the following
-interfaces:
-</p><pre class="programlisting">
-	bytea EWKB = asEWKB(geometry);
-	text EWKT = asEWKT(geometry);
-	geometry = GeomFromEWKB(bytea EWKB);
-	geometry = GeomFromEWKT(text EWKT);
-	</pre><p>
-For example, a valid insert statement to create and insert a PostGIS spatial object would be:
-</p><pre class="programlisting">
-	INSERT INTO SPATIALTABLE ( 
-		  THE_GEOM, 
-		  THE_NAME 
-	) 
-	VALUES ( 
-		  GeomFromEWKT('SRID=312;POINTM(-126.4 45.32 15)'), 
-		  'A Place' 
-	)</pre><p>
-The "canonical forms" of a PostgreSQL type are the representations
-you get with a simple query (without any function call) and the one
-which is guaranteed to be accepted with a simple insert, update or
-copy. For the postgis 'geometry' type these are:
-
-	</p><pre class="programlisting">
-	- Output -
-	binary: EWKB
-	 ascii: HEXEWKB (EWKB in hex form)
-
-	- Input -
-	binary: EWKB
-	 ascii: HEXEWKB|EWKT
-	</pre><p>
-</p><p>
-For example this statement reads EWKT and returns HEXEWKB in the
-process of canonical ascii input/output:
-</p><pre class="programlisting">
-	=# SELECT 'SRID=4;POINT(0 0)'::geometry;
-			      geometry
-	----------------------------------------------------
-	 01010000200400000000000000000000000000000000000000
-	(1 row)
-	</pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2523004"></a>4.2. Using OpenGIS Standards</h2></div></div><div></div></div><p>The OpenGIS "Simple Features Specification for SQL" defines
-      standard GIS object types, the functions required to manipulate them,
-      and a set of meta-data tables. In order to ensure that meta-data remain
-      consistent, operations such as creating and removing a spatial column
-      are carried out through special procedures defined by OpenGIS.</p><p>There are two OpenGIS meta-data tables:
-      <tt class="varname">SPATIAL_REF_SYS</tt> and
-      <tt class="varname">GEOMETRY_COLUMNS</tt>. The
-      <tt class="varname">SPATIAL_REF_SYS</tt> table holds the numeric IDs and
-      textual descriptions of coordinate systems used in the spatial
-      database.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523037"></a>4.2.1. The SPATIAL_REF_SYS Table</h3></div></div><div></div></div><p>The <tt class="varname">SPATIAL_REF_SYS</tt> table definition is as
-        follows:</p><pre class="programlisting">CREATE TABLE SPATIAL_REF_SYS ( 
-  SRID INTEGER NOT NULL PRIMARY KEY, 
-  AUTH_NAME VARCHAR(256), 
-  AUTH_SRID INTEGER, 
-  SRTEXT VARCHAR(2048), 
-  PROJ4TEXT VARCHAR(2048)
-)</pre><p>The <tt class="varname">SPATIAL_REF_SYS</tt> columns are as
-        follows:</p><div class="variablelist"><dl><dt><span class="term">SRID</span></dt><dd><p>An integer value that uniquely identifies the Spatial
-              Referencing System (SRS) within the database.</p></dd><dt><span class="term">AUTH_NAME</span></dt><dd><p>The name of the standard or standards body that is being
-              cited for this reference system. For example, "EPSG" would be a
-              valid <tt class="varname">AUTH_NAME</tt>.</p></dd><dt><span class="term">AUTH_SRID</span></dt><dd><p>The ID of the Spatial Reference System as defined by the
-              Authority cited in the <tt class="varname">AUTH_NAME</tt>. In the case
-              of EPSG, this is where the EPSG projection code would go.</p></dd><dt><span class="term">SRTEXT</span></dt><dd><p>The Well-Known Text representation of the Spatial
-              Reference System. An example of a WKT SRS representation
-              is:</p><pre class="programlisting">PROJCS["NAD83 / UTM Zone 10N", 
-  GEOGCS["NAD83",
-    DATUM["North_American_Datum_1983", 
-      SPHEROID["GRS 1980",6378137,298.257222101]
-    ], 
-    PRIMEM["Greenwich",0], 
-    UNIT["degree",0.0174532925199433] 
-  ],
-  PROJECTION["Transverse_Mercator"], 
-  PARAMETER["latitude_of_origin",0],
-  PARAMETER["central_meridian",-123], 
-  PARAMETER["scale_factor",0.9996],
-  PARAMETER["false_easting",500000], 
-  PARAMETER["false_northing",0],
-  UNIT["metre",1] 
-]</pre><p>For a listing of EPSG projection codes and their
-              corresponding WKT representations, see <a href="http://www.opengis.org/techno/interop/EPSG2WKT.TXT" target="_top">http://www.opengis.org/techno/interop/EPSG2WKT.TXT</a>.
-              For a discussion of WKT in general, see the OpenGIS "Coordinate
-              Transformation Services Implementation Specification" at <a href="http://www.opengis.org/techno/specs.htm" target="_top">http://www.opengis.org/techno/specs.htm</a>.
-              For information on the European Petroleum Survey Group (EPSG)
-              and their database of spatial reference systems, see <a href="http://epsg.org" target="_top">http://epsg.org</a>.</p></dd><dt><span class="term">PROJ4TEXT</span></dt><dd><p>PostGIS uses the Proj4 library to provide coordinate
-              transformation capabilities. The <tt class="varname">PROJ4TEXT</tt>
-              column contains the Proj4 coordinate definition string for a
-              particular SRID. For example:</p><pre class="programlisting">+proj=utm +zone=10 +ellps=clrk66 +datum=NAD27 +units=m</pre><p>For more information about, see the Proj4 web site at
-              <a href="http://www.remotesensing.org/proj" target="_top">http://www.remotesensing.org/proj</a>.
-              The <tt class="filename">spatial_ref_sys.sql</tt> file contains both
-              <tt class="varname">SRTEXT</tt> and <tt class="varname">PROJ4TEXT</tt>
-              definitions for all EPSG projections.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523246"></a>4.2.2. The GEOMETRY_COLUMNS Table</h3></div></div><div></div></div><p>The <tt class="varname">GEOMETRY_COLUMNS</tt> table definition is as
-        follows:</p><pre class="programlisting">CREATE TABLE GEOMETRY_COLUMNS ( 
-  F_TABLE_CATALOG VARCHAR(256) NOT NULL, 
-  F_TABLE_SCHEMA VARCHAR(256) NOT NULL, 
-  F_TABLE_NAME VARCHAR(256) NOT NULL, 
-  F_GEOMETRY_COLUMN VARCHAR(256) NOT NULL,
-  COORD_DIMENSION INTEGER NOT NULL, 
-  SRID INTEGER NOT NULL, 
-  TYPE VARCHAR(30) NOT NULL 
-)</pre><p>The columns are as follows:</p><div class="variablelist"><dl><dt><span class="term">F_TABLE_CATALOG, F_TABLE_SCHEMA, F_TABLE_NAME</span></dt><dd><p>The fully qualified name of the feature table containing
-              the geometry column. Note that the terms "catalog" and "schema"
-              are Oracle-ish. There is not PostgreSQL analogue of "catalog" so
-              that column is left blank -- for "schema" the PostgreSQL schema
-              name is used (<tt class="varname">public</tt> is the default).</p></dd><dt><span class="term">F_GEOMETRY_COLUMN</span></dt><dd><p>The name of the geometry column in the feature
-              table.</p></dd><dt><span class="term">COORD_DIMENSION</span></dt><dd><p>The spatial dimension (2, 3 or 4 dimensional) of the
-              column.</p></dd><dt><span class="term">SRID</span></dt><dd><p>The ID of the spatial reference system used for the
-              coordinate geometry in this table. It is a foreign key reference
-              to the <tt class="varname">SPATIAL_REF_SYS</tt>.</p></dd><dt><span class="term">TYPE</span></dt><dd><p>The type of the spatial object. To restrict the spatial
-              column to a single type, use one of: POINT, LINESTRING, POLYGON,
-              MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION or
-	      corresponding XYM versions POINTM, LINESTRINGM, POLYGONM,
-	      MULTIPOINTM, MULTILINESTRINGM, MULTIPOLYGONM, GEOMETRYCOLLECTIONM.
-              For heterogeneous (mixed-type) collections, you can use
-              "GEOMETRY" as the type.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This attribute is (probably) not part of the OpenGIS
-                specification, but is required for ensuring type
-                homogeneity.</p></div></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523380"></a>4.2.3. Creating a Spatial Table</h3></div></div><div></div></div><p>Creating a table with spatial data is done in two stages:</p><div class="itemizedlist"><ul type="disc"><li><p>Create a normal non-spatial table.</p><p>For example: <span><b class="command">CREATE TABLE ROADS_GEOM ( ID int4,
-            NAME varchar(25) )</b></span></p></li><li><p>Add a spatial column to the table using the OpenGIS
-            "AddGeometryColumn" function.</p><p>The syntax is:
-            </p><pre class="programlisting">AddGeometryColumn(&lt;schema_name&gt;, &lt;table_name&gt;,
-            &lt;column_name&gt;, &lt;srid&gt;, &lt;type&gt;,
-            &lt;dimension&gt;)</pre><p>
-
-	    Or, using current schema:
-            </p><pre class="programlisting">AddGeometryColumn(&lt;table_name&gt;,
-            &lt;column_name&gt;, &lt;srid&gt;, &lt;type&gt;,
-            &lt;dimension&gt;)</pre><p>
-	    </p><p>Example1: <span><b class="command">SELECT AddGeometryColumn('public',
-            'roads_geom', 'geom', 423, 'LINESTRING', 2)</b></span></p><p>Example2: <span><b class="command">SELECT AddGeometryColumn(
-            'roads_geom', 'geom', 423, 'LINESTRING', 2)</b></span></p></li></ul></div><p>Here is an example of SQL used to create a table and add a
-        spatial column (assuming that an SRID of 128
-        exists already):</p><pre class="programlisting">CREATE TABLE parks ( PARK_ID int4, PARK_NAME varchar(128), PARK_DATE date, PARK_TYPE varchar(2) );
-SELECT AddGeometryColumn('parks', 'park_geom', 128, 'MULTIPOLYGON', 2 );</pre><p>Here is another example, using the generic "geometry" type and
-        the undefined SRID value of -1:</p><pre class="programlisting">CREATE TABLE roads ( ROAD_ID int4, ROAD_NAME varchar(128) ); 
-SELECT AddGeometryColumn( 'roads', 'roads_geom', -1, 'GEOMETRY', 3 );</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523486"></a>4.2.4. Ensuring OpenGIS compliancy of geometries</h3></div></div><div></div></div><p>Most of the functions implemented by the GEOS library
-	rely on the assumption that your geometries are valid
-        as specified by the OpenGIS Simple Feature Specification.
-	To check validity of geometries you can use the
-	<a href="ch06.html#IsValid">IsValid()</a> function:</p><pre class="programlisting">gisdb=# select isvalid('LINESTRING(0 0, 1 1)'), isvalid('LINESTRING(0 0,0 0)');
- isvalid | isvalid
----------+---------
- t       | f</pre><p>By default, PostGIS does not apply this validity check on geometry input, because
-        testing for validity needs lots of CPU time for complex geometries, especially polygons.
-        If you do not trust your data sources, you can manually enforce such a check to your tables
-        by adding a check constraint:</p><pre class="programlisting">ALTER TABLE mytable ADD CONSTRAINT geometry_valid_check CHECK (isvalid(the_geom));</pre><p>If you encounter any strange error messages such as "GEOS Intersection() threw an 
-        error!" or "JTS Intersection() threw an error!" when calling PostGIS functions with valid
-        input geometries, you likely found an error in either PostGIS or one of the libraries it
-        uses, and you should contact the PostGIS developers. The same is true if a PostGIS function returns
-        an invalid geometry for valid input.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-	Strictly compliant OGC geometries cannot have Z or M values.
-	The <a href="ch06.html#IsValid">IsValid()</a> function won't
-	consider higher dimensioned geometries invalid! Invocations
-	of <a href="ch06.html#AddGeometryColumn">AddGeometryColumn()</a>
-        will add a constraint checking geometry dimensions, so it is
-        enough to specify 2 there.
-	</p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2523576"></a>4.3. Loading GIS Data</h2></div></div><div></div></div><p>Once you have created a spatial table, you are ready to upload GIS
-      data to the database. Currently, there are two ways to get data into a
-      PostGIS/PostgreSQL database: using formatted SQL statements or using the
-      Shape file loader/dumper.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523590"></a>4.3.1. Using SQL</h3></div></div><div></div></div><p>If you can convert your data to a text representation, then
-        using formatted SQL might be the easiest way to get your data into
-        PostGIS. As with Oracle and other SQL databases, data can be bulk
-        loaded by piping a large text file full of SQL "INSERT" statements
-        into the SQL terminal monitor.</p><p>A data upload file (<tt class="filename">roads.sql</tt> for example)
-        might look like this:</p><pre class="programlisting">BEGIN;
-INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (1,GeomFromText('LINESTRING(191232 243118,191108 243242)',-1),'Jeff Rd'); 
-INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (2,GeomFromText('LINESTRING(189141 244158,189265 244817)',-1),'Geordie Rd'); 
-INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (3,GeomFromText('LINESTRING(192783 228138,192612 229814)',-1),'Paul St'); 
-INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (4,GeomFromText('LINESTRING(189412 252431,189631 259122)',-1),'Graeme Ave'); 
-INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (5,GeomFromText('LINESTRING(190131 224148,190871 228134)',-1),'Phil Tce'); 
-INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (6,GeomFromText('LINESTRING(198231 263418,198213 268322)',-1),'Dave Cres');
-COMMIT;</pre><p>The data file can be piped into PostgreSQL very easily using the
-        "psql" SQL terminal monitor:</p><pre class="programlisting">psql -d [database] -f roads.sql</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523645"></a>4.3.2. Using the Loader</h3></div></div><div></div></div><p>The <tt class="filename">shp2pgsql</tt> data loader converts ESRI
-        Shape files into SQL suitable for insertion into a PostGIS/PostgreSQL
-        database. The loader has several operating modes distinguished by
-        command line flags:</p><div class="variablelist"><dl><dt><span class="term">-d</span></dt><dd><p>Drops the database table before creating a new table with
-              the data in the Shape file.</p></dd><dt><span class="term">-a</span></dt><dd><p>Appends data from the Shape file into the database table.
-              Note that to use this option to load multiple files, the files
-              must have the same attributes and same data types.</p></dd><dt><span class="term">-c</span></dt><dd><p>Creates a new table and populates it from the Shape file.
-              <span class="emphasis"><em>This is the default mode.</em></span></p></dd><dt><span class="term">-p</span></dt><dd><p>Only produces the table creation SQL code, without adding 
-              any actual data. This can be used if you need to completely
-              separate the table creation and data loading steps.</p></dd><dt><span class="term">-D</span></dt><dd><p>Use the PostgreSQL "dump" format for the output data. This 
-              can be combined with -a, -c and -d. It is much faster to load
-              than the default "insert" SQL format. Use this for very large data
-              sets.</p></dd><dt><span class="term">-s &lt;SRID&gt;</span></dt><dd><p>Creates and populates the geometry tables with the
-              specified SRID.</p></dd><dt><span class="term">-k</span></dt><dd><p>Keep idendifiers case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.</p></dd><dt><span class="term">-i</span></dt><dd><p>Coerce all integers to standard 32-bit integers, do not
-              create 64-bit bigints, even if the DBF header signature appears
-              to warrant it.</p></dd><dt><span class="term">-I</span></dt><dd><p>Create a GiST index on the geometry column.</p></dd><dt><span class="term">-w</span></dt><dd><p>
-       	      Output WKT format, for use with older (0.x) versions of PostGIS.
-              Note  that this will introduce coordinate drifts and will drop M
-              values from shapefiles.
-              </p></dd><dt><span class="term">-W &lt;encoding&gt;</span></dt><dd><p>
-Specify encoding of the input data (dbf file).
-When used, all attributes of the dbf are converted from the specified
-encoding to UTF8. The resulting SQL output will contain a <tt class="code">SET
-CLIENT_ENCODING to UTF8</tt> command, so that the backend will be able
-to reconvert from UTF8 to whatever encoding the database is configured
-to use internally.
-		</p></dd></dl></div><p>Note that -a, -c, -d and -p are mutually exclusive.</p><p>An example session using the loader to create an input file and
-        uploading it might look like this:</p><pre class="programlisting"># shp2pgsql shaperoads myschema.roadstable &gt; roads.sql 
-# psql -d roadsdb -f roads.sql</pre><p>A conversion and upload can be done all in one step using UNIX
-        pipes:</p><pre class="programlisting"># shp2pgsql shaperoads myschema.roadstable | psql -d roadsdb</pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2523875"></a>4.4. Retrieving GIS Data</h2></div></div><div></div></div><p>Data can be extracted from the database using either SQL or the
-      Shape file loader/dumper. In the section on SQL we will discuss some of
-      the operators available to do comparisons and queries on spatial
-      tables.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2523888"></a>4.4.1. Using SQL</h3></div></div><div></div></div><p>The most straightforward means of pulling data out of the
-        database is to use a SQL select query and dump the resulting columns
-        into a parsable text file:</p><pre class="programlisting">db=# SELECT id, AsText(geom) AS geom, name FROM ROADS_GEOM; 
-id | geom                                    | name 
----+-----------------------------------------+-----------
- 1 | LINESTRING(191232 243118,191108 243242) | Jeff Rd  
- 2 | LINESTRING(189141 244158,189265 244817) | Geordie Rd 
- 3 | LINESTRING(192783 228138,192612 229814) | Paul St 
- 4 | LINESTRING(189412 252431,189631 259122) | Graeme Ave 
- 5 | LINESTRING(190131 224148,190871 228134) | Phil Tce 
- 6 | LINESTRING(198231 263418,198213 268322) | Dave Cres 
- 7 | LINESTRING(218421 284121,224123 241231) | Chris Way 
-(6 rows)</pre><p>However, there will be times when some kind of restriction is
-        necessary to cut down the number of fields returned. In the case of
-        attribute-based restrictions, just use the same SQL syntax as normal
-        with a non-spatial table. In the case of spatial restrictions, the
-        following operators are available/useful:</p><div class="variablelist"><dl><dt><span class="term">&amp;&amp;</span></dt><dd><p>This operator tells whether the bounding box of one
-              geometry intersects the bounding box of another.</p></dd><dt><span class="term">~=</span></dt><dd><p>This operators tests whether two geometries are
-              geometrically identical. For example, if 'POLYGON((0 0,1 1,1 0,0
-              0))' is the same as 'POLYGON((0 0,1 1,1 0,0 0))' (it is).</p></dd><dt><span class="term">=</span></dt><dd><p>This operator is a little more naive, it only tests
-              whether the bounding boxes of to geometries are the same.</p></dd></dl></div><p>Next, you can use these operators in queries. Note that when
-        specifying geometries and boxes on the SQL command line, you must
-        explicitly turn the string representations into geometries by using
-        the "GeomFromText()" function. So, for example:</p><pre class="programlisting">SELECT 
-  ID, NAME 
-FROM ROADS_GEOM 
-WHERE 
-  GEOM ~= GeomFromText('LINESTRING(191232 243118,191108 243242)',-1);</pre><p>The above query would return the single record from the
-        "ROADS_GEOM" table in which the geometry was equal to that
-        value.</p><p>When using the "&amp;&amp;" operator, you can specify either a
-        BOX3D as the comparison feature or a GEOMETRY. When you specify a
-        GEOMETRY, however, its bounding box will be used for the
-        comparison.</p><pre class="programlisting">SELECT 
-  ID, NAME 
-FROM ROADS_GEOM 
-WHERE 
-  GEOM &amp;&amp; GeomFromText('POLYGON((191232 243117,191232 243119,191234 243117,191232 243117))',-1);</pre><p>The above query will use the bounding box of the polygon for
-        comparison purposes.</p><p>The most common spatial query will probably be a "frame-based"
-        query, used by client software, like data browsers and web mappers, to
-        grab a "map frame" worth of data for display. Using a "BOX3D" object
-        for the frame, such a query looks like this:</p><pre class="programlisting">SELECT 
-  AsText(GEOM) AS GEOM 
-FROM ROADS_GEOM 
-WHERE 
-  GEOM &amp;&amp; SetSRID('BOX3D(191232 243117,191232 243119)'::box3d,-1);</pre><p>Note the use of the SRID, to specify the projection of the
-        BOX3D. The value -1 is used to indicate no specified SRID.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2524054"></a>4.4.2. Using the Dumper</h3></div></div><div></div></div><p>The <tt class="filename">pgsql2shp</tt> table dumper connects
-        directly to the database and converts a table (possibly defined by
-	a query) into a shape file. The
-        basic syntax is:</p><pre class="programlisting">pgsql2shp [&lt;options&gt;] &lt;database&gt; [&lt;schema&gt;.]&lt;table&gt;</pre><pre class="programlisting">pgsql2shp [&lt;options&gt;] &lt;database&gt; &lt;query&gt;</pre><p>The commandline options are:</p><div class="variablelist"><dl><dt><span class="term">-f &lt;filename&gt;</span></dt><dd><p>Write the output to a particular filename.</p></dd><dt><span class="term">-h &lt;host&gt;</span></dt><dd><p>The database host to connect to.</p></dd><dt><span class="term">-p &lt;port&gt;</span></dt><dd><p>The port to connect to on the database host.</p></dd><dt><span class="term">-P &lt;password&gt;</span></dt><dd><p>The password to use when connecting to the
-              database.</p></dd><dt><span class="term">-u &lt;user&gt;</span></dt><dd><p>The username to use when connecting to the
-              database.</p></dd><dt><span class="term">-g &lt;geometry column&gt;</span></dt><dd><p>In the case of tables with multiple geometry columns, the
-              geometry column to use when writing the shape file.</p></dd><dt><span class="term">-b</span></dt><dd><p>Use a binary cursor. This will make the operation faster,
-	      but will not work if any NON-geometry attribute in the table
-	      lacks a cast to text.</p></dd><dt><span class="term">-r</span></dt><dd><p>Raw mode. Do not drop the <tt class="varname">gid</tt> field, or
-              escape column names.</p></dd><dt><span class="term">-d</span></dt><dd><p>For backward compatibility: write a 3-dimensional shape
-	      file when dumping from old (pre-1.0.0) postgis databases (the
-	      default is to write a 2-dimensional shape file in that case).
-	      Starting from postgis-1.0.0+, dimensions are fully encoded.
-	      </p></dd></dl></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2524232"></a>4.5. Building Indexes</h2></div></div><div></div></div><p>Indexes are what make using a spatial database for large data sets
-      possible. Without indexing, any search for a feature would require a
-      "sequential scan" of every record in the database. Indexing speeds up
-      searching by organizing the data into a search tree which can be quickly
-      traversed to find a particular record. PostgreSQL supports three kinds
-      of indexes by default: B-Tree indexes, R-Tree indexes, and GiST
-      indexes.</p><div class="itemizedlist"><ul type="disc"><li><p>B-Trees are used for data which can be sorted along one axis;
-          for example, numbers, letters, dates. GIS data cannot be rationally
-          sorted along one axis (which is greater, (0,0) or (0,1) or (1,0)?)
-          so B-Tree indexing is of no use for us.</p></li><li><p>R-Trees break up data into rectangles, and sub-rectangles, and
-          sub-sub rectangles, etc. R-Trees are used by some spatial databases
-          to index GIS data, but the PostgreSQL R-Tree implementation is not
-          as robust as the GiST implementation.</p></li><li><p>GiST (Generalized Search Trees) indexes break up data into
-          "things to one side", "things which overlap", "things which are
-          inside" and can be used on a wide range of data-types, including GIS
-          data. PostGIS uses an R-Tree index implemented on top of GiST to
-          index GIS data.</p></li></ul></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2524285"></a>4.5.1. GiST Indexes</h3></div></div><div></div></div><p>GiST stands for "Generalized Search Tree" and is a generic form
-        of indexing. In addition to GIS indexing, GiST is used to speed up
-        searches on all kinds of irregular data structures (integer arrays,
-        spectral data, etc) which are not amenable to normal B-Tree
-        indexing.</p><p>Once a GIS data table exceeds a few thousand rows, you will want
-        to build an index to speed up spatial searches of the data (unless all
-        your searches are based on attributes, in which case you'll want to
-        build a normal index on the attribute fields).</p><p>The syntax for building a GiST index on a "geometry" column is
-        as follows:</p><pre class="programlisting">CREATE INDEX [indexname] ON [tablename] 
-  USING GIST ( [geometryfield] GIST_GEOMETRY_OPS ); </pre><p>Building a spatial index is a computationally intensive
-        exercise: on tables of around 1 million rows, on a 300MHz Solaris
-        machine, we have found building a GiST index takes about 1 hour. After
-        building an index, it is important to force PostgreSQL to collect
-        table statistics, which are used to optimize query plans:</p><pre class="programlisting">VACUUM ANALYZE [table_name] [column_name];
-
--- This is only needed for PostgreSQL 7.4 installations and below
-SELECT UPDATE_GEOMETRY_STATS([table_name], [column_name]);</pre><p>GiST indexes have two advantages over R-Tree indexes in
-        PostgreSQL. Firstly, GiST indexes are "null safe", meaning they can
-        index columns which include null values. Secondly, GiST indexes
-        support the concept of "lossiness" which is important when dealing
-        with GIS objects larger than the PostgreSQL 8K page size. Lossiness
-        allows PostgreSQL to store only the "important" part of an object in
-        an index -- in the case of GIS objects, just the bounding box. GIS
-        objects larger than 8K will cause R-Tree indexes to fail in the
-        process of being built.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2524354"></a>4.5.2. Using Indexes</h3></div></div><div></div></div><p>Ordinarily, indexes invisibly speed up data access: once the
-        index is built, the query planner transparently decides when to use
-        index information to speed up a query plan. Unfortunately, the
-        PostgreSQL query planner does not optimize the use of GiST indexes
-        well, so sometimes searches which should use a spatial index instead
-        default to a sequence scan of the whole table.</p><p>If you find your spatial indexes are not being used (or your
-        attribute indexes, for that matter) there are a couple things you can
-        do:</p><div class="itemizedlist"><ul type="disc"><li><p>Firstly, make sure statistics are gathered about the number
-            and distributions of values in a table, to provide the query
-            planner with better information to make decisions around index
-            usage. For PostgreSQL 7.4 installations and below this is done by
-            running <span><b class="command">update_geometry_stats([table_name,
-            column_name])</b></span> (compute distribution) and <span><b class="command">VACUUM
-            ANALYZE [table_name] [column_name]</b></span> (compute number of
-            values). Starting with PostgreSQL 8.0 running <span><b class="command">VACUUM
-            ANALYZE</b></span> will do both operations. You should regularly
-            vacuum your databases anyways -- many PostgreSQL DBAs have
-            <span><b class="command">VACUUM</b></span> run as an off-peak cron job on a regular
-            basis.</p></li><li><p>If vacuuming does not work, you can force the planner to use
-            the index information by using the <span><b class="command">SET
-            ENABLE_SEQSCAN=OFF</b></span> command. You should only use this
-            command sparingly, and only on spatially indexed queries:
-            generally speaking, the planner knows better than you do about
-            when to use normal B-Tree indexes. Once you have run your query,
-            you should consider setting <tt class="varname">ENABLE_SEQSCAN</tt> back
-            on, so that other queries will utilize the planner as
-            normal.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>As of version 0.6, it should not be necessary to force the
-              planner to use the index with
-              <tt class="varname">ENABLE_SEQSCAN</tt>.</p></div></li><li><p>If you find the planner wrong about the cost of sequencial
-            vs index scans try reducing the value of random_page_cost in
-            postgresql.conf or using SET random_page_cost=#. Default value for
-            the parameter is 4, try setting it to 1 or 2. Decrementing the
-            value makes the planner more inclined of using Index scans.</p></li></ul></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2524472"></a>4.6. Complex Queries</h2></div></div><div></div></div><p>The <span class="emphasis"><em>raison d'etre</em></span> of spatial database
-      functionality is performing queries inside the database which would
-      ordinarily require desktop GIS functionality. Using PostGIS effectively
-      requires knowing what spatial functions are available, and ensuring that
-      appropriate indexes are in place to provide good performance.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2524491"></a>4.6.1. Taking Advantage of Indexes</h3></div></div><div></div></div><p>When constructing a query it is important to remember that only
-        the bounding-box-based operators such as &amp;&amp; can take advatage
-        of the GiST spatial index. Functions such as
-        <tt class="varname">distance()</tt> cannot use the index to optimize their
-        operation. For example, the following query would be quite slow on a
-        large table:</p><pre class="programlisting">SELECT the_geom FROM geom_table
-WHERE distance( the_geom, GeomFromText( 'POINT(100000 200000)', -1 ) ) &lt; 100</pre><p>This query is selecting all the geometries in geom_table which
-        are within 100 units of the point (100000, 200000). It will be slow
-        because it is calculating the distance between each point in the table
-        and our specified point, ie. one <tt class="varname">distance()</tt>
-        calculation for each row in the table. We can avoid this by using the
-        &amp;&amp; operator to reduce the number of distance calculations
-        required:</p><pre class="programlisting">SELECT the_geom FROM geom_table
-WHERE the_geom &amp;&amp; 'BOX3D(90900 190900, 100100 200100)'::box3d
-  AND distance( the_geom, GeomFromText( 'POINT(100000 200000)', -1 ) ) &lt; 100</pre><p>This query selects the same geometries, but it does it in a more
-        efficient way. Assuming there is a GiST index on the_geom, the query
-        planner will recognize that it can use the index to reduce the number
-        of rows before calculating the result of the
-        <tt class="varname">distance()</tt> function. Notice that the
-        <tt class="varname">BOX3D</tt> geometry which is used in the &amp;&amp;
-        operation is a 200 unit square box centered on the original point -
-        this is our "query box". The &amp;&amp; operator uses the index to
-        quickly reduce the result set down to only those geometries which have
-        bounding boxes that overlap the "query box". Assuming that our query
-        box is much smaller than the extents of the entire geometry table,
-        this will drastically reduce the number of distance calculations that
-        need to be done.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2524587"></a>4.6.2. Examples of Spatial SQL</h3></div></div><div></div></div><p>The examples in this section will make use of two tables, a
-        table of linear roads, and a table of polygonal municipality
-        boundaries. The table definitions for the <tt class="varname">bc_roads</tt>
-        table is:</p><pre class="programlisting">  Column    |       Type        |   Description
-------------+-------------------+-------------------
- gid        | integer           | Unique ID
- name       | character varying | Road Name
- the_geom   | geometry          | Location Geometry (Linestring)</pre><p>The table definition for the <tt class="varname">bc_municipality</tt>
-        table is:</p><pre class="programlisting">  Column   |       Type        |   Description
------------+-------------------+-------------------
- gid       | integer           | Unique ID
- code      | integer           | Unique ID
- name      | character varying | City / Town Name
- the_geom  | geometry          | Location Geometry (Polygon)</pre><div class="qandaset"><dl><dt>4.6.2.1. <a href="ch04.html#id2524633">What is the total length of all roads, expressed in
-                kilometers?</a></dt><dt>4.6.2.2. <a href="ch04.html#id2524660">How large is the city of Prince George, in
-                hectares?</a></dt><dt>4.6.2.3. <a href="ch04.html#id2524689">What is the largest municipality in the province, by
-                area?</a></dt><dt>4.6.2.4. <a href="ch04.html#id2524731">What is the length of roads fully contained within each
-                municipality?</a></dt><dt>4.6.2.5. <a href="ch04.html#id2524793">Create a new table with all the roads within the city of
-                Prince George.</a></dt><dt>4.6.2.6. <a href="ch04.html#id2524832">What is the length in kilometers of "Douglas St" in
-                Victoria?</a></dt><dt>4.6.2.7. <a href="ch04.html#id2524866">What is the largest municipality polygon that has a
-                hole?</a></dt></dl><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="question"><td align="left" valign="top"><a name="id2524633"></a><a name="id2524635"></a><b>4.6.2.1.</b></td><td align="left" valign="top"><p>What is the total length of all roads, expressed in
-                kilometers?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>You can answer this question with a very simple piece of
-                SQL:</p><pre class="programlisting">postgis=# SELECT sum(length(the_geom))/1000 AS km_roads FROM bc_roads;
-     km_roads
-------------------
- 70842.1243039643
-(1 row)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2524660"></a><a name="id2524663"></a><b>4.6.2.2.</b></td><td align="left" valign="top"><p>How large is the city of Prince George, in
-                hectares?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This query combines an attribute condition (on the
-                municipality name) with a spatial calculation (of the
-                area):</p><pre class="programlisting">postgis=# SELECT area(the_geom)/10000 AS hectares FROM bc_municipality 
-          WHERE name = 'PRINCE GEORGE';
-     hectares
-------------------
- 32657.9103824927
-(1 row) </pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2524689"></a><a name="id2524691"></a><b>4.6.2.3.</b></td><td align="left" valign="top"><p>What is the largest municipality in the province, by
-                area?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This query brings a spatial measurement into the query
-                condition. There are several ways of approaching this problem,
-                but the most efficient is below:</p><pre class="programlisting">postgis=# SELECT name, area(the_geom)/10000 AS hectares 
-          FROM bc_municipality 
-          ORDER BY hectares DESC 
-          LIMIT 1;
-     name      |    hectares
----------------+-----------------
- TUMBLER RIDGE | 155020.02556131
-(1 row)</pre><p>Note that in order to answer this query we have to
-                calculate the area of every polygon. If we were doing this a
-                lot it would make sense to add an area column to the table
-                that we could separately index for performance. By ordering
-                the results in a descending direction, and them using the
-                PostgreSQL "LIMIT" command we can easily pick off the largest
-                value without using an aggregate function like max().</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2524731"></a><a name="id2524733"></a><b>4.6.2.4.</b></td><td align="left" valign="top"><p>What is the length of roads fully contained within each
-                municipality?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This is an example of a "spatial join", because we are
-                bringing together data from two tables (doing a join) but
-                using a spatial interaction condition ("contained") as the
-                join condition rather than the usual relational approach of
-                joining on a common key:</p><pre class="programlisting">postgis=# SELECT m.name, sum(length(r.the_geom))/1000 as roads_km 
-          FROM bc_roads AS r,bc_municipality AS m 
-          WHERE r.the_geom &amp;&amp; m.the_geom 
-          AND contains(m.the_geom,r.the_geom) 
-          GROUP BY m.name 
-          ORDER BY roads_km;
-
-            name            |     roads_km
-----------------------------+------------------
- SURREY                     | 1539.47553551242
- VANCOUVER                  | 1450.33093486576
- LANGLEY DISTRICT           | 833.793392535662
- BURNABY                    | 773.769091404338
- PRINCE GEORGE              |  694.37554369147
- ...</pre><p>This query takes a while, because every road in the
-                table is summarized into the final result (about 250K roads
-                for our particular example table). For smaller overlays
-                (several thousand records on several hundred) the response can
-                be very fast.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2524793"></a><a name="id2524795"></a><b>4.6.2.5.</b></td><td align="left" valign="top"><p>Create a new table with all the roads within the city of
-                Prince George.</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This is an example of an "overlay", which takes in two
-                tables and outputs a new table that consists of spatially
-                clipped or cut resultants. Unlike the "spatial join"
-                demonstrated above, this query actually creates new
-                geometries. An overlay is like a turbo-charged spatial join,
-                and is useful for more exact analysis work:</p><pre class="programlisting">postgis=# CREATE TABLE pg_roads as
-          SELECT intersection(r.the_geom, m.the_geom) AS intersection_geom, 
-                 length(r.the_geom) AS rd_orig_length, 
-                 r.* 
-          FROM bc_roads AS r, bc_municipality AS m 
-          WHERE r.the_geom &amp;&amp; m.the_geom 
-          AND intersects(r.the_geom, m.the_geom) 
-          AND m.name = 'PRINCE GEORGE';</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2524832"></a><a name="id2524834"></a><b>4.6.2.6.</b></td><td align="left" valign="top"><p>What is the length in kilometers of "Douglas St" in
-                Victoria?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><pre class="programlisting">postgis=# SELECT sum(length(r.the_geom))/1000 AS kilometers 
-          FROM bc_roads r, bc_municipality m 
-          WHERE r.the_geom &amp;&amp; m.the_geom 
-          AND r.name = 'Douglas St' 
-          AND m.name = 'VICTORIA';
-    kilometers
-------------------
- 4.89151904172838
-(1 row)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2524866"></a><a name="id2524868"></a><b>4.6.2.7.</b></td><td align="left" valign="top"><p>What is the largest municipality polygon that has a
-                hole?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><pre class="programlisting">postgis=# SELECT gid, name, area(the_geom) AS area 
-          FROM bc_municipality 
-          WHERE nrings(the_geom) &gt; 1 
-          ORDER BY area DESC LIMIT 1;
- gid |     name     |       area
------+--------------+------------------
-  12 | SPALLUMCHEEN | 257374619.430216
-(1 row)</pre></td></tr></tbody></table></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2524902"></a>4.7. Using Mapserver</h2></div></div><div></div></div><p>The Minnesota Mapserver is an internet web-mapping server which
-      conforms to the OpenGIS Web Mapping Server specification.</p><div class="itemizedlist"><ul type="disc"><li><p>The Mapserver homepage is at <a href="http://mapserver.gis.umn.edu" target="_top">http://mapserver.gis.umn.edu</a>.</p></li><li><p>The OpenGIS Web Map Specification is at <a href="http://www.opengis.org/techno/specs/01-047r2.pdf" target="_top">http://www.opengis.org/techno/specs/01-047r2.pdf</a>.</p></li></ul></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2524945"></a>4.7.1. Basic Usage</h3></div></div><div></div></div><p>To use PostGIS with Mapserver, you will need to know about how
-        to configure Mapserver, which is beyond the scope of this
-        documentation. This section will cover specific PostGIS issues and
-        configuration details.</p><p>To use PostGIS with Mapserver, you will need:</p><div class="itemizedlist"><ul type="disc"><li><p>Version 0.6 or newer of PostGIS.</p></li><li><p>Version 3.5 or newer of Mapserver.</p></li></ul></div><p>Mapserver accesses PostGIS/PostgreSQL data like any other
-        PostgreSQL client -- using <tt class="filename">libpq</tt>. This means that
-        Mapserver can be installed on any machine with network access to the
-        PostGIS server, as long as the system has the
-        <tt class="filename">libpq</tt> PostgreSQL client libraries.</p><div class="orderedlist"><ol type="1"><li><p>Compile and install Mapserver, with whatever options you
-            desire, including the "--with-postgis" configuration
-            option.</p></li><li><p>In your Mapserver map file, add a PostGIS layer. For
-            example:</p><pre class="programlisting">LAYER
-  CONNECTIONTYPE postgis
-  NAME "widehighways"
-  # Connect to a remote spatial database
-  CONNECTION "user=dbuser dbname=gisdatabase host=bigserver"
-  # Get the lines from the 'geom' column of the 'roads' table
-  DATA "geom from roads"
-  STATUS ON
-  TYPE LINE
-  # Of the lines in the extents, only render the wide highways
-  FILTER "type = 'highway' and numlanes &gt;= 4"
-  CLASS
-    # Make the superhighways brighter and 2 pixels wide
-    EXPRESSION ([numlanes] &gt;= 6)
-    COLOR 255 22 22      
-    SYMBOL "solid"
-    SIZE 2
-  END
-  CLASS
-    # All the rest are darker and only 1 pixel wide
-    EXPRESSION ([numlanes] &lt; 6)
-    COLOR 205 92 82      
-  END
-END</pre><p>In the example above, the PostGIS-specific directives are as
-            follows:</p><div class="variablelist"><dl><dt><span class="term">CONNECTIONTYPE</span></dt><dd><p>For PostGIS layers, this is always "postgis".</p></dd><dt><span class="term">CONNECTION</span></dt><dd><p>The database connection is governed by the a
-                  'connection string' which is a standard set of keys and
-                  values like this (with the default values in
-                  &lt;&gt;):</p><p>user=&lt;username&gt; password=&lt;password&gt;
-                  dbname=&lt;username&gt; hostname=&lt;server&gt;
-                  port=&lt;5432&gt;</p><p>An empty connection string is still valid, and any of
-                  the key/value pairs can be omitted. At a minimum you will
-                  generally supply the database name and username to connect
-                  with.</p></dd><dt><span class="term">DATA</span></dt><dd><p>The form of this parameter is "&lt;column&gt; from
-                  &lt;tablename&gt;" where the column is the spatial column to
-                  be rendered to the map.</p></dd><dt><span class="term">FILTER</span></dt><dd><p>The filter must be a valid SQL string corresponding to
-                  the logic normally following the "WHERE" keyword in a SQL
-                  query. So, for example, to render only roads with 6 or more
-                  lanes, use a filter of "num_lanes &gt;= 6".</p></dd></dl></div></li><li><p>In your spatial database, ensure you have spatial (GiST)
-            indexes built for any the layers you will be drawing.</p><pre class="programlisting">CREATE INDEX [indexname]
-  ON [tablename] 
-  USING GIST ( [geometrycolumn] GIST_GEOMETRY_OPS );</pre></li><li><p>If you will be querying your layers using Mapserver you will
-            also need an "oid index".</p><p>Mapserver requires unique identifiers for each spatial
-            record when doing queries, and the PostGIS module of Mapserver
-            uses the PostgreSQL <tt class="varname">oid</tt> value to provide these
-            unique identifiers. A side-effect of this is that in order to do
-            fast random access of records during queries, an index on the
-            <tt class="varname">oid</tt> is needed.</p><p>To build an "oid index", use the following SQL:</p><pre class="programlisting">CREATE INDEX [indexname] ON [tablename] ( oid );</pre></li></ol></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2525193"></a>4.7.2. Frequently Asked Questions</h3></div></div><div></div></div><div class="qandaset"><dl><dt>4.7.2.1. <a href="ch04.html#id2525201">When I use an EXPRESSION in my map
-                file, the condition never returns as true, even though I know
-                the values exist in my table.</a></dt><dt>4.7.2.2. <a href="ch04.html#id2525235">The FILTER I use for my Shape files is not working for
-                my PostGIS table of the same data.</a></dt><dt>4.7.2.3. <a href="ch04.html#id2525264">My PostGIS layer draws much slower than my Shape file
-                layer, is this normal?</a></dt><dt>4.7.2.4. <a href="ch04.html#id2525302">My PostGIS layer draws fine, but queries are really
-                slow. What is wrong?</a></dt></dl><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="question"><td align="left" valign="top"><a name="id2525201"></a><a name="id2525203"></a><b>4.7.2.1.</b></td><td align="left" valign="top"><p>When I use an <tt class="varname">EXPRESSION</tt> in my map
-                file, the condition never returns as true, even though I know
-                the values exist in my table.</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Unlike shape files, PostGIS field names have to be
-                referenced in EXPRESSIONS using <span class="emphasis"><em>lower
-                case</em></span>.</p><pre class="programlisting">EXPRESSION ([numlanes] &gt;= 6)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2525235"></a><a name="id2525237"></a><b>4.7.2.2.</b></td><td align="left" valign="top"><p>The FILTER I use for my Shape files is not working for
-                my PostGIS table of the same data.</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Unlike shape files, filters for PostGIS layers use SQL
-                syntax (they are appended to the SQL statement the PostGIS
-                connector generates for drawing layers in Mapserver).</p><pre class="programlisting">FILTER "type = 'highway' and numlanes &gt;= 4"</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2525264"></a><a name="id2525266"></a><b>4.7.2.3.</b></td><td align="left" valign="top"><p>My PostGIS layer draws much slower than my Shape file
-                layer, is this normal?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>In general, expect PostGIS layers to be 10% slower than
-                equivalent Shape files layers, due to the extra overhead
-                involved in database connections, data transformations and
-                data transit between the database and Mapserver.</p><p>If you are finding substantial draw performance
-                problems, it is likely that you have not build a spatial index
-                on your table.</p><pre class="programlisting">postgis# CREATE INDEX geotable_gix ON geotable USING GIST ( geocolumn );
-postgis# SELECT update_geometry_stats();  -- For PGSQL &lt; 8.0
-postgis# VACUUM ANALYZE;                  -- For PGSQL &gt;= 8.0</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2525302"></a><a name="id2525304"></a><b>4.7.2.4.</b></td><td align="left" valign="top"><p>My PostGIS layer draws fine, but queries are really
-                slow. What is wrong?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>For queries to be fast, you must have a unique key for
-                your spatial table and you must have an index on that unique
-                key.</p><p>You can specify what unique key for mapserver to use
-                with the <tt class="varname">USING UNIQUE</tt> clause in your
-                <tt class="varname">DATA</tt> line:</p><pre class="programlisting">DATA "the_geom FROM geotable USING UNIQUE gid"</pre><p>If your table does not have an explicit unique column,
-                you can "fake" a unique column by using the PostgreSQL row
-                "oid" for your unique column. "oid" is the default unique
-                column if you do not declare one, so enhancing your query
-                speed is a matter of building an index on your spatial table
-                oid value.</p><pre class="programlisting">postgis# CREATE INDEX geotable_oid_idx ON geotable (oid);</pre></td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2525360"></a>4.7.3. Advanced Usage</h3></div></div><div></div></div><p>The <tt class="varname">USING</tt> pseudo-SQL clause is used to add
-        some information to help mapserver understand the results of more
-        complex queries. More specifically, when either a view or a subselect
-        is used as the source table (the thing to the right of "FROM" in a
-        <tt class="varname">DATA</tt> definition) it is more difficult for mapserver
-        to automatically determine a unique identifier for each row and also
-        the SRID for the table. The <tt class="varname">USING</tt> clause can
-        provide mapserver with these two pieces of information as
-        follows:</p><pre class="programlisting">DATA "the_geom FROM (SELECT table1.the_geom AS the_geom, table1.oid AS oid, table2.data AS data
- FROM table1 LEFT JOIN table2 ON table1.id = table2.id) AS new_table USING UNIQUE oid USING SRID=-1"</pre><div class="variablelist"><dl><dt><span class="term">USING UNIQUE &lt;uniqueid&gt;</span></dt><dd><p>Mapserver requires a unique id for each row in order to
-              identify the row when doing map queries. Normally, it would use
-              the oid as the unique identifier, but views and subselects don't
-              automatically have an oid column. If you want to use Mapserver's
-              query functionality, you need to add a unique column to your
-              view or subselect, and declare it with <tt class="varname">USING
-              UNIQUE</tt>. For example, you could explicitly select one
-              of the table's oid values for this purpose, or any other column
-              which is guaranteed to be unique for the result set.</p><p>The <tt class="varname">USING</tt> statement can also be useful
-              even for simple <tt class="varname">DATA</tt> statements, if you are
-              doing map queries. It was previously recommended to add an index
-              on the oid column of tables used in query-able layers, in order
-              to speed up the performance of map queries. However, with the
-              <tt class="varname">USING</tt> clause, it is possible to tell
-              mapserver to use your table's primary key as the identifier for
-              map queries, and then it is no longer necessary to have an
-              additional index.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>"Querying a Map" is the action of clicking on a map to
-                ask for information about the map features in that location.
-                Don't confuse "map queries" with the SQL query in a
-                <tt class="varname">DATA</tt> definition.</p></div></dd><dt><span class="term">USING SRID=&lt;srid&gt;</span></dt><dd><p>PostGIS needs to know which spatial referencing system is
-              being used by the geometries in order to return the correct data
-              back to mapserver. Normally it is possible to find this
-              information in the "geometry_columns" table in the PostGIS
-              database, however, this is not possible for tables which are
-              created on the fly such as subselects and views. So the
-              <tt class="varname">USING SRID=</tt> option allows the correct SRID to
-              be specified in the <tt class="varname">DATA</tt> definition.</p></dd></dl></div><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>The parser for Mapserver PostGIS layers is fairly primitive,
-          and is case sensitive in a few areas. Be careful to ensure that all
-          SQL keywords and all your <tt class="varname">USING</tt> clauses are in
-          upper case, and that your <tt class="varname">USING UNIQUE</tt> clause
-          precedes your <tt class="varname">USING SRID</tt> clause.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2453149"></a>4.7.4. Examples</h3></div></div><div></div></div><p>Lets start with a simple example and work our way up. Consider
-        the following Mapserver layer definition:</p><pre class="programlisting">LAYER
- CONNECTIONTYPE postgis
- NAME "roads"
- CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
- DATA "the_geom FROM roads"
- STATUS ON
- TYPE LINE
- CLASS
-  COLOR 0 0 0
- END
-END</pre><p>This layer will display all the road geometries in the roads
-        table as black lines.</p><p>Now lets say we want to show only the highways until we get
-        zoomed in to at least a 1:100000 scale - the next two layers will
-        acheive this effect:</p><pre class="programlisting">LAYER
- CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
- DATA "the_geom FROM roads"
- MINSCALE 100000
- STATUS ON
- TYPE LINE
- FILTER "road_type = 'highway'"
- CLASS
-  COLOR 0 0 0
- END
-END
-
-LAYER
- CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
- DATA "the_geom FROM roads"
- MAXSCALE 100000
- STATUS ON
- TYPE LINE
- CLASSITEM road_type
- CLASS
-  EXPRESSION "highway"
-  SIZE 2
-  COLOR 255 0 0
- END
- CLASS
-  COLOR 0 0 0
- END
-END</pre><p>The first layer is used when the scale is greater than 1:100000,
-        and displays only the roads of type "highway" as black lines. The
-        <tt class="varname">FILTER</tt> option causes only roads of type "highway"
-        to be displayed.</p><p>The second layer is used when the scale is less than 1:100000,
-        and will display highways as double-thick red lines, and other roads
-        as regular black lines.</p><p>So, we have done a couple of interesting things using only
-        mapserver functionality, but our <tt class="varname">DATA</tt> SQL statement
-        has remained simple. Suppose that the name of the road is stored in
-        another table (for whatever reason) and we need to do a join to get it
-        and label our roads.</p><pre class="programlisting">LAYER
- CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
- DATA "the_geom FROM (SELECT roads.oid AS oid, roads.the_geom AS the_geom, road_names.name as name
-   FROM roads LEFT JOIN road_names ON roads.road_name_id = road_names.road_name_id) AS named_roads
-   USING UNIQUE oid USING SRID=-1"
- MAXSCALE 20000
- STATUS ON
- TYPE ANNOTATION
- LABELITEM name
- CLASS
-  LABEL
-   ANGLE auto
-   SIZE 8
-   COLOR 0 192 0
-   TYPE truetype
-   FONT arial
-  END
- END
-END</pre><p>This annotation layer adds green labels to all the roads when
-        the scale gets down to 1:20000 or less. It also demonstrates how to
-        use an SQL join in a <tt class="varname">DATA</tt> definition.</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2453247"></a>4.8. Java Clients (JDBC)</h2></div></div><div></div></div><p>Java clients can access PostGIS "geometry" objects in the
-      PostgreSQL database either directly as text representations or using the
-      JDBC extension objects bundled with PostGIS. In order to use the
-      extension objects, the "postgis.jar" file must be in your CLASSPATH
-      along with the "postgresql.jar" JDBC driver package.</p><pre class="programlisting">import java.sql.*; 
-import java.util.*; 
-import java.lang.*; 
-import org.postgis.*; 
-
-public class JavaGIS { 
-  public static void main(String[] args) 
-  { 
-    java.sql.Connection conn; 
-    try 
-    { 
-      /* 
-      * Load the JDBC driver and establish a connection. 
-      */  
-      Class.forName("org.postgresql.Driver"); 
-      String url = "jdbc:postgresql://localhost:5432/database"; 
-      conn = DriverManager.getConnection(url, "postgres", ""); 
-    
-      /* 
-      * Add the geometry types to the connection. Note that you 
-      * must cast the connection to the pgsql-specific connection * implementation before calling the addDataType() method. 
-      */
-      ((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
-      ((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
-
-      /* 
-      * Create a statement and execute a select query. 
-      */ 
-      Statement s = conn.createStatement(); 
-      ResultSet r = s.executeQuery("select AsText(geom) as geom,id from geomtable"); 
-      while( r.next() ) 
-      { 
-        /* 
-        * Retrieve the geometry as an object then cast it to the geometry type. 
-        * Print things out. 
-        */ 
-        PGgeometry geom = (PGgeometry)r.getObject(1); 
-        int id = r.getInt(2);
-        System.out.println("Row " + id + ":"); 
-        System.out.println(geom.toString()); 
-      }
-      s.close(); 
-      conn.close(); 
-    } 
-    catch( Exception e ) 
-    { 
-      e.printStackTrace(); 
-    }  
-  }
-}</pre><p>The "PGgeometry" object is a wrapper object which contains a
-      specific topological geometry object (subclasses of the abstract class
-      "Geometry") depending on the type: Point, LineString, Polygon,
-      MultiPoint, MultiLineString, MultiPolygon.</p><pre class="programlisting">PGgeometry geom = (PGgeometry)r.getObject(1); 
-if( geom.getType() = Geometry.POLYGON ) 
-{ 
-  Polygon pl = (Polygon)geom.getGeometry();
-  for( int r = 0; r &lt; pl.numRings(); r++ ) 
-  { 
-    LinearRing rng = pl.getRing(r);
-    System.out.println("Ring: " + r); 
-    for( int p = 0; p &lt; rng.numPoints(); p++ ) 
-    { 
-      Point pt = rng.getPoint(p); 
-      System.out.println("Point: " + p);
-      System.out.println(pt.toString()); 
-    } 
-  } 
-}</pre><p>The JavaDoc for the extension objects provides a reference for the
-      various data accessor functions in the geometric objects.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2525835"></a>4.9. C Clients (libpq)</h2></div></div><div></div></div><p>...</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2525844"></a>4.9.1. Text Cursors</h3></div></div><div></div></div><p>...</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2525854"></a>4.9.2. Binary Cursors</h3></div></div><div></div></div><p>...</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 3. Frequently Asked Questions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 5. Performance tips</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch05.html
===================================================================
--- packages/postgis/upstream/doc/html/ch05.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch05.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,111 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 5. Performance tips</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch04.html" title="Chapter 4. Using PostGIS"><link rel="next" href="ch06.html" title="Chapter 6. PostGIS Reference"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 5. Performance tips</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch06.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2525866"></a>Chapter 5. Performance tips</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch05.html#id2525872">5.1. Small tables of large geometries</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch05.html#id2525878">5.1.1. Problem description</a></span></dt><dt><span class="sect2"><a href="ch05.html#id2525930">5.1.2. Workarounds</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch05.html#id2525990">5.2. CLUSTERing on geometry indices</a></span></dt><dt><span class="sect1"><a href="ch05.html#id2526046">5.3. Avoiding dimension conversion</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2525872"></a>5.1. Small tables of large geometries</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2525878"></a>5.1.1. Problem description</h3></div></div><div></div></div><p>
-Current PostgreSQL versions (including 8.0) suffer from a query
-optimizer weakness regarding TOAST tables. TOAST tables are a kind of
-"extension room" used to store large (in the sense of data size) values
-that do not fit into normal data pages (like long texts, images or
-complex geometries with lots of vertices), see
-http://www.postgresql.org/docs/8.0/static/storage-toast.html for more
-information).
-</p><p>
-The problem appears if you happen to have a table with rather large
-geometries, but not too much rows of them (like a table containing the
-boundaries of all european countries in high resolution). Then the table
-itsself is small, but it uses lots of TOAST space. In our example case,
-the table itsself had about 80 rows and used only 3 data pages, but the
-TOAST table used 8225 pages.
-</p><p>
-Now issue a query where you use the geometry operator &amp;&amp; to search for a
-bounding box that matches only very few of those rows. Now the query
-optimizer sees that the table has only 3 pages and 80 rows. He estimates
-that a sequential scan on such a small table is much faster than using
-an index. And so he decides to ignore the GIST index. Usually, this
-estimation is correct. But in our case, the &amp;&amp; operator has to fetch
-every geometry from disk to compare the bounding boxes, thus reading all
-TOAST pages, too.
-</p><p>
-To see whether your suffer from this bug, use the "EXPLAIN ANALYZE"
-postgresql command. For more information and the technical details, you
-can read the thread on the postgres performance mailing list:
-http://archives.postgresql.org/pgsql-performance/2005-02/msg00030.php
-</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2525930"></a>5.1.2. Workarounds</h3></div></div><div></div></div><p>
-The PostgreSQL people are trying to solve this issue by making the query
-estimation TOAST-aware. For now, here are two workarounds:
-</p><p>
-The first workaround is to force the query planner to use the index.
-Send "SET enable_seqscan TO off;" to the server before issuing the
-query. This basically forces the query planner to avoid sequential scans
-whenever possible. So it uses the GIST index as usual. But this flag has
-to be set on every connection, and it causes the query planner to make
-misestimations in other cases, so you should "SET enable_seqscan TO on;"
-after the query.
-</p><p>
-The second workaround is to make the sequential scan as fast as the
-query planner thinks. This can be achieved by creating an additional
-column that "caches" the bbox, and matching against this. In our
-example, the commands are like:
-</p><pre class="programlisting">
-SELECT addGeometryColumn('myschema','mytable','bbox','4326','GEOMETRY','2');
-
-UPDATE mytable set bbox = Envelope(Force_2d(the_geom));
-</pre><p>
-Now change your query to use the &amp;&amp; operator against bbox instead of
-geom_column, like:
-</p><pre class="programlisting">
-SELECT geom_column FROM mytable WHERE bbox &amp;&amp; SetSrid('BOX3D(0 0,1 1)'::box3d,4326);
-</pre><p>
-Of yourse, if you change or add rows to mytable, you have to keep the
-bbox "in sync". The most transparent way to do this would be triggers,
-but you also can modify your application to keep the bbox column current
-or run the UPDATE query above after every modification.
-</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2525990"></a>5.2. CLUSTERing on geometry indices</h2></div></div><div></div></div><p>
-For tables that are mostly read-only, and where a single index is used for the
-majority of queries, PostgreSQL offers the CLUSTER command. This command 
-physically reorders all the data rows in the same order as the index criteria,
-yielding two performance advantages: First, for index range scans, the number of 
-seeks on the data table is drastically reduced. Second, if your working set
-concentrates to some small intervals on the indices, you have a more efficient
-caching because the data rows are spread along fewer data pages. (Feel invited
-to read the CLUSTER command documentation from the PostgreSQL manual at this
-point.)
-</p><p>
-However, currently PostgreSQL does not allow clustering on PostGIS GIST indices
-because GIST indices simply ignores NULL values, you get an error message like:
-</p><pre class="programlisting">
-lwgeom=# CLUSTER my_geom_index ON my_table;
-ERROR:  cannot cluster when index access method does not handle null values
-HINT:  You may be able to work around this by marking column "the_geom" NOT NULL.
-</pre><p>
-As the HINT message tells you, one can work around this deficiency by adding a
-"not null" constraint to the table:
-</p><pre class="programlisting">
-lwgeom=# ALTER TABLE my_table ALTER COLUMN the_geom SET not null;
-ALTER TABLE
-</pre><p>
-Of course, this will not work if you in fact need NULL values in your geometry
-column. Additionally, you must use the above method to add the constraint, using
-a CHECK constraint like "ALTER TABLE blubb ADD CHECK (geometry is not null);" will
-not work.
-</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2526046"></a>5.3. Avoiding dimension conversion</h2></div></div><div></div></div><p>
-Sometimes, you happen to have 3D or 4D data in your table, but always access
-it using OpenGIS compliant asText() or asBinary() functions that only output
-2D geometries. They do this by internally calling the force_2d() function,
-which introduces a significant overhead for large geometries. To avoid this
-overhead, it may be feasible to pre-drop those additional dimensions once and
-forever:
-</p><pre class="programlisting">
-UPDATE mytable SET the_geom = force_2d(the_geom);
-VACUUM FULL ANALYZE mytable;
-</pre><p>
-Note that if you added your geometry column using AddGeometryColumn()
-there'll be a constraint on geometry dimension.
-To bypass it you will need to drop the constraint.
-Remember to update the entry in the geometry_columns table and
-recreate the constraint afterwards.
-</p><p>
-In case of large tables, it may be wise to divide this UPDATE into smaller portions
-by constraining the UPDATE to a part of the table via a WHERE clause and your
-primary key or another feasible criteria, and running a simple "VACUUM;" between
-your UPDATEs. This drastically reduces the need for temporary disk space.
-Additionally, if you have mixed dimension geometries, restricting the UPDATE by "WHERE 
-dimension(the_geom)&gt;2" skips re-writing of geometries that already are in 2D. 
-</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. Using PostGIS </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 6. PostGIS Reference</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch06.html
===================================================================
--- packages/postgis/upstream/doc/html/ch06.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch06.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,599 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 6. PostGIS Reference</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch05.html" title="Chapter 5. Performance tips"><link rel="next" href="ch07.html" title="Chapter 7. Reporting Bugs"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 6. PostGIS Reference</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch07.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2526096"></a>Chapter 6. PostGIS Reference</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch06.html#id2526109">6.1. OpenGIS Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch06.html#id2526115">6.1.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2526205">6.1.2. Geometry Relationship Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2526581">6.1.3. Geometry Processing Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2526907">6.1.4. Geometry Accessors</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2527394">6.1.5. Geometry Constructors</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch06.html#id2527996">6.2. Postgis Extensions</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch06.html#id2528002">6.2.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528326">6.2.2. Operators</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528534">6.2.3. Measurement Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528817">6.2.4. Geometry Outputs</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528926">6.2.5. Geometry Constructors</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2529258">6.2.6. Geometry Editors</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2529854">6.2.7. Linear Referencing</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2530074">6.2.8. Misc</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2531072">6.2.9. Long Transactions support</a></span></dt></dl></dd></dl></div><p>The functions given below are the ones which a user of PostGIS is
-    likely to need. There are other functions which are required support
-    functions to the PostGIS objects which are not of use to a general
-    user.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2526109"></a>6.1. OpenGIS Functions</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2526115"></a>6.1.1. Management Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><a name="AddGeometryColumn"></a><span class="term">AddGeometryColumn(varchar, varchar, varchar, integer,
-            varchar, integer)</span></dt><dd><p>Syntax: AddGeometryColumn(&lt;schema_name&gt;,
-              &lt;table_name&gt;, &lt;column_name&gt;, &lt;srid&gt;,
-              &lt;type&gt;, &lt;dimension&gt;). Adds a geometry column to an
-              existing table of attributes. The <tt class="varname">schema_name</tt>
-              is the name of the table schema (unused for pre-schema
-              PostgreSQL installations). The <tt class="varname">srid</tt> must be
-              an integer value reference to an entry in the SPATIAL_REF_SYS
-              table. The <tt class="varname">type</tt> must be an uppercase string
-              corresponding to the geometry type, eg, 'POLYGON' or
-              'MULTILINESTRING'.</p></dd><dt><span class="term">DropGeometryColumn(varchar, varchar, varchar)</span></dt><dd><p>Syntax: DropGeometryColumn(&lt;schema_name&gt;,
-              &lt;table_name&gt;, &lt;column_name&gt;). Remove a geometry
-              column from a spatial table. Note that schema_name will need to
-              match the f_schema_name field of the table's row in the
-              geometry_columns table.</p></dd><dt><span class="term">SetSRID(geometry, integer)</span></dt><dd><p>Set the SRID on a geometry to a particular integer value.
-              Useful in constructing bounding boxes for queries.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2526205"></a>6.1.2. Geometry Relationship Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Distance(geometry, geometry)</span></dt><dd><p>Return the cartesian distance between two geometries in
-              projected units.</p></dd><dt><span class="term">Equals(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the given Geometries are
-	      "spatially equal". Use this for a 'better' answer than '='.
-	      equals('LINESTRING(0 0, 10 10)','LINESTRING(0 0, 5 5, 10 10)')
-	      is true.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.2</p></dd><dt><span class="term">Disjoint(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries are "spatially disjoint".
-	      </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 //s2.1.13.3 - a.Relate(b,
-              'FF*FF****')</p></dd><dt><span class="term">Intersects(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially intersect".
-              </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 //s2.1.13.3 - Intersects(g1, g2 ) --&gt;
-              Not (Disjoint(g1, g2 ))</p></dd><dt><span class="term">Touches(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially touch".
-              </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3- a.Touches(b) -&gt; (I(a)
-              intersection I(b) = {empty set} ) and (a intersection b) not
-              empty</p></dd><dt><span class="term">Crosses(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially cross".
-              </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - a.Relate(b,
-              'T*T******')</p></dd><dt><span class="term">Within(geometry A, geometry B)</span></dt><dd><p>Returns 1 (TRUE) if Geometry A is "spatially within"
-              Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - a.Relate(b,
-              'T*F**F***')</p></dd><dt><span class="term">Overlaps(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially
-              overlap".</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3</p></dd><dt><span class="term">Contains(geometry A, geometry B)</span></dt><dd><p>Returns 1 (TRUE) if Geometry A "spatially contains"
-              Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - same as
-              within(geometry B, geometry A)</p></dd><dt><span class="term">Intersects(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially
-              intersect".</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - NOT
-              disjoint(geometry, geometry)</p></dd><dt><span class="term">Relate(geometry, geometry, intersectionPatternMatrix)</span></dt><dd><p>Returns 1 (TRUE) if this Geometry is spatially related to
-              anotherGeometry, by testing for intersections between the
-              Interior, Boundary and Exterior of the two geometries as
-              specified by the values in the intersectionPatternMatrix.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is the "allowable" version that returns a
-              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3</p></dd><dt><span class="term">Relate(geometry, geometry)</span></dt><dd><p>returns the DE-9IM (dimensionally extended
-              nine-intersection matrix)</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>not in OGC spec, but implied. see s2.1.13.2</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2526581"></a>6.1.3. Geometry Processing Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Centroid(geometry)</span></dt><dd><p>Returns the centroid of the geometry as a point.</p><p>Computation will be more accurate if performed by the GEOS
-              module (enabled at compile time).</p></dd><dt><span class="term">Area(geometry)</span></dt><dd><p>Returns the area of the geometry if it is a polygon or
-              multi-polygon. </p></dd><dt><span class="term">Length(geometry)</span></dt><dd><p>The length of this Curve in its associated spatial
-              reference.</p><p>synonym for length2d()</p><p>OGC SPEC 2.1.5.1</p></dd><dt><span class="term">PointOnSurface(geometry)</span></dt><dd><p>Return a Point guaranteed to lie on the surface</p><p>Implemented using GEOS</p><p>OGC SPEC 3.2.14.2 and 3.2.18.2 -</p></dd><dt><span class="term">Boundary(geometry)</span></dt><dd><p>Returns the closure of the combinatorial boundary of this
-              Geometry. The combinatorial boundary is defined as described in
-              section 3.12.3.2 of the OGC SPEC. Because the result of this
-              function is a closure, and hence topologically closed, the
-              resulting boundary can be represented using representational
-              geometry primitives as discussed in the OGC SPEC, section
-              3.12.2.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.1</p></dd><dt><span class="term">Buffer(geometry, double, [integer])</span></dt><dd><p>Returns a geometry that represents all points whose
-              distance from this Geometry is less than or equal to distance.
-              Calculations are in the Spatial Reference System of this
-              Geometry. The optional third parameter sets the
-	      number of segment used to approximate a quarter circle
-	      (defaults to 8).</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">ConvexHull(geometry)</span></dt><dd><p>Returns a geometry that represents the convex hull of this
-              Geometry.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">Intersection(geometry, geometry)</span></dt><dd><p>Returns a geometry that represents the point set
-              intersection of the Geometies.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">SymDifference(geometry A, geometry B)</span></dt><dd><p>Returns a geometry that represents the point set symmetric
-              difference of Geometry A with Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">Difference(geometry A, geometry B)</span></dt><dd><p>Returns a geometry that represents the point set symmetric
-              difference of Geometry A with Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">GeomUnion(geometry, geometry)</span></dt><dd><p>Returns a geometry that represents the point set union of
-              the Geometries.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
-              argument</p><p>NOTE: this is renamed from "union" because union is an SQL
-              reserved word</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">GeomUnion(geometry set)</span></dt><dd><p>Returns a geometry that represents the point set union of
-              this all Geometries in given set.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection in the argument
-              set</p><p>Not explicitly defined in OGC SPEC</p></dd><dt><span class="term">MemGeomUnion(geometry set)</span></dt><dd><p>Same as the above, only memory-friendly (uses less memory
-              and more processor time).</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2526907"></a>6.1.4. Geometry Accessors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">AsText(geometry)</span></dt><dd><p>Return the Well-Known Text representation of the geometry.
-              For example: POLYGON(0 0,0 1,1 1,1 0,0 0)</p><p>OGC SPEC s2.1.1.1</p></dd><dt><span class="term">AsBinary(geometry)</span></dt><dd><p>Returns the geometry in the OGC "well-known-binary"
-              format, using the endian encoding of the server on which the
-              database is running. This is useful in binary cursors to pull
-              data out of the database without converting it to a string
-              representation.</p><p>OGC SPEC s2.1.1.1 - also see
-              asBinary(&lt;geometry&gt;,'XDR') and
-              asBinary(&lt;geometry&gt;,'NDR')</p></dd><dt><span class="term">SRID(geometry)</span></dt><dd><p>Returns the integer SRID number of the spatial reference
-              system of the geometry.</p><p>OGC SPEC s2.1.1.1</p></dd><dt><span class="term">Dimension(geometry)</span></dt><dd><p>The inherent dimension of this Geometry object, which must
-              be less than or equal to the coordinate dimension. OGC SPEC
-              s2.1.1.1 - returns 0 for points, 1 for lines, 2 for polygons,
-              and the largest dimension of the components of a
-              GEOMETRYCOLLECTION.</p><pre class="programlisting">select dimension('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0)'); 
-dimension 
------------
-1</pre></dd><dt><span class="term">Envelope(geometry)</span></dt><dd><p>Returns a POLYGON representing the bounding box of the
-              geometry.</p><p>OGC SPEC s2.1.1.1 - The minimum bounding box for this
-              Geometry, returned as a Geometry. The polygon is defined by the
-              corner points of the bounding box ((MINX, MINY), (MAXX, MINY),
-              (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)).</p><p>NOTE:PostGIS will add a Zmin/Zmax coordinate as
-              well.</p></dd><dt><span class="term">IsEmpty(geometry)</span></dt><dd><p>Returns 1 (TRUE) if this Geometry is the empty geometry .
-              If true, then this Geometry represents the empty point set -
-              i.e. GEOMETRYCOLLECTION(EMPTY).</p><p>OGC SPEC s2.1.1.1</p></dd><dt><a name="IsSimple"></a><span class="term">IsSimple(geometry)</span></dt><dd><p>Returns 1 (TRUE) if this Geometry has no anomalous
-              geometric points, such as self intersection or self
-              tangency.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.1</p></dd><dt><a name="IsClosed"></a><span class="term">IsClosed(geometry)</span></dt><dd><p>Returns true of the geometry start and end points are
-              coincident.</p></dd><dt><span class="term">IsRing(geometry)</span></dt><dd><p>Returns 1 (TRUE) if this Curve is closed (StartPoint ( ) =
-              EndPoint ( )) and this Curve is simple (does not pass through
-              the same point more than once).</p><p>performed by GEOS</p><p>OGC spec 2.1.5.1</p></dd><dt><span class="term">NumGeometries(geometry)</span></dt><dd><p>If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the
-              number of geometries, otherwise return NULL.</p></dd><dt><span class="term">GeometryN(geometry,int)</span></dt><dd><p>Return the N'th geometry if the geometry is a
-              GEOMETRYCOLLECTION, MULTIPOINT, MULTILINESTRING or MULTIPOLYGON.
-              Otherwise, return NULL.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-		Index is 1-based as for OGC specs since version 0.8.0.
-		Previous versions implemented this as 0-based instead.
-		</p></div></dd><dt><span class="term">NumPoints(geometry)</span></dt><dd><p>Find and return the number of points in the first
-              linestring in the geometry. Return NULL if there is no
-              linestring in the geometry.</p></dd><dt><span class="term">PointN(geometry,integer)</span></dt><dd><p>Return the N'th point in the first linestring in the
-              geometry. Return NULL if there is no linestring in the
-              geometry.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-		Index is 1-based as for OGC specs since version 0.8.0.
-		Previous versions implemented this as 0-based instead.
-		</p></div></dd><dt><span class="term">ExteriorRing(geometry)</span></dt><dd><p>Return the exterior ring of the polygon geometry.
-	      Return NULL if the geometry is not a polygon.</p></dd><dt><span class="term">NumInteriorRings(geometry)</span></dt><dd><p>Return the number of interior rings of the first polygon
-              in the geometry. Return NULL if there is no polygon in the
-              geometry.</p></dd><dt><span class="term">NumInteriorRing(geometry)</span></dt><dd><p>Synonym to NumInteriorRings(geometry). The OpenGIS specs
-	      are ambigous about the exact function naming, so we provide
-	      both spellings.</p></dd><dt><span class="term">InteriorRingN(geometry,integer)</span></dt><dd><p>Return the N'th interior ring of the polygon geometry.
-	      Return NULL if the geometry is not a polygon or the given
-	      N is out of range.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-		Index is 1-based as for OGC specs since version 0.8.0.
-		Previous versions implemented this as 0-based instead.
-		</p></div></dd><dt><span class="term">EndPoint(geometry)</span></dt><dd><p>Returns the last point of the LineString geometry as a point.</p></dd><dt><a name="StartPoint"></a><span class="term">StartPoint(geometry)</span></dt><dd><p>Returns the first point of the LineString geometry as a point.</p></dd><dt><a name="GeometryType"></a><span class="term">GeometryType(geometry)</span></dt><dd><p>Returns the type of the geometry as a string. Eg:
-              'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.</p><p>OGC SPEC s2.1.1.1 - Returns the name of the instantiable
-              subtype of Geometry of which this Geometry instance is a member.
-              The name of the instantiable subtype of Geometry is returned as
-              a string.</p></dd><dt><span class="term">X(geometry)</span></dt><dd><p>Return the X coordinate of the point.
-	      Input must be a point.</p></dd><dt><span class="term">Y(geometry)</span></dt><dd><p>Return the Y coordinate of the point.
-	      Input must be a point.</p></dd><dt><span class="term">Z(geometry)</span></dt><dd><p>Return the Z coordinate of the point,
-	      or NULL if not available.
-	      Input must be a point.</p></dd><dt><span class="term">M(geometry)</span></dt><dd><p>Return the M coordinate of the point, 
-	      or NULL if not available.
-	      Input must be a point.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This is not (yet) part of the OGC spec,
-		but is listed here to complete the point coordinate
-	        extractor function list.</p></div></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2527394"></a>6.1.5. Geometry Constructors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">GeomFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p></dd><dt><span class="term">PointFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a Point</p></dd><dt><span class="term">LineFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a Line</p></dd><dt><span class="term">LinestringFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>from the conformance suite</p><p>Throws an error if the WKT is not a Line</p></dd><dt><span class="term">PolyFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a Polygon</p></dd><dt><span class="term">PolygonFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>from the conformance suite</p><p>Throws an error if the WKT is not a Polygon</p></dd><dt><span class="term">MPointFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a MULTIPOINT</p></dd><dt><span class="term">MLineFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a MULTILINESTRING</p></dd><dt><span class="term">MPolyFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a MULTIPOLYGON</p></dd><dt><span class="term">GeomCollFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p><p>Throws an error if the WKT is not a
-              GEOMETRYCOLLECTION</p></dd><dt><span class="term">GeomFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
-              suite</p></dd><dt><span class="term">GeomFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p></dd><dt><span class="term">PointFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a POINT</p></dd><dt><span class="term">LineFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a LINESTRING</p></dd><dt><span class="term">LinestringFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>from the conformance suite</p><p>throws an error if WKB is not a LINESTRING</p></dd><dt><span class="term">PolyFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a POLYGON</p></dd><dt><span class="term">PolygonFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>from the conformance suite</p><p>throws an error if WKB is not a POLYGON</p></dd><dt><span class="term">MPointFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a MULTIPOINT</p></dd><dt><span class="term">MLineFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a MULTILINESTRING</p></dd><dt><span class="term">MPolyFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a MULTIPOLYGON</p></dd><dt><span class="term">GeomCollFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
-              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
-              suite</p><p>throws an error if WKB is not a GEOMETRYCOLLECTION</p></dd><dt><a name="BdPolyFromText"></a><span class="term">BdPolyFromText(text WKT, integer SRID)</span></dt><dd><p>
-		Construct a Polygon given an arbitrary
-		collection of closed linestrings as a
-		MultiLineString text representation.
-		</p><p>
-	      Throws an error if WKT is not a MULTILINESTRING.
-	      Throws an error if output is a MULTIPOLYGON; use <a href="ch06.html#BdMPolyFromText">BdMPolyFromText</a> in
-	      that case, or see 
-		<a href="ch06.html#BuildArea">BuildArea()</a>
-		for a postgis-specific approach.
-		</p><p>OGC SFSQL 1.1 - 3.2.6.2</p><p>
-		    Availability: 1.1.0 - requires GEOS &gt;= 2.1.0.
-		</p></dd><dt><a name="BdMPolyFromText"></a><span class="term">BdMPolyFromText(text WKT, integer SRID)</span></dt><dd><p>
-		Construct a MultiPolygon given an arbitrary
-		collection of closed linestrings as a
-		MultiLineString text representation.
-		</p><p>
-                Throws an error if WKT is not a MULTILINESTRING.
-		Forces MULTIPOLYGON output even when result is really
-		only composed by a single POLYGON; use <a href="ch06.html#BdPolyFromText">BdPolyFromText</a> if you're sure
-		a single POLYGON will result from
-		operation, or see
-		<a href="ch06.html#BuildArea">BuildArea()</a>
-		for a postgis-specific approach.
-		</p><p>OGC SFSQL 1.1 - 3.2.6.2</p><p>
-		    Availability: 1.1.0 - requires GEOS &gt;= 2.1.0.
-		</p></dd></dl></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2527996"></a>6.2. Postgis Extensions</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2528002"></a>6.2.1. Management Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">DropGeometryTable([&lt;schema_name&gt;],
-		  &lt;table_name&gt;)</span></dt><dd><p>Drops a table and all its references in geometry_columns.
-		    Note: uses current_schema() on schema-aware pgsql installations if
-		    schema is not provided.</p></dd><dt><span class="term">UpdateGeometrySRID([&lt;schema_name&gt;],
-		  &lt;table_name&gt;, &lt;column_name&gt;, &lt;srid&gt;)</span></dt><dd><p>Update the SRID of all features in a geometry column updating constraints and reference in geometry_columns.
-		    Note: uses current_schema() on schema-aware pgsql installations if schema is not provided.</p></dd><dt><span class="term">update_geometry_stats([&lt;table_name&gt;,
-		  &lt;column_name&gt;])</span></dt><dd><p>Update statistics about spatial tables for use by the query
-		    planner. You will also need to run "VACUUM ANALYZE [table_name]
-		    [column_name]" for the statistics gathering process to be
-		    complete. NOTE: starting with PostgreSQL 8.0 statistics gathering
-		    is automatically performed running "VACUUM ANALYZE".</p></dd><dt><span class="term">postgis_version()</span></dt><dd><p>Returns PostGIS version number and compile-time options</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-		Prior to version 1.1.0 this was a procedural function, thus possibly
-		returning inaccurate information (in case of incomplete database upgrades).
-		</p></div></dd><dt><a name="postgis_lib_version"></a><span class="term">postgis_lib_version()</span></dt><dd><p>Returns the version number of the PostGIS library.</p><p>
-	Availability: 0.9.0
-		</p></dd><dt><span class="term">postgis_lib_build_date()</span></dt><dd><p>Returns build date of the PostGIS library.</p><p>
-	Availability: 1.0.0RC1
-		</p></dd><dt><span class="term">postgis_script_build_date()</span></dt><dd><p>Returns build date of the PostGIS scripts.</p><p>
-	Availability: 1.0.0RC1
-		</p></dd><dt><span class="term">postgis_scripts_installed()</span></dt><dd><p>
-		Returns version of the postgis scripts
-		installed in this database.
-		</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-		If the output of this function doesn't match the output of
-		<a href="ch06.html#postgis_scripts_released">postgis_scripts_released()</a>
-		you probably missed to properly upgrade an existing database.
-		See the <a href="ch02.html#upgrading" title="2.2.1. Upgrading">Upgrading</a> section for more info.
-		</p></div><p>
-	Availability: 0.9.0
-		</p></dd><dt><a name="postgis_scripts_released"></a><span class="term">postgis_scripts_released()</span></dt><dd><p>Returns the version number of the lwpostgis.sql script
-            released with the installed postgis lib.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-		Starting with version 1.1.0 this function returns the same
-		value of <a href="ch06.html#postgis_lib_version">postgis_lib_version()</a>.
-		Kept for backward compatibility.
-		</p></div><p>
-	Availability: 0.9.0 
-		</p></dd><dt><span class="term">postgis_geos_version()</span></dt><dd><p>Returns the version number of the GEOS library, or NULL if
-            GEOS support is not enabled.</p><p>
-	Availability: 0.9.0
-		</p></dd><dt><span class="term">postgis_jts_version()</span></dt><dd><p>Returns the version number of the JTS library, or NULL if
-            JTS support is not enabled.</p><p>
-	Availability: 1.1.0
-		</p></dd><dt><span class="term">postgis_proj_version()</span></dt><dd><p>Returns the version number of the PROJ4 library, or NULL if
-            PROJ4 support is not enabled.</p><p>
-	Availability: 0.9.0
-		</p></dd><dt><span class="term">postgis_uses_stats()</span></dt><dd><p>Returns true if STATS usage has been enabled, false
-            otherwise.</p><p>
-	Availability: 0.9.0
-		</p></dd><dt><a name="postgis_full_version"></a><span class="term">postgis_full_version()</span></dt><dd><p>Reports full postgis version and build configuration
-            infos.</p><p>Availability: 0.9.0</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2528326"></a>6.2.2. Operators</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">A &amp;&lt; B</span></dt><dd><p>The "&amp;&lt;" operator returns true if A's bounding box
-		    overlaps or is to the left of B's bounding box.</p></dd><dt><span class="term">A &amp;&gt; B</span></dt><dd><p>The "&amp;&gt;" operator returns true if A's bounding box
-		    overlaps or is to the right of B's bounding box.</p></dd><dt><span class="term">A &lt;&lt; B</span></dt><dd><p>The "&lt;&lt;" operator returns true if A's bounding box is
-		    strictly to the left of B's bounding box.</p></dd><dt><span class="term">A &gt;&gt; B</span></dt><dd><p>The "&gt;&gt;" operator returns true if A's bounding box is
-		    strictly to the right of B's bounding box.</p></dd><dt><span class="term">A &amp;&lt;| B</span></dt><dd><p>The "&amp;&lt;|" operator returns true if A's bounding box
-		    overlaps or is below B's bounding box.</p></dd><dt><span class="term">A |&amp;&gt; B</span></dt><dd><p>The "|&amp;&gt;" operator returns true if A's bounding box
-		    overlaps or is above B's bounding box.</p></dd><dt><span class="term">A &lt;&lt;| B</span></dt><dd><p>The "&lt;&lt;|" operator returns true if A's bounding box is
-		    strictly below B's bounding box.</p></dd><dt><span class="term">A |&gt;&gt; B</span></dt><dd><p>The "|&gt;&gt;" operator returns true if A's bounding box is
-		    strictly above B's bounding box.</p></dd><dt><span class="term">A ~= B</span></dt><dd><p>The "~=" operator is the "same as" operator. It tests actual
-		    geometric equality of two features. So if A and B are the same
-		    feature, vertex-by-vertex, the operator returns true.</p></dd><dt><span class="term">A @ B</span></dt><dd><p>The "@" operator returns true if A's bounding box is
-		    completely contained by B's bounding box.</p></dd><dt><span class="term">A ~ B</span></dt><dd><p>The "~" operator returns true if A's bounding box completely
-		    contains B's bounding box.</p></dd><dt><span class="term">A &amp;&amp; B</span></dt><dd><p>The "&amp;&amp;" operator is the "overlaps" operator. If A's
-		    bounding boux overlaps B's bounding box the operator returns
-		    true.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2528534"></a>6.2.3. Measurement Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">area2d(geometry)</span></dt><dd><p>Returns the area of the geometry if it is a polygon or
-		    multi-polygon.</p></dd><dt><span class="term">distance_sphere(point, point)</span></dt><dd><p>Returns linear distance in meters between two lat/lon
-            points. Uses a spherical earth and radius of 6370986 meters.
-            Faster than <a href="ch06.html#distance_spheroid">distance_spheroid()</a>, but
-            less accurate.
-			Only implemented for points.</p></dd><dt><a name="distance_spheroid"></a><span class="term">distance_spheroid(point, point, spheroid)</span></dt><dd><p>Returns linear distance between two lat/lon points given a
-            particular spheroid. See the explanation of spheroids given for
-            <a href="ch06.html#length_spheroid">length_spheroid()</a>.
-            Currently only implemented for points.</p></dd><dt><a name="length2d"></a><span class="term">length2d(geometry)</span></dt><dd><p>Returns the 2-dimensional length of the geometry if it is a
-            linestring or multi-linestring.</p></dd><dt><span class="term">length3d(geometry)</span></dt><dd><p>Returns the 3-dimensional length of the geometry if it is a
-            linestring or multi-linestring.</p></dd><dt><a name="length_spheroid"></a><span class="term">length_spheroid(geometry,spheroid)</span></dt><dd><p>Calculates the length of of a geometry on an elipsoid. This
-            is useful if the coordinates of the geometry are in
-            latitude/longitude and a length is desired without reprojection.
-            The elipsoid is a separate database type and can be constructed as
-            follows:</p><div class="literallayout"><p>SPHEROID[&lt;NAME&gt;,&lt;SEMI-MAJOR AXIS&gt;,&lt;INVERSE FLATTENING&gt;]</p></div><p>Eg:</p><div class="literallayout"><p>SPHEROID["GRS_1980",6378137,298.257222101]</p></div><p>An example calculation might look like this:</p><div class="literallayout"><p>SELECT<br>
- length_spheroid(<br>
-  geometry_column,<br>
-  'SPHEROID["GRS_1980",6378137,298.257222101]'<br>
- )<br>
-FROM geometry_table;</p></div></dd><dt><span class="term">length3d_spheroid(geometry,spheroid)</span></dt><dd><p>Calculates the length of of a geometry on an elipsoid,
-            taking the elevation into account. This is just like
-            length_spheroid except vertical coordinates (expressed in the same
-            units as the spheroid axes) are used to calculate the extra
-            distance vertical displacement adds.</p></dd><dt><span class="term">distance(geometry, geometry)</span></dt><dd><p>Returns the smaller distance between two geometries.</p></dd><dt><span class="term">max_distance(linestring,linestring)</span></dt><dd><p>Returns the largest distance between two line
-            strings.</p></dd><dt><span class="term">perimeter(geometry)</span></dt><dd><p>Returns the 2-dimensional perimeter of the geometry, if it
-            is a polygon or multi-polygon.</p></dd><dt><span class="term">perimeter2d(geometry)</span></dt><dd><p>Returns the 2-dimensional perimeter of the geometry, if it
-            is a polygon or multi-polygon.</p></dd><dt><span class="term">perimeter3d(geometry)</span></dt><dd><p>Returns the 3-dimensional perimeter of the geometry, if it
-            is a polygon or multi-polygon.</p></dd><dt><span class="term">azimuth(geometry, geometry)</span></dt><dd><p>
-	Returns the azimuth of the segment defined by the given Point
-	geometries, or NULL if the two points are coincident.
-	Return value is in radians.
-            </p><p>
-			Availability: 1.1.0
-		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2528817"></a>6.2.4. Geometry Outputs</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">AsBinary(geometry,{'NDR'|'XDR'})</span></dt><dd><p>Returns the geometry in the OGC "well-known-binary" format as a bytea, using little-endian (NDR) or big-endian (XDR) encoding. This is useful in binary cursors to pull data out of the database without converting it to a string representation.</p></dd><dt><span class="term">AsEWKT(geometry)</span></dt><dd><p>Returns a Geometry in EWKT format (as text).</p></dd><dt><span class="term">AsEWKB(geometry, {'NDR'|'XDR'})</span></dt><dd><p>Returns a Geometry in EWKB format (as bytea) using either little-endian (NDR) or big-endian (XDR) encoding.</p></dd><dt><span class="term">AsHEXEWKB(geometry, {'NDR'|'XDR'})</span></dt><dd><p>Returns a Geometry in HEXEWKB format (as text) using either little-endian (NDR) or big-endian (XDR) encoding.</p></dd><dt><span class="term">AsSVG(geometry, [rel], [precision])</span></dt><dd><p>Return the geometry as an SVG path data. Use 1 as second argument to have the path data implemented in terms of relative moves, the default (or 0) uses absolute moves. Third argument may be used to reduce the maximum number of decimal digits used in output (defaults to 15). Point geometries will be rendered as cx/cy when 'rel' arg is 0, x/y when 'rel' is 1.</p></dd><dt><span class="term">AsGML(geometry, [precision])</span></dt><dd><p>Return the geometry as a GML element.  Second argument may be used to reduce the maximum number of significant digits used in output (defaults to 15).</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2528926"></a>6.2.5. Geometry Constructors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">GeomFromEWKT(text)</span></dt><dd><p>Makes a Geometry from EWKT.</p></dd><dt><span class="term">GeomFromEWKB(bytea)</span></dt><dd><p>Makes a Geometry from EWKB.</p></dd><dt><span class="term">MakePoint(&lt;x&gt;, &lt;y&gt;, [&lt;z&gt;], [&lt;m&gt;])</span></dt><dd><p>Creates a 2d,3dz or 4d point geometry.</p></dd><dt><span class="term">MakePointM(&lt;x&gt;, &lt;y&gt;, &lt;m&gt;)</span></dt><dd><p>Creates a 3dm point geometry.</p></dd><dt><span class="term">MakeBox2D(&lt;LL&gt;, &lt;UR&gt;)</span></dt><dd><p>Creates a BOX2D defined by the given point geometries.</p></dd><dt><span class="term">MakeBox3D(&lt;LLB&gt;, &lt;URT&gt;)</span></dt><dd><p>Creates a BOX3D defined by the given point geometries.</p></dd><dt><span class="term">MakeLine(geometry set)</span></dt><dd><p>Creates a Linestring from a set of point geometries.
-		    You might want to use a subselect to order points before
-		    feeding them to this aggregate.</p></dd><dt><span class="term">MakeLine(geometry, geometry)</span></dt><dd><p>Creates a Linestring from the two given point
-		    geometries.</p></dd><dt><span class="term">LineFromMultiPoint(multipoint)</span></dt><dd><p>Creates a LineString from a MultiPoint geometry.</p></dd><dt><span class="term">MakePolygon(linestring, [linestring[]])</span></dt><dd><p>Creates a Polygon formed by the given 
-		    shell and array of holes. You can construct
-		    a geometry array using <a href="ch06.html#Accum">Accum</a>.
-		    Input geometries must be closed LINESTRINGS (see <a href="ch06.html#IsClosed">IsClosed</a> and <a href="ch06.html#GeometryType">GeometryType</a>).
-		    </p></dd><dt><a name="BuildArea"></a><span class="term">BuildArea(geometry)</span></dt><dd><p>Creates an areal geometry formed by the costituent
-		    linework of given geometry. The return type can
-		    be a Polygon or MultiPolygon, depending on input.
-		    If the input lineworks do not form polygons NULL is
-		    returned.
-		    </p><p>
-		    See also <a href="ch06.html#BdPolyFromText">BdPolyFromText</a> and <a href="ch06.html#BdMPolyFromText">BdMPolyFromText</a> - wrappers to this function with standard OGC interface.
-		    </p><p>
-		    Availability: 1.1.0 - requires GEOS &gt;= 2.1.0.
-		</p></dd><dt><span class="term">Polygonize(geometry set)</span></dt><dd><p>
-			Aggregate. Creates a GeometryCollection containing
-			possible polygons formed from the costituent linework
-			of a set of geometries.
-		</p><p>
-		    Availability: 1.0.0RC1 - requires GEOS &gt;= 2.1.0.
-		</p></dd><dt><span class="term">Collect(geometry set)</span></dt><dd><p>This function returns a GEOMETRYCOLLECTION or a MULTI object from a set
-		    of geometries. The collect() function is an "aggregate" function
-		    in the terminology of PostgreSQL. That means that it operators on
-		    lists of data, in the same way the sum() and mean() functions do.
-		    For example, "SELECT COLLECT(GEOM) FROM GEOMTABLE GROUP BY
-		    ATTRCOLUMN" will return a separate GEOMETRYCOLLECTION for each
-		    distinct value of ATTRCOLUMN.</p></dd><dt><span class="term">Collect(geometry, geometry)</span></dt><dd><p>This function returns a geometry being a collection
-		    of two input geometries. Output type can be a MULTI* or 
-		    a GEOMETRYCOLLECTION.</p></dd><dt><span class="term">Dump(geometry)</span></dt><dd><p>This is a set-returning function (SRF).
-		    It returns a set of geometry_dump rows, formed
-		    by a geometry (geom) and an array of integers (path).
-		    When the input geometry is a simple type
-		    (POINT,LINESTRING,POLYGON)
-		    a single record will be returned with an empty
-		    path array and the input geometry as geom.
-		    When the input geometry is a collection or multi
-		    it will return a record for each of the collection
-		    components, and the path will express the position
-		    of the component inside the collection.
-		    </p><p>
-		    Availability: PostGIS 1.0.0RC1.
-		    Requires PostgreSQL 7.3 or higher.
-		</p></dd><dt><span class="term">DumpRings(geometry)</span></dt><dd><p>This is a set-returning function (SRF).
-		    It returns a set of geometry_dump rows, formed
-		    by a geometry (geom) and an array of integers (path).
-		    The 'path' field holds the polygon ring index, contains
-		    a single element: 0 for the shell, hole number for holes.
-		    The 'geom' field contains the corresponding ring
-		    as a polygon.
-		    </p><p>
-		    Availability: PostGIS 1.1.3.
-		    Requires PostgreSQL 7.3 or higher.
-		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2529258"></a>6.2.6. Geometry Editors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><a name="addbbox"></a><span class="term">AddBBOX(geometry)</span></dt><dd><p>Add bounding box to the geometry. This would make bounding
-	    box based queries faster, but will increase the size of the
-	    geometry.</p></dd><dt><a name="dropbbox"></a><span class="term">DropBBOX(geometry)</span></dt><dd><p>Drop the bounding box cache from the geometry.
-	    This reduces geometry size, but makes bounding-box based
-	    queries slower.</p></dd><dt><span class="term">AddPoint(linestring, point, [&lt;position&gt;])</span></dt><dd><p>Adds a point to a LineString before point &lt;pos&gt;
-	    (0-based index).
-	    Third parameter can be omitted or set to -1 for appending.
-	    </p></dd><dt><span class="term">RemovePoint(linestring, offset)</span></dt><dd><p>
-			Removes point from a linestring. Offset is 0-based.
-		</p><p>
-			Availability: 1.1.0
-		</p></dd><dt><span class="term">SetPoint(linestring, N, point)</span></dt><dd><p>
-			Replace point N of linestring with given point.
-			Index is 0-based.
-		</p><p>
-			Availability: 1.1.0
-		</p></dd><dt><span class="term">Force_collection(geometry)</span></dt><dd><p>Converts the geometry into a GEOMETRYCOLLECTION. This is
-            useful for simplifying the WKB representation.</p></dd><dt><a name="force_2d"></a><span class="term">Force_2d(geometry)</span></dt><dd><p>Forces the geometries into a "2-dimensional mode" so that
-            all output representations will only have the X and Y coordinates.
-            This is useful for force OGC-compliant output (since OGC only
-            specifies 2-D geometries).</p></dd><dt><a name="force_3dz"></a><span class="term">Force_3dz(geometry), </span><span class="term">Force_3d(geometry), </span></dt><dd><p>Forces the geometries into XYZ mode.</p></dd><dt><a name="force_3dm"></a><span class="term">Force_3dm(geometry)</span></dt><dd><p>Forces the geometries into XYM mode.</p></dd><dt><a name="force_4d"></a><span class="term">Force_4d(geometry)</span></dt><dd><p>Forces the geometries into XYZM mode.</p></dd><dt><span class="term">Multi(geometry)</span></dt><dd><p>Returns the geometry as a MULTI* geometry. If the geometry
-            is already a MULTI*, it is returned unchanged.</p></dd><dt><span class="term">Transform(geometry,integer)</span></dt><dd><p>Returns a new geometry with its coordinates transformed to
-            the SRID referenced by the integer parameter. The destination SRID
-            must exist in the <tt class="varname">SPATIAL_REF_SYS</tt> table.</p></dd><dt><span class="term">Affine(geometry,float8,float8,float8,float8,float8,float8,float8,float8,float8,float8,float8,float8)</span></dt><dd><p>Applies an 3d affine transformation to the geometry. The call 
-                </p><pre class="programlisting">
-                    Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff)
-                </pre><p>
-                represents the transformation matrix
-                </p><pre class="programlisting">
-                    /  a  b  c  xoff  \
-                    |  d  e  f  yoff  |
-                    |  g  h  i  zoff  |
-                    \  0  0  0  1     /
-                </pre><p>
-                and the vertices are transformed as follows:
-                </p><pre class="programlisting">
-                    x' = a*x + b*y + c*z + xoff
-                    y' = d*x + e*y + f*z + yoff
-                    z' = g*x + h*y + i*z + zoff   
-                </pre><p>
-                All of the translate / scale functions below are expressed via such an affine transformation.
-            </p><p>
-                Availability: 1.1.2.
-            </p></dd><dt><span class="term">Affine(geometry,float8,float8,float8,float8,float8,float8)</span></dt><dd><p>Applies an 2d affine transformation to the geometry. The call 
-                </p><pre class="programlisting">
-                    Affine(geom, a, b, d, e, xoff, yoff)
-                </pre><p>
-                represents the transformation matrix
-                </p><pre class="programlisting">
-                    /  a  b  0  xoff  \        /  a  b  xoff  \
-                    |  d  e  0  yoff  |  rsp.  |  d  e  yoff  |
-                    |  0  0  1  0     |        \  0  0  1     /
-                    \  0  0  0  1     /
-                </pre><p>
-                and the vertices are transformed as follows:
-                </p><pre class="programlisting">
-                    x' = a*x + b*y + xoff
-                    y' = d*x + e*y + yoff
-                    z' = z   
-                </pre><p>
-                This method is a subcase of the 3D method above.
-            </p><p>
-		Availability: 1.1.2.
-            </p></dd><dt><span class="term">Translate(geometry,float8,float8,float8)</span></dt><dd><p>Translates the geometry to a new location using the numeric
-            parameters as offsets. Ie: translate(geom, X, Y, Z).</p></dd><dt><span class="term">Scale(geometry,float8,float8,float8)</span></dt><dd><p>scales the geometry to a new size by multiplying the
-            ordinates with the parameters. Ie: scale(geom, Xfactor, Yfactor, Zfactor).</p><p>
-			Availability: 1.1.0
-		</p></dd><dt><a name="Rotate"></a><span class="term">RotateZ(geometry,float8), </span><span class="term">RotateX(geometry,float8), </span><span class="term">RotateY(geometry,float8), </span></dt><dd><p>
-			Rotate the geometry around the Z, X or Y axis by
-			the given angle given in radians. Follows the
-			right-hand rule. This is the same in
-			PostScript but opposite of SVG.
-		</p><p>
-			Availability: 1.1.2.
-		</p></dd><dt><span class="term">TransScale(geometry,float8,float8,float8,float8)</span></dt><dd><p>First, translates the geometry using the first two floats, then scales it
-                    using the second two floats, working in 2D only. Using
-                    <tt class="code">transscale(geom, X, Y, XFactor, YFactor)</tt> internally calls
-                    <tt class="code">affine(geom, XFactor, 0, 0,  0, YFactor, 0,  0, 0, 1,  X*XFactor, Y*YFactor, 0)</tt>.                
-                </p><p>
-                        Availability: 1.1.0.
-                </p></dd><dt><span class="term">Reverse(geometry)</span></dt><dd><p>Returns the geometry with vertex order reversed.</p></dd><dt><span class="term">ForceRHR(geometry)</span></dt><dd><p>Force polygons of the collection to obey Right-Hand-Rule.</p></dd><dt><span class="term">Simplify(geometry, tolerance)</span></dt><dd><p>Returns a "simplified" version of the given geometry using
-            the Douglas-Peuker algorithm. Will actually do something only with
-            (multi)lines and (multi)polygons but you can safely call it with
-            any kind of geometry. Since simplification occurs on a
-            object-by-object basis you can also feed a GeometryCollection to
-            this function. Note that returned geometry might loose its
-            simplicity (see <a href="ch06.html#IsSimple">IsSimple</a>)</p></dd><dt><span class="term">SnapToGrid(geometry, originX, originY, sizeX, sizeY), </span><span class="term">SnapToGrid(geometry, sizeX, sizeY), </span><span class="term">SnapToGrid(geometry, size), </span></dt><dd><p>Snap all points of the input geometry to the grid
-	    defined by its origin and cell size.
-            Remove consecutive points falling on the same cell,
-	    eventually returning NULL if output points are not
-	    enough to define a geometry of the given type.
-	    Collapsed geometries in a collection are stripped
-	    from it.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-            The returned geometry might loose its
-            simplicity (see <a href="ch06.html#IsSimple">IsSimple</a>).
-	</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-            Before release 1.1.0 this function always returned
-	    a 2d geometry. Starting at 1.1.0 the returned geometry
-	    will have same dimensionality as the input one with higher
-	    dimension values untouched. Use the version taking a second
-	    geometry argument to define all grid dimensions.
-	</p></div><p>
-			Availability: 1.0.0RC1
-		</p></dd><dt><span class="term">SnapToGrid(geometry, geometry, sizeX, sizeY, sizeZ, sizeM)</span></dt><dd><p>
-	    Snap all points of the input geometry to the grid
-	    defined by its origin (the second argument, must be a point)
-	    and cell sizes. Specify 0 as size for any dimension you don't
-	    want to snap to a grid.
-	    </p><p>
-			Availability: 1.1.0
-		</p></dd><dt><span class="term">Segmentize(geometry, maxlength)</span></dt><dd><p>Return a modified geometry having no segment
-            longer then the given distance. Interpolated points will have Z
-            and M values (if needed) set to 0. Distance computation is
-            performed in 2d only.</p></dd><dt><span class="term">LineMerge(geometry)</span></dt><dd><p>
-			Returns a (set of) LineString(s) formed by sewing
-			togheter costituent linework of input.
-		</p><p>
-			Availability: 1.1.0 - requires GEOS &gt;= 2.1.0
-		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2529854"></a>6.2.7. Linear Referencing</h3></div></div><div></div></div><div class="variablelist"><dl><dt><a name="line_interpolate_point"></a><span class="term">line_interpolate_point(linestring, location)</span></dt><dd><p>
-		Returns a poin interpolated along a line.
-		First argument must be a LINESTRING.
-		Second argument is a float8 between 0 and 1
-		representing fraction of total
-		<a href="ch06.html#length2d">2d length</a> the point has
-		to be located.
-		</p><p>
-		See <a href="ch06.html#line_locate_point">line_locate_point()</a>
-		for computing the line location nearest to a Point.
-		</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-            Since release 1.1.1 this function also interpolates
-	    M and Z values (when present), while prior releases
-	    set them to 0.0.
-	</p></div><p>
-			Availability: 0.8.2
-		</p></dd><dt><a name="line_substring"></a><span class="term">line_substring(linestring, start, end)</span></dt><dd><p>
-		Return a linestring being a substring of the input one starting
-		and ending at the given fractions of total 2d length. Second
-		and third arguments are float8 values between 0 and 1.
-		</p><p>
-		If 'start' and 'end' have the same value this is equivalent 
-		to <a href="ch06.html#line_interpolate_point">line_interpolate_point()</a>.
-		</p><p>
-		See <a href="ch06.html#line_locate_point">line_locate_point()</a>
-		for computing the line location nearest to a Point.
-		</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-            Since release 1.1.1 this function also interpolates
-	    M and Z values (when present), while prior releases
-	    set them to unspecified values.
-	</p></div><p>
-			Availability: 1.1.0
-		</p></dd><dt><a name="line_locate_point"></a><span class="term">line_locate_point(LineString, Point)</span></dt><dd><p>
-		Returns a float between 0 and 1 representing 
-		the location of the closest point on LineString
-		to the given Point, as a fraction of
-		total <a href="ch06.html#length2d">2d line</a> length.
-		</p><p>
-	You can use the returned location to extract a Point (<a href="ch06.html#line_interpolate_point">line_interpolate_point</a>) or a substring (<a href="ch06.html#line_substring">line_substring</a>).
-		</p><p>
-			Availability: 1.1.0
-		</p></dd><dt><span class="term">locate_along_measure(geometry, float8)</span></dt><dd><p>
-		Return a derived geometry collection value with elements that
-		match the specified measure.
-		Polygonal elements are not supported.
-		</p><p>
-		Semantic is specified by: ISO/IEC CD 13249-3:200x(E) -
-		Text for Continuation CD Editing Meeting
-		</p><p>
-			Availability: 1.1.0
-		</p></dd><dt><span class="term">locate_between_measures(geometry, float8, float8)</span></dt><dd><p>
-		Return a derived geometry collection value with elements that
-		match the specified range of measures inclusively.
-		Polygonal elements are not supported. 
-		</p><p>
-		Semantic is specified by: ISO/IEC CD 13249-3:200x(E) -
-		Text for Continuation CD Editing Meeting
-		</p><p>
-			Availability: 1.1.0
-		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2530074"></a>6.2.8. Misc</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Summary(geometry)</span></dt><dd><p>Returns a text summary of the contents of the geometry.</p></dd><dt><span class="term">box2d(geometry)</span></dt><dd><p>Returns a BOX2D representing the maximum extents of the geometry.</p></dd><dt><span class="term">box3d(geometry)</span></dt><dd><p>Returns a BOX3D representing the maximum extents of the geometry.</p></dd><dt><span class="term">extent(geometry set)</span></dt><dd><p>The extent() function is an "aggregate" function in the terminology of PostgreSQL. That means that it operators on lists of data, in the same way the sum() and mean() functions do. For example, "SELECT EXTENT(GEOM) FROM GEOMTABLE" will return a BOX3D giving the maximum extend of all features in the table. Similarly, "SELECT EXTENT(GEOM) FROM GEOMTABLE GROUP BY CATEGORY" will return one extent result for each category.</p></dd><dt><a name="zmflag"></a><span class="term">zmflag(geometry)</span></dt><dd><p>Returns ZM (dimension semantic) flag of the geometries as a small int. Values are: 0=2d, 1=3dm, 2=3dz, 3=4d.  </p></dd><dt><a name="hasbbox"></a><span class="term">HasBBOX(geometry)</span></dt><dd><p>Returns TRUE if the bbox of this geometry is cached, FALSE otherwise. Use <a href="ch06.html#addbbox">addBBOX()</a> and <a href="ch06.html#dropbbox">dropBBOX()</a> to control caching.</p></dd><dt><a name="ndims"></a><span class="term">ndims(geometry)</span></dt><dd><p>Returns number of dimensions of the geometry as a small int. Values are: 2,3 or 4.</p></dd><dt><span class="term">nrings(geometry)</span></dt><dd><p>If the geometry is a polygon or multi-polygon returns the number of rings.</p></dd><dt><span class="term">npoints(geometry)</span></dt><dd><p>Returns the number of points in the geometry.</p></dd><dt><a name="IsValid"></a><span class="term">isvalid(geometry)</span></dt><dd><p>returns true if this geometry is valid.</p></dd><dt><span class="term">expand(geometry, float)</span></dt><dd><p>This function returns a bounding box expanded in all
-		    directions from the bounding box of the input geometry, by an
-		    amount specified in the second argument. Very useful for
-		    distance() queries, to add an index filter to the query.</p></dd><dt><span class="term">estimated_extent([schema], table, geocolumn)</span></dt><dd><p> Return the 'estimated' extent of the given spatial table.  The estimated is taken from the geometry column's statistics. The current schema will be used if not specified.</p><p>For PostgreSQL&gt;=8.0.0 statistics are gathered by VACUUM ANALYZE and resulting extent will be about 95% of the real one.</p><p>For PostgreSQL&lt;8.0.0 statistics are gathered by update_geometry_stats() and resulting extent will be exact.</p></dd><dt><span class="term">find_srid(varchar,varchar,varchar)</span></dt><dd><p>The syntax is find_srid(&lt;db/schema&gt;, &lt;table&gt;,
-            &lt;column&gt;) and the function returns the integer SRID of the
-            specified column by searching through the GEOMETRY_COLUMNS table.
-            If the geometry column has not been properly added with the
-            AddGeometryColumns() function, this function will not work
-            either.</p></dd><dt><span class="term">mem_size(geometry)</span></dt><dd><p>Returns the amount of space (in bytes) the geometry
-            takes.</p></dd><dt><span class="term">numb_sub_objects(geometry)</span></dt><dd><p>Returns the number of objects stored in the geometry. This
-            is useful for MULTI-geometries and GEOMETRYCOLLECTIONs.</p></dd><dt><span class="term">point_inside_circle(geometry,float,float,float)</span></dt><dd><p>The syntax for this functions is
-            point_inside_circle(&lt;geometry&gt;,&lt;circle_center_x&gt;,&lt;circle_center_y&gt;,&lt;radius&gt;).
-            Returns the true if the geometry is a point and is inside the
-            circle. Returns false otherwise.</p></dd><dt><span class="term">xmin(box3d) ymin(box3d) zmin(box3d)</span></dt><dd><p>Returns the requested minima of a bounding box.</p></dd><dt><span class="term">xmax(box3d) ymax(box3d) zmax(box3d)</span></dt><dd><p>Returns the requested maxima of a bounding box.</p></dd><dt><a name="Accum"></a><span class="term">Accum(geometry set)</span></dt><dd><p>Aggregate. Constructs an array of geometries.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2531072"></a>6.2.9. Long Transactions support</h3></div></div><div></div></div><p>
-This module and associated pl/pgsql functions have been implemented
-to provide long locking support required by
-<a href="https://portal.opengeospatial.org/files/?artifact_id=7176" target="_top">Web Feature Service</a> specification.
-	</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
-  Users must use <a href="http://www.postgresql.org/docs/7.4/static/transaction-iso.html" target="_top">serializable transaction level</a> otherwise locking mechanism would break.
-	  </p></div><div class="variablelist"><dl><dt><a name="EnableLongTransactions"></a><span class="term">EnableLongTransactions()</span></dt><dd><p>
-		Enable long transaction support. This function creates the
-		required metadata tables, needs to be called once before
-		using the other functions in this section. Calling it twice
-		is harmless.
-	    </p><p>
-		    Availability: 1.1.3
-		</p></dd><dt><a name="DisableLongTransactions"></a><span class="term">DisableLongTransactions()</span></dt><dd><p>
-		Disable long transaction support. This function removes the
-		long transaction support metadata tables, and drops all
-		triggers attached to lock-checked tables.
-	    </p><p>
-		    Availability: 1.1.3
-		</p></dd><dt><a name="CheckAuth"></a><span class="term">CheckAuth([&lt;schema&gt;], &lt;table&gt;, &lt;rowid_col&gt;)</span></dt><dd><p>
-		Check updates and deletes of rows in
-		given table for being authorized.
-		Identify rows using &lt;rowid_col&gt; column.
-	    </p><p>
-		    Availability: 1.1.3
-		</p></dd><dt><a name="LockRow"></a><span class="term">LockRow([&lt;schema&gt;], &lt;table&gt;, &lt;rowid&gt;, &lt;authid&gt;, [&lt;expires&gt;])</span></dt><dd><p>
-	Set lock/authorization for specific row in table
-	&lt;authid&gt; is a text value, &lt;expires&gt; is a timestamp
-	defaulting to now()+1hour.
-	Returns 1 if lock has been assigned, 0 otherwise
-	(already locked by other auth)
-	    </p><p>
-		    Availability: 1.1.3
-		</p></dd><dt><a name="UnlockRows"></a><span class="term">UnlockRows(&lt;authid&gt;)</span></dt><dd><p>
-	Remove all locks held by specified authorization id.
-	Returns the number of locks released.
-	    </p><p>
-		    Availability: 1.1.3
-		</p></dd><dt><a name="AddAuth"></a><span class="term">AddAuth(&lt;authid&gt;)</span></dt><dd><p>
-	Add an authorization token to be used in current
-	transaction. 
-	    </p><p>
-		    Availability: 1.1.3
-		</p></dd></dl></div></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. Performance tips </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 7. Reporting Bugs</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/ch07.html
===================================================================
--- packages/postgis/upstream/doc/html/ch07.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/ch07.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,23 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 7. Reporting Bugs</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="up" href="index.html" title="PostGIS Manual"><link rel="previous" href="ch06.html" title="Chapter 6. PostGIS Reference"><link rel="next" href="apa.html" title="Appendix A. Appendix"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 7. Reporting Bugs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2530656"></a>Chapter 7. Reporting Bugs</h2></div></div><div></div></div><p>
-	Reporting bugs effectively is a fundamental way to help PostGIS
-	development. The most effective bug report is that enabling 
-	PostGIS developers to reproduce it, so it would ideally contain
-	a script triggering it and every information reguarding the
-	environment in which it was detected. Good enough info can
-	be extracted running <tt class="code">SELECT postgis_full_version()</tt>
-	[for postgis] and <tt class="code">SELECT version()</tt> [for postgresql].
-		</p><p>
-	If you aren't using latest release, it's worth taking a look
-	at its <a href="http://postgis.refractions.net/CHANGES.txt" target="_top">release
-	changelog</a> first, to find out if your bug has already been
-	fixed.
-		</p><p>
-	Using the <a href="http://postgis.refractions.net/bugs/" target="_top">PostGIS
-	bug tracker</a> will ensure your reports are not discarded, and
-	will keep you informed on it's handling process. Before reporting
-	a new bug please query the database to see if it is a known one, and
-	if it is please add any new information you have about it.
-		</p><p>
-	You might want to read Simon Tatham's paper about <a href="http://www.chiark.greenend.org.uk/~sgtatham/bugs.html" target="_top">How
-	to Report Bugs Effectively</a> before filing a new report.
-		</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6. PostGIS Reference </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Appendix A. Appendix</td></tr></table></div></body></html>

Deleted: packages/postgis/upstream/doc/html/index.html
===================================================================
--- packages/postgis/upstream/doc/html/index.html	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/html/index.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,9 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>PostGIS Manual</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><meta name="description" content="PostGIS is an extension to the PostgreSQL object-relational
-      database system which allows GIS (Geographic Information Systems)
-      objects to be stored in the database. PostGIS includes support for
-      GiST-based R-Tree spatial indexes, and functions for analysis and
-      processing of GIS objects. This is the manual for version 1.1.3"><link rel="home" href="index.html" title="PostGIS Manual"><link rel="next" href="ch01.html" title="Chapter 1. Introduction"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">PostGIS Manual</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch01.html">Next</a></td></tr></table><hr></div><div class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id2398070"></a>PostGIS Manual</h1></div><div><div class="abstract"><p class="title"><b>Abstract</b></p><p>PostGIS is an extension to the PostgreSQL object-relational
-      database system which allows GIS (Geographic Information Systems)
-      objects to be stored in the database. PostGIS includes support for
-      GiST-based R-Tree spatial indexes, and functions for analysis and
-      processing of GIS objects.</p><p>This is the manual for version 1.1.3</p></div></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="ch01.html">1. Introduction</a></span></dt><dd><dl><dt><span class="sect1"><a href="ch01.html#credits">1.1. Credits</a></span></dt><dt><span class="sect1"><a href="ch01.html#id2454630">1.2. More Information</a></span></dt></dl></dd><dt><span class="chapter"><a href="ch02.html">2. Installation</a></span></dt><dd><dl><dt><span class="sect1"><a href="ch02.html#id2481880">2.1. Requirements</a></span></dt><dt><span class="sect1"><a href="ch02.html#PGInstall">2.2. PostGIS</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02.html#upgrading">2.2.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="ch02.html#id2453863">2.2.2. Common Problems</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02.html#id2522143">2.3. JDBC</a></span></dt><dt><span class="sect1"><a href="ch02.html#id2522219">2.4. Loader/Dumper</a></span></dt></dl></dd><dt><span class="chapter"><a href="ch03.html">3. Frequently Asked Questions</a></span></dt><dt><span class="chapter"><a href="ch04.html">4. Using PostGIS</a></span></dt><dd><dl><dt><span class="sect1"><a href="ch04.html#RefObject">4.1. GIS Objects</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2522740">4.1.1. OpenGIS WKB and WKT</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2522847">4.1.2. PostGIS EWKB, EWKT and Canonical Forms</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2523004">4.2. Using OpenGIS Standards</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2523037">4.2.1. The SPATIAL_REF_SYS Table</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523246">4.2.2. The GEOMETRY_COLUMNS Table</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523380">4.2.3. Creating a Spatial Table</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523486">4.2.4. Ensuring OpenGIS compliancy of geometries</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2523576">4.3. Loading GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2523590">4.3.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2523645">4.3.2. Using the Loader</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2523875">4.4. Retrieving GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2523888">4.4.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2524054">4.4.2. Using the Dumper</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2524232">4.5. Building Indexes</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2524285">4.5.1. GiST Indexes</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2524354">4.5.2. Using Indexes</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2524472">4.6. Complex Queries</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2524491">4.6.1. Taking Advantage of Indexes</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2524587">4.6.2. Examples of Spatial SQL</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2524902">4.7. Using Mapserver</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2524945">4.7.1. Basic Usage</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2525193">4.7.2. Frequently Asked Questions</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2525360">4.7.3. Advanced Usage</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2453149">4.7.4. Examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04.html#id2453247">4.8. Java Clients (JDBC)</a></span></dt><dt><span class="sect1"><a href="ch04.html#id2525835">4.9. C Clients (libpq)</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2525844">4.9.1. Text Cursors</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2525854">4.9.2. Binary Cursors</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="ch05.html">5. Performance tips</a></span></dt><dd><dl><dt><span class="sect1"><a href="ch05.html#id2525872">5.1. Small tables of large geometries</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch05.html#id2525878">5.1.1. Problem description</a></span></dt><dt><span class="sect2"><a href="ch05.html#id2525930">5.1.2. Workarounds</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch05.html#id2525990">5.2. CLUSTERing on geometry indices</a></span></dt><dt><span class="sect1"><a href="ch05.html#id2526046">5.3. Avoiding dimension conversion</a></span></dt></dl></dd><dt><span class="chapter"><a href="ch06.html">6. PostGIS Reference</a></span></dt><dd><dl><dt><span class="sect1"><a href="ch06.html#id2526109">6.1. OpenGIS Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch06.html#id2526115">6.1.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2526205">6.1.2. Geometry Relationship Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2526581">6.1.3. Geometry Processing Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2526907">6.1.4. Geometry Accessors</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2527394">6.1.5. Geometry Constructors</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch06.html#id2527996">6.2. Postgis Extensions</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch06.html#id2528002">6.2.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528326">6.2.2. Operators</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528534">6.2.3. Measurement Functions</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528817">6.2.4. Geometry Outputs</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2528926">6.2.5. Geometry Constructors</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2529258">6.2.6. Geometry Editors</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2529854">6.2.7. Linear Referencing</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2530074">6.2.8. Misc</a></span></dt><dt><span class="sect2"><a href="ch06.html#id2531072">6.2.9. Long Transactions support</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="ch07.html">7. Reporting Bugs</a></span></dt><dt><span class="appendix"><a href="apa.html">A. Appendix</a></span></dt><dd><dl><dt><span class="sect1"><a href="apa.html#id2530726">A.1. Release Notes</a></span></dt><dd><dl><dt><span class="sect2"><a href="apa.html#id2530732">A.1.1. Release 1.1.3</a></span></dt><dt><span class="sect2"><a href="apa.html#id2530900">A.1.2. Release 1.1.2</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531032">A.1.3. Release 1.1.1</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531325">A.1.4. Release 1.1.0</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531650">A.1.5. Release 1.0.6</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531758">A.1.6. Release 1.0.5</a></span></dt><dt><span class="sect2"><a href="apa.html#id2531890">A.1.7. Release 1.0.4</a></span></dt><dt><span class="sect2"><a href="apa.html#rel_1.0.3_upgrading">A.1.8. Release 1.0.3</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532137">A.1.9. Release 1.0.2</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532216">A.1.10. Release 1.0.1</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532315">A.1.11. Release 1.0.0</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532414">A.1.12. Release 1.0.0RC6</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532488">A.1.13. Release 1.0.0RC5</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532560">A.1.14. Release 1.0.0RC4</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532685">A.1.15. Release 1.0.0RC3</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532857">A.1.16. Release 1.0.0RC2</a></span></dt><dt><span class="sect2"><a href="apa.html#id2532955">A.1.17. Release 1.0.0RC1</a></span></dt></dl></dd></dl></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> Chapter 1. Introduction</td></tr></table></div></body></html>

Added: packages/postgis/upstream/doc/html/postgis.html
===================================================================
--- packages/postgis/upstream/doc/html/postgis.html	                        (rev 0)
+++ packages/postgis/upstream/doc/html/postgis.html	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,2092 @@
+<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>PostGIS Manual</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><meta name="description" content="PostGIS is an extension to the PostgreSQL object-relational
+      database system which allows GIS (Geographic Information Systems)
+      objects to be stored in the database. PostGIS includes support for
+      GiST-based R-Tree spatial indexes, and functions for analysis and
+      processing of GIS objects. This is the manual for version 1.1.4"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id2580166"></a>PostGIS Manual</h1></div><div><div class="abstract"><p class="title"><b>Abstract</b></p><p>PostGIS is an extension to the PostgreSQL object-relational
+      database system which allows GIS (Geographic Information Systems)
+      objects to be stored in the database. PostGIS includes support for
+      GiST-based R-Tree spatial indexes, and functions for analysis and
+      processing of GIS objects.</p><p>This is the manual for version 1.1.4</p></div></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#id2582151">1. Introduction</a></span></dt><dd><dl><dt><span class="sect1"><a href="#credits">1.1. Credits</a></span></dt><dt><span class="sect1"><a href="#id2581981">1.2. More Information</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id2609268">2. Installation</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2609274">2.1. Requirements</a></span></dt><dt><span class="sect1"><a href="#PGInstall">2.2. PostGIS</a></span></dt><dd><dl><dt><span class="sect2"><a href="#upgrading">2.2.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2581192">2.2.2. Common Problems</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2649517">2.3. JDBC</a></span></dt><dt><span class="sect1"><a href="#id2649594">2.4. Loader/Dumper</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id2649632">3. Frequently Asked Questions</a></span></dt><dt><span class="chapter"><a href="#id2650088">4. Using PostGIS</a></span></dt><dd><dl><dt><span class="sect1"><a href="#RefObject">4.1. GIS Objects</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2650115">4.1.1. OpenGIS WKB and WKT</a></span></dt><dt><span class="sect2"><a href="#id2650222">4.1.2. PostGIS EWKB, EWKT and Canonical Forms</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2650378">4.2. Using OpenGIS Standards</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2650411">4.2.1. The SPATIAL_REF_SYS Table</a></span></dt><dt><span class="sect2"><a href="#id2650620">4.2.2. The GEOMETRY_COLUMNS Table</a></span></dt><dt><span class="sect2"><a href="#id2650754">4.2.3. Creating a Spatial Table</a></span></dt><dt><span class="sect2"><a href="#id2650861">4.2.4. Ensuring OpenGIS compliancy of geometries</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2650951">4.3. Loading GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2650964">4.3.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2651020">4.3.2. Using the Loader</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2651250">4.4. Retrieving GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2651263">4.4.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2651429">4.4.2. Using the Dumper</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2651607">4.5. Building Indexes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2651660">4.5.1. GiST Indexes</a></span></dt><dt><span class="sect2"><a href="#id2651729">4.5.2. Using Indexes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2651847">4.6. Complex Queries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2651866">4.6.1. Taking Advantage of Indexes</a></span></dt><dt><span class="sect2"><a href="#id2651962">4.6.2. Examples of Spatial SQL</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2652277">4.7. Using Mapserver</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2652320">4.7.1. Basic Usage</a></span></dt><dt><span class="sect2"><a href="#id2652568">4.7.2. Frequently Asked Questions</a></span></dt><dt><span class="sect2"><a href="#id2652735">4.7.3. Advanced Usage</a></span></dt><dt><span class="sect2"><a href="#id2580495">4.7.4. Examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2580593">4.8. Java Clients (JDBC)</a></span></dt><dt><span class="sect1"><a href="#id2653210">4.9. C Clients (libpq)</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2653219">4.9.1. Text Cursors</a></span></dt><dt><span class="sect2"><a href="#id2653229">4.9.2. Binary Cursors</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#id2653241">5. Performance tips</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2653247">5.1. Small tables of large geometries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2653253">5.1.1. Problem description</a></span></dt><dt><span class="sect2"><a href="#id2653305">5.1.2. Workarounds</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2653365">5.2. CLUSTERing on geometry indices</a></span></dt><dt><span class="sect1"><a href="#id2653421">5.3. Avoiding dimension conversion</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id2653471">6. PostGIS Reference</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2653484">6.1. OpenGIS Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2653490">6.1.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2653580">6.1.2. Geometry Relationship Functions</a></span></dt><dt><span class="sect2"><a href="#id2653956">6.1.3. Geometry Processing Functions</a></span></dt><dt><span class="sect2"><a href="#id2654282">6.1.4. Geometry Accessors</a></span></dt><dt><span class="sect2"><a href="#id2654768">6.1.5. Geometry Constructors</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2655371">6.2. Postgis Extensions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2655376">6.2.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2655701">6.2.2. Operators</a></span></dt><dt><span class="sect2"><a href="#id2655909">6.2.3. Measurement Functions</a></span></dt><dt><span class="sect2"><a href="#id2656192">6.2.4. Geometry Outputs</a></span></dt><dt><span class="sect2"><a href="#id2656300">6.2.5. Geometry Constructors</a></span></dt><dt><span class="sect2"><a href="#id2656633">6.2.6. Geometry Editors</a></span></dt><dt><span class="sect2"><a href="#id2657229">6.2.7. Linear Referencing</a></span></dt><dt><span class="sect2"><a href="#id2657449">6.2.8. Misc</a></span></dt><dt><span class="sect2"><a href="#id2658447">6.2.9. Long Transactions support</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#id2658031">7. Reporting Bugs</a></span></dt><dt><span class="appendix"><a href="#release_notes">A. Appendix</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2658101">A.1. Release Notes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2658106">A.1.1. Release 1.1.4</a></span></dt><dt><span class="sect2"><a href="#id2658230">A.1.2. Release 1.1.3</a></span></dt><dt><span class="sect2"><a href="#id2658396">A.1.3. Release 1.1.2</a></span></dt><dt><span class="sect2"><a href="#id2658690">A.1.4. Release 1.1.1</a></span></dt><dt><span class="sect2"><a href="#id2658820">A.1.5. Release 1.1.0</a></span></dt><dt><span class="sect2"><a href="#id2659145">A.1.6. Release 1.0.6</a></span></dt><dt><span class="sect2"><a href="#id2659254">A.1.7. Release 1.0.5</a></span></dt><dt><span class="sect2"><a href="#id2659386">A.1.8. Release 1.0.4</a></span></dt><dt><span class="sect2"><a href="#rel_1.0.3_upgrading">A.1.9. Release 1.0.3</a></span></dt><dt><span class="sect2"><a href="#id2659632">A.1.10. Release 1.0.2</a></span></dt><dt><span class="sect2"><a href="#id2659711">A.1.11. Release 1.0.1</a></span></dt><dt><span class="sect2"><a href="#id2659811">A.1.12. Release 1.0.0</a></span></dt><dt><span class="sect2"><a href="#id2659910">A.1.13. Release 1.0.0RC6</a></span></dt><dt><span class="sect2"><a href="#id2659984">A.1.14. Release 1.0.0RC5</a></span></dt><dt><span class="sect2"><a href="#id2660056">A.1.15. Release 1.0.0RC4</a></span></dt><dt><span class="sect2"><a href="#id2660181">A.1.16. Release 1.0.0RC3</a></span></dt><dt><span class="sect2"><a href="#id2660352">A.1.17. Release 1.0.0RC2</a></span></dt><dt><span class="sect2"><a href="#id2660450">A.1.18. Release 1.0.0RC1</a></span></dt></dl></dd></dl></dd></dl></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2582151"></a>Chapter 1. Introduction</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#credits">1.1. Credits</a></span></dt><dt><span class="sect1"><a href="#id2581981">1.2. More Information</a></span></dt></dl></div><p>PostGIS is developed by Refractions Research Inc, as a spatial
+    database technology research project. Refractions is a GIS and database
+    consulting company in Victoria, British Columbia, Canada, specializing in
+    data integration and custom software development. We plan on supporting
+    and developing PostGIS to support a range of important GIS functionality,
+    including full OpenGIS support, advanced topological constructs
+    (coverages, surfaces, networks), desktop user interface tools for viewing
+    and editing GIS data, and web-based access tools.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="credits"></a>1.1. Credits</h2></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Sandro Santilli &lt;strk at refractions.net&gt;</span></dt><dd><p>Coordinates all bug fixing and maintenance effort,
+            integration of new GEOS functionality, and new function
+            enhancements.</p></dd><dt><span class="term">Chris Hodgson &lt;chodgson at refractions.net&gt;</span></dt><dd><p>Maintains new functions and the 7.2 index bindings.</p></dd><dt><span class="term">Paul Ramsey &lt;pramsey at refractions.net&gt;</span></dt><dd><p>Keeps track of the
+            documentation and packaging.</p></dd><dt><span class="term">Jeff Lounsbury &lt;jeffloun at refractions.net&gt;</span></dt><dd><p>Original development of the Shape file loader/dumper.</p></dd><dt><span class="term">Dave Blasby &lt;dblasby at gmail.com&gt;</span></dt><dd><p>The original developer of PostGIS. Dave wrote the server
+            side objects, index bindings, and many of the server side
+            analytical functions.</p></dd><dt><span class="term">Other contributors</span></dt><dd><p>
+		In alphabetical order: 
+		Alex Bodnaru, Alex Mayrhofer, Bruce Rindahl,
+		Bernhard Reiter, 
+		Bruno Wolff III, Carl Anderson, Charlie Savage,
+		David Skea, David Techer, 
+		IIDA Tetsushi, Geographic Data BC, Gerald Fenoy,
+		Gino Lucrezi, Klaus Foerster, Kris Jurka, Mark Cave-Ayland,
+		Mark Sondheim, Markus Schaber, Michael Fuhr, Nikita Shulga,
+		Norman Vine, Olivier Courtin, Ralph Mason, Steffen Macke.
+            </p></dd><dt><span class="term">Important Support Libraries</span></dt><dd><p>The <a href="http://geos.refractions.net" target="_top">GEOS</a>
+            geometry operations library, and the algorithmic work of 
+            Martin Davis &lt;mbdavis at vividsolutions.com&gt; of Vivid Solutions
+            in making it all work.</p><p>The <a href="http://proj4.maptools.org" target="_top">Proj4</a>
+            cartographic projection library, and the work of Gerald Evenden
+            and Frank Warmerdam in creating and maintaining it.</p></dd></dl></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2581981"></a>1.2. More Information</h2></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><p>The latest software, documentation and news items are
+          available at the PostGIS web site, <a href="http://postgis.refractions.net" target="_top">http://postgis.refractions.net</a>.</p></li><li><p>More information about the GEOS geometry operations library is
+          available at<a href="http://geos.refractions.net" target="_top">
+          http://geos.refractions.net</a>.</p></li><li><p>More information about the Proj4 reprojection library is
+          available at <a href="http://www.remotesensing.org/proj" target="_top">http://www.remotesensing.org/proj</a>.</p></li><li><p>More information about the PostgreSQL database server is
+          available at the PostgreSQL main site <a href="http://www.postgresql.org" target="_top">http://www.postgresql.org</a>.</p></li><li><p>More information about GiST indexing is available at the
+          PostgreSQL GiST development site, <a href="http://www.sai.msu.su/~megera/postgres/gist" target="_top">http://www.sai.msu.su/~megera/postgres/gist</a>.</p></li><li><p>More information about Mapserver internet map server is
+          available at <a href="http://mapserver.gis.umn.edu/" target="_top">http://mapserver.gis.umn.edu</a>.</p></li><li><p>The "<a href="http://www.opengis.org/docs/99-049.pdf" target="_top">Simple Features
+          for Specification for SQL</a>" is available at the OpenGIS
+          Consortium web site: <a href="http://www.opengis.org" target="_top">http://www.opengis.org</a>.</p></li></ul></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2609268"></a>Chapter 2. Installation</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#id2609274">2.1. Requirements</a></span></dt><dt><span class="sect1"><a href="#PGInstall">2.2. PostGIS</a></span></dt><dd><dl><dt><span class="sect2"><a href="#upgrading">2.2.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2581192">2.2.2. Common Problems</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2649517">2.3. JDBC</a></span></dt><dt><span class="sect1"><a href="#id2649594">2.4. Loader/Dumper</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2609274"></a>2.1. Requirements</h2></div></div><div></div></div><p>PostGIS has the following requirements for building and
+      usage:</p><div class="itemizedlist"><ul type="disc"><li><p>
+	  A complete installation of PostgreSQL (including server headers).
+          PostgreSQL is available from <a href="http://www.postgresql.org" target="_top">http://www.postgresql.org</a>.
+	  Version 7.2 or higher is required.
+	  </p></li><li><p>GNU C compiler (<tt class="filename">gcc</tt>). Some other ANSI C
+          compilers can be used to compile PostGIS, but we find far fewer
+          problems when compiling with <tt class="filename">gcc</tt>.</p></li><li><p>GNU Make (<tt class="filename">gmake</tt> or
+          <tt class="filename">make</tt>). For many systems, GNU
+          <tt class="filename">make</tt> is the default version of make. Check the
+          version by invoking <tt class="filename">make -v</tt>. Other versions of
+          <tt class="filename">make</tt> may not process the PostGIS
+          <tt class="filename">Makefile</tt> properly.</p></li><li><p>(Recommended) Proj4 reprojection library. The Proj4 library is
+          used to provide coordinate reprojection support within PostGIS.
+          Proj4 is available for download from <a href="http://www.remotesensing.org/proj" target="_top">http://www.remotesensing.org/proj</a>.</p></li><li><p>(Recommended) GEOS geometry library. The GEOS library is used
+          to provide geometry tests (Touches(), Contains(), Intersects()) and
+          operations (Buffer(), GeomUnion(), Difference()) within PostGIS.
+          GEOS is available for download from <a href="http://geos.refractions.net" target="_top">http://geos.refractions.net</a>.</p></li></ul></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="PGInstall"></a>2.2. PostGIS</h2></div></div><div></div></div><p>The PostGIS module is a extension to the PostgreSQL backend
+      server. As such, PostGIS 1.1.4
+      <span class="emphasis"><em>requires</em></span> full PostgreSQL server headers access
+      in order to compile. The PostgreSQL source code is available at <a href="http://www.postgresql.org" target="_top">http://www.postgresql.org</a>.</p><p>PostGIS 1.1.4 can be built against PostgreSQL
+      versions 7.2.0 or higher. Earlier versions of PostgreSQL are
+      <span class="emphasis"><em>not</em></span> supported.</p><div class="orderedlist"><ol type="1"><li><p>Before you can compile the PostGIS server modules, you must
+          compile and install the PostgreSQL package.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you plan to use GEOS functionality you might need to
+            explicitly link PostgreSQL against the standard C++
+            library:</p><pre class="programlisting">LDFLAGS=-lstdc++ ./configure [YOUR OPTIONS HERE]</pre><p>This is a workaround for bogus C++ exceptions interaction
+            with older development tools. If you experience weird problems
+            (backend unexpectedly closed or similar things) try this trick.
+            This will require recompiling your PostgreSQL from scratch, of
+            course.</p></div></li><li><p>Retrieve the PostGIS source archive from <a href="http://postgis.refractions.net/postgis-1.1.4.tar.gz" target="_top">http://postgis.refractions.net/postgis-1.1.4.tar.gz</a>.
+          Uncompress and untar the archive.
+	  </p><pre class="programlisting"># gzip -d -c postgis-1.1.4.tar.gz | tar xvf -</pre></li><li><p>Enter the postgis-1.1.4 directory, and run:
+</p><pre class="programlisting"># ./configure</pre><p>
+	  </p><div class="itemizedlist"><ul type="disc"><li><p>
+		If you want support for coordinate reprojection, you must have
+		the Proj4 library installed. If ./configure didn't find
+		it, try using <tt class="code">--with-proj=PATH</tt>
+		switch specify a specific Proj4 installation directory.
+		</p></li><li><p>
+		If you want to use GEOS functionality, you must have the GEOS
+		library installed. If ./configure didn't find it, try
+		using <tt class="code">--with-geos=PATH</tt> to specify the full 
+                path to the geos-config program full path.
+		</p></li></ul></div></li><li><p>Run the compile and install commands.</p><pre class="programlisting"># make 
+# make install</pre><p>All files are installed using information provided
+	  by <tt class="filename">pg_config</tt></p><div class="itemizedlist"><ul type="disc"><li><p>Libraries are installed
+              <tt class="filename">[pkglibdir]/lib/contrib</tt>.</p></li><li><p>Important support files such as
+              <tt class="filename">lwpostgis.sql</tt> are installed in
+              <tt class="filename">[prefix]/share/contrib</tt>.</p></li><li><p>Loader and dumper binaries are installed in
+              <tt class="filename">[bindir]/</tt>.</p></li></ul></div></li><li><p>PostGIS requires the PL/pgSQL procedural language extension.
+          Before loading the <tt class="filename">lwpostgis.sql</tt> file, you must
+          first enable PL/pgSQL. You should use the
+          <tt class="filename">createlang</tt> command. The PostgreSQL 
+          Programmer's Guide has the details if you want to this manually for
+          some reason.</p><pre class="programlisting"># createlang plpgsql [yourdatabase]</pre></li><li><p>Now load the PostGIS object and function definitions into your
+          database by loading the <tt class="filename">lwpostgis.sql</tt> definitions
+          file.</p><pre class="programlisting"># psql -d [yourdatabase] -f lwpostgis.sql</pre><p>The PostGIS server extensions are now loaded and ready to
+          use.</p></li><li><p>For a complete set of EPSG coordinate system definition
+          identifiers, you can also load the
+          <tt class="filename">spatial_ref_sys.sql</tt> definitions file and
+          populate the <tt class="varname">SPATIAL_REF_SYS</tt> table.</p><pre class="programlisting"># psql -d [yourdatabase] -f spatial_ref_sys.sql</pre></li></ol></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="upgrading"></a>2.2.1. Upgrading</h3></div></div><div></div></div><p>
+Upgrading existing spatial databases can be tricky as it requires
+replacement or introduction of new PostGIS object definitions.
+</p><p>
+Unfortunately not all definitions can be easily replaced in 
+a live database, so sometimes your best bet is a dump/reload
+process. 
+</p><p>
+PostGIS provides a SOFT UPGRADE procedure for minor or bugfix
+releases, and an HARD UPGRADE procedure for major releases.
+</p><p>
+Before attempting to upgrade postgis, it is always worth to backup
+your data. If you use the -Fc flag to pg_dump you will always be able
+to restore the dump with an HARD UPGRADE.
+	</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="soft_upgrade"></a>2.2.1.1. Soft upgrade</h4></div></div><div></div></div><p>
+Soft upgrade consists of sourcing the lwpostgis_upgrade.sql
+script in your spatial database:
+</p><pre class="programlisting">psql -f lwpostgis_upgrade.sql -d your_spatial_database</pre><p>
+If a soft upgrade is not possible the script will abort and 
+you will be warned about HARD UPGRADE being required,
+so do not hesitate to try a soft upgrade first.
+</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+If you can't find the <tt class="filename">lwpostgis_upgrade.sql</tt> file
+you are probably using a version prior to 1.1 and must generate that
+file by yourself. This is done with the following command:
+</p><pre class="programlisting">utils/postgis_proc_upgrade.pl lwpostgis.sql &gt; lwpostgis_upgrade.sql</pre></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="hard_upgrade"></a>2.2.1.2. Hard upgrade</h4></div></div><div></div></div><p>
+By HARD UPGRADE we intend full dump/reload of postgis-enabled databases.
+You need an HARD UPGRADE when postgis objects' internal storage
+changes or when SOFT UPGRADE is not possible.
+The <a href="#release_notes" title="Appendix A. Appendix">Release Notes</a> appendix reports for each version whether you need a
+dump/reload (HARD UPGRADE) to upgrade.
+	</p><p>
+PostGIS provides an utility script to restore a dump
+produced with the pg_dump -Fc command. It is experimental so redirecting
+its output to a file will help in case of problems. The procedure is
+as follow:
+	</p><pre class="programlisting">
+	# Create a "custom-format" dump of the database you want
+	# to upgrade (let's call it "olddb")
+	$ pg_dump -Fc olddb &gt; olddb.dump
+
+	# Restore the dump contextually upgrading postgis into
+	# a new database. The new database doesn't have to exist.
+	# Let's call it "newdb"
+	$ sh utils/postgis_restore.pl lwpostgis.sql newdb olddb.dump &gt; restore.log
+
+	# Check that all restored dump objects really had to be restored from dump
+	# and do not conflict with the ones defined in lwpostgis.sql
+	$ grep ^KEEPING restore.log | less
+
+	# If upgrading from PostgreSQL &lt; 8.0 to &gt;= 8.0 you might want to 
+	# drop the attrelid, varattnum and stats columns in the geometry_columns
+	# table, which are no-more needed. Keeping them won't hurt.
+	# !!! DROPPING THEM WHEN REALLY NEEDED WILL DO HURT !!!!
+	$ psql newdb -c "ALTER TABLE geometry_columns DROP attrelid"
+	$ psql newdb -c "ALTER TABLE geometry_columns DROP varattnum"
+	$ psql newdb -c "ALTER TABLE geometry_columns DROP stats"
+
+	# spatial_ref_sys table is restore from the dump, to ensure your custom
+	# additions are kept, but the distributed one might contain modification
+	# so you should backup your entries, drop the table and source the new one.
+	# If you did make additions we assume you know how to backup them before
+	# upgrading the table. Replace of it with the new one is done like this:
+	$ psql newdb
+	newdb=&gt; delete from spatial_ref_sys; 
+	DROP
+	newdb=&gt; \i spatial_ref_sys.sql
+	</pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2581192"></a>2.2.2. Common Problems</h3></div></div><div></div></div><p>There are several things to check when your installation or
+        upgrade doesn't go as you expected.</p><div class="orderedlist"><ol type="1"><li><p>It is easiest if you untar the PostGIS distribution into the
+            contrib directory under the PostgreSQL source tree. However, if
+            this is not possible for some reason, you can set the
+            <tt class="varname">PGSQL_SRC</tt> environment variable to the path to
+            the PostgreSQL source directory. This will allow you to compile
+            PostGIS, but the <span><b class="command">make install</b></span> may not work, so
+            be prepared to copy the PostGIS library and executable files to
+            the appropriate locations yourself.</p></li><li><p>Check that you you have installed PostgreSQL 7.2 or newer,
+            and that you are compiling against the same version of the
+            PostgreSQL source as the version of PostgreSQL that is running.
+            Mix-ups can occur when your (Linux) distribution has already
+            installed PostgreSQL, or you have otherwise installed PostgreSQL
+            before and forgotten about it. PostGIS will only work with
+            PostgreSQL 7.2 or newer, and strange, unexpected error messages
+            will result if you use an older version. To check the version of
+            PostgreSQL which is running, connect to the database using psql
+            and run this query:</p><pre class="programlisting">SELECT version();</pre><p>If you are running an RPM based distribution, you can check
+            for the existence of pre-installed packages using the
+            <span><b class="command">rpm</b></span> command as follows: <span><b class="command">rpm -qa | grep
+            postgresql</b></span></p></li></ol></div><p>Also check that you have made any necessary changes to the top
+        of the Makefile.config. This includes:</p><div class="orderedlist"><ol type="1"><li><p>If you want to be able to do coordinate reprojections, you
+            must install the Proj4 library on your system, set the
+            <tt class="varname">USE_PROJ</tt> variable to 1 and the
+            <tt class="varname">PROJ_DIR</tt> to your installation prefix in the
+            Makefile.config.</p></li><li><p>If you want to be able to use GEOS functions you must
+            install the GEOS library on your system, and set the
+            <tt class="varname">USE_GEOS</tt> to 1 and the
+            <tt class="varname">GEOS_DIR</tt> to your installation prefix in the
+            Makefile.config</p></li></ol></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2649517"></a>2.3. JDBC</h2></div></div><div></div></div><p>The JDBC extensions provide Java objects corresponding to the
+      internal PostGIS types. These objects can be used to write Java clients
+      which query the PostGIS database and draw or do calculations on the GIS
+      data in PostGIS.</p><div class="orderedlist"><ol type="1"><li><p>Enter the <tt class="filename">jdbc</tt> sub-directory of the
+          PostGIS distribution.</p></li><li><p>Edit the <tt class="filename">Makefile</tt> to provide the correct
+          paths of your java compiler (<tt class="varname">JAVAC</tt>) and
+          interpreter (<tt class="varname">JAVA</tt>).</p></li><li><p>Run the <tt class="filename">make</tt> command. Copy the
+          <tt class="filename">postgis.jar</tt> file to wherever you keep your java
+          libraries.</p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2649594"></a>2.4. Loader/Dumper</h2></div></div><div></div></div><p>The data loader and dumper are built and installed automatically
+      as part of the PostGIS build. To build and install them manually:</p><pre class="programlisting"># cd postgis-1.1.4/loader 
+# make
+# make install</pre><p>The loader is called <tt class="filename">shp2pgsql</tt> and converts
+      ESRI Shape files into SQL suitable for loading in PostGIS/PostgreSQL.
+      The dumper is called <tt class="filename">pgsql2shp</tt> and converts PostGIS
+      tables (or queries) into ESRI Shape files.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2649632"></a>Chapter 3. Frequently Asked Questions</h2></div></div><div></div></div><div class="qandaset"><dl><dt>3.1. <a href="#id2649640">What kind of geometric objects can I store?</a></dt><dt>3.2. <a href="#id2649661">How do I insert a GIS object into the database?</a></dt><dt>3.3. <a href="#id2649756">How do I construct a spatial query?</a></dt><dt>3.4. <a href="#id2649822">How do I speed up spatial queries on large tables?</a></dt><dt>3.5. <a href="#id2649903">Why aren't PostgreSQL R-Tree indexes supported?</a></dt><dt>3.6. <a href="#id2649956">Why should I use the AddGeometryColumn()
+          function and all the other OpenGIS stuff?</a></dt><dt>3.7. <a href="#id2650004">What is the best way to find all objects within a radius of
+          another object?</a></dt><dt>3.8. <a href="#id2650056">How do I perform a coordinate reprojection as part of a
+          query?</a></dt></dl><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="question"><td align="left" valign="top"><a name="id2649640"></a><a name="id2649642"></a><b>3.1.</b></td><td align="left" valign="top"><p>What kind of geometric objects can I store?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>You can store point, line, polygon, multipoint, multiline,
+          multipolygon, and geometrycollections. These are specified in the
+          Open GIS Well Known Text Format (with XYZ,XYM,XYZM extentions).</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2649661"></a><a name="id2649663"></a><b>3.2.</b></td><td align="left" valign="top"><p>How do I insert a GIS object into the database?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>First, you need to create a table with a column of type
+          "geometry" to hold your GIS data. Connect to your database with
+          <tt class="filename">psql</tt> and try the following SQL:</p><pre class="programlisting">CREATE TABLE gtest ( ID int4, NAME varchar(20) );
+SELECT AddGeometryColumn('', 'gtest','geom',-1,'LINESTRING',2);</pre><p>If the geometry column addition fails, you probably have not
+          loaded the PostGIS functions and objects into this database. See the
+          <a href="#PGInstall" title="2.2. PostGIS">installation instructions</a>.</p><p>Then, you can insert a geometry into the table using a SQL
+          insert statement. The GIS object itself is formatted using the
+          OpenGIS Consortium "well-known text" format:</p><pre class="programlisting">INSERT INTO gtest (ID, NAME, GEOM) VALUES (1, 'First Geometry', GeomFromText('LINESTRING(2 3,4 5,6 5,7 8)', -1));</pre><p>For more information about other GIS objects, see the <a href="#RefObject" title="4.1. GIS Objects">object reference</a>.</p><p>To view your GIS data in the table:</p><pre class="programlisting">SELECT id, name, AsText(geom) AS geom FROM gtest;</pre><p>The return value should look something like this:</p><pre class="programlisting"> id | name           | geom
+----+----------------+-----------------------------
+  1 | First Geometry | LINESTRING(2 3,4 5,6 5,7 8) 
+(1 row)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2649756"></a><a name="id2649758"></a><b>3.3.</b></td><td align="left" valign="top"><p>How do I construct a spatial query?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>The same way you construct any other database query, as an SQL
+          combination of return values, functions, and boolean tests.</p><p>For spatial queries, there are two issues that are important
+          to keep in mind while constructing your query: is there a spatial
+          index you can make use of; and, are you doing expensive calculations
+          on a large number of geometries.</p><p>In general, you will want to use the "intersects operator"
+          (&amp;&amp;) which tests whether the bounding boxes of features
+          intersect. The reason the &amp;&amp; operator is useful is because
+          if a spatial index is available to speed up the test, the &amp;&amp;
+          operator will make use of this. This can make queries much much
+          faster.</p><p>You will also make use of spatial functions, such as
+          Distance(), Intersects(), Contains() and Within(), among others, to
+          narrow down the results of your search. Most spatial queries include
+          both an indexed test and a spatial function test. The index test
+          serves to limit the number of return tuples to only tuples that
+          <span class="emphasis"><em>might</em></span> meet the condition of interest. The
+          spatial functions are then use to test the condition exactly.</p><pre class="programlisting">SELECT id, the_geom FROM thetable
+WHERE
+  the_geom &amp;&amp; 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'
+AND
+  Contains(the_geom,'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))';</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2649822"></a><a name="id2649824"></a><b>3.4.</b></td><td align="left" valign="top"><p>How do I speed up spatial queries on large tables?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Fast queries on large tables is the <span class="emphasis"><em>raison
+          d'etre</em></span> of spatial databases (along with transaction
+          support) so having a good index is important.</p><p>To build a spatial index on a table with a
+          <tt class="varname">geometry</tt> column, use the "CREATE INDEX" function
+          as follows:</p><pre class="programlisting">CREATE INDEX [indexname] ON [tablename]  
+  USING GIST ( [geometrycolumn] );</pre><p>The "USING GIST" option tells the server to use a GiST
+          (Generalized Search Tree) index.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+            GiST indexes are assumed to be lossy.
+	    Lossy indexes uses a proxy object (in the spatial case,
+	    a bounding box) for building the index.</p></div><p>You should also ensure that the PostgreSQL query planner has
+          enough information about your index to make rational decisions about
+          when to use it. To do this, you have to "gather statistics" on your
+          geometry tables.</p><p>For PostgreSQL 8.0.x and greater, just run the <span><b class="command">VACUUM
+          ANALYZE</b></span> command.</p><p>For PostgreSQL 7.4.x and below, run the <span><b class="command">SELECT
+          UPDATE_GEOMETRY_STATS()</b></span> command.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2649903"></a><a name="id2649906"></a><b>3.5.</b></td><td align="left" valign="top"><p>Why aren't PostgreSQL R-Tree indexes supported?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Early versions of PostGIS used the PostgreSQL R-Tree indexes.
+          However, PostgreSQL R-Trees have been completely discarded since
+          version 0.6, and spatial indexing is provided with an
+          R-Tree-over-GiST scheme.</p><p>Our tests have shown search speed for native R-Tree and GiST
+          to be comparable. Native PostgreSQL R-Trees have two limitations
+          which make them undesirable for use with GIS features (note that
+          these limitations are due to the current PostgreSQL native R-Tree
+          implementation, not the R-Tree concept in general):</p><div class="itemizedlist"><ul type="disc"><li><p>R-Tree indexes in PostgreSQL cannot handle features which
+              are larger than 8K in size. GiST indexes can, using the "lossy"
+              trick of substituting the bounding box for the feature
+              itself.</p></li><li><p>R-Tree indexes in PostgreSQL are not "null safe", so
+              building an index on a geometry column which contains null
+              geometries will fail.</p></li></ul></div></td></tr><tr class="question"><td align="left" valign="top"><a name="id2649956"></a><a name="id2649958"></a><b>3.6.</b></td><td align="left" valign="top"><p>Why should I use the <tt class="varname">AddGeometryColumn()</tt>
+          function and all the other OpenGIS stuff?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>If you do not want to use the OpenGIS support functions, you
+          do not have to. Simply create tables as in older versions, defining
+          your geometry columns in the CREATE statement. All your geometries
+          will have SRIDs of -1, and the OpenGIS meta-data tables will
+          <span class="emphasis"><em>not</em></span> be filled in properly. However, this will
+          cause most applications based on PostGIS to fail, and it is
+          generally suggested that you do use
+          <tt class="varname">AddGeometryColumn()</tt> to create geometry
+          tables.</p><p>Mapserver is one application which makes use of the
+          <tt class="varname">geometry_columns</tt> meta-data. Specifically,
+          Mapserver can use the SRID of the geometry column to do on-the-fly
+          reprojection of features into the correct map projection.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2650004"></a><a name="id2650006"></a><b>3.7.</b></td><td align="left" valign="top"><p>What is the best way to find all objects within a radius of
+          another object?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>To use the database most efficiently, it is best to do radius
+          queries which combine the radius test with a bounding box test: the
+          bounding box test uses the spatial index, giving fast access to a
+          subset of data which the radius test is then applied to.</p><p>The <tt class="varname">Expand()</tt> function is a handy way of
+          enlarging a bounding box to allow an index search of a region of
+          interest. The combination of a fast access index clause and a slower
+          accurate distance test provides the best combination of speed and
+          precision for this query.</p><p>For example, to find all objects with 100 meters of POINT(1000
+          1000) the following query would work well:</p><pre class="programlisting">SELECT * 
+FROM GEOTABLE 
+WHERE 
+  GEOCOLUMN &amp;&amp; Expand(GeomFromText('POINT(1000 1000)',-1),100)
+AND
+  Distance(GeomFromText('POINT(1000 1000)',-1),GEOCOLUMN) &lt; 100;</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2650056"></a><a name="id2650058"></a><b>3.8.</b></td><td align="left" valign="top"><p>How do I perform a coordinate reprojection as part of a
+          query?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>To perform a reprojection, both the source and destination
+          coordinate systems must be defined in the SPATIAL_REF_SYS table, and
+          the geometries being reprojected must already have an SRID set on
+          them. Once that is done, a reprojection is as simple as referring to
+          the desired destination SRID.</p><pre class="programlisting">SELECT Transform(GEOM,4269) FROM GEOTABLE;</pre></td></tr></tbody></table></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2650088"></a>Chapter 4. Using PostGIS</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#RefObject">4.1. GIS Objects</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2650115">4.1.1. OpenGIS WKB and WKT</a></span></dt><dt><span class="sect2"><a href="#id2650222">4.1.2. PostGIS EWKB, EWKT and Canonical Forms</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2650378">4.2. Using OpenGIS Standards</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2650411">4.2.1. The SPATIAL_REF_SYS Table</a></span></dt><dt><span class="sect2"><a href="#id2650620">4.2.2. The GEOMETRY_COLUMNS Table</a></span></dt><dt><span class="sect2"><a href="#id2650754">4.2.3. Creating a Spatial Table</a></span></dt><dt><span class="sect2"><a href="#id2650861">4.2.4. Ensuring OpenGIS compliancy of geometries</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2650951">4.3. Loading GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2650964">4.3.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2651020">4.3.2. Using the Loader</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2651250">4.4. Retrieving GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2651263">4.4.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2651429">4.4.2. Using the Dumper</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2651607">4.5. Building Indexes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2651660">4.5.1. GiST Indexes</a></span></dt><dt><span class="sect2"><a href="#id2651729">4.5.2. Using Indexes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2651847">4.6. Complex Queries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2651866">4.6.1. Taking Advantage of Indexes</a></span></dt><dt><span class="sect2"><a href="#id2651962">4.6.2. Examples of Spatial SQL</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2652277">4.7. Using Mapserver</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2652320">4.7.1. Basic Usage</a></span></dt><dt><span class="sect2"><a href="#id2652568">4.7.2. Frequently Asked Questions</a></span></dt><dt><span class="sect2"><a href="#id2652735">4.7.3. Advanced Usage</a></span></dt><dt><span class="sect2"><a href="#id2580495">4.7.4. Examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2580593">4.8. Java Clients (JDBC)</a></span></dt><dt><span class="sect1"><a href="#id2653210">4.9. C Clients (libpq)</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2653219">4.9.1. Text Cursors</a></span></dt><dt><span class="sect2"><a href="#id2653229">4.9.2. Binary Cursors</a></span></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="RefObject"></a>4.1. GIS Objects</h2></div></div><div></div></div><p>The GIS objects supported by PostGIS are a superset of
+      the "Simple Features" defined by the OpenGIS Consortium (OGC).
+      As of version 0.9, PostGIS supports all the objects and functions
+      specified in the OGC "Simple Features for SQL" specification.</p><p>PostGIS extends the standard with support for 3DZ,3DM and 4D
+      coordinates.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650115"></a>4.1.1. OpenGIS WKB and WKT</h3></div></div><div></div></div><p>The OpenGIS specification defines two standard ways of
+        expressing spatial objects: the Well-Known Text (WKT) form and
+	the Well-Known Binary (WKB) form. Both WKT and WKB include
+	information about the type of the object and the
+        coordinates which form the object.</p><p>Examples of the text representations (WKT) of the spatial
+      objects of the features are as follows:</p><div class="itemizedlist"><ul type="disc"><li><p>POINT(0 0)</p></li><li><p>LINESTRING(0 0,1 1,1 2)</p></li><li><p>POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))</p></li><li><p>MULTIPOINT(0 0,1 2)</p></li><li><p>MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))</p></li><li><p>MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)),
+	  ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))</p></li><li><p>GEOMETRYCOLLECTION(POINT(2 3),LINESTRING((2 3,3 4)))</p></li></ul></div><p>The OpenGIS specification also requires that the
+        internal storage format of spatial objects include a spatial
+        referencing system identifier (SRID). The SRID is required when
+        creating spatial objects for insertion into the database.</p><p>
+Input/Output of these formats are available using the following
+interfaces:
+</p><pre class="programlisting">
+	bytea WKB = asBinary(geometry);
+	text WKT = asText(geometry);
+	geometry = GeomFromWKB(bytea WKB, SRID); 
+	geometry = GeometryFromText(text WKT, SRID);
+	</pre><p> For example, a valid insert statement to create and insert an OGC spatial object would be:</p><pre class="programlisting">
+	INSERT INTO SPATIALTABLE ( 
+		  THE_GEOM, 
+		  THE_NAME 
+	) 
+	VALUES ( 
+		  GeomFromText('POINT(-126.4 45.32)', 312), 
+		  'A Place' 
+	)</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650222"></a>4.1.2. PostGIS EWKB, EWKT and Canonical Forms</h3></div></div><div></div></div><p>
+OGC formats only support 2d geometries, and the associated SRID
+is *never* embedded in the input/output representations.
+</p><p>
+Postgis extended formats are currently superset of OGC one (every
+valid WKB/WKT is a valid EWKB/EWKT) but this might vary in the
+future, specifically if OGC comes out with a new format conflicting
+with our extensions. Thus you SHOULD NOT rely on this feature!
+</p><p>
+Postgis EWKB/EWKT add 3dm,3dz,4d coordinates support and embedded
+SRID information.
+</p><p>Examples of the text representations (EWKT) of the
+      extended spatial objects of the features are as follows:</p><div class="itemizedlist"><ul type="disc"><li><p>POINT(0 0 0) -- XYZ</p></li><li><p>SRID=32632;POINT(0 0) -- XY with SRID</p></li><li><p>POINTM(0 0 0) -- XYM</p></li><li><p>POINT(0 0 0 0) -- XYZM</p></li><li><p>SRID=4326;MULTIPOINTM(0 0 0,1 2 1) -- XYM with SRID</p></li><li><p>MULTILINESTRING((0 0 0,1 1 0,1 2 1),(2 3 1,3 2 1,5 4
+          1))</p></li><li><p>POLYGON((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2 0,1 2
+          0,1 1 0))</p></li><li><p>MULTIPOLYGON(((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2
+          0,1 2 0,1 1 0)),((-1 -1 0,-1 -2 0,-2 -2 0,-2 -1 0,-1 -1 0)))</p></li><li><p>GEOMETRYCOLLECTIONM(POINTM(2 3 9),LINESTRINGM((2 3 4,3 4
+          5)))</p></li></ul></div><p>
+Input/Output of these formats are available using the following
+interfaces:
+</p><pre class="programlisting">
+	bytea EWKB = asEWKB(geometry);
+	text EWKT = asEWKT(geometry);
+	geometry = GeomFromEWKB(bytea EWKB);
+	geometry = GeomFromEWKT(text EWKT);
+	</pre><p>
+For example, a valid insert statement to create and insert a PostGIS spatial object would be:
+</p><pre class="programlisting">
+	INSERT INTO SPATIALTABLE ( 
+		  THE_GEOM, 
+		  THE_NAME 
+	) 
+	VALUES ( 
+		  GeomFromEWKT('SRID=312;POINTM(-126.4 45.32 15)'), 
+		  'A Place' 
+	)</pre><p>
+The "canonical forms" of a PostgreSQL type are the representations
+you get with a simple query (without any function call) and the one
+which is guaranteed to be accepted with a simple insert, update or
+copy. For the postgis 'geometry' type these are:
+
+	</p><pre class="programlisting">
+	- Output -
+	binary: EWKB
+	 ascii: HEXEWKB (EWKB in hex form)
+
+	- Input -
+	binary: EWKB
+	 ascii: HEXEWKB|EWKT
+	</pre><p>
+</p><p>
+For example this statement reads EWKT and returns HEXEWKB in the
+process of canonical ascii input/output:
+</p><pre class="programlisting">
+	=# SELECT 'SRID=4;POINT(0 0)'::geometry;
+			      geometry
+	----------------------------------------------------
+	 01010000200400000000000000000000000000000000000000
+	(1 row)
+	</pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2650378"></a>4.2. Using OpenGIS Standards</h2></div></div><div></div></div><p>The OpenGIS "Simple Features Specification for SQL" defines
+      standard GIS object types, the functions required to manipulate them,
+      and a set of meta-data tables. In order to ensure that meta-data remain
+      consistent, operations such as creating and removing a spatial column
+      are carried out through special procedures defined by OpenGIS.</p><p>There are two OpenGIS meta-data tables:
+      <tt class="varname">SPATIAL_REF_SYS</tt> and
+      <tt class="varname">GEOMETRY_COLUMNS</tt>. The
+      <tt class="varname">SPATIAL_REF_SYS</tt> table holds the numeric IDs and
+      textual descriptions of coordinate systems used in the spatial
+      database.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650411"></a>4.2.1. The SPATIAL_REF_SYS Table</h3></div></div><div></div></div><p>The <tt class="varname">SPATIAL_REF_SYS</tt> table definition is as
+        follows:</p><pre class="programlisting">CREATE TABLE SPATIAL_REF_SYS ( 
+  SRID INTEGER NOT NULL PRIMARY KEY, 
+  AUTH_NAME VARCHAR(256), 
+  AUTH_SRID INTEGER, 
+  SRTEXT VARCHAR(2048), 
+  PROJ4TEXT VARCHAR(2048)
+)</pre><p>The <tt class="varname">SPATIAL_REF_SYS</tt> columns are as
+        follows:</p><div class="variablelist"><dl><dt><span class="term">SRID</span></dt><dd><p>An integer value that uniquely identifies the Spatial
+              Referencing System (SRS) within the database.</p></dd><dt><span class="term">AUTH_NAME</span></dt><dd><p>The name of the standard or standards body that is being
+              cited for this reference system. For example, "EPSG" would be a
+              valid <tt class="varname">AUTH_NAME</tt>.</p></dd><dt><span class="term">AUTH_SRID</span></dt><dd><p>The ID of the Spatial Reference System as defined by the
+              Authority cited in the <tt class="varname">AUTH_NAME</tt>. In the case
+              of EPSG, this is where the EPSG projection code would go.</p></dd><dt><span class="term">SRTEXT</span></dt><dd><p>The Well-Known Text representation of the Spatial
+              Reference System. An example of a WKT SRS representation
+              is:</p><pre class="programlisting">PROJCS["NAD83 / UTM Zone 10N", 
+  GEOGCS["NAD83",
+    DATUM["North_American_Datum_1983", 
+      SPHEROID["GRS 1980",6378137,298.257222101]
+    ], 
+    PRIMEM["Greenwich",0], 
+    UNIT["degree",0.0174532925199433] 
+  ],
+  PROJECTION["Transverse_Mercator"], 
+  PARAMETER["latitude_of_origin",0],
+  PARAMETER["central_meridian",-123], 
+  PARAMETER["scale_factor",0.9996],
+  PARAMETER["false_easting",500000], 
+  PARAMETER["false_northing",0],
+  UNIT["metre",1] 
+]</pre><p>For a listing of EPSG projection codes and their
+              corresponding WKT representations, see <a href="http://www.opengis.org/techno/interop/EPSG2WKT.TXT" target="_top">http://www.opengis.org/techno/interop/EPSG2WKT.TXT</a>.
+              For a discussion of WKT in general, see the OpenGIS "Coordinate
+              Transformation Services Implementation Specification" at <a href="http://www.opengis.org/techno/specs.htm" target="_top">http://www.opengis.org/techno/specs.htm</a>.
+              For information on the European Petroleum Survey Group (EPSG)
+              and their database of spatial reference systems, see <a href="http://epsg.org" target="_top">http://epsg.org</a>.</p></dd><dt><span class="term">PROJ4TEXT</span></dt><dd><p>PostGIS uses the Proj4 library to provide coordinate
+              transformation capabilities. The <tt class="varname">PROJ4TEXT</tt>
+              column contains the Proj4 coordinate definition string for a
+              particular SRID. For example:</p><pre class="programlisting">+proj=utm +zone=10 +ellps=clrk66 +datum=NAD27 +units=m</pre><p>For more information about, see the Proj4 web site at
+              <a href="http://www.remotesensing.org/proj" target="_top">http://www.remotesensing.org/proj</a>.
+              The <tt class="filename">spatial_ref_sys.sql</tt> file contains both
+              <tt class="varname">SRTEXT</tt> and <tt class="varname">PROJ4TEXT</tt>
+              definitions for all EPSG projections.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650620"></a>4.2.2. The GEOMETRY_COLUMNS Table</h3></div></div><div></div></div><p>The <tt class="varname">GEOMETRY_COLUMNS</tt> table definition is as
+        follows:</p><pre class="programlisting">CREATE TABLE GEOMETRY_COLUMNS ( 
+  F_TABLE_CATALOG VARCHAR(256) NOT NULL, 
+  F_TABLE_SCHEMA VARCHAR(256) NOT NULL, 
+  F_TABLE_NAME VARCHAR(256) NOT NULL, 
+  F_GEOMETRY_COLUMN VARCHAR(256) NOT NULL,
+  COORD_DIMENSION INTEGER NOT NULL, 
+  SRID INTEGER NOT NULL, 
+  TYPE VARCHAR(30) NOT NULL 
+)</pre><p>The columns are as follows:</p><div class="variablelist"><dl><dt><span class="term">F_TABLE_CATALOG, F_TABLE_SCHEMA, F_TABLE_NAME</span></dt><dd><p>The fully qualified name of the feature table containing
+              the geometry column. Note that the terms "catalog" and "schema"
+              are Oracle-ish. There is not PostgreSQL analogue of "catalog" so
+              that column is left blank -- for "schema" the PostgreSQL schema
+              name is used (<tt class="varname">public</tt> is the default).</p></dd><dt><span class="term">F_GEOMETRY_COLUMN</span></dt><dd><p>The name of the geometry column in the feature
+              table.</p></dd><dt><span class="term">COORD_DIMENSION</span></dt><dd><p>The spatial dimension (2, 3 or 4 dimensional) of the
+              column.</p></dd><dt><span class="term">SRID</span></dt><dd><p>The ID of the spatial reference system used for the
+              coordinate geometry in this table. It is a foreign key reference
+              to the <tt class="varname">SPATIAL_REF_SYS</tt>.</p></dd><dt><span class="term">TYPE</span></dt><dd><p>The type of the spatial object. To restrict the spatial
+              column to a single type, use one of: POINT, LINESTRING, POLYGON,
+              MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION or
+	      corresponding XYM versions POINTM, LINESTRINGM, POLYGONM,
+	      MULTIPOINTM, MULTILINESTRINGM, MULTIPOLYGONM, GEOMETRYCOLLECTIONM.
+              For heterogeneous (mixed-type) collections, you can use
+              "GEOMETRY" as the type.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This attribute is (probably) not part of the OpenGIS
+                specification, but is required for ensuring type
+                homogeneity.</p></div></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650754"></a>4.2.3. Creating a Spatial Table</h3></div></div><div></div></div><p>Creating a table with spatial data is done in two stages:</p><div class="itemizedlist"><ul type="disc"><li><p>Create a normal non-spatial table.</p><p>For example: <span><b class="command">CREATE TABLE ROADS_GEOM ( ID int4,
+            NAME varchar(25) )</b></span></p></li><li><p>Add a spatial column to the table using the OpenGIS
+            "AddGeometryColumn" function.</p><p>The syntax is:
+            </p><pre class="programlisting">AddGeometryColumn(&lt;schema_name&gt;, &lt;table_name&gt;,
+            &lt;column_name&gt;, &lt;srid&gt;, &lt;type&gt;,
+            &lt;dimension&gt;)</pre><p>
+
+	    Or, using current schema:
+            </p><pre class="programlisting">AddGeometryColumn(&lt;table_name&gt;,
+            &lt;column_name&gt;, &lt;srid&gt;, &lt;type&gt;,
+            &lt;dimension&gt;)</pre><p>
+	    </p><p>Example1: <span><b class="command">SELECT AddGeometryColumn('public',
+            'roads_geom', 'geom', 423, 'LINESTRING', 2)</b></span></p><p>Example2: <span><b class="command">SELECT AddGeometryColumn(
+            'roads_geom', 'geom', 423, 'LINESTRING', 2)</b></span></p></li></ul></div><p>Here is an example of SQL used to create a table and add a
+        spatial column (assuming that an SRID of 128
+        exists already):</p><pre class="programlisting">CREATE TABLE parks ( PARK_ID int4, PARK_NAME varchar(128), PARK_DATE date, PARK_TYPE varchar(2) );
+SELECT AddGeometryColumn('parks', 'park_geom', 128, 'MULTIPOLYGON', 2 );</pre><p>Here is another example, using the generic "geometry" type and
+        the undefined SRID value of -1:</p><pre class="programlisting">CREATE TABLE roads ( ROAD_ID int4, ROAD_NAME varchar(128) ); 
+SELECT AddGeometryColumn( 'roads', 'roads_geom', -1, 'GEOMETRY', 3 );</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650861"></a>4.2.4. Ensuring OpenGIS compliancy of geometries</h3></div></div><div></div></div><p>Most of the functions implemented by the GEOS library
+	rely on the assumption that your geometries are valid
+        as specified by the OpenGIS Simple Feature Specification.
+	To check validity of geometries you can use the
+	<a href="#IsValid">IsValid()</a> function:</p><pre class="programlisting">gisdb=# select isvalid('LINESTRING(0 0, 1 1)'), isvalid('LINESTRING(0 0,0 0)');
+ isvalid | isvalid
+---------+---------
+ t       | f</pre><p>By default, PostGIS does not apply this validity check on geometry input, because
+        testing for validity needs lots of CPU time for complex geometries, especially polygons.
+        If you do not trust your data sources, you can manually enforce such a check to your tables
+        by adding a check constraint:</p><pre class="programlisting">ALTER TABLE mytable ADD CONSTRAINT geometry_valid_check CHECK (isvalid(the_geom));</pre><p>If you encounter any strange error messages such as "GEOS Intersection() threw an 
+        error!" or "JTS Intersection() threw an error!" when calling PostGIS functions with valid
+        input geometries, you likely found an error in either PostGIS or one of the libraries it
+        uses, and you should contact the PostGIS developers. The same is true if a PostGIS function returns
+        an invalid geometry for valid input.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+	Strictly compliant OGC geometries cannot have Z or M values.
+	The <a href="#IsValid">IsValid()</a> function won't
+	consider higher dimensioned geometries invalid! Invocations
+	of <a href="#AddGeometryColumn">AddGeometryColumn()</a>
+        will add a constraint checking geometry dimensions, so it is
+        enough to specify 2 there.
+	</p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2650951"></a>4.3. Loading GIS Data</h2></div></div><div></div></div><p>Once you have created a spatial table, you are ready to upload GIS
+      data to the database. Currently, there are two ways to get data into a
+      PostGIS/PostgreSQL database: using formatted SQL statements or using the
+      Shape file loader/dumper.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2650964"></a>4.3.1. Using SQL</h3></div></div><div></div></div><p>If you can convert your data to a text representation, then
+        using formatted SQL might be the easiest way to get your data into
+        PostGIS. As with Oracle and other SQL databases, data can be bulk
+        loaded by piping a large text file full of SQL "INSERT" statements
+        into the SQL terminal monitor.</p><p>A data upload file (<tt class="filename">roads.sql</tt> for example)
+        might look like this:</p><pre class="programlisting">BEGIN;
+INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (1,GeomFromText('LINESTRING(191232 243118,191108 243242)',-1),'Jeff Rd'); 
+INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (2,GeomFromText('LINESTRING(189141 244158,189265 244817)',-1),'Geordie Rd'); 
+INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (3,GeomFromText('LINESTRING(192783 228138,192612 229814)',-1),'Paul St'); 
+INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (4,GeomFromText('LINESTRING(189412 252431,189631 259122)',-1),'Graeme Ave'); 
+INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (5,GeomFromText('LINESTRING(190131 224148,190871 228134)',-1),'Phil Tce'); 
+INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES (6,GeomFromText('LINESTRING(198231 263418,198213 268322)',-1),'Dave Cres');
+COMMIT;</pre><p>The data file can be piped into PostgreSQL very easily using the
+        "psql" SQL terminal monitor:</p><pre class="programlisting">psql -d [database] -f roads.sql</pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651020"></a>4.3.2. Using the Loader</h3></div></div><div></div></div><p>The <tt class="filename">shp2pgsql</tt> data loader converts ESRI
+        Shape files into SQL suitable for insertion into a PostGIS/PostgreSQL
+        database. The loader has several operating modes distinguished by
+        command line flags:</p><div class="variablelist"><dl><dt><span class="term">-d</span></dt><dd><p>Drops the database table before creating a new table with
+              the data in the Shape file.</p></dd><dt><span class="term">-a</span></dt><dd><p>Appends data from the Shape file into the database table.
+              Note that to use this option to load multiple files, the files
+              must have the same attributes and same data types.</p></dd><dt><span class="term">-c</span></dt><dd><p>Creates a new table and populates it from the Shape file.
+              <span class="emphasis"><em>This is the default mode.</em></span></p></dd><dt><span class="term">-p</span></dt><dd><p>Only produces the table creation SQL code, without adding 
+              any actual data. This can be used if you need to completely
+              separate the table creation and data loading steps.</p></dd><dt><span class="term">-D</span></dt><dd><p>Use the PostgreSQL "dump" format for the output data. This 
+              can be combined with -a, -c and -d. It is much faster to load
+              than the default "insert" SQL format. Use this for very large data
+              sets.</p></dd><dt><span class="term">-s &lt;SRID&gt;</span></dt><dd><p>Creates and populates the geometry tables with the
+              specified SRID.</p></dd><dt><span class="term">-k</span></dt><dd><p>Keep identifiers' case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.</p></dd><dt><span class="term">-i</span></dt><dd><p>Coerce all integers to standard 32-bit integers, do not
+              create 64-bit bigints, even if the DBF header signature appears
+              to warrant it.</p></dd><dt><span class="term">-I</span></dt><dd><p>Create a GiST index on the geometry column.</p></dd><dt><span class="term">-w</span></dt><dd><p>
+       	      Output WKT format, for use with older (0.x) versions of PostGIS.
+              Note  that this will introduce coordinate drifts and will drop M
+              values from shapefiles.
+              </p></dd><dt><span class="term">-W &lt;encoding&gt;</span></dt><dd><p>
+Specify encoding of the input data (dbf file).
+When used, all attributes of the dbf are converted from the specified
+encoding to UTF8. The resulting SQL output will contain a <tt class="code">SET
+CLIENT_ENCODING to UTF8</tt> command, so that the backend will be able
+to reconvert from UTF8 to whatever encoding the database is configured
+to use internally.
+		</p></dd></dl></div><p>Note that -a, -c, -d and -p are mutually exclusive.</p><p>An example session using the loader to create an input file and
+        uploading it might look like this:</p><pre class="programlisting"># shp2pgsql shaperoads myschema.roadstable &gt; roads.sql 
+# psql -d roadsdb -f roads.sql</pre><p>A conversion and upload can be done all in one step using UNIX
+        pipes:</p><pre class="programlisting"># shp2pgsql shaperoads myschema.roadstable | psql -d roadsdb</pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2651250"></a>4.4. Retrieving GIS Data</h2></div></div><div></div></div><p>Data can be extracted from the database using either SQL or the
+      Shape file loader/dumper. In the section on SQL we will discuss some of
+      the operators available to do comparisons and queries on spatial
+      tables.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651263"></a>4.4.1. Using SQL</h3></div></div><div></div></div><p>The most straightforward means of pulling data out of the
+        database is to use a SQL select query and dump the resulting columns
+        into a parsable text file:</p><pre class="programlisting">db=# SELECT id, AsText(geom) AS geom, name FROM ROADS_GEOM; 
+id | geom                                    | name 
+---+-----------------------------------------+-----------
+ 1 | LINESTRING(191232 243118,191108 243242) | Jeff Rd  
+ 2 | LINESTRING(189141 244158,189265 244817) | Geordie Rd 
+ 3 | LINESTRING(192783 228138,192612 229814) | Paul St 
+ 4 | LINESTRING(189412 252431,189631 259122) | Graeme Ave 
+ 5 | LINESTRING(190131 224148,190871 228134) | Phil Tce 
+ 6 | LINESTRING(198231 263418,198213 268322) | Dave Cres 
+ 7 | LINESTRING(218421 284121,224123 241231) | Chris Way 
+(6 rows)</pre><p>However, there will be times when some kind of restriction is
+        necessary to cut down the number of fields returned. In the case of
+        attribute-based restrictions, just use the same SQL syntax as normal
+        with a non-spatial table. In the case of spatial restrictions, the
+        following operators are available/useful:</p><div class="variablelist"><dl><dt><span class="term">&amp;&amp;</span></dt><dd><p>This operator tells whether the bounding box of one
+              geometry intersects the bounding box of another.</p></dd><dt><span class="term">~=</span></dt><dd><p>This operators tests whether two geometries are
+              geometrically identical. For example, if 'POLYGON((0 0,1 1,1 0,0
+              0))' is the same as 'POLYGON((0 0,1 1,1 0,0 0))' (it is).</p></dd><dt><span class="term">=</span></dt><dd><p>This operator is a little more naive, it only tests
+              whether the bounding boxes of to geometries are the same.</p></dd></dl></div><p>Next, you can use these operators in queries. Note that when
+        specifying geometries and boxes on the SQL command line, you must
+        explicitly turn the string representations into geometries by using
+        the "GeomFromText()" function. So, for example:</p><pre class="programlisting">SELECT 
+  ID, NAME 
+FROM ROADS_GEOM 
+WHERE 
+  GEOM ~= GeomFromText('LINESTRING(191232 243118,191108 243242)',-1);</pre><p>The above query would return the single record from the
+        "ROADS_GEOM" table in which the geometry was equal to that
+        value.</p><p>When using the "&amp;&amp;" operator, you can specify either a
+        BOX3D as the comparison feature or a GEOMETRY. When you specify a
+        GEOMETRY, however, its bounding box will be used for the
+        comparison.</p><pre class="programlisting">SELECT 
+  ID, NAME 
+FROM ROADS_GEOM 
+WHERE 
+  GEOM &amp;&amp; GeomFromText('POLYGON((191232 243117,191232 243119,191234 243117,191232 243117))',-1);</pre><p>The above query will use the bounding box of the polygon for
+        comparison purposes.</p><p>The most common spatial query will probably be a "frame-based"
+        query, used by client software, like data browsers and web mappers, to
+        grab a "map frame" worth of data for display. Using a "BOX3D" object
+        for the frame, such a query looks like this:</p><pre class="programlisting">SELECT 
+  AsText(GEOM) AS GEOM 
+FROM ROADS_GEOM 
+WHERE 
+  GEOM &amp;&amp; SetSRID('BOX3D(191232 243117,191232 243119)'::box3d,-1);</pre><p>Note the use of the SRID, to specify the projection of the
+        BOX3D. The value -1 is used to indicate no specified SRID.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651429"></a>4.4.2. Using the Dumper</h3></div></div><div></div></div><p>The <tt class="filename">pgsql2shp</tt> table dumper connects
+        directly to the database and converts a table (possibly defined by
+	a query) into a shape file. The
+        basic syntax is:</p><pre class="programlisting">pgsql2shp [&lt;options&gt;] &lt;database&gt; [&lt;schema&gt;.]&lt;table&gt;</pre><pre class="programlisting">pgsql2shp [&lt;options&gt;] &lt;database&gt; &lt;query&gt;</pre><p>The commandline options are:</p><div class="variablelist"><dl><dt><span class="term">-f &lt;filename&gt;</span></dt><dd><p>Write the output to a particular filename.</p></dd><dt><span class="term">-h &lt;host&gt;</span></dt><dd><p>The database host to connect to.</p></dd><dt><span class="term">-p &lt;port&gt;</span></dt><dd><p>The port to connect to on the database host.</p></dd><dt><span class="term">-P &lt;password&gt;</span></dt><dd><p>The password to use when connecting to the
+              database.</p></dd><dt><span class="term">-u &lt;user&gt;</span></dt><dd><p>The username to use when connecting to the
+              database.</p></dd><dt><span class="term">-g &lt;geometry column&gt;</span></dt><dd><p>In the case of tables with multiple geometry columns, the
+              geometry column to use when writing the shape file.</p></dd><dt><span class="term">-b</span></dt><dd><p>Use a binary cursor. This will make the operation faster,
+	      but will not work if any NON-geometry attribute in the table
+	      lacks a cast to text.</p></dd><dt><span class="term">-r</span></dt><dd><p>Raw mode. Do not drop the <tt class="varname">gid</tt> field, or
+              escape column names.</p></dd><dt><span class="term">-d</span></dt><dd><p>For backward compatibility: write a 3-dimensional shape
+	      file when dumping from old (pre-1.0.0) postgis databases (the
+	      default is to write a 2-dimensional shape file in that case).
+	      Starting from postgis-1.0.0+, dimensions are fully encoded.
+	      </p></dd></dl></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2651607"></a>4.5. Building Indexes</h2></div></div><div></div></div><p>Indexes are what make using a spatial database for large data sets
+      possible. Without indexing, any search for a feature would require a
+      "sequential scan" of every record in the database. Indexing speeds up
+      searching by organizing the data into a search tree which can be quickly
+      traversed to find a particular record. PostgreSQL supports three kinds
+      of indexes by default: B-Tree indexes, R-Tree indexes, and GiST
+      indexes.</p><div class="itemizedlist"><ul type="disc"><li><p>B-Trees are used for data which can be sorted along one axis;
+          for example, numbers, letters, dates. GIS data cannot be rationally
+          sorted along one axis (which is greater, (0,0) or (0,1) or (1,0)?)
+          so B-Tree indexing is of no use for us.</p></li><li><p>R-Trees break up data into rectangles, and sub-rectangles, and
+          sub-sub rectangles, etc. R-Trees are used by some spatial databases
+          to index GIS data, but the PostgreSQL R-Tree implementation is not
+          as robust as the GiST implementation.</p></li><li><p>GiST (Generalized Search Trees) indexes break up data into
+          "things to one side", "things which overlap", "things which are
+          inside" and can be used on a wide range of data-types, including GIS
+          data. PostGIS uses an R-Tree index implemented on top of GiST to
+          index GIS data.</p></li></ul></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651660"></a>4.5.1. GiST Indexes</h3></div></div><div></div></div><p>GiST stands for "Generalized Search Tree" and is a generic form
+        of indexing. In addition to GIS indexing, GiST is used to speed up
+        searches on all kinds of irregular data structures (integer arrays,
+        spectral data, etc) which are not amenable to normal B-Tree
+        indexing.</p><p>Once a GIS data table exceeds a few thousand rows, you will want
+        to build an index to speed up spatial searches of the data (unless all
+        your searches are based on attributes, in which case you'll want to
+        build a normal index on the attribute fields).</p><p>The syntax for building a GiST index on a "geometry" column is
+        as follows:</p><pre class="programlisting">CREATE INDEX [indexname] ON [tablename] 
+  USING GIST ( [geometryfield] GIST_GEOMETRY_OPS ); </pre><p>Building a spatial index is a computationally intensive
+        exercise: on tables of around 1 million rows, on a 300MHz Solaris
+        machine, we have found building a GiST index takes about 1 hour. After
+        building an index, it is important to force PostgreSQL to collect
+        table statistics, which are used to optimize query plans:</p><pre class="programlisting">VACUUM ANALYZE [table_name] [column_name];
+
+-- This is only needed for PostgreSQL 7.4 installations and below
+SELECT UPDATE_GEOMETRY_STATS([table_name], [column_name]);</pre><p>GiST indexes have two advantages over R-Tree indexes in
+        PostgreSQL. Firstly, GiST indexes are "null safe", meaning they can
+        index columns which include null values. Secondly, GiST indexes
+        support the concept of "lossiness" which is important when dealing
+        with GIS objects larger than the PostgreSQL 8K page size. Lossiness
+        allows PostgreSQL to store only the "important" part of an object in
+        an index -- in the case of GIS objects, just the bounding box. GIS
+        objects larger than 8K will cause R-Tree indexes to fail in the
+        process of being built.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651729"></a>4.5.2. Using Indexes</h3></div></div><div></div></div><p>Ordinarily, indexes invisibly speed up data access: once the
+        index is built, the query planner transparently decides when to use
+        index information to speed up a query plan. Unfortunately, the
+        PostgreSQL query planner does not optimize the use of GiST indexes
+        well, so sometimes searches which should use a spatial index instead
+        default to a sequence scan of the whole table.</p><p>If you find your spatial indexes are not being used (or your
+        attribute indexes, for that matter) there are a couple things you can
+        do:</p><div class="itemizedlist"><ul type="disc"><li><p>Firstly, make sure statistics are gathered about the number
+            and distributions of values in a table, to provide the query
+            planner with better information to make decisions around index
+            usage. For PostgreSQL 7.4 installations and below this is done by
+            running <span><b class="command">update_geometry_stats([table_name,
+            column_name])</b></span> (compute distribution) and <span><b class="command">VACUUM
+            ANALYZE [table_name] [column_name]</b></span> (compute number of
+            values). Starting with PostgreSQL 8.0 running <span><b class="command">VACUUM
+            ANALYZE</b></span> will do both operations. You should regularly
+            vacuum your databases anyways -- many PostgreSQL DBAs have
+            <span><b class="command">VACUUM</b></span> run as an off-peak cron job on a regular
+            basis.</p></li><li><p>If vacuuming does not work, you can force the planner to use
+            the index information by using the <span><b class="command">SET
+            ENABLE_SEQSCAN=OFF</b></span> command. You should only use this
+            command sparingly, and only on spatially indexed queries:
+            generally speaking, the planner knows better than you do about
+            when to use normal B-Tree indexes. Once you have run your query,
+            you should consider setting <tt class="varname">ENABLE_SEQSCAN</tt> back
+            on, so that other queries will utilize the planner as
+            normal.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>As of version 0.6, it should not be necessary to force the
+              planner to use the index with
+              <tt class="varname">ENABLE_SEQSCAN</tt>.</p></div></li><li><p>If you find the planner wrong about the cost of sequential
+            vs index scans try reducing the value of random_page_cost in
+            postgresql.conf or using SET random_page_cost=#. Default value for
+            the parameter is 4, try setting it to 1 or 2. Decrementing the
+            value makes the planner more inclined of using Index scans.</p></li></ul></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2651847"></a>4.6. Complex Queries</h2></div></div><div></div></div><p>The <span class="emphasis"><em>raison d'etre</em></span> of spatial database
+      functionality is performing queries inside the database which would
+      ordinarily require desktop GIS functionality. Using PostGIS effectively
+      requires knowing what spatial functions are available, and ensuring that
+      appropriate indexes are in place to provide good performance.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651866"></a>4.6.1. Taking Advantage of Indexes</h3></div></div><div></div></div><p>When constructing a query it is important to remember that only
+        the bounding-box-based operators such as &amp;&amp; can take advantage
+        of the GiST spatial index. Functions such as
+        <tt class="varname">distance()</tt> cannot use the index to optimize their
+        operation. For example, the following query would be quite slow on a
+        large table:</p><pre class="programlisting">SELECT the_geom FROM geom_table
+WHERE distance( the_geom, GeomFromText( 'POINT(100000 200000)', -1 ) ) &lt; 100</pre><p>This query is selecting all the geometries in geom_table which
+        are within 100 units of the point (100000, 200000). It will be slow
+        because it is calculating the distance between each point in the table
+        and our specified point, ie. one <tt class="varname">distance()</tt>
+        calculation for each row in the table. We can avoid this by using the
+        &amp;&amp; operator to reduce the number of distance calculations
+        required:</p><pre class="programlisting">SELECT the_geom FROM geom_table
+WHERE the_geom &amp;&amp; 'BOX3D(90900 190900, 100100 200100)'::box3d
+  AND distance( the_geom, GeomFromText( 'POINT(100000 200000)', -1 ) ) &lt; 100</pre><p>This query selects the same geometries, but it does it in a more
+        efficient way. Assuming there is a GiST index on the_geom, the query
+        planner will recognize that it can use the index to reduce the number
+        of rows before calculating the result of the
+        <tt class="varname">distance()</tt> function. Notice that the
+        <tt class="varname">BOX3D</tt> geometry which is used in the &amp;&amp;
+        operation is a 200 unit square box centered on the original point -
+        this is our "query box". The &amp;&amp; operator uses the index to
+        quickly reduce the result set down to only those geometries which have
+        bounding boxes that overlap the "query box". Assuming that our query
+        box is much smaller than the extents of the entire geometry table,
+        this will drastically reduce the number of distance calculations that
+        need to be done.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2651962"></a>4.6.2. Examples of Spatial SQL</h3></div></div><div></div></div><p>The examples in this section will make use of two tables, a
+        table of linear roads, and a table of polygonal municipality
+        boundaries. The table definitions for the <tt class="varname">bc_roads</tt>
+        table is:</p><pre class="programlisting">  Column    |       Type        |   Description
+------------+-------------------+-------------------
+ gid        | integer           | Unique ID
+ name       | character varying | Road Name
+ the_geom   | geometry          | Location Geometry (Linestring)</pre><p>The table definition for the <tt class="varname">bc_municipality</tt>
+        table is:</p><pre class="programlisting">  Column   |       Type        |   Description
+-----------+-------------------+-------------------
+ gid       | integer           | Unique ID
+ code      | integer           | Unique ID
+ name      | character varying | City / Town Name
+ the_geom  | geometry          | Location Geometry (Polygon)</pre><div class="qandaset"><dl><dt>4.6.2.1. <a href="#id2652008">What is the total length of all roads, expressed in
+                kilometers?</a></dt><dt>4.6.2.2. <a href="#id2652035">How large is the city of Prince George, in
+                hectares?</a></dt><dt>4.6.2.3. <a href="#id2652064">What is the largest municipality in the province, by
+                area?</a></dt><dt>4.6.2.4. <a href="#id2652106">What is the length of roads fully contained within each
+                municipality?</a></dt><dt>4.6.2.5. <a href="#id2652168">Create a new table with all the roads within the city of
+                Prince George.</a></dt><dt>4.6.2.6. <a href="#id2652207">What is the length in kilometers of "Douglas St" in
+                Victoria?</a></dt><dt>4.6.2.7. <a href="#id2652241">What is the largest municipality polygon that has a
+                hole?</a></dt></dl><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="question"><td align="left" valign="top"><a name="id2652008"></a><a name="id2652010"></a><b>4.6.2.1.</b></td><td align="left" valign="top"><p>What is the total length of all roads, expressed in
+                kilometers?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>You can answer this question with a very simple piece of
+                SQL:</p><pre class="programlisting">postgis=# SELECT sum(length(the_geom))/1000 AS km_roads FROM bc_roads;
+     km_roads
+------------------
+ 70842.1243039643
+(1 row)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652035"></a><a name="id2652038"></a><b>4.6.2.2.</b></td><td align="left" valign="top"><p>How large is the city of Prince George, in
+                hectares?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This query combines an attribute condition (on the
+                municipality name) with a spatial calculation (of the
+                area):</p><pre class="programlisting">postgis=# SELECT area(the_geom)/10000 AS hectares FROM bc_municipality 
+          WHERE name = 'PRINCE GEORGE';
+     hectares
+------------------
+ 32657.9103824927
+(1 row) </pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652064"></a><a name="id2652066"></a><b>4.6.2.3.</b></td><td align="left" valign="top"><p>What is the largest municipality in the province, by
+                area?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This query brings a spatial measurement into the query
+                condition. There are several ways of approaching this problem,
+                but the most efficient is below:</p><pre class="programlisting">postgis=# SELECT name, area(the_geom)/10000 AS hectares 
+          FROM bc_municipality 
+          ORDER BY hectares DESC 
+          LIMIT 1;
+     name      |    hectares
+---------------+-----------------
+ TUMBLER RIDGE | 155020.02556131
+(1 row)</pre><p>Note that in order to answer this query we have to
+                calculate the area of every polygon. If we were doing this a
+                lot it would make sense to add an area column to the table
+                that we could separately index for performance. By ordering
+                the results in a descending direction, and them using the
+                PostgreSQL "LIMIT" command we can easily pick off the largest
+                value without using an aggregate function like max().</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652106"></a><a name="id2652108"></a><b>4.6.2.4.</b></td><td align="left" valign="top"><p>What is the length of roads fully contained within each
+                municipality?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This is an example of a "spatial join", because we are
+                bringing together data from two tables (doing a join) but
+                using a spatial interaction condition ("contained") as the
+                join condition rather than the usual relational approach of
+                joining on a common key:</p><pre class="programlisting">postgis=# SELECT m.name, sum(length(r.the_geom))/1000 as roads_km 
+          FROM bc_roads AS r,bc_municipality AS m 
+          WHERE r.the_geom &amp;&amp; m.the_geom 
+          AND contains(m.the_geom,r.the_geom) 
+          GROUP BY m.name 
+          ORDER BY roads_km;
+
+            name            |     roads_km
+----------------------------+------------------
+ SURREY                     | 1539.47553551242
+ VANCOUVER                  | 1450.33093486576
+ LANGLEY DISTRICT           | 833.793392535662
+ BURNABY                    | 773.769091404338
+ PRINCE GEORGE              |  694.37554369147
+ ...</pre><p>This query takes a while, because every road in the
+                table is summarized into the final result (about 250K roads
+                for our particular example table). For smaller overlays
+                (several thousand records on several hundred) the response can
+                be very fast.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652168"></a><a name="id2652170"></a><b>4.6.2.5.</b></td><td align="left" valign="top"><p>Create a new table with all the roads within the city of
+                Prince George.</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>This is an example of an "overlay", which takes in two
+                tables and outputs a new table that consists of spatially
+                clipped or cut resultants. Unlike the "spatial join"
+                demonstrated above, this query actually creates new
+                geometries. An overlay is like a turbo-charged spatial join,
+                and is useful for more exact analysis work:</p><pre class="programlisting">postgis=# CREATE TABLE pg_roads as
+          SELECT intersection(r.the_geom, m.the_geom) AS intersection_geom, 
+                 length(r.the_geom) AS rd_orig_length, 
+                 r.* 
+          FROM bc_roads AS r, bc_municipality AS m 
+          WHERE r.the_geom &amp;&amp; m.the_geom 
+          AND intersects(r.the_geom, m.the_geom) 
+          AND m.name = 'PRINCE GEORGE';</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652207"></a><a name="id2652209"></a><b>4.6.2.6.</b></td><td align="left" valign="top"><p>What is the length in kilometers of "Douglas St" in
+                Victoria?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><pre class="programlisting">postgis=# SELECT sum(length(r.the_geom))/1000 AS kilometers 
+          FROM bc_roads r, bc_municipality m 
+          WHERE r.the_geom &amp;&amp; m.the_geom 
+          AND r.name = 'Douglas St' 
+          AND m.name = 'VICTORIA';
+    kilometers
+------------------
+ 4.89151904172838
+(1 row)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652241"></a><a name="id2652243"></a><b>4.6.2.7.</b></td><td align="left" valign="top"><p>What is the largest municipality polygon that has a
+                hole?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><pre class="programlisting">postgis=# SELECT gid, name, area(the_geom) AS area 
+          FROM bc_municipality 
+          WHERE nrings(the_geom) &gt; 1 
+          ORDER BY area DESC LIMIT 1;
+ gid |     name     |       area
+-----+--------------+------------------
+  12 | SPALLUMCHEEN | 257374619.430216
+(1 row)</pre></td></tr></tbody></table></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2652277"></a>4.7. Using Mapserver</h2></div></div><div></div></div><p>The Minnesota Mapserver is an internet web-mapping server which
+      conforms to the OpenGIS Web Mapping Server specification.</p><div class="itemizedlist"><ul type="disc"><li><p>The Mapserver homepage is at <a href="http://mapserver.gis.umn.edu" target="_top">http://mapserver.gis.umn.edu</a>.</p></li><li><p>The OpenGIS Web Map Specification is at <a href="http://www.opengis.org/techno/specs/01-047r2.pdf" target="_top">http://www.opengis.org/techno/specs/01-047r2.pdf</a>.</p></li></ul></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2652320"></a>4.7.1. Basic Usage</h3></div></div><div></div></div><p>To use PostGIS with Mapserver, you will need to know about how
+        to configure Mapserver, which is beyond the scope of this
+        documentation. This section will cover specific PostGIS issues and
+        configuration details.</p><p>To use PostGIS with Mapserver, you will need:</p><div class="itemizedlist"><ul type="disc"><li><p>Version 0.6 or newer of PostGIS.</p></li><li><p>Version 3.5 or newer of Mapserver.</p></li></ul></div><p>Mapserver accesses PostGIS/PostgreSQL data like any other
+        PostgreSQL client -- using <tt class="filename">libpq</tt>. This means that
+        Mapserver can be installed on any machine with network access to the
+        PostGIS server, as long as the system has the
+        <tt class="filename">libpq</tt> PostgreSQL client libraries.</p><div class="orderedlist"><ol type="1"><li><p>Compile and install Mapserver, with whatever options you
+            desire, including the "--with-postgis" configuration
+            option.</p></li><li><p>In your Mapserver map file, add a PostGIS layer. For
+            example:</p><pre class="programlisting">LAYER
+  CONNECTIONTYPE postgis
+  NAME "widehighways"
+  # Connect to a remote spatial database
+  CONNECTION "user=dbuser dbname=gisdatabase host=bigserver"
+  # Get the lines from the 'geom' column of the 'roads' table
+  DATA "geom from roads"
+  STATUS ON
+  TYPE LINE
+  # Of the lines in the extents, only render the wide highways
+  FILTER "type = 'highway' and numlanes &gt;= 4"
+  CLASS
+    # Make the superhighways brighter and 2 pixels wide
+    EXPRESSION ([numlanes] &gt;= 6)
+    COLOR 255 22 22      
+    SYMBOL "solid"
+    SIZE 2
+  END
+  CLASS
+    # All the rest are darker and only 1 pixel wide
+    EXPRESSION ([numlanes] &lt; 6)
+    COLOR 205 92 82      
+  END
+END</pre><p>In the example above, the PostGIS-specific directives are as
+            follows:</p><div class="variablelist"><dl><dt><span class="term">CONNECTIONTYPE</span></dt><dd><p>For PostGIS layers, this is always "postgis".</p></dd><dt><span class="term">CONNECTION</span></dt><dd><p>The database connection is governed by the a
+                  'connection string' which is a standard set of keys and
+                  values like this (with the default values in
+                  &lt;&gt;):</p><p>user=&lt;username&gt; password=&lt;password&gt;
+                  dbname=&lt;username&gt; hostname=&lt;server&gt;
+                  port=&lt;5432&gt;</p><p>An empty connection string is still valid, and any of
+                  the key/value pairs can be omitted. At a minimum you will
+                  generally supply the database name and username to connect
+                  with.</p></dd><dt><span class="term">DATA</span></dt><dd><p>The form of this parameter is "&lt;column&gt; from
+                  &lt;tablename&gt;" where the column is the spatial column to
+                  be rendered to the map.</p></dd><dt><span class="term">FILTER</span></dt><dd><p>The filter must be a valid SQL string corresponding to
+                  the logic normally following the "WHERE" keyword in a SQL
+                  query. So, for example, to render only roads with 6 or more
+                  lanes, use a filter of "num_lanes &gt;= 6".</p></dd></dl></div></li><li><p>In your spatial database, ensure you have spatial (GiST)
+            indexes built for any the layers you will be drawing.</p><pre class="programlisting">CREATE INDEX [indexname]
+  ON [tablename] 
+  USING GIST ( [geometrycolumn] GIST_GEOMETRY_OPS );</pre></li><li><p>If you will be querying your layers using Mapserver you will
+            also need an "oid index".</p><p>Mapserver requires unique identifiers for each spatial
+            record when doing queries, and the PostGIS module of Mapserver
+            uses the PostgreSQL <tt class="varname">oid</tt> value to provide these
+            unique identifiers. A side-effect of this is that in order to do
+            fast random access of records during queries, an index on the
+            <tt class="varname">oid</tt> is needed.</p><p>To build an "oid index", use the following SQL:</p><pre class="programlisting">CREATE INDEX [indexname] ON [tablename] ( oid );</pre></li></ol></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2652568"></a>4.7.2. Frequently Asked Questions</h3></div></div><div></div></div><div class="qandaset"><dl><dt>4.7.2.1. <a href="#id2652576">When I use an EXPRESSION in my map
+                file, the condition never returns as true, even though I know
+                the values exist in my table.</a></dt><dt>4.7.2.2. <a href="#id2652610">The FILTER I use for my Shape files is not working for
+                my PostGIS table of the same data.</a></dt><dt>4.7.2.3. <a href="#id2652639">My PostGIS layer draws much slower than my Shape file
+                layer, is this normal?</a></dt><dt>4.7.2.4. <a href="#id2652677">My PostGIS layer draws fine, but queries are really
+                slow. What is wrong?</a></dt></dl><table border="0" summary="Q and A Set"><col align="left" width="1%"><tbody><tr class="question"><td align="left" valign="top"><a name="id2652576"></a><a name="id2652578"></a><b>4.7.2.1.</b></td><td align="left" valign="top"><p>When I use an <tt class="varname">EXPRESSION</tt> in my map
+                file, the condition never returns as true, even though I know
+                the values exist in my table.</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Unlike shape files, PostGIS field names have to be
+                referenced in EXPRESSIONS using <span class="emphasis"><em>lower
+                case</em></span>.</p><pre class="programlisting">EXPRESSION ([numlanes] &gt;= 6)</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652610"></a><a name="id2652612"></a><b>4.7.2.2.</b></td><td align="left" valign="top"><p>The FILTER I use for my Shape files is not working for
+                my PostGIS table of the same data.</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>Unlike shape files, filters for PostGIS layers use SQL
+                syntax (they are appended to the SQL statement the PostGIS
+                connector generates for drawing layers in Mapserver).</p><pre class="programlisting">FILTER "type = 'highway' and numlanes &gt;= 4"</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652639"></a><a name="id2652641"></a><b>4.7.2.3.</b></td><td align="left" valign="top"><p>My PostGIS layer draws much slower than my Shape file
+                layer, is this normal?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>In general, expect PostGIS layers to be 10% slower than
+                equivalent Shape files layers, due to the extra overhead
+                involved in database connections, data transformations and
+                data transit between the database and Mapserver.</p><p>If you are finding substantial draw performance
+                problems, it is likely that you have not build a spatial index
+                on your table.</p><pre class="programlisting">postgis# CREATE INDEX geotable_gix ON geotable USING GIST ( geocolumn );
+postgis# SELECT update_geometry_stats();  -- For PGSQL &lt; 8.0
+postgis# VACUUM ANALYZE;                  -- For PGSQL &gt;= 8.0</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="id2652677"></a><a name="id2652679"></a><b>4.7.2.4.</b></td><td align="left" valign="top"><p>My PostGIS layer draws fine, but queries are really
+                slow. What is wrong?</p></td></tr><tr class="answer"><td align="left" valign="top"><b></b></td><td align="left" valign="top"><p>For queries to be fast, you must have a unique key for
+                your spatial table and you must have an index on that unique
+                key.</p><p>You can specify what unique key for mapserver to use
+                with the <tt class="varname">USING UNIQUE</tt> clause in your
+                <tt class="varname">DATA</tt> line:</p><pre class="programlisting">DATA "the_geom FROM geotable USING UNIQUE gid"</pre><p>If your table does not have an explicit unique column,
+                you can "fake" a unique column by using the PostgreSQL row
+                "oid" for your unique column. "oid" is the default unique
+                column if you do not declare one, so enhancing your query
+                speed is a matter of building an index on your spatial table
+                oid value.</p><pre class="programlisting">postgis# CREATE INDEX geotable_oid_idx ON geotable (oid);</pre></td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2652735"></a>4.7.3. Advanced Usage</h3></div></div><div></div></div><p>The <tt class="varname">USING</tt> pseudo-SQL clause is used to add
+        some information to help mapserver understand the results of more
+        complex queries. More specifically, when either a view or a subselect
+        is used as the source table (the thing to the right of "FROM" in a
+        <tt class="varname">DATA</tt> definition) it is more difficult for mapserver
+        to automatically determine a unique identifier for each row and also
+        the SRID for the table. The <tt class="varname">USING</tt> clause can
+        provide mapserver with these two pieces of information as
+        follows:</p><pre class="programlisting">DATA "the_geom FROM (SELECT table1.the_geom AS the_geom, table1.oid AS oid, table2.data AS data
+ FROM table1 LEFT JOIN table2 ON table1.id = table2.id) AS new_table USING UNIQUE oid USING SRID=-1"</pre><div class="variablelist"><dl><dt><span class="term">USING UNIQUE &lt;uniqueid&gt;</span></dt><dd><p>Mapserver requires a unique id for each row in order to
+              identify the row when doing map queries. Normally, it would use
+              the oid as the unique identifier, but views and subselects don't
+              automatically have an oid column. If you want to use Mapserver's
+              query functionality, you need to add a unique column to your
+              view or subselect, and declare it with <tt class="varname">USING
+              UNIQUE</tt>. For example, you could explicitly select one
+              of the table's oid values for this purpose, or any other column
+              which is guaranteed to be unique for the result set.</p><p>The <tt class="varname">USING</tt> statement can also be useful
+              even for simple <tt class="varname">DATA</tt> statements, if you are
+              doing map queries. It was previously recommended to add an index
+              on the oid column of tables used in query-able layers, in order
+              to speed up the performance of map queries. However, with the
+              <tt class="varname">USING</tt> clause, it is possible to tell
+              mapserver to use your table's primary key as the identifier for
+              map queries, and then it is no longer necessary to have an
+              additional index.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>"Querying a Map" is the action of clicking on a map to
+                ask for information about the map features in that location.
+                Don't confuse "map queries" with the SQL query in a
+                <tt class="varname">DATA</tt> definition.</p></div></dd><dt><span class="term">USING SRID=&lt;srid&gt;</span></dt><dd><p>PostGIS needs to know which spatial referencing system is
+              being used by the geometries in order to return the correct data
+              back to mapserver. Normally it is possible to find this
+              information in the "geometry_columns" table in the PostGIS
+              database, however, this is not possible for tables which are
+              created on the fly such as subselects and views. So the
+              <tt class="varname">USING SRID=</tt> option allows the correct SRID to
+              be specified in the <tt class="varname">DATA</tt> definition.</p></dd></dl></div><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>The parser for Mapserver PostGIS layers is fairly primitive,
+          and is case sensitive in a few areas. Be careful to ensure that all
+          SQL keywords and all your <tt class="varname">USING</tt> clauses are in
+          upper case, and that your <tt class="varname">USING UNIQUE</tt> clause
+          precedes your <tt class="varname">USING SRID</tt> clause.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2580495"></a>4.7.4. Examples</h3></div></div><div></div></div><p>Lets start with a simple example and work our way up. Consider
+        the following Mapserver layer definition:</p><pre class="programlisting">LAYER
+ CONNECTIONTYPE postgis
+ NAME "roads"
+ CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
+ DATA "the_geom FROM roads"
+ STATUS ON
+ TYPE LINE
+ CLASS
+  COLOR 0 0 0
+ END
+END</pre><p>This layer will display all the road geometries in the roads
+        table as black lines.</p><p>Now lets say we want to show only the highways until we get
+        zoomed in to at least a 1:100000 scale - the next two layers will
+        achieve this effect:</p><pre class="programlisting">LAYER
+ CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
+ DATA "the_geom FROM roads"
+ MINSCALE 100000
+ STATUS ON
+ TYPE LINE
+ FILTER "road_type = 'highway'"
+ CLASS
+  COLOR 0 0 0
+ END
+END
+
+LAYER
+ CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
+ DATA "the_geom FROM roads"
+ MAXSCALE 100000
+ STATUS ON
+ TYPE LINE
+ CLASSITEM road_type
+ CLASS
+  EXPRESSION "highway"
+  SIZE 2
+  COLOR 255 0 0
+ END
+ CLASS
+  COLOR 0 0 0
+ END
+END</pre><p>The first layer is used when the scale is greater than 1:100000,
+        and displays only the roads of type "highway" as black lines. The
+        <tt class="varname">FILTER</tt> option causes only roads of type "highway"
+        to be displayed.</p><p>The second layer is used when the scale is less than 1:100000,
+        and will display highways as double-thick red lines, and other roads
+        as regular black lines.</p><p>So, we have done a couple of interesting things using only
+        mapserver functionality, but our <tt class="varname">DATA</tt> SQL statement
+        has remained simple. Suppose that the name of the road is stored in
+        another table (for whatever reason) and we need to do a join to get it
+        and label our roads.</p><pre class="programlisting">LAYER
+ CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
+ DATA "the_geom FROM (SELECT roads.oid AS oid, roads.the_geom AS the_geom, road_names.name as name
+   FROM roads LEFT JOIN road_names ON roads.road_name_id = road_names.road_name_id) AS named_roads
+   USING UNIQUE oid USING SRID=-1"
+ MAXSCALE 20000
+ STATUS ON
+ TYPE ANNOTATION
+ LABELITEM name
+ CLASS
+  LABEL
+   ANGLE auto
+   SIZE 8
+   COLOR 0 192 0
+   TYPE truetype
+   FONT arial
+  END
+ END
+END</pre><p>This annotation layer adds green labels to all the roads when
+        the scale gets down to 1:20000 or less. It also demonstrates how to
+        use an SQL join in a <tt class="varname">DATA</tt> definition.</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2580593"></a>4.8. Java Clients (JDBC)</h2></div></div><div></div></div><p>Java clients can access PostGIS "geometry" objects in the
+      PostgreSQL database either directly as text representations or using the
+      JDBC extension objects bundled with PostGIS. In order to use the
+      extension objects, the "postgis.jar" file must be in your CLASSPATH
+      along with the "postgresql.jar" JDBC driver package.</p><pre class="programlisting">import java.sql.*; 
+import java.util.*; 
+import java.lang.*; 
+import org.postgis.*; 
+
+public class JavaGIS { 
+  public static void main(String[] args) 
+  { 
+    java.sql.Connection conn; 
+    try 
+    { 
+      /* 
+      * Load the JDBC driver and establish a connection. 
+      */  
+      Class.forName("org.postgresql.Driver"); 
+      String url = "jdbc:postgresql://localhost:5432/database"; 
+      conn = DriverManager.getConnection(url, "postgres", ""); 
+    
+      /* 
+      * Add the geometry types to the connection. Note that you 
+      * must cast the connection to the pgsql-specific connection * implementation before calling the addDataType() method. 
+      */
+      ((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
+      ((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
+
+      /* 
+      * Create a statement and execute a select query. 
+      */ 
+      Statement s = conn.createStatement(); 
+      ResultSet r = s.executeQuery("select AsText(geom) as geom,id from geomtable"); 
+      while( r.next() ) 
+      { 
+        /* 
+        * Retrieve the geometry as an object then cast it to the geometry type. 
+        * Print things out. 
+        */ 
+        PGgeometry geom = (PGgeometry)r.getObject(1); 
+        int id = r.getInt(2);
+        System.out.println("Row " + id + ":"); 
+        System.out.println(geom.toString()); 
+      }
+      s.close(); 
+      conn.close(); 
+    } 
+    catch( Exception e ) 
+    { 
+      e.printStackTrace(); 
+    }  
+  }
+}</pre><p>The "PGgeometry" object is a wrapper object which contains a
+      specific topological geometry object (subclasses of the abstract class
+      "Geometry") depending on the type: Point, LineString, Polygon,
+      MultiPoint, MultiLineString, MultiPolygon.</p><pre class="programlisting">PGgeometry geom = (PGgeometry)r.getObject(1); 
+if( geom.getType() = Geometry.POLYGON ) 
+{ 
+  Polygon pl = (Polygon)geom.getGeometry();
+  for( int r = 0; r &lt; pl.numRings(); r++ ) 
+  { 
+    LinearRing rng = pl.getRing(r);
+    System.out.println("Ring: " + r); 
+    for( int p = 0; p &lt; rng.numPoints(); p++ ) 
+    { 
+      Point pt = rng.getPoint(p); 
+      System.out.println("Point: " + p);
+      System.out.println(pt.toString()); 
+    } 
+  } 
+}</pre><p>The JavaDoc for the extension objects provides a reference for the
+      various data accessor functions in the geometric objects.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2653210"></a>4.9. C Clients (libpq)</h2></div></div><div></div></div><p>...</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653219"></a>4.9.1. Text Cursors</h3></div></div><div></div></div><p>...</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653229"></a>4.9.2. Binary Cursors</h3></div></div><div></div></div><p>...</p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2653241"></a>Chapter 5. Performance tips</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#id2653247">5.1. Small tables of large geometries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2653253">5.1.1. Problem description</a></span></dt><dt><span class="sect2"><a href="#id2653305">5.1.2. Workarounds</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2653365">5.2. CLUSTERing on geometry indices</a></span></dt><dt><span class="sect1"><a href="#id2653421">5.3. Avoiding dimension conversion</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2653247"></a>5.1. Small tables of large geometries</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653253"></a>5.1.1. Problem description</h3></div></div><div></div></div><p>
+Current PostgreSQL versions (including 8.0) suffer from a query
+optimizer weakness regarding TOAST tables. TOAST tables are a kind of
+"extension room" used to store large (in the sense of data size) values
+that do not fit into normal data pages (like long texts, images or
+complex geometries with lots of vertices), see
+http://www.postgresql.org/docs/8.0/static/storage-toast.html for more
+information).
+</p><p>
+The problem appears if you happen to have a table with rather large
+geometries, but not too much rows of them (like a table containing the
+boundaries of all European countries in high resolution). Then the table
+itself is small, but it uses lots of TOAST space. In our example case,
+the table itself had about 80 rows and used only 3 data pages, but the
+TOAST table used 8225 pages.
+</p><p>
+Now issue a query where you use the geometry operator &amp;&amp; to search for a
+bounding box that matches only very few of those rows. Now the query
+optimizer sees that the table has only 3 pages and 80 rows. He estimates
+that a sequential scan on such a small table is much faster than using
+an index. And so he decides to ignore the GIST index. Usually, this
+estimation is correct. But in our case, the &amp;&amp; operator has to fetch
+every geometry from disk to compare the bounding boxes, thus reading all
+TOAST pages, too.
+</p><p>
+To see whether your suffer from this bug, use the "EXPLAIN ANALYZE"
+postgresql command. For more information and the technical details, you
+can read the thread on the postgres performance mailing list:
+http://archives.postgresql.org/pgsql-performance/2005-02/msg00030.php
+</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653305"></a>5.1.2. Workarounds</h3></div></div><div></div></div><p>
+The PostgreSQL people are trying to solve this issue by making the query
+estimation TOAST-aware. For now, here are two workarounds:
+</p><p>
+The first workaround is to force the query planner to use the index.
+Send "SET enable_seqscan TO off;" to the server before issuing the
+query. This basically forces the query planner to avoid sequential scans
+whenever possible. So it uses the GIST index as usual. But this flag has
+to be set on every connection, and it causes the query planner to make
+misestimations in other cases, so you should "SET enable_seqscan TO on;"
+after the query.
+</p><p>
+The second workaround is to make the sequential scan as fast as the
+query planner thinks. This can be achieved by creating an additional
+column that "caches" the bbox, and matching against this. In our
+example, the commands are like:
+</p><pre class="programlisting">
+SELECT addGeometryColumn('myschema','mytable','bbox','4326','GEOMETRY','2');
+
+UPDATE mytable set bbox = Envelope(Force_2d(the_geom));
+</pre><p>
+Now change your query to use the &amp;&amp; operator against bbox instead of
+geom_column, like:
+</p><pre class="programlisting">
+SELECT geom_column FROM mytable WHERE bbox &amp;&amp; SetSrid('BOX3D(0 0,1 1)'::box3d,4326);
+</pre><p>
+Of course, if you change or add rows to mytable, you have to keep the
+bbox "in sync". The most transparent way to do this would be triggers,
+but you also can modify your application to keep the bbox column current
+or run the UPDATE query above after every modification.
+</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2653365"></a>5.2. CLUSTERing on geometry indices</h2></div></div><div></div></div><p>
+For tables that are mostly read-only, and where a single index is used for the
+majority of queries, PostgreSQL offers the CLUSTER command. This command 
+physically reorders all the data rows in the same order as the index criteria,
+yielding two performance advantages: First, for index range scans, the number of 
+seeks on the data table is drastically reduced. Second, if your working set
+concentrates to some small intervals on the indices, you have a more efficient
+caching because the data rows are spread along fewer data pages. (Feel invited
+to read the CLUSTER command documentation from the PostgreSQL manual at this
+point.)
+</p><p>
+However, currently PostgreSQL does not allow clustering on PostGIS GIST indices
+because GIST indices simply ignores NULL values, you get an error message like:
+</p><pre class="programlisting">
+lwgeom=# CLUSTER my_geom_index ON my_table;
+ERROR:  cannot cluster when index access method does not handle null values
+HINT:  You may be able to work around this by marking column "the_geom" NOT NULL.
+</pre><p>
+As the HINT message tells you, one can work around this deficiency by adding a
+"not null" constraint to the table:
+</p><pre class="programlisting">
+lwgeom=# ALTER TABLE my_table ALTER COLUMN the_geom SET not null;
+ALTER TABLE
+</pre><p>
+Of course, this will not work if you in fact need NULL values in your geometry
+column. Additionally, you must use the above method to add the constraint, using
+a CHECK constraint like "ALTER TABLE blubb ADD CHECK (geometry is not null);" will
+not work.
+</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2653421"></a>5.3. Avoiding dimension conversion</h2></div></div><div></div></div><p>
+Sometimes, you happen to have 3D or 4D data in your table, but always access
+it using OpenGIS compliant asText() or asBinary() functions that only output
+2D geometries. They do this by internally calling the force_2d() function,
+which introduces a significant overhead for large geometries. To avoid this
+overhead, it may be feasible to pre-drop those additional dimensions once and
+forever:
+</p><pre class="programlisting">
+UPDATE mytable SET the_geom = force_2d(the_geom);
+VACUUM FULL ANALYZE mytable;
+</pre><p>
+Note that if you added your geometry column using AddGeometryColumn()
+there'll be a constraint on geometry dimension.
+To bypass it you will need to drop the constraint.
+Remember to update the entry in the geometry_columns table and
+recreate the constraint afterwards.
+</p><p>
+In case of large tables, it may be wise to divide this UPDATE into smaller portions
+by constraining the UPDATE to a part of the table via a WHERE clause and your
+primary key or another feasible criteria, and running a simple "VACUUM;" between
+your UPDATEs. This drastically reduces the need for temporary disk space.
+Additionally, if you have mixed dimension geometries, restricting the UPDATE by "WHERE 
+dimension(the_geom)&gt;2" skips re-writing of geometries that already are in 2D. 
+</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2653471"></a>Chapter 6. PostGIS Reference</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#id2653484">6.1. OpenGIS Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2653490">6.1.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2653580">6.1.2. Geometry Relationship Functions</a></span></dt><dt><span class="sect2"><a href="#id2653956">6.1.3. Geometry Processing Functions</a></span></dt><dt><span class="sect2"><a href="#id2654282">6.1.4. Geometry Accessors</a></span></dt><dt><span class="sect2"><a href="#id2654768">6.1.5. Geometry Constructors</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2655371">6.2. Postgis Extensions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2655376">6.2.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2655701">6.2.2. Operators</a></span></dt><dt><span class="sect2"><a href="#id2655909">6.2.3. Measurement Functions</a></span></dt><dt><span class="sect2"><a href="#id2656192">6.2.4. Geometry Outputs</a></span></dt><dt><span class="sect2"><a href="#id2656300">6.2.5. Geometry Constructors</a></span></dt><dt><span class="sect2"><a href="#id2656633">6.2.6. Geometry Editors</a></span></dt><dt><span class="sect2"><a href="#id2657229">6.2.7. Linear Referencing</a></span></dt><dt><span class="sect2"><a href="#id2657449">6.2.8. Misc</a></span></dt><dt><span class="sect2"><a href="#id2658447">6.2.9. Long Transactions support</a></span></dt></dl></dd></dl></div><p>The functions given below are the ones which a user of PostGIS is
+    likely to need. There are other functions which are required support
+    functions to the PostGIS objects which are not of use to a general
+    user.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2653484"></a>6.1. OpenGIS Functions</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653490"></a>6.1.1. Management Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><a name="AddGeometryColumn"></a><span class="term">AddGeometryColumn(varchar, varchar, varchar, integer,
+            varchar, integer)</span></dt><dd><p>Syntax: AddGeometryColumn(&lt;schema_name&gt;,
+              &lt;table_name&gt;, &lt;column_name&gt;, &lt;srid&gt;,
+              &lt;type&gt;, &lt;dimension&gt;). Adds a geometry column to an
+              existing table of attributes. The <tt class="varname">schema_name</tt>
+              is the name of the table schema (unused for pre-schema
+              PostgreSQL installations). The <tt class="varname">srid</tt> must be
+              an integer value reference to an entry in the SPATIAL_REF_SYS
+              table. The <tt class="varname">type</tt> must be an uppercase string
+              corresponding to the geometry type, eg, 'POLYGON' or
+              'MULTILINESTRING'.</p></dd><dt><span class="term">DropGeometryColumn(varchar, varchar, varchar)</span></dt><dd><p>Syntax: DropGeometryColumn(&lt;schema_name&gt;,
+              &lt;table_name&gt;, &lt;column_name&gt;). Remove a geometry
+              column from a spatial table. Note that schema_name will need to
+              match the f_schema_name field of the table's row in the
+              geometry_columns table.</p></dd><dt><span class="term">SetSRID(geometry, integer)</span></dt><dd><p>Set the SRID on a geometry to a particular integer value.
+              Useful in constructing bounding boxes for queries.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653580"></a>6.1.2. Geometry Relationship Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Distance(geometry, geometry)</span></dt><dd><p>Return the cartesian distance between two geometries in
+              projected units.</p></dd><dt><span class="term">Equals(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the given Geometries are
+	      "spatially equal". Use this for a 'better' answer than '='.
+	      equals('LINESTRING(0 0, 10 10)','LINESTRING(0 0, 5 5, 10 10)')
+	      is true.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.2</p></dd><dt><span class="term">Disjoint(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries are "spatially disjoint".
+	      </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 //s2.1.13.3 - a.Relate(b,
+              'FF*FF****')</p></dd><dt><span class="term">Intersects(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially intersect".
+              </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 //s2.1.13.3 - Intersects(g1, g2 ) --&gt;
+              Not (Disjoint(g1, g2 ))</p></dd><dt><span class="term">Touches(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially touch".
+              </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3- a.Touches(b) -&gt; (I(a)
+              intersection I(b) = {empty set} ) and (a intersection b) not
+              empty</p></dd><dt><span class="term">Crosses(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially cross".
+              </p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - a.Relate(b,
+              'T*T******')</p></dd><dt><span class="term">Within(geometry A, geometry B)</span></dt><dd><p>Returns 1 (TRUE) if Geometry A is "spatially within"
+              Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - a.Relate(b,
+              'T*F**F***')</p></dd><dt><span class="term">Overlaps(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially
+              overlap".</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3</p></dd><dt><span class="term">Contains(geometry A, geometry B)</span></dt><dd><p>Returns 1 (TRUE) if Geometry A "spatially contains"
+              Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - same as
+              within(geometry B, geometry A)</p></dd><dt><span class="term">Intersects(geometry, geometry)</span></dt><dd><p>Returns 1 (TRUE) if the Geometries "spatially
+              intersect".</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3 - NOT
+              disjoint(geometry, geometry)</p></dd><dt><span class="term">Relate(geometry, geometry, intersectionPatternMatrix)</span></dt><dd><p>Returns 1 (TRUE) if this Geometry is spatially related to
+              anotherGeometry, by testing for intersections between the
+              Interior, Boundary and Exterior of the two geometries as
+              specified by the values in the intersectionPatternMatrix.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is the "allowable" version that returns a
+              boolean, not an integer.</p><p>OGC SPEC s2.1.1.2 // s2.1.13.3</p></dd><dt><span class="term">Relate(geometry, geometry)</span></dt><dd><p>returns the DE-9IM (dimensionally extended
+              nine-intersection matrix)</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>not in OGC spec, but implied. see s2.1.13.2</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2653956"></a>6.1.3. Geometry Processing Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Centroid(geometry)</span></dt><dd><p>Returns the centroid of the geometry as a point.</p><p>Computation will be more accurate if performed by the GEOS
+              module (enabled at compile time).</p></dd><dt><span class="term">Area(geometry)</span></dt><dd><p>Returns the area of the geometry if it is a polygon or
+              multi-polygon. </p></dd><dt><span class="term">Length(geometry)</span></dt><dd><p>The length of this Curve in its associated spatial
+              reference.</p><p>synonym for length2d()</p><p>OGC SPEC 2.1.5.1</p></dd><dt><span class="term">PointOnSurface(geometry)</span></dt><dd><p>Return a Point guaranteed to lie on the surface</p><p>Implemented using GEOS</p><p>OGC SPEC 3.2.14.2 and 3.2.18.2 -</p></dd><dt><span class="term">Boundary(geometry)</span></dt><dd><p>Returns the closure of the combinatorial boundary of this
+              Geometry. The combinatorial boundary is defined as described in
+              section 3.12.3.2 of the OGC SPEC. Because the result of this
+              function is a closure, and hence topologically closed, the
+              resulting boundary can be represented using representational
+              geometry primitives as discussed in the OGC SPEC, section
+              3.12.2.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.1</p></dd><dt><span class="term">Buffer(geometry, double, [integer])</span></dt><dd><p>Returns a geometry that represents all points whose
+              distance from this Geometry is less than or equal to distance.
+              Calculations are in the Spatial Reference System of this
+              Geometry. The optional third parameter sets the
+	      number of segment used to approximate a quarter circle
+	      (defaults to 8).</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">ConvexHull(geometry)</span></dt><dd><p>Returns a geometry that represents the convex hull of this
+              Geometry.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">Intersection(geometry, geometry)</span></dt><dd><p>Returns a geometry that represents the point set
+              intersection of the Geometies.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">SymDifference(geometry A, geometry B)</span></dt><dd><p>Returns a geometry that represents the point set symmetric
+              difference of Geometry A with Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">Difference(geometry A, geometry B)</span></dt><dd><p>Returns a geometry that represents the point set difference
+              of Geometry A with Geometry B.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">GeomUnion(geometry, geometry)</span></dt><dd><p>Returns a geometry that represents the point set union of
+              the Geometries.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection as an
+              argument</p><p>NOTE: this is renamed from "union" because union is an SQL
+              reserved word</p><p>OGC SPEC s2.1.1.3</p></dd><dt><span class="term">GeomUnion(geometry set)</span></dt><dd><p>Returns a geometry that represents the point set union of
+              this all Geometries in given set.</p><p>Performed by the GEOS module</p><p>Do not call with a GeometryCollection in the argument
+              set</p><p>Not explicitly defined in OGC SPEC</p></dd><dt><span class="term">MemGeomUnion(geometry set)</span></dt><dd><p>Same as the above, only memory-friendly (uses less memory
+              and more processor time).</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2654282"></a>6.1.4. Geometry Accessors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">AsText(geometry)</span></dt><dd><p>Return the Well-Known Text representation of the geometry.
+              For example: POLYGON(0 0,0 1,1 1,1 0,0 0)</p><p>OGC SPEC s2.1.1.1</p></dd><dt><span class="term">AsBinary(geometry)</span></dt><dd><p>Returns the geometry in the OGC "well-known-binary"
+              format, using the endian encoding of the server on which the
+              database is running. This is useful in binary cursors to pull
+              data out of the database without converting it to a string
+              representation.</p><p>OGC SPEC s2.1.1.1 - also see
+              asBinary(&lt;geometry&gt;,'XDR') and
+              asBinary(&lt;geometry&gt;,'NDR')</p></dd><dt><span class="term">SRID(geometry)</span></dt><dd><p>Returns the integer SRID number of the spatial reference
+              system of the geometry.</p><p>OGC SPEC s2.1.1.1</p></dd><dt><span class="term">Dimension(geometry)</span></dt><dd><p>The inherent dimension of this Geometry object, which must
+              be less than or equal to the coordinate dimension. OGC SPEC
+              s2.1.1.1 - returns 0 for points, 1 for lines, 2 for polygons,
+              and the largest dimension of the components of a
+              GEOMETRYCOLLECTION.</p><pre class="programlisting">select dimension('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0)'); 
+dimension 
+-----------
+1</pre></dd><dt><span class="term">Envelope(geometry)</span></dt><dd><p>Returns a POLYGON representing the bounding box of the
+              geometry.</p><p>OGC SPEC s2.1.1.1 - The minimum bounding box for this
+              Geometry, returned as a Geometry. The polygon is defined by the
+              corner points of the bounding box ((MINX, MINY), (MAXX, MINY),
+              (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)).</p><p>NOTE:PostGIS will add a Zmin/Zmax coordinate as
+              well.</p></dd><dt><span class="term">IsEmpty(geometry)</span></dt><dd><p>Returns 1 (TRUE) if this Geometry is the empty geometry .
+              If true, then this Geometry represents the empty point set -
+              i.e. GEOMETRYCOLLECTION(EMPTY).</p><p>OGC SPEC s2.1.1.1</p></dd><dt><a name="IsSimple"></a><span class="term">IsSimple(geometry)</span></dt><dd><p>Returns 1 (TRUE) if this Geometry has no anomalous
+              geometric points, such as self intersection or self
+              tangency.</p><p>Performed by the GEOS module</p><p>OGC SPEC s2.1.1.1</p></dd><dt><a name="IsClosed"></a><span class="term">IsClosed(geometry)</span></dt><dd><p>Returns true of the geometry start and end points are
+              coincident.</p></dd><dt><span class="term">IsRing(geometry)</span></dt><dd><p>Returns 1 (TRUE) if this Curve is closed (StartPoint ( ) =
+              EndPoint ( )) and this Curve is simple (does not pass through
+              the same point more than once).</p><p>performed by GEOS</p><p>OGC spec 2.1.5.1</p></dd><dt><span class="term">NumGeometries(geometry)</span></dt><dd><p>If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the
+              number of geometries, otherwise return NULL.</p></dd><dt><span class="term">GeometryN(geometry,int)</span></dt><dd><p>Return the N'th geometry if the geometry is a
+              GEOMETRYCOLLECTION, MULTIPOINT, MULTILINESTRING or MULTIPOLYGON.
+              Otherwise, return NULL.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+		Index is 1-based as for OGC specs since version 0.8.0.
+		Previous versions implemented this as 0-based instead.
+		</p></div></dd><dt><span class="term">NumPoints(geometry)</span></dt><dd><p>Find and return the number of points in the first
+              linestring in the geometry. Return NULL if there is no
+              linestring in the geometry.</p></dd><dt><span class="term">PointN(geometry,integer)</span></dt><dd><p>Return the N'th point in the first linestring in the
+              geometry. Return NULL if there is no linestring in the
+              geometry.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+		Index is 1-based as for OGC specs since version 0.8.0.
+		Previous versions implemented this as 0-based instead.
+		</p></div></dd><dt><span class="term">ExteriorRing(geometry)</span></dt><dd><p>Return the exterior ring of the polygon geometry.
+	      Return NULL if the geometry is not a polygon.</p></dd><dt><span class="term">NumInteriorRings(geometry)</span></dt><dd><p>Return the number of interior rings of the first polygon
+              in the geometry. Return NULL if there is no polygon in the
+              geometry.</p></dd><dt><span class="term">NumInteriorRing(geometry)</span></dt><dd><p>Synonym to NumInteriorRings(geometry). The OpenGIS specs
+	      are ambiguous about the exact function naming, so we provide
+	      both spellings.</p></dd><dt><span class="term">InteriorRingN(geometry,integer)</span></dt><dd><p>Return the N'th interior ring of the polygon geometry.
+	      Return NULL if the geometry is not a polygon or the given
+	      N is out of range.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+		Index is 1-based as for OGC specs since version 0.8.0.
+		Previous versions implemented this as 0-based instead.
+		</p></div></dd><dt><span class="term">EndPoint(geometry)</span></dt><dd><p>Returns the last point of the LineString geometry as a point.</p></dd><dt><a name="StartPoint"></a><span class="term">StartPoint(geometry)</span></dt><dd><p>Returns the first point of the LineString geometry as a point.</p></dd><dt><a name="GeometryType"></a><span class="term">GeometryType(geometry)</span></dt><dd><p>Returns the type of the geometry as a string. Eg:
+              'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.</p><p>OGC SPEC s2.1.1.1 - Returns the name of the instantiable
+              subtype of Geometry of which this Geometry instance is a member.
+              The name of the instantiable subtype of Geometry is returned as
+              a string.</p></dd><dt><span class="term">X(geometry)</span></dt><dd><p>Return the X coordinate of the point.
+	      Input must be a point.</p></dd><dt><span class="term">Y(geometry)</span></dt><dd><p>Return the Y coordinate of the point.
+	      Input must be a point.</p></dd><dt><span class="term">Z(geometry)</span></dt><dd><p>Return the Z coordinate of the point,
+	      or NULL if not available.
+	      Input must be a point.</p></dd><dt><span class="term">M(geometry)</span></dt><dd><p>Return the M coordinate of the point, 
+	      or NULL if not available.
+	      Input must be a point.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This is not (yet) part of the OGC spec,
+		but is listed here to complete the point coordinate
+	        extractor function list.</p></div></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2654768"></a>6.1.5. Geometry Constructors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">GeomFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p></dd><dt><span class="term">PointFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a Point</p></dd><dt><span class="term">LineFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a Line</p></dd><dt><span class="term">LinestringFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>from the conformance suite</p><p>Throws an error if the WKT is not a Line</p></dd><dt><span class="term">PolyFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a Polygon</p></dd><dt><span class="term">PolygonFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>from the conformance suite</p><p>Throws an error if the WKT is not a Polygon</p></dd><dt><span class="term">MPointFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a MULTIPOINT</p></dd><dt><span class="term">MLineFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a MULTILINESTRING</p></dd><dt><span class="term">MPolyFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a MULTIPOLYGON</p></dd><dt><span class="term">GeomCollFromText(text,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKT with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p><p>Throws an error if the WKT is not a
+              GEOMETRYCOLLECTION</p></dd><dt><span class="term">GeomFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.6.2 - option SRID is from the conformance
+              suite</p></dd><dt><span class="term">GeomFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p></dd><dt><span class="term">PointFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a POINT</p></dd><dt><span class="term">LineFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a LINESTRING</p></dd><dt><span class="term">LinestringFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>from the conformance suite</p><p>throws an error if WKB is not a LINESTRING</p></dd><dt><span class="term">PolyFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a POLYGON</p></dd><dt><span class="term">PolygonFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>from the conformance suite</p><p>throws an error if WKB is not a POLYGON</p></dd><dt><span class="term">MPointFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a MULTIPOINT</p></dd><dt><span class="term">MLineFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a MULTILINESTRING</p></dd><dt><span class="term">MPolyFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a MULTIPOLYGON</p></dd><dt><span class="term">GeomCollFromWKB(bytea,[&lt;srid&gt;])</span></dt><dd><p>Makes a Geometry from WKB with the given SRID. If SRID is
+              not give, it defaults to -1.</p><p>OGC SPEC 3.2.7.2 - option SRID is from the conformance
+              suite</p><p>throws an error if WKB is not a GEOMETRYCOLLECTION</p></dd><dt><a name="BdPolyFromText"></a><span class="term">BdPolyFromText(text WKT, integer SRID)</span></dt><dd><p>
+		Construct a Polygon given an arbitrary
+		collection of closed linestrings as a
+		MultiLineString text representation.
+		</p><p>
+	      Throws an error if WKT is not a MULTILINESTRING.
+	      Throws an error if output is a MULTIPOLYGON; use <a href="#BdMPolyFromText">BdMPolyFromText</a> in
+	      that case, or see 
+		<a href="#BuildArea">BuildArea()</a>
+		for a postgis-specific approach.
+		</p><p>OGC SFSQL 1.1 - 3.2.6.2</p><p>
+		    Availability: 1.1.0 - requires GEOS &gt;= 2.1.0.
+		</p></dd><dt><a name="BdMPolyFromText"></a><span class="term">BdMPolyFromText(text WKT, integer SRID)</span></dt><dd><p>
+		Construct a MultiPolygon given an arbitrary
+		collection of closed linestrings as a
+		MultiLineString text representation.
+		</p><p>
+                Throws an error if WKT is not a MULTILINESTRING.
+		Forces MULTIPOLYGON output even when result is really
+		only composed by a single POLYGON; use <a href="#BdPolyFromText">BdPolyFromText</a> if you're sure
+		a single POLYGON will result from
+		operation, or see
+		<a href="#BuildArea">BuildArea()</a>
+		for a postgis-specific approach.
+		</p><p>OGC SFSQL 1.1 - 3.2.6.2</p><p>
+		    Availability: 1.1.0 - requires GEOS &gt;= 2.1.0.
+		</p></dd></dl></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2655371"></a>6.2. Postgis Extensions</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2655376"></a>6.2.1. Management Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">DropGeometryTable([&lt;schema_name&gt;],
+		  &lt;table_name&gt;)</span></dt><dd><p>Drops a table and all its references in geometry_columns.
+		    Note: uses current_schema() on schema-aware pgsql installations if
+		    schema is not provided.</p></dd><dt><span class="term">UpdateGeometrySRID([&lt;schema_name&gt;],
+		  &lt;table_name&gt;, &lt;column_name&gt;, &lt;srid&gt;)</span></dt><dd><p>Update the SRID of all features in a geometry column updating constraints and reference in geometry_columns.
+		    Note: uses current_schema() on schema-aware pgsql installations if schema is not provided.</p></dd><dt><span class="term">update_geometry_stats([&lt;table_name&gt;,
+		  &lt;column_name&gt;])</span></dt><dd><p>Update statistics about spatial tables for use by the query
+		    planner. You will also need to run "VACUUM ANALYZE [table_name]
+		    [column_name]" for the statistics gathering process to be
+		    complete. NOTE: starting with PostgreSQL 8.0 statistics gathering
+		    is automatically performed running "VACUUM ANALYZE".</p></dd><dt><span class="term">postgis_version()</span></dt><dd><p>Returns PostGIS version number and compile-time options</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+		Prior to version 1.1.0 this was a procedural function, thus possibly
+		returning inaccurate information (in case of incomplete database upgrades).
+		</p></div></dd><dt><a name="postgis_lib_version"></a><span class="term">postgis_lib_version()</span></dt><dd><p>Returns the version number of the PostGIS library.</p><p>
+	Availability: 0.9.0
+		</p></dd><dt><span class="term">postgis_lib_build_date()</span></dt><dd><p>Returns build date of the PostGIS library.</p><p>
+	Availability: 1.0.0RC1
+		</p></dd><dt><span class="term">postgis_script_build_date()</span></dt><dd><p>Returns build date of the PostGIS scripts.</p><p>
+	Availability: 1.0.0RC1
+		</p></dd><dt><span class="term">postgis_scripts_installed()</span></dt><dd><p>
+		Returns version of the postgis scripts
+		installed in this database.
+		</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+		If the output of this function doesn't match the output of
+		<a href="#postgis_scripts_released">postgis_scripts_released()</a>
+		you probably missed to properly upgrade an existing database.
+		See the <a href="#upgrading" title="2.2.1. Upgrading">Upgrading</a> section for more info.
+		</p></div><p>
+	Availability: 0.9.0
+		</p></dd><dt><a name="postgis_scripts_released"></a><span class="term">postgis_scripts_released()</span></dt><dd><p>Returns the version number of the lwpostgis.sql script
+            released with the installed postgis lib.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+		Starting with version 1.1.0 this function returns the same
+		value of <a href="#postgis_lib_version">postgis_lib_version()</a>.
+		Kept for backward compatibility.
+		</p></div><p>
+	Availability: 0.9.0 
+		</p></dd><dt><span class="term">postgis_geos_version()</span></dt><dd><p>Returns the version number of the GEOS library, or NULL if
+            GEOS support is not enabled.</p><p>
+	Availability: 0.9.0
+		</p></dd><dt><span class="term">postgis_jts_version()</span></dt><dd><p>Returns the version number of the JTS library, or NULL if
+            JTS support is not enabled.</p><p>
+	Availability: 1.1.0
+		</p></dd><dt><span class="term">postgis_proj_version()</span></dt><dd><p>Returns the version number of the PROJ4 library, or NULL if
+            PROJ4 support is not enabled.</p><p>
+	Availability: 0.9.0
+		</p></dd><dt><span class="term">postgis_uses_stats()</span></dt><dd><p>Returns true if STATS usage has been enabled, false
+            otherwise.</p><p>
+	Availability: 0.9.0
+		</p></dd><dt><a name="postgis_full_version"></a><span class="term">postgis_full_version()</span></dt><dd><p>Reports full postgis version and build configuration
+            infos.</p><p>Availability: 0.9.0</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2655701"></a>6.2.2. Operators</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">A &amp;&lt; B</span></dt><dd><p>The "&amp;&lt;" operator returns true if A's bounding box
+		    overlaps or is to the left of B's bounding box.</p></dd><dt><span class="term">A &amp;&gt; B</span></dt><dd><p>The "&amp;&gt;" operator returns true if A's bounding box
+		    overlaps or is to the right of B's bounding box.</p></dd><dt><span class="term">A &lt;&lt; B</span></dt><dd><p>The "&lt;&lt;" operator returns true if A's bounding box is
+		    strictly to the left of B's bounding box.</p></dd><dt><span class="term">A &gt;&gt; B</span></dt><dd><p>The "&gt;&gt;" operator returns true if A's bounding box is
+		    strictly to the right of B's bounding box.</p></dd><dt><span class="term">A &amp;&lt;| B</span></dt><dd><p>The "&amp;&lt;|" operator returns true if A's bounding box
+		    overlaps or is below B's bounding box.</p></dd><dt><span class="term">A |&amp;&gt; B</span></dt><dd><p>The "|&amp;&gt;" operator returns true if A's bounding box
+		    overlaps or is above B's bounding box.</p></dd><dt><span class="term">A &lt;&lt;| B</span></dt><dd><p>The "&lt;&lt;|" operator returns true if A's bounding box is
+		    strictly below B's bounding box.</p></dd><dt><span class="term">A |&gt;&gt; B</span></dt><dd><p>The "|&gt;&gt;" operator returns true if A's bounding box is
+		    strictly above B's bounding box.</p></dd><dt><span class="term">A ~= B</span></dt><dd><p>The "~=" operator is the "same as" operator. It tests actual
+		    geometric equality of two features. So if A and B are the same
+		    feature, vertex-by-vertex, the operator returns true.</p></dd><dt><span class="term">A @ B</span></dt><dd><p>The "@" operator returns true if A's bounding box is
+		    completely contained by B's bounding box.</p></dd><dt><span class="term">A ~ B</span></dt><dd><p>The "~" operator returns true if A's bounding box completely
+		    contains B's bounding box.</p></dd><dt><span class="term">A &amp;&amp; B</span></dt><dd><p>The "&amp;&amp;" operator is the "overlaps" operator. If A's
+		    bounding box overlaps B's bounding box the operator returns
+		    true.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2655909"></a>6.2.3. Measurement Functions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">area2d(geometry)</span></dt><dd><p>Returns the area of the geometry if it is a polygon or
+		    multi-polygon.</p></dd><dt><span class="term">distance_sphere(point, point)</span></dt><dd><p>Returns linear distance in meters between two lat/lon
+            points. Uses a spherical earth and radius of 6370986 meters.
+            Faster than <a href="#distance_spheroid">distance_spheroid()</a>, but
+            less accurate.
+			Only implemented for points.</p></dd><dt><a name="distance_spheroid"></a><span class="term">distance_spheroid(point, point, spheroid)</span></dt><dd><p>Returns linear distance between two lat/lon points given a
+            particular spheroid. See the explanation of spheroids given for
+            <a href="#length_spheroid">length_spheroid()</a>.
+            Currently only implemented for points.</p></dd><dt><a name="length2d"></a><span class="term">length2d(geometry)</span></dt><dd><p>Returns the 2-dimensional length of the geometry if it is a
+            linestring or multi-linestring.</p></dd><dt><span class="term">length3d(geometry)</span></dt><dd><p>Returns the 3-dimensional length of the geometry if it is a
+            linestring or multi-linestring.</p></dd><dt><a name="length_spheroid"></a><span class="term">length_spheroid(geometry,spheroid)</span></dt><dd><p>Calculates the length of of a geometry on an ellipsoid. This
+            is useful if the coordinates of the geometry are in
+            latitude/longitude and a length is desired without reprojection.
+            The ellipsoid is a separate database type and can be constructed as
+            follows:</p><div class="literallayout"><p>SPHEROID[&lt;NAME&gt;,&lt;SEMI-MAJOR AXIS&gt;,&lt;INVERSE FLATTENING&gt;]</p></div><p>Eg:</p><div class="literallayout"><p>SPHEROID["GRS_1980",6378137,298.257222101]</p></div><p>An example calculation might look like this:</p><div class="literallayout"><p>SELECT<br>
+ length_spheroid(<br>
+  geometry_column,<br>
+  'SPHEROID["GRS_1980",6378137,298.257222101]'<br>
+ )<br>
+FROM geometry_table;</p></div></dd><dt><span class="term">length3d_spheroid(geometry,spheroid)</span></dt><dd><p>Calculates the length of of a geometry on an ellipsoid,
+            taking the elevation into account. This is just like
+            length_spheroid except vertical coordinates (expressed in the same
+            units as the spheroid axes) are used to calculate the extra
+            distance vertical displacement adds.</p></dd><dt><span class="term">distance(geometry, geometry)</span></dt><dd><p>Returns the smaller distance between two geometries.</p></dd><dt><span class="term">max_distance(linestring,linestring)</span></dt><dd><p>Returns the largest distance between two line
+            strings.</p></dd><dt><span class="term">perimeter(geometry)</span></dt><dd><p>Returns the 2-dimensional perimeter of the geometry, if it
+            is a polygon or multi-polygon.</p></dd><dt><span class="term">perimeter2d(geometry)</span></dt><dd><p>Returns the 2-dimensional perimeter of the geometry, if it
+            is a polygon or multi-polygon.</p></dd><dt><span class="term">perimeter3d(geometry)</span></dt><dd><p>Returns the 3-dimensional perimeter of the geometry, if it
+            is a polygon or multi-polygon.</p></dd><dt><span class="term">azimuth(geometry, geometry)</span></dt><dd><p>
+	Returns the azimuth of the segment defined by the given Point
+	geometries, or NULL if the two points are coincident.
+	Return value is in radians.
+            </p><p>
+			Availability: 1.1.0
+		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2656192"></a>6.2.4. Geometry Outputs</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">AsBinary(geometry,{'NDR'|'XDR'})</span></dt><dd><p>Returns the geometry in the OGC "well-known-binary" format as a bytea, using little-endian (NDR) or big-endian (XDR) encoding. This is useful in binary cursors to pull data out of the database without converting it to a string representation.</p></dd><dt><span class="term">AsEWKT(geometry)</span></dt><dd><p>Returns a Geometry in EWKT format (as text).</p></dd><dt><span class="term">AsEWKB(geometry, {'NDR'|'XDR'})</span></dt><dd><p>Returns a Geometry in EWKB format (as bytea) using either little-endian (NDR) or big-endian (XDR) encoding.</p></dd><dt><span class="term">AsHEXEWKB(geometry, {'NDR'|'XDR'})</span></dt><dd><p>Returns a Geometry in HEXEWKB format (as text) using either little-endian (NDR) or big-endian (XDR) encoding.</p></dd><dt><span class="term">AsSVG(geometry, [rel], [precision])</span></dt><dd><p>Return the geometry as an SVG path data. Use 1 as second argument to have the path data implemented in terms of relative moves, the default (or 0) uses absolute moves. Third argument may be used to reduce the maximum number of decimal digits used in output (defaults to 15). Point geometries will be rendered as cx/cy when 'rel' arg is 0, x/y when 'rel' is 1.</p></dd><dt><span class="term">AsGML(geometry, [precision])</span></dt><dd><p>Return the geometry as a GML element.  Second argument may be used to reduce the maximum number of significant digits used in output (defaults to 15).</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2656300"></a>6.2.5. Geometry Constructors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">GeomFromEWKT(text)</span></dt><dd><p>Makes a Geometry from EWKT.</p></dd><dt><span class="term">GeomFromEWKB(bytea)</span></dt><dd><p>Makes a Geometry from EWKB.</p></dd><dt><span class="term">MakePoint(&lt;x&gt;, &lt;y&gt;, [&lt;z&gt;], [&lt;m&gt;])</span></dt><dd><p>Creates a 2d,3dz or 4d point geometry.</p></dd><dt><span class="term">MakePointM(&lt;x&gt;, &lt;y&gt;, &lt;m&gt;)</span></dt><dd><p>Creates a 3dm point geometry.</p></dd><dt><span class="term">MakeBox2D(&lt;LL&gt;, &lt;UR&gt;)</span></dt><dd><p>Creates a BOX2D defined by the given point geometries.</p></dd><dt><span class="term">MakeBox3D(&lt;LLB&gt;, &lt;URT&gt;)</span></dt><dd><p>Creates a BOX3D defined by the given point geometries.</p></dd><dt><span class="term">MakeLine(geometry set)</span></dt><dd><p>Creates a Linestring from a set of point geometries.
+		    You might want to use a subselect to order points before
+		    feeding them to this aggregate.</p></dd><dt><span class="term">MakeLine(geometry, geometry)</span></dt><dd><p>Creates a Linestring from the two given point
+		    geometries.</p></dd><dt><span class="term">LineFromMultiPoint(multipoint)</span></dt><dd><p>Creates a LineString from a MultiPoint geometry.</p></dd><dt><span class="term">MakePolygon(linestring, [linestring[]])</span></dt><dd><p>Creates a Polygon formed by the given 
+		    shell and array of holes. You can construct
+		    a geometry array using <a href="#Accum">Accum</a>.
+		    Input geometries must be closed LINESTRINGS (see <a href="#IsClosed">IsClosed</a> and <a href="#GeometryType">GeometryType</a>).
+		    </p></dd><dt><a name="BuildArea"></a><span class="term">BuildArea(geometry)</span></dt><dd><p>Creates an areal geometry formed by the constituent
+		    linework of given geometry. The return type can
+		    be a Polygon or MultiPolygon, depending on input.
+		    If the input lineworks do not form polygons NULL is
+		    returned.
+		    </p><p>
+		    See also <a href="#BdPolyFromText">BdPolyFromText</a> and <a href="#BdMPolyFromText">BdMPolyFromText</a> - wrappers to this function with standard OGC interface.
+		    </p><p>
+		    Availability: 1.1.0 - requires GEOS &gt;= 2.1.0.
+		</p></dd><dt><span class="term">Polygonize(geometry set)</span></dt><dd><p>
+			Aggregate. Creates a GeometryCollection containing
+			possible polygons formed from the constituent linework
+			of a set of geometries.
+		</p><p>
+		    Availability: 1.0.0RC1 - requires GEOS &gt;= 2.1.0.
+		</p></dd><dt><span class="term">Collect(geometry set)</span></dt><dd><p>This function returns a GEOMETRYCOLLECTION or a MULTI object from a set
+		    of geometries. The collect() function is an "aggregate" function
+		    in the terminology of PostgreSQL. That means that it operators on
+		    lists of data, in the same way the sum() and mean() functions do.
+		    For example, "SELECT COLLECT(GEOM) FROM GEOMTABLE GROUP BY
+		    ATTRCOLUMN" will return a separate GEOMETRYCOLLECTION for each
+		    distinct value of ATTRCOLUMN.</p></dd><dt><span class="term">Collect(geometry, geometry)</span></dt><dd><p>This function returns a geometry being a collection
+		    of two input geometries. Output type can be a MULTI* or 
+		    a GEOMETRYCOLLECTION.</p></dd><dt><span class="term">Dump(geometry)</span></dt><dd><p>This is a set-returning function (SRF).
+		    It returns a set of geometry_dump rows, formed
+		    by a geometry (geom) and an array of integers (path).
+		    When the input geometry is a simple type
+		    (POINT,LINESTRING,POLYGON)
+		    a single record will be returned with an empty
+		    path array and the input geometry as geom.
+		    When the input geometry is a collection or multi
+		    it will return a record for each of the collection
+		    components, and the path will express the position
+		    of the component inside the collection.
+		    </p><p>
+		    Availability: PostGIS 1.0.0RC1.
+		    Requires PostgreSQL 7.3 or higher.
+		</p></dd><dt><span class="term">DumpRings(geometry)</span></dt><dd><p>This is a set-returning function (SRF).
+		    It returns a set of geometry_dump rows, formed
+		    by a geometry (geom) and an array of integers (path).
+		    The 'path' field holds the polygon ring index, contains
+		    a single element: 0 for the shell, hole number for holes.
+		    The 'geom' field contains the corresponding ring
+		    as a polygon.
+		    </p><p>
+		    Availability: PostGIS 1.1.3.
+		    Requires PostgreSQL 7.3 or higher.
+		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2656633"></a>6.2.6. Geometry Editors</h3></div></div><div></div></div><div class="variablelist"><dl><dt><a name="addbbox"></a><span class="term">AddBBOX(geometry)</span></dt><dd><p>Add bounding box to the geometry. This would make bounding
+	    box based queries faster, but will increase the size of the
+	    geometry.</p></dd><dt><a name="dropbbox"></a><span class="term">DropBBOX(geometry)</span></dt><dd><p>Drop the bounding box cache from the geometry.
+	    This reduces geometry size, but makes bounding-box based
+	    queries slower.</p></dd><dt><span class="term">AddPoint(linestring, point, [&lt;position&gt;])</span></dt><dd><p>Adds a point to a LineString before point &lt;pos&gt;
+	    (0-based index).
+	    Third parameter can be omitted or set to -1 for appending.
+	    </p></dd><dt><span class="term">RemovePoint(linestring, offset)</span></dt><dd><p>
+			Removes point from a linestring. Offset is 0-based.
+		</p><p>
+			Availability: 1.1.0
+		</p></dd><dt><span class="term">SetPoint(linestring, N, point)</span></dt><dd><p>
+			Replace point N of linestring with given point.
+			Index is 0-based.
+		</p><p>
+			Availability: 1.1.0
+		</p></dd><dt><span class="term">Force_collection(geometry)</span></dt><dd><p>Converts the geometry into a GEOMETRYCOLLECTION. This is
+            useful for simplifying the WKB representation.</p></dd><dt><a name="force_2d"></a><span class="term">Force_2d(geometry)</span></dt><dd><p>Forces the geometries into a "2-dimensional mode" so that
+            all output representations will only have the X and Y coordinates.
+            This is useful for force OGC-compliant output (since OGC only
+            specifies 2-D geometries).</p></dd><dt><a name="force_3dz"></a><span class="term">Force_3dz(geometry), </span><span class="term">Force_3d(geometry), </span></dt><dd><p>Forces the geometries into XYZ mode.</p></dd><dt><a name="force_3dm"></a><span class="term">Force_3dm(geometry)</span></dt><dd><p>Forces the geometries into XYM mode.</p></dd><dt><a name="force_4d"></a><span class="term">Force_4d(geometry)</span></dt><dd><p>Forces the geometries into XYZM mode.</p></dd><dt><span class="term">Multi(geometry)</span></dt><dd><p>Returns the geometry as a MULTI* geometry. If the geometry
+            is already a MULTI*, it is returned unchanged.</p></dd><dt><span class="term">Transform(geometry,integer)</span></dt><dd><p>Returns a new geometry with its coordinates transformed to
+            the SRID referenced by the integer parameter. The destination SRID
+            must exist in the <tt class="varname">SPATIAL_REF_SYS</tt> table.</p></dd><dt><span class="term">Affine(geometry,float8,float8,float8,float8,float8,float8,float8,float8,float8,float8,float8,float8)</span></dt><dd><p>Applies an 3d affine transformation to the geometry. The call 
+                </p><pre class="programlisting">
+                    Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff)
+                </pre><p>
+                represents the transformation matrix
+                </p><pre class="programlisting">
+                    /  a  b  c  xoff  \
+                    |  d  e  f  yoff  |
+                    |  g  h  i  zoff  |
+                    \  0  0  0  1     /
+                </pre><p>
+                and the vertices are transformed as follows:
+                </p><pre class="programlisting">
+                    x' = a*x + b*y + c*z + xoff
+                    y' = d*x + e*y + f*z + yoff
+                    z' = g*x + h*y + i*z + zoff   
+                </pre><p>
+                All of the translate / scale functions below are expressed via such an affine transformation.
+            </p><p>
+                Availability: 1.1.2.
+            </p></dd><dt><span class="term">Affine(geometry,float8,float8,float8,float8,float8,float8)</span></dt><dd><p>Applies an 2d affine transformation to the geometry. The call 
+                </p><pre class="programlisting">
+                    Affine(geom, a, b, d, e, xoff, yoff)
+                </pre><p>
+                represents the transformation matrix
+                </p><pre class="programlisting">
+                    /  a  b  0  xoff  \        /  a  b  xoff  \
+                    |  d  e  0  yoff  |  rsp.  |  d  e  yoff  |
+                    |  0  0  1  0     |        \  0  0  1     /
+                    \  0  0  0  1     /
+                </pre><p>
+                and the vertices are transformed as follows:
+                </p><pre class="programlisting">
+                    x' = a*x + b*y + xoff
+                    y' = d*x + e*y + yoff
+                    z' = z   
+                </pre><p>
+                This method is a subcase of the 3D method above.
+            </p><p>
+		Availability: 1.1.2.
+            </p></dd><dt><span class="term">Translate(geometry,float8,float8,float8)</span></dt><dd><p>Translates the geometry to a new location using the numeric
+            parameters as offsets. Ie: translate(geom, X, Y, Z).</p></dd><dt><span class="term">Scale(geometry,float8,float8,float8)</span></dt><dd><p>scales the geometry to a new size by multiplying the
+            ordinates with the parameters. Ie: scale(geom, Xfactor, Yfactor, Zfactor).</p><p>
+			Availability: 1.1.0
+		</p></dd><dt><a name="Rotate"></a><span class="term">RotateZ(geometry,float8), </span><span class="term">RotateX(geometry,float8), </span><span class="term">RotateY(geometry,float8), </span></dt><dd><p>
+			Rotate the geometry around the Z, X or Y axis by
+			the given angle given in radians. Follows the
+			right-hand rule. This is the same in
+			PostScript but opposite of SVG.
+		</p><p>
+			Availability: 1.1.2.
+		</p></dd><dt><span class="term">TransScale(geometry,float8,float8,float8,float8)</span></dt><dd><p>First, translates the geometry using the first two floats, then scales it
+                    using the second two floats, working in 2D only. Using
+                    <tt class="code">transscale(geom, X, Y, XFactor, YFactor)</tt> internally calls
+                    <tt class="code">affine(geom, XFactor, 0, 0,  0, YFactor, 0,  0, 0, 1,  X*XFactor, Y*YFactor, 0)</tt>.                
+                </p><p>
+                        Availability: 1.1.0.
+                </p></dd><dt><span class="term">Reverse(geometry)</span></dt><dd><p>Returns the geometry with vertex order reversed.</p></dd><dt><span class="term">ForceRHR(geometry)</span></dt><dd><p>Force polygons of the collection to obey Right-Hand-Rule.</p></dd><dt><span class="term">Simplify(geometry, tolerance)</span></dt><dd><p>Returns a "simplified" version of the given geometry using
+            the Douglas-Peuker algorithm. Will actually do something only with
+            (multi)lines and (multi)polygons but you can safely call it with
+            any kind of geometry. Since simplification occurs on a
+            object-by-object basis you can also feed a GeometryCollection to
+            this function. Note that returned geometry might loose its
+            simplicity (see <a href="#IsSimple">IsSimple</a>)</p></dd><dt><span class="term">SnapToGrid(geometry, originX, originY, sizeX, sizeY), </span><span class="term">SnapToGrid(geometry, sizeX, sizeY), </span><span class="term">SnapToGrid(geometry, size), </span></dt><dd><p>Snap all points of the input geometry to the grid
+	    defined by its origin and cell size.
+            Remove consecutive points falling on the same cell,
+	    eventually returning NULL if output points are not
+	    enough to define a geometry of the given type.
+	    Collapsed geometries in a collection are stripped
+	    from it.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+            The returned geometry might loose its
+            simplicity (see <a href="#IsSimple">IsSimple</a>).
+	</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+            Before release 1.1.0 this function always returned
+	    a 2d geometry. Starting at 1.1.0 the returned geometry
+	    will have same dimensionality as the input one with higher
+	    dimension values untouched. Use the version taking a second
+	    geometry argument to define all grid dimensions.
+	</p></div><p>
+			Availability: 1.0.0RC1
+		</p></dd><dt><span class="term">SnapToGrid(geometry, geometry, sizeX, sizeY, sizeZ, sizeM)</span></dt><dd><p>
+	    Snap all points of the input geometry to the grid
+	    defined by its origin (the second argument, must be a point)
+	    and cell sizes. Specify 0 as size for any dimension you don't
+	    want to snap to a grid.
+	    </p><p>
+			Availability: 1.1.0
+		</p></dd><dt><span class="term">Segmentize(geometry, maxlength)</span></dt><dd><p>Return a modified geometry having no segment
+            longer then the given distance. Interpolated points will have Z
+            and M values (if needed) set to 0. Distance computation is
+            performed in 2d only.</p></dd><dt><span class="term">LineMerge(geometry)</span></dt><dd><p>
+			Returns a (set of) LineString(s) formed by sewing
+			together constituent linework of input.
+		</p><p>
+			Availability: 1.1.0 - requires GEOS &gt;= 2.1.0
+		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2657229"></a>6.2.7. Linear Referencing</h3></div></div><div></div></div><div class="variablelist"><dl><dt><a name="line_interpolate_point"></a><span class="term">line_interpolate_point(linestring, location)</span></dt><dd><p>
+		Returns a point interpolated along a line.
+		First argument must be a LINESTRING.
+		Second argument is a float8 between 0 and 1
+		representing fraction of total
+		<a href="#length2d">2d length</a> the point has
+		to be located.
+		</p><p>
+		See <a href="#line_locate_point">line_locate_point()</a>
+		for computing the line location nearest to a Point.
+		</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+            Since release 1.1.1 this function also interpolates
+	    M and Z values (when present), while prior releases
+	    set them to 0.0.
+	</p></div><p>
+			Availability: 0.8.2
+		</p></dd><dt><a name="line_substring"></a><span class="term">line_substring(linestring, start, end)</span></dt><dd><p>
+		Return a linestring being a substring of the input one starting
+		and ending at the given fractions of total 2d length. Second
+		and third arguments are float8 values between 0 and 1.
+		</p><p>
+		If 'start' and 'end' have the same value this is equivalent 
+		to <a href="#line_interpolate_point">line_interpolate_point()</a>.
+		</p><p>
+		See <a href="#line_locate_point">line_locate_point()</a>
+		for computing the line location nearest to a Point.
+		</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+            Since release 1.1.1 this function also interpolates
+	    M and Z values (when present), while prior releases
+	    set them to unspecified values.
+	</p></div><p>
+			Availability: 1.1.0
+		</p></dd><dt><a name="line_locate_point"></a><span class="term">line_locate_point(LineString, Point)</span></dt><dd><p>
+		Returns a float between 0 and 1 representing 
+		the location of the closest point on LineString
+		to the given Point, as a fraction of
+		total <a href="#length2d">2d line</a> length.
+		</p><p>
+	You can use the returned location to extract a Point (<a href="#line_interpolate_point">line_interpolate_point</a>) or a substring (<a href="#line_substring">line_substring</a>).
+		</p><p>
+			Availability: 1.1.0
+		</p></dd><dt><span class="term">locate_along_measure(geometry, float8)</span></dt><dd><p>
+		Return a derived geometry collection value with elements that
+		match the specified measure.
+		Polygonal elements are not supported.
+		</p><p>
+		Semantic is specified by: ISO/IEC CD 13249-3:200x(E) -
+		Text for Continuation CD Editing Meeting
+		</p><p>
+			Availability: 1.1.0
+		</p></dd><dt><span class="term">locate_between_measures(geometry, float8, float8)</span></dt><dd><p>
+		Return a derived geometry collection value with elements that
+		match the specified range of measures inclusively.
+		Polygonal elements are not supported. 
+		</p><p>
+		Semantic is specified by: ISO/IEC CD 13249-3:200x(E) -
+		Text for Continuation CD Editing Meeting
+		</p><p>
+			Availability: 1.1.0
+		</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2657449"></a>6.2.8. Misc</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Summary(geometry)</span></dt><dd><p>Returns a text summary of the contents of the geometry.</p></dd><dt><span class="term">box2d(geometry)</span></dt><dd><p>Returns a BOX2D representing the maximum extents of the geometry.</p></dd><dt><span class="term">box3d(geometry)</span></dt><dd><p>Returns a BOX3D representing the maximum extents of the geometry.</p></dd><dt><span class="term">extent(geometry set)</span></dt><dd><p>The extent() function is an "aggregate" function in the terminology of PostgreSQL. That means that it operators on lists of data, in the same way the sum() and mean() functions do. For example, "SELECT EXTENT(GEOM) FROM GEOMTABLE" will return a BOX3D giving the maximum extend of all features in the table. Similarly, "SELECT EXTENT(GEOM) FROM GEOMTABLE GROUP BY CATEGORY" will return one extent result for each category.</p></dd><dt><a name="zmflag"></a><span class="term">zmflag(geometry)</span></dt><dd><p>Returns ZM (dimension semantic) flag of the geometries as a small int. Values are: 0=2d, 1=3dm, 2=3dz, 3=4d.  </p></dd><dt><a name="hasbbox"></a><span class="term">HasBBOX(geometry)</span></dt><dd><p>Returns TRUE if the bbox of this geometry is cached, FALSE otherwise. Use <a href="#addbbox">addBBOX()</a> and <a href="#dropbbox">dropBBOX()</a> to control caching.</p></dd><dt><a name="ndims"></a><span class="term">ndims(geometry)</span></dt><dd><p>Returns number of dimensions of the geometry as a small int. Values are: 2,3 or 4.</p></dd><dt><span class="term">nrings(geometry)</span></dt><dd><p>If the geometry is a polygon or multi-polygon returns the number of rings.</p></dd><dt><span class="term">npoints(geometry)</span></dt><dd><p>Returns the number of points in the geometry.</p></dd><dt><a name="IsValid"></a><span class="term">isvalid(geometry)</span></dt><dd><p>returns true if this geometry is valid.</p></dd><dt><span class="term">expand(geometry, float)</span></dt><dd><p>This function returns a bounding box expanded in all
+		    directions from the bounding box of the input geometry, by an
+		    amount specified in the second argument. Very useful for
+		    distance() queries, to add an index filter to the query.</p></dd><dt><span class="term">estimated_extent([schema], table, geocolumn)</span></dt><dd><p> Return the 'estimated' extent of the given spatial table.  The estimated is taken from the geometry column's statistics. The current schema will be used if not specified.</p><p>For PostgreSQL&gt;=8.0.0 statistics are gathered by VACUUM ANALYZE and resulting extent will be about 95% of the real one.</p><p>For PostgreSQL&lt;8.0.0 statistics are gathered by update_geometry_stats() and resulting extent will be exact.</p></dd><dt><span class="term">find_srid(varchar,varchar,varchar)</span></dt><dd><p>The syntax is find_srid(&lt;db/schema&gt;, &lt;table&gt;,
+            &lt;column&gt;) and the function returns the integer SRID of the
+            specified column by searching through the GEOMETRY_COLUMNS table.
+            If the geometry column has not been properly added with the
+            AddGeometryColumns() function, this function will not work
+            either.</p></dd><dt><span class="term">mem_size(geometry)</span></dt><dd><p>Returns the amount of space (in bytes) the geometry
+            takes.</p></dd><dt><span class="term">numb_sub_objects(geometry)</span></dt><dd><p>Returns the number of objects stored in the geometry. This
+            is useful for MULTI-geometries and GEOMETRYCOLLECTIONs.</p></dd><dt><span class="term">point_inside_circle(geometry,float,float,float)</span></dt><dd><p>The syntax for this functions is
+            point_inside_circle(&lt;geometry&gt;,&lt;circle_center_x&gt;,&lt;circle_center_y&gt;,&lt;radius&gt;).
+            Returns the true if the geometry is a point and is inside the
+            circle. Returns false otherwise.</p></dd><dt><span class="term">xmin(box3d) ymin(box3d) zmin(box3d)</span></dt><dd><p>Returns the requested minima of a bounding box.</p></dd><dt><span class="term">xmax(box3d) ymax(box3d) zmax(box3d)</span></dt><dd><p>Returns the requested maxima of a bounding box.</p></dd><dt><a name="Accum"></a><span class="term">Accum(geometry set)</span></dt><dd><p>Aggregate. Constructs an array of geometries.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2658447"></a>6.2.9. Long Transactions support</h3></div></div><div></div></div><p>
+This module and associated pl/pgsql functions have been implemented
+to provide long locking support required by
+<a href="https://portal.opengeospatial.org/files/?artifact_id=7176" target="_top">Web Feature Service</a> specification.
+	</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+  Users must use <a href="http://www.postgresql.org/docs/7.4/static/transaction-iso.html" target="_top">serializable transaction level</a> otherwise locking mechanism would break.
+	  </p></div><div class="variablelist"><dl><dt><a name="EnableLongTransactions"></a><span class="term">EnableLongTransactions()</span></dt><dd><p>
+		Enable long transaction support. This function creates the
+		required metadata tables, needs to be called once before
+		using the other functions in this section. Calling it twice
+		is harmless.
+	    </p><p>
+		    Availability: 1.1.3
+		</p></dd><dt><a name="DisableLongTransactions"></a><span class="term">DisableLongTransactions()</span></dt><dd><p>
+		Disable long transaction support. This function removes the
+		long transaction support metadata tables, and drops all
+		triggers attached to lock-checked tables.
+	    </p><p>
+		    Availability: 1.1.3
+		</p></dd><dt><a name="CheckAuth"></a><span class="term">CheckAuth([&lt;schema&gt;], &lt;table&gt;, &lt;rowid_col&gt;)</span></dt><dd><p>
+		Check updates and deletes of rows in
+		given table for being authorized.
+		Identify rows using &lt;rowid_col&gt; column.
+	    </p><p>
+		    Availability: 1.1.3
+		</p></dd><dt><a name="LockRow"></a><span class="term">LockRow([&lt;schema&gt;], &lt;table&gt;, &lt;rowid&gt;, &lt;authid&gt;, [&lt;expires&gt;])</span></dt><dd><p>
+	Set lock/authorization for specific row in table
+	&lt;authid&gt; is a text value, &lt;expires&gt; is a timestamp
+	defaulting to now()+1hour.
+	Returns 1 if lock has been assigned, 0 otherwise
+	(already locked by other auth)
+	    </p><p>
+		    Availability: 1.1.3
+		</p></dd><dt><a name="UnlockRows"></a><span class="term">UnlockRows(&lt;authid&gt;)</span></dt><dd><p>
+	Remove all locks held by specified authorization id.
+	Returns the number of locks released.
+	    </p><p>
+		    Availability: 1.1.3
+		</p></dd><dt><a name="AddAuth"></a><span class="term">AddAuth(&lt;authid&gt;)</span></dt><dd><p>
+	Add an authorization token to be used in current
+	transaction. 
+	    </p><p>
+		    Availability: 1.1.3
+		</p></dd></dl></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2658031"></a>Chapter 7. Reporting Bugs</h2></div></div><div></div></div><p>
+	Reporting bugs effectively is a fundamental way to help PostGIS
+	development. The most effective bug report is that enabling 
+	PostGIS developers to reproduce it, so it would ideally contain
+	a script triggering it and every information regarding the
+	environment in which it was detected. Good enough info can
+	be extracted running <tt class="code">SELECT postgis_full_version()</tt>
+	[for postgis] and <tt class="code">SELECT version()</tt> [for postgresql].
+		</p><p>
+	If you aren't using latest release, it's worth taking a look
+	at its <a href="http://postgis.refractions.net/CHANGES.txt" target="_top">release
+	changelog</a> first, to find out if your bug has already been
+	fixed.
+		</p><p>
+	Using the <a href="http://postgis.refractions.net/bugs/" target="_top">PostGIS
+	bug tracker</a> will ensure your reports are not discarded, and
+	will keep you informed on it's handling process. Before reporting
+	a new bug please query the database to see if it is a known one, and
+	if it is please add any new information you have about it.
+		</p><p>
+	You might want to read Simon Tatham's paper about <a href="http://www.chiark.greenend.org.uk/~sgtatham/bugs.html" target="_top">How
+	to Report Bugs Effectively</a> before filing a new report.
+		</p></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="release_notes"></a>Appendix A. Appendix</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#id2658101">A.1. Release Notes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2658106">A.1.1. Release 1.1.4</a></span></dt><dt><span class="sect2"><a href="#id2658230">A.1.2. Release 1.1.3</a></span></dt><dt><span class="sect2"><a href="#id2658396">A.1.3. Release 1.1.2</a></span></dt><dt><span class="sect2"><a href="#id2658690">A.1.4. Release 1.1.1</a></span></dt><dt><span class="sect2"><a href="#id2658820">A.1.5. Release 1.1.0</a></span></dt><dt><span class="sect2"><a href="#id2659145">A.1.6. Release 1.0.6</a></span></dt><dt><span class="sect2"><a href="#id2659254">A.1.7. Release 1.0.5</a></span></dt><dt><span class="sect2"><a href="#id2659386">A.1.8. Release 1.0.4</a></span></dt><dt><span class="sect2"><a href="#rel_1.0.3_upgrading">A.1.9. Release 1.0.3</a></span></dt><dt><span class="sect2"><a href="#id2659632">A.1.10. Release 1.0.2</a></span></dt><dt><span class="sect2"><a href="#id2659711">A.1.11. Release 1.0.1</a></span></dt><dt><span class="sect2"><a href="#id2659811">A.1.12. Release 1.0.0</a></span></dt><dt><span class="sect2"><a href="#id2659910">A.1.13. Release 1.0.0RC6</a></span></dt><dt><span class="sect2"><a href="#id2659984">A.1.14. Release 1.0.0RC5</a></span></dt><dt><span class="sect2"><a href="#id2660056">A.1.15. Release 1.0.0RC4</a></span></dt><dt><span class="sect2"><a href="#id2660181">A.1.16. Release 1.0.0RC3</a></span></dt><dt><span class="sect2"><a href="#id2660352">A.1.17. Release 1.0.0RC2</a></span></dt><dt><span class="sect2"><a href="#id2660450">A.1.18. Release 1.0.0RC1</a></span></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2658101"></a>A.1. Release Notes</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2658106"></a>A.1.1. Release 1.1.4</h3></div></div><div></div></div><p>Release date: 2006/09/27</p><p>
+This is an bugfix release including some improvements in the Java interface.
+Upgrade is <span class="emphasis"><em>encouraged</em></span>.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658124"></a>A.1.1.1. Upgrading</h4></div></div><div></div></div><p>
+If you are upgrading from release 1.0.3 or later follow the
+<a href="#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
+				</p><p>
+If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
+1.0.2</em></span> (inclusive) and really want a live upgrade read the
+<a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade section</a> of the 1.0.3
+release notes chapter.
+				</p><p>
+Upgrade from any release prior to 1.0.0RC6 requires an
+<a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658173"></a>A.1.1.2. Bug fixes</h4></div></div><div></div></div><p>
+	Fixed support for PostgreSQL 8.2
+		</p><p>
+	Fixed bug in collect() function discarding SRID of
+	  input
+		</p><p>
+	Added SRID match check in MakeBox2d and MakeBox3d
+		</p><p>
+	Fixed regress tests to pass with GEOS-3.0.0
+		</p><p>
+	Improved pgsql2shp run concurrency.
+		</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658201"></a>A.1.1.3. Java changes</h4></div></div><div></div></div><p>
+		reworked JTS support to reflect new upstream
+		JTS developers' attitude to SRID handling.
+		Simplifies code and drops build depend on GNU trove.
+		</p><p>
+		Added EJB2 support generously donated by the
+		"Geodetix s.r.l. Company" http://www.geodetix.it/
+		</p><p>
+		Added EJB3 tutorial / examples donated by
+		Norman Barker &lt;nbarker at ittvis.com&gt;
+		</p><p>
+		Reorganized java directory layout a little.
+		</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2658230"></a>A.1.2. Release 1.1.3</h3></div></div><div></div></div><p>Release date: 2006/06/30</p><p>
+This is an bugfix release including also some new functionalities (most notably long transaction support) and portability enhancements.
+Upgrade is <span class="emphasis"><em>encouraged</em></span>.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658249"></a>A.1.2.1. Upgrading</h4></div></div><div></div></div><p>
+If you are upgrading from release 1.0.3 or later follow the
+<a href="#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
+				</p><p>
+If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
+1.0.2</em></span> (inclusive) and really want a live upgrade read the
+<a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade section</a> of the 1.0.3
+release notes chapter.
+				</p><p>
+Upgrade from any release prior to 1.0.0RC6 requires an
+<a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658295"></a>A.1.2.2. Bug fixes / correctness</h4></div></div><div></div></div><p> BUGFIX in distance(poly,poly) giving wrong results. </p><p> BUGFIX in pgsql2shp successful return code. </p><p> BUGFIX in shp2pgsql handling of MultiLine WKT. </p><p> BUGFIX in affine() failing to update bounding box. </p><p> WKT parser: forbidden construction of multigeometries with 
+	  EMPTY elements (still supported for GEOMETRYCOLLECTION). </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658324"></a>A.1.2.3. New functionalities</h4></div></div><div></div></div><p> NEW Long Transactions support. </p><p> NEW DumpRings() function. </p><p> NEW AsHEXEWKB(geom, XDR|NDR) function. </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658343"></a>A.1.2.4. JDBC changes</h4></div></div><div></div></div><p> Improved regression tests: MultiPoint and scientific ordinates </p><p> Fixed some minor bugs in jdbc code </p><p>
+Added proper accessor functions for all fields in preparation of 
+making those fields private later
+</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658363"></a>A.1.2.5. Other changes</h4></div></div><div></div></div><p> NEW regress test support for loader/dumper. </p><p> Added --with-proj-libdir and --with-geos-libdir configure switches. </p><p> Support for build Tru64 build. </p><p> Use Jade for generating documentation. </p><p> Don't link pgsql2shp to more libs then required. </p><p> Initial support for PostgreSQL 8.2. </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2658396"></a>A.1.3. Release 1.1.2</h3></div></div><div></div></div><p>Release date: 2006/03/30</p><p>
+This is an bugfix release including some new functions and portability enhancements.
+Upgrade is <span class="emphasis"><em>encouraged</em></span>.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658414"></a>A.1.3.1. Upgrading</h4></div></div><div></div></div><p>
+If you are upgrading from release 1.0.3 or later follow the
+<a href="#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
+				</p><p>
+If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
+1.0.2</em></span> (inclusive) and really want a live upgrade read the
+<a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade section</a> of the 1.0.3
+release notes chapter.
+				</p><p>
+Upgrade from any release prior to 1.0.0RC6 requires an
+<a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658623"></a>A.1.3.2. Bug fixes</h4></div></div><div></div></div><p>BUGFIX in SnapToGrid() computation of output bounding box</p><p>BUGFIX in EnforceRHR() </p><p>jdbc2 SRID handling fixes in JTS code</p><p>Fixed support for 64bit archs</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658646"></a>A.1.3.3. New functionalities</h4></div></div><div></div></div><p>Regress tests can now be run *before* postgis installation</p><p>New affine() matrix transformation functions</p><p>New rotate{,X,Y,Z}() function </p><p>Old translating and scaling functions now use affine() internally</p><p>Embedded access control in estimated_extent() for builds against pgsql &gt;= 8.0.0</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658674"></a>A.1.3.4. Other changes</h4></div></div><div></div></div><p>More portable ./configure script</p><p>Changed ./run_test script to have more sane default behaviour</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2658690"></a>A.1.4. Release 1.1.1</h3></div></div><div></div></div><p>Release date: 2006/01/23</p><p>
+This is an important Bugfix release, upgrade is <span class="emphasis"><em>highly
+recommended</em></span>.
+Previous version contained a bug in postgis_restore.pl preventing
+<a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a> procedure to complete
+and a bug in GEOS-2.2+ connector preventing GeometryCollection objects
+to be used in topological operations.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658718"></a>A.1.4.1. Upgrading</h4></div></div><div></div></div><p>
+If you are upgrading from release 1.0.3 or later follow the
+<a href="#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> procedure.
+				</p><p>
+If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
+1.0.2</em></span> (inclusive) and really want a live upgrade read the
+<a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade section</a> of the 1.0.3
+release notes chapter.
+				</p><p>
+Upgrade from any release prior to 1.0.0RC6 requires an
+<a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658765"></a>A.1.4.2. Bug fixes</h4></div></div><div></div></div><p>Fixed a premature exit in postgis_restore.pl </p><p>BUGFIX in geometrycollection handling of GEOS-CAPI connector</p><p>Solaris 2.7 and MingW support improvements</p><p>BUGFIX in line_locate_point()</p><p>Fixed handling of postgresql paths</p><p>BUGFIX in line_substring()</p><p>Added support for localized cluster in regress tester</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658800"></a>A.1.4.3. New functionalities</h4></div></div><div></div></div><p>New Z and M interpolation in line_substring()</p><p>New Z and M interpolation in line_interpolate_point()</p><p>added NumInteriorRing() alias due to OpenGIS ambiguity</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2658820"></a>A.1.5. Release 1.1.0</h3></div></div><div></div></div><p>Release date: 2005/12/21</p><p>
+This is a Minor release, containing many improvements and new things.
+Most notably: build procedure greatly simplified; transform() performance
+drastically improved; more stable GEOS connectivity (CAPI support);
+lots of new functions; draft topology support.
+			</p><p>
+It is <span class="emphasis"><em>highly recommended</em></span> that you upgrade to GEOS-2.2.x
+before installing PostGIS, this will ensure future GEOS upgrades won't
+require a rebuild of the PostGIS library.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658847"></a>A.1.5.1. Credits</h4></div></div><div></div></div><p>
+This release includes code from Mark Cave Ayland for caching of proj4
+objects. Markus Schaber added many improvements in his JDBC2 code.
+Alex Bodnaru helped with PostgreSQL source dependency relief and
+provided Debian specfiles.  Michael Fuhr tested new things on Solaris arch.
+David Techer and Gerald Fenoy helped testing GEOS C-API connector.
+Hartmut Tschauner provided code for the azimuth() function. 
+Devrim GUNDUZ provided RPM specfiles. Carl Anderson helped with
+the new area building functions.
+See the <a href="#credits" title="1.1. Credits">credits</a> section for more names.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658874"></a>A.1.5.2. Upgrading</h4></div></div><div></div></div><p>
+If you are upgrading from release 1.0.3 or later you <span class="emphasis"><em>DO
+NOT</em></span> need a dump/reload.
+Simply sourcing the new lwpostgis_upgrade.sql script in all your
+existing databases will work.
+See the <a href="#soft_upgrade" title="2.2.1.1. Soft upgrade">soft upgrade</a> chapter
+for more information.
+				</p><p>
+If you are upgrading from a release <span class="emphasis"><em>between 1.0.0RC6 and
+1.0.2</em></span> (inclusive) and really want a live upgrade read the
+<a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade section</a> of the 1.0.3
+release notes chapter.
+				</p><p>
+Upgrade from any release prior to 1.0.0RC6 requires an
+<a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658927"></a>A.1.5.3. New functions</h4></div></div><div></div></div><p>scale() and transscale() companion methods to translate()</p><p>line_substring() </p><p>line_locate_point()</p><p>M(point) </p><p>LineMerge(geometry) </p><p>shift_longitude(geometry) </p><p>azimuth(geometry) </p><p>locate_along_measure(geometry, float8) </p><p>locate_between_measures(geometry, float8, float8) </p><p>SnapToGrid by point offset (up to 4d support)</p><p>BuildArea(any_geometry) </p><p>OGC BdPolyFromText(linestring_wkt, srid) </p><p>OGC BdMPolyFromText(linestring_wkt, srid)</p><p>RemovePoint(linestring, offset)</p><p>ReplacePoint(linestring, offset, point)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2658991"></a>A.1.5.4. Bug fixes</h4></div></div><div></div></div><p>Fixed memory leak in polygonize()</p><p>Fixed bug in lwgeom_as_anytype cast functions</p><p>
+Fixed USE_GEOS, USE_PROJ and USE_STATS elements of postgis_version()
+output to always reflect library state.
+</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659011"></a>A.1.5.5. Function semantic changes</h4></div></div><div></div></div><p>SnapToGrid doesn't discard higher dimensions</p><p>Changed Z() function to return NULL if requested dimension is not available</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659027"></a>A.1.5.6. Performance improvements</h4></div></div><div></div></div><p>
+Much faster transform() function, caching proj4 objects
+</p><p>
+Removed automatic call to fix_geometry_columns() in
+AddGeometryColumns() and update_geometry_stats()
+</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659043"></a>A.1.5.7. JDBC2 works</h4></div></div><div></div></div><p>Makefile improvements</p><p>JTS support improvements</p><p>Improved regression test system</p><p>Basic consistency check method for geometry collections</p><p>Support for (Hex)(E)wkb</p><p>Autoprobing DriverWrapper for HexWKB / EWKT switching</p><p>fix compile problems in ValueSetter for ancient jdk releases.</p><p>fix EWKT constructors to accept SRID=4711; representation</p><p>added preliminary read-only support for java2d geometries</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659086"></a>A.1.5.8. Other new things</h4></div></div><div></div></div><p>
+Full autoconf-based configuration, with PostgreSQL source dependency relief
+</p><p>GEOS C-API support (2.2.0 and higher)</p><p>Initial support for topology modelling</p><p>Debian and RPM specfiles</p><p>New lwpostgis_upgrade.sql script</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659113"></a>A.1.5.9. Other changes</h4></div></div><div></div></div><p>JTS support improvements</p><p>Stricter mapping between DBF and SQL integer and string attributes</p><p>Wider and cleaner regression test suite</p><p>old jdbc code removed from release</p><p>obsoleted direct use of postgis_proc_upgrade.pl</p><p>scripts version unified with release version</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659145"></a>A.1.6. Release 1.0.6</h3></div></div><div></div></div><p>Release date: 2005/12/06</p><p>
+Contains a few bug fixes and improvements.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659159"></a>A.1.6.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.3 or later you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.
+				</p><p>If you are upgrading from
+				a release <span class="emphasis"><em>between 1.0.0RC6 and
+				1.0.2</em></span> (inclusive) and really want
+				a live upgrade read the <a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade
+				section</a> of the 1.0.3 release notes
+				chapter.
+				</p><p>
+				Upgrade from any release prior to 1.0.0RC6
+				requires an <a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard
+				upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659203"></a>A.1.6.2. Bug fixes</h4></div></div><div></div></div><p>Fixed palloc(0) call in collection deserializer (only gives problem with --enable-cassert)</p><p>Fixed bbox cache handling bugs</p><p>Fixed geom_accum(NULL, NULL) segfault</p><p>Fixed segfault in addPoint()</p><p>Fixed short-allocation in lwcollection_clone()</p><p>Fixed bug in segmentize()</p><p>Fixed bbox computation of SnapToGrid output</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659238"></a>A.1.6.3. Improvements</h4></div></div><div></div></div><p>Initial support for postgresql 8.2</p><p>Added missing SRID mismatch checks in GEOS ops</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659254"></a>A.1.7. Release 1.0.5</h3></div></div><div></div></div><p>Release date: 2005/11/25</p><p>
+Contains memory-alignment fixes in the library, a segfault fix in loader's
+handling of UTF8 attributes and a few improvements and cleanups.
+			</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+Return code of shp2pgsql changed from previous releases to conform to unix
+standards (return 0 on success).
+			</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659275"></a>A.1.7.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.3 or later you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.
+				</p><p>If you are upgrading from
+				a release <span class="emphasis"><em>between 1.0.0RC6 and
+				1.0.2</em></span> (inclusive) and really want
+				a live upgrade read the <a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade
+				section</a> of the 1.0.3 release notes
+				chapter.
+				</p><p>
+				Upgrade from any release prior to 1.0.0RC6
+				requires an <a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard
+				upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659319"></a>A.1.7.2. Library changes</h4></div></div><div></div></div><p>Fixed memory alignment problems</p><p>Fixed computation of null values fraction in analyzer</p><p>Fixed a small bug in the getPoint4d_p() low-level function</p><p>Speedup of serializer functions</p><p>Fixed a bug in force_3dm(), force_3dz() and force_4d()</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659346"></a>A.1.7.3. Loader changes</h4></div></div><div></div></div><p>Fixed return code of shp2pgsql</p><p>Fixed back-compatibility issue in loader (load of null shapefiles)</p><p>Fixed handling of trailing dots in dbf numerical attributes</p><p>Segfault fix in shp2pgsql (utf8 encoding)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659369"></a>A.1.7.4. Other changes</h4></div></div><div></div></div><p>Schema aware postgis_proc_upgrade.pl, support for pgsql 7.2+</p><p>New "Reporting Bugs" chapter in manual</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659386"></a>A.1.8. Release 1.0.4</h3></div></div><div></div></div><p>Release date: 2005/09/09</p><p>
+Contains important bug fixes and a few improvements. In particular, it
+fixes a memory leak preventing successful build of GiST indexes
+for large spatial tables.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659401"></a>A.1.8.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.3 you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.
+				</p><p>If you are upgrading from
+				a release <span class="emphasis"><em>between 1.0.0RC6 and
+				1.0.2</em></span> (inclusive) and really want
+				a live upgrade read the <a href="#rel_1.0.3_upgrading" title="A.1.9. Release 1.0.3">upgrade
+				section</a> of the 1.0.3 release notes
+				chapter.
+				</p><p>
+				Upgrade from any release prior to 1.0.0RC6
+				requires an <a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard
+				upgrade</a>.
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659445"></a>A.1.8.2. Bug fixes</h4></div></div><div></div></div><p>Memory leak plugged in GiST indexing</p><p>Segfault fix in transform() handling of proj4 errors</p><p>Fixed some proj4 texts in spatial_ref_sys (missing +proj)</p><p>Loader: fixed string functions usage, reworked NULL objects check, fixed segfault on MULTILINESTRING input.</p><p>Fixed bug in MakeLine dimension handling</p><p>Fixed bug in translate() corrupting output bounding box</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659477"></a>A.1.8.3. Improvements</h4></div></div><div></div></div><p>Documentation improvements</p><p>More robust selectivity estimator </p><p>Minor speedup in distance()</p><p>Minor cleanups </p><p>GiST indexing cleanup</p><p>Looser syntax acceptance in box3d parser</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="rel_1.0.3_upgrading"></a>A.1.9. Release 1.0.3</h3></div></div><div></div></div><p>Release date: 2005/08/08</p><p>
+Contains some bug fixes - <span class="emphasis"><em>including a severe one affecting
+correctness of stored geometries</em></span> - and a few improvements.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659530"></a>A.1.9.1. Upgrading</h4></div></div><div></div></div><p>
+Due to a bug in a bounding box computation routine, the upgrade procedure
+requires special attention, as bounding boxes cached in the database could
+be incorrect.
+				</p><p>
+An <a href="#hard_upgrade" title="2.2.1.2. Hard upgrade">hard upgrade</a> procedure (dump/reload)
+will force recomputation of all bounding boxes (not included in dumps).
+This is <span class="emphasis"><em>required</em></span> if upgrading from releases prior
+to 1.0.0RC6.
+				</p><p>
+If you are upgrading from versions 1.0.0RC6 or up, this release includes a
+perl script (utils/rebuild_bbox_caches.pl) to force recomputation of
+geometries' bounding boxes and invoke all operations required to propagate
+eventual changes in them (geometry statistics update, reindexing).
+Invoke the script after a make install (run with no args for syntax help).
+Optionally run utils/postgis_proc_upgrade.pl to refresh postgis procedures
+and functions signatures (see <a href="#soft_upgrade" title="2.2.1.1. Soft upgrade">Soft upgrade</a>).
+				</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659578"></a>A.1.9.2. Bug fixes</h4></div></div><div></div></div><p>Severe bugfix in lwgeom's 2d bounding box computation</p><p>Bugfix in WKT (-w) POINT handling in loader</p><p>Bugfix in dumper on 64bit machines</p><p>Bugfix in dumper handling of user-defined queries </p><p>Bugfix in create_undef.pl script</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659604"></a>A.1.9.3. Improvements</h4></div></div><div></div></div><p>Small performance improvement in canonical input function</p><p>Minor cleanups in loader</p><p>Support for multibyte field names in loader</p><p>Improvement in the postgis_restore.pl script</p><p>New rebuild_bbox_caches.pl util script</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659632"></a>A.1.10. Release 1.0.2</h3></div></div><div></div></div><p>Release date: 2005/07/04</p><p>
+			Contains a few bug fixes and improvements.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659646"></a>A.1.10.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.0RC6 or up you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.</p><p>Upgrading from older releases
+				requires a dump/reload. 
+				See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659673"></a>A.1.10.2. Bug fixes</h4></div></div><div></div></div><p>Fault tolerant btree ops</p><p>Memory leak plugged in pg_error</p><p>Rtree index fix</p><p>Cleaner build scripts (avoided mix of CFLAGS and CXXFLAGS)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659695"></a>A.1.10.3. Improvements</h4></div></div><div></div></div><p>New index creation capabilities in loader (-I switch)</p><p>Initial support for postgresql 8.1dev</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659711"></a>A.1.11. Release 1.0.1</h3></div></div><div></div></div><p>Release date: 2005/05/24</p><p>
+			Contains a few bug fixes and some improvements.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659725"></a>A.1.11.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.0RC6 or up you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.</p><p>Upgrading from older releases
+				requires a dump/reload. 
+				See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659752"></a>A.1.11.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in 3d computation of length_spheroid()</p><p>BUGFIX in join selectivity estimator</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659767"></a>A.1.11.3. Other changes/additions</h4></div></div><div></div></div><p>BUGFIX in shp2pgsql escape functions</p><p>better support for concurrent postgis in multiple schemas</p><p>documentation fixes</p><p>jdbc2: compile with "-target 1.2 -source 1.2" by default</p><p>NEW -k switch for pgsql2shp</p><p>NEW support for custom createdb options in postgis_restore.pl</p><p>BUGFIX in pgsql2shp attribute names unicity enforcement</p><p>BUGFIX in Paris projections definitions</p><p>postgis_restore.pl cleanups</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659811"></a>A.1.12. Release 1.0.0</h3></div></div><div></div></div><p>Release date: 2005/04/19</p><p>Final 1.0.0 release.
+			Contains a few bug fixes, some improvements
+			in the loader (most notably support for older
+			postgis versions), and more docs.
+			</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659826"></a>A.1.12.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.0RC6 you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.</p><p>Upgrading from any other precedent
+				release requires a dump/reload. 
+				See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659853"></a>A.1.12.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in transform() releasing random memory address</p><p>BUGFIX in force_3dm() allocating less memory then required</p><p>BUGFIX in join selectivity estimator (defaults, leaks, tuplecount, sd)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659873"></a>A.1.12.3. Other changes/additions</h4></div></div><div></div></div><p>BUGFIX in shp2pgsql escape of values starting with tab or single-quote</p><p>NEW manual pages for loader/dumper</p><p>NEW shp2pgsql support for old (HWGEOM) postgis versions</p><p>NEW -p (prepare) flag for shp2pgsql</p><p>NEW manual chapter about OGC compliancy enforcement</p><p>NEW autoconf support for JTS lib</p><p>BUGFIX in estimator testers (support for LWGEOM and schema parsing)</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659910"></a>A.1.13. Release 1.0.0RC6</h3></div></div><div></div></div><p>Release date: 2005/03/30</p><p>Sixth release candidate for 1.0.0.
+			Contains a few bug fixes and cleanups.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659924"></a>A.1.13.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
+				from precedent releases. See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659943"></a>A.1.13.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in multi()</p><p>early return [when noop] from multi()</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659957"></a>A.1.13.3. Scripts changes</h4></div></div><div></div></div><p>dropped {x,y}{min,max}(box2d) functions</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659968"></a>A.1.13.4. Other changes</h4></div></div><div></div></div><p>BUGFIX in postgis_restore.pl scrip</p><p>BUGFIX in dumper's 64bit support</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2659984"></a>A.1.14. Release 1.0.0RC5</h3></div></div><div></div></div><p>Release date: 2005/03/25</p><p>Fifth release candidate for 1.0.0.
+			Contains a few bug fixes and a improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2659998"></a>A.1.14.1. Upgrading</h4></div></div><div></div></div><p>If you are upgrading from
+				release 1.0.0RC4 you <span class="emphasis"><em>DO
+				NOT</em></span> need a dump/reload.</p><p>Upgrading from any other precedent
+				release requires a dump/reload. 
+				See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660025"></a>A.1.14.2. Library changes</h4></div></div><div></div></div><p>BUGFIX (segfaulting) in box3d computation (yes, another!).</p><p>BUGFIX (segfaulting) in estimated_extent().</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660040"></a>A.1.14.3. Other changes</h4></div></div><div></div></div><p>Small build scripts and utilities refinements.</p><p>Additional performance tips documented.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2660056"></a>A.1.15. Release 1.0.0RC4</h3></div></div><div></div></div><p>Release date: 2005/03/18</p><p>Fourth release candidate for 1.0.0.
+			Contains bug fixes and a few improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660070"></a>A.1.15.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
+				from precedent releases. See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660088"></a>A.1.15.2. Library changes</h4></div></div><div></div></div><p>BUGFIX (segfaulting) in geom_accum().</p><p>BUGFIX in 64bit architectures support.</p><p>BUGFIX in box3d computation function with collections.</p><p>NEW subselects support in selectivity estimator.</p><p>Early return from force_collection.</p><p>Consistency check fix in SnapToGrid().</p><p>Box2d output changed back to 15 significant digits.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660124"></a>A.1.15.3. Scripts changes</h4></div></div><div></div></div><p>NEW distance_sphere() function.</p><p>Changed get_proj4_from_srid implementation to use PL/PGSQL instead of SQL.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660139"></a>A.1.15.4. Other changes</h4></div></div><div></div></div><p>BUGFIX in loader and dumper handling of MultiLine shapes</p><p>BUGFIX in loader, skipping all but first hole of polygons.</p><p>jdbc2: code cleanups, Makefile improvements</p><p>FLEX and YACC variables set *after* pgsql Makefile.global is included and only if the pgsql *stripped* version evaluates to the empty string</p><p>Added already generated parser in release</p><p>Build scripts refinements</p><p>improved version handling, central Version.config</p><p>improvements in postgis_restore.pl</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2660181"></a>A.1.16. Release 1.0.0RC3</h3></div></div><div></div></div><p>Release date: 2005/02/24</p><p>Third release candidate for 1.0.0.
+			Contains many bug fixes and improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660195"></a>A.1.16.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
+				from precedent releases. See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660213"></a>A.1.16.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in transform(): missing SRID, better error handling.</p><p>BUGFIX in memory alignment handling</p><p>BUGFIX in force_collection() causing mapserver connector failures on simple (single) geometry types.</p><p>BUGFIX in GeometryFromText() missing to add a bbox cache.</p><p>reduced precision of box2d output.</p><p>prefixed DEBUG macros with PGIS_ to avoid clash with pgsql one</p><p>plugged a leak in GEOS2POSTGIS converter</p><p>Reduced memory usage by early releasing query-context palloced one.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660254"></a>A.1.16.3. Scripts changes</h4></div></div><div></div></div><p>BUGFIX in 72 index bindings.</p><p>BUGFIX in probe_geometry_columns() to work with PG72 and support multiple geometry columns in a single table</p><p>NEW bool::text cast</p><p>Some functions made IMMUTABLE from STABLE, for performance
+	improvement.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660278"></a>A.1.16.4. JDBC changes</h4></div></div><div></div></div><p>jdbc2: small patches, box2d/3d tests, revised docs and license.</p><p>jdbc2: bug fix and testcase in for pgjdbc 8.0 type autoregistration</p><p>jdbc2: Removed use of jdk1.4 only features to enable build with older jdk releases.</p><p>jdbc2: Added support for building against pg72jdbc2.jar</p><p>jdbc2: updated and cleaned makefile</p><p>jdbc2: added BETA support for jts geometry classes</p><p>jdbc2: Skip known-to-fail tests against older PostGIS servers.</p><p>jdbc2: Fixed handling of measured geometries in EWKT.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660319"></a>A.1.16.5. Other changes</h4></div></div><div></div></div><p>new performance tips chapter in manual</p><p>documentation updates: pgsql72 requirement, lwpostgis.sql</p><p>few changes in autoconf </p><p>BUILDDATE extraction made more portable</p><p>fixed spatial_ref_sys.sql to avoid vacuuming the whole
+	database.</p><p>spatial_ref_sys: changed Paris entries to match the ones
+	distributed with 0.x.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2660352"></a>A.1.17. Release 1.0.0RC2</h3></div></div><div></div></div><p>Release date: 2005/01/26</p><p>Second release candidate for 1.0.0
+			containing bug fixes and a few improvements.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660366"></a>A.1.17.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
+				from precedent releases. See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660385"></a>A.1.17.2. Library changes</h4></div></div><div></div></div><p>BUGFIX in pointarray box3d computation</p><p>BUGFIX in distance_spheroid definition</p><p>BUGFIX in transform() missing to update bbox cache</p><p>NEW jdbc driver (jdbc2)</p><p>GEOMETRYCOLLECTION(EMPTY) syntax support for backward compatibility</p><p>Faster binary outputs</p><p>Stricter OGC WKB/WKT constructors</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660420"></a>A.1.17.3. Scripts changes</h4></div></div><div></div></div><p>More correct STABLE, IMMUTABLE, STRICT uses in lwpostgis.sql</p><p>stricter OGC WKB/WKT constructors</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660435"></a>A.1.17.4. Other changes</h4></div></div><div></div></div><p>Faster and more robust loader (both i18n and not)</p><p>Initial autoconf script</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2660450"></a>A.1.18. Release 1.0.0RC1</h3></div></div><div></div></div><p>Release date: 2005/01/13</p><p>This is the first candidate of a
+			major postgis release, with internal
+			storage of postgis types redesigned to be smaller
+			and faster on indexed queries.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660466"></a>A.1.18.1. Upgrading</h4></div></div><div></div></div><p>You need a dump/reload to upgrade
+				from precedent releases. See the <a href="#upgrading" title="2.2.1. Upgrading">upgrading</a>
+				chapter for more informations.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2660484"></a>A.1.18.2. Changes</h4></div></div><div></div></div><p>
+				Faster canonical input parsing.
+				</p><p>
+				Lossless canonical output.
+				</p><p>
+				EWKB Canonical binary IO with PG&gt;73.
+				</p><p>
+				Support for up to 4d coordinates, providing
+				lossless shapefile-&gt;postgis-&gt;shapefile
+				conversion.
+				</p><p>
+				New function: UpdateGeometrySRID(), AsGML(),
+				SnapToGrid(), ForceRHR(), estimated_extent(),
+				accum().
+				</p><p>
+				Vertical positioning indexed operators.
+				</p><p>
+				JOIN selectivity function.
+				</p><p>
+				More geometry constructors / editors.
+				</p><p>
+				Postgis extension API.
+				</p><p>
+				UTF8 support in loader.
+				</p></div></div></div></div></div></body></html>

Modified: packages/postgis/upstream/doc/postgis.xml
===================================================================
--- packages/postgis/upstream/doc/postgis.xml	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/doc/postgis.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -17,7 +17,7 @@
         Inc</ulink></orgname>
 
         <address>
-     <street>Suite 400, 1207 Douglas Street</street>
+     <street>Suite 300, 1207 Douglas Street</street>
      <city>Victoria</city>
      <state>British Columbia</state>
      <country>Canada</country>
@@ -56,7 +56,7 @@
           <term>Sandro Santilli &lt;strk at refractions.net&gt;</term>
 
           <listitem>
-            <para>Coordinates all bug fixing and maintainance effort,
+            <para>Coordinates all bug fixing and maintenance effort,
             integration of new GEOS functionality, and new function
             enhancements.</para>
           </listitem>
@@ -423,7 +423,7 @@
 By HARD UPGRADE we intend full dump/reload of postgis-enabled databases.
 You need an HARD UPGRADE when postgis objects' internal storage
 changes or when SOFT UPGRADE is not possible.
-The <link linkend="release_notes">Release Notes</link> appendix reports for each version wheter you need a
+The <link linkend="release_notes">Release Notes</link> appendix reports for each version whether you need a
 dump/reload (HARD UPGRADE) to upgrade.
 	</para>
 
@@ -493,7 +493,7 @@
             <para>Check that you you have installed PostgreSQL 7.2 or newer,
             and that you are compiling against the same version of the
             PostgreSQL source as the version of PostgreSQL that is running.
-            Mix-ups can occur when your (Linux) distrubution has already
+            Mix-ups can occur when your (Linux) distribution has already
             installed PostgreSQL, or you have otherwise installed PostgreSQL
             before and forgotten about it. PostGIS will only work with
             PostgreSQL 7.2 or newer, and strange, unexpected error messages
@@ -1437,7 +1437,7 @@
             <term>-k</term>
 
             <listitem>
-              <para>Keep idendifiers case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.</para>
+              <para>Keep identifiers' case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.</para>
             </listitem>
           </varlistentry>
 
@@ -1836,7 +1836,7 @@
           </listitem>
 
           <listitem>
-            <para>If you find the planner wrong about the cost of sequencial
+            <para>If you find the planner wrong about the cost of sequential
             vs index scans try reducing the value of random_page_cost in
             postgresql.conf or using SET random_page_cost=#. Default value for
             the parameter is 4, try setting it to 1 or 2. Decrementing the
@@ -1859,7 +1859,7 @@
         <title>Taking Advantage of Indexes</title>
 
         <para>When constructing a query it is important to remember that only
-        the bounding-box-based operators such as &amp;&amp; can take advatage
+        the bounding-box-based operators such as &amp;&amp; can take advantage
         of the GiST spatial index. Functions such as
         <varname>distance()</varname> cannot use the index to optimize their
         operation. For example, the following query would be quite slow on a
@@ -2437,7 +2437,7 @@
 
         <para>Now lets say we want to show only the highways until we get
         zoomed in to at least a 1:100000 scale - the next two layers will
-        acheive this effect:</para>
+        achieve this effect:</para>
 
         <programlisting>LAYER
  CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
@@ -2633,9 +2633,9 @@
 <para>
 The problem appears if you happen to have a table with rather large
 geometries, but not too much rows of them (like a table containing the
-boundaries of all european countries in high resolution). Then the table
-itsself is small, but it uses lots of TOAST space. In our example case,
-the table itsself had about 80 rows and used only 3 data pages, but the
+boundaries of all European countries in high resolution). Then the table
+itself is small, but it uses lots of TOAST space. In our example case,
+the table itself had about 80 rows and used only 3 data pages, but the
 TOAST table used 8225 pages.
 </para>
 
@@ -2699,7 +2699,7 @@
 </programlisting>
 
 <para>
-Of yourse, if you change or add rows to mytable, you have to keep the
+Of course, if you change or add rows to mytable, you have to keep the
 bbox "in sync". The most transparent way to do this would be triggers,
 but you also can modify your application to keep the bbox column current
 or run the UPDATE query above after every modification.
@@ -3210,8 +3210,8 @@
             <term>Difference(geometry A, geometry B)</term>
 
             <listitem>
-              <para>Returns a geometry that represents the point set symmetric
-              difference of Geometry A with Geometry B.</para>
+              <para>Returns a geometry that represents the point set difference
+              of Geometry A with Geometry B.</para>
 
               <para>Performed by the GEOS module</para>
 
@@ -3464,7 +3464,7 @@
 
             <listitem>
               <para>Synonym to NumInteriorRings(geometry). The OpenGIS specs
-	      are ambigous about the exact function naming, so we provide
+	      are ambiguous about the exact function naming, so we provide
 	      both spellings.</para>
             </listitem>
           </varlistentry>
@@ -4204,7 +4204,7 @@
 
 		  <listitem>
 		    <para>The "&amp;&amp;" operator is the "overlaps" operator. If A's
-		    bounding boux overlaps B's bounding box the operator returns
+		    bounding box overlaps B's bounding box the operator returns
 		    true.</para>
 		  </listitem>
 		</varlistentry>
@@ -4269,10 +4269,10 @@
           <term>length_spheroid(geometry,spheroid)</term>
 
           <listitem>
-            <para>Calculates the length of of a geometry on an elipsoid. This
+            <para>Calculates the length of of a geometry on an ellipsoid. This
             is useful if the coordinates of the geometry are in
             latitude/longitude and a length is desired without reprojection.
-            The elipsoid is a separate database type and can be constructed as
+            The ellipsoid is a separate database type and can be constructed as
             follows:</para>
 
             <literallayout>SPHEROID[&lt;NAME&gt;,&lt;SEMI-MAJOR AXIS&gt;,&lt;INVERSE FLATTENING&gt;]</literallayout>
@@ -4296,7 +4296,7 @@
           <term>length3d_spheroid(geometry,spheroid)</term>
 
           <listitem>
-            <para>Calculates the length of of a geometry on an elipsoid,
+            <para>Calculates the length of of a geometry on an ellipsoid,
             taking the elevation into account. This is just like
             length_spheroid except vertical coordinates (expressed in the same
             units as the spheroid axes) are used to calculate the extra
@@ -4512,7 +4512,7 @@
 		<varlistentry id="BuildArea">
 		  <term>BuildArea(geometry)</term>
 		  <listitem>
-		    <para>Creates an areal geometry formed by the costituent
+		    <para>Creates an areal geometry formed by the constituent
 		    linework of given geometry. The return type can
 		    be a Polygon or MultiPolygon, depending on input.
 		    If the input lineworks do not form polygons NULL is
@@ -4536,7 +4536,7 @@
 
 		<para>
 			Aggregate. Creates a GeometryCollection containing
-			possible polygons formed from the costituent linework
+			possible polygons formed from the constituent linework
 			of a set of geometries.
 		</para>
 
@@ -4949,7 +4949,7 @@
 
 		<para>
 			Returns a (set of) LineString(s) formed by sewing
-			togheter costituent linework of input.
+			together constituent linework of input.
 		</para>
 
 		<para>
@@ -4972,7 +4972,7 @@
 
           <listitem>
 		<para>
-		Returns a poin interpolated along a line.
+		Returns a point interpolated along a line.
 		First argument must be a LINESTRING.
 		Second argument is a float8 between 0 and 1
 		representing fraction of total
@@ -5275,7 +5275,7 @@
 	Reporting bugs effectively is a fundamental way to help PostGIS
 	development. The most effective bug report is that enabling 
 	PostGIS developers to reproduce it, so it would ideally contain
-	a script triggering it and every information reguarding the
+	a script triggering it and every information regarding the
 	environment in which it was detected. Good enough info can
 	be extracted running <code>SELECT postgis_full_version()</code>
 	[for postgis] and <code>SELECT version()</code> [for postgresql].
@@ -5313,6 +5313,78 @@
 		<title>Release Notes</title>
 
     		<sect2>
+			<title>Release 1.1.4</title>
+			<para>Release date: 2006/09/27</para>
+
+			<para>
+This is an bugfix release including some improvements in the Java interface.
+Upgrade is <emphasis>encouraged</emphasis>.
+			</para>
+
+			<sect3>
+				<title>Upgrading</title>
+
+				<para>
+If you are upgrading from release 1.0.3 or later follow the
+<link linkend="soft_upgrade">soft upgrade</link> procedure.
+				</para>
+
+				<para>
+If you are upgrading from a release <emphasis>between 1.0.0RC6 and
+1.0.2</emphasis> (inclusive) and really want a live upgrade read the
+<link linkend="rel_1.0.3_upgrading">upgrade section</link> of the 1.0.3
+release notes chapter.
+				</para>
+
+				<para>
+Upgrade from any release prior to 1.0.0RC6 requires an
+<link linkend="hard_upgrade">hard upgrade</link>.
+				</para>
+			</sect3>
+
+
+			<sect3>
+				<title>Bug fixes</title>
+		<para>
+	Fixed support for PostgreSQL 8.2
+		</para>
+		<para>
+	Fixed bug in collect() function discarding SRID of
+	  input
+		</para>
+		<para>
+	Added SRID match check in MakeBox2d and MakeBox3d
+		</para>
+		<para>
+	Fixed regress tests to pass with GEOS-3.0.0
+		</para>
+		<para>
+	Improved pgsql2shp run concurrency.
+		</para>
+			</sect3>
+
+			<sect3>
+				<title>Java changes</title>
+		<para>
+		reworked JTS support to reflect new upstream
+		JTS developers' attitude to SRID handling.
+		Simplifies code and drops build depend on GNU trove.
+		</para>
+		<para>
+		Added EJB2 support generously donated by the
+		"Geodetix s.r.l. Company" http://www.geodetix.it/
+		</para>
+		<para>
+		Added EJB3 tutorial / examples donated by
+		Norman Barker &lt;nbarker at ittvis.com&gt;
+		</para>
+        	<para>
+		Reorganized java directory layout a little.
+		</para>
+			</sect3>
+
+		</sect2>
+    		<sect2>
 			<title>Release 1.1.3</title>
 			<para>Release date: 2006/06/30</para>
 
@@ -5422,7 +5494,7 @@
 
 			<sect3>
 				<title>New functionalities</title>
-<para>Regress tests can now be run *before* postgis intallation</para>
+<para>Regress tests can now be run *before* postgis installation</para>
 <para>New affine() matrix transformation functions</para>
 <para>New rotate{,X,Y,Z}() function </para>
 <para>Old translating and scaling functions now use affine() internally</para>
@@ -5532,7 +5604,7 @@
 Simply sourcing the new lwpostgis_upgrade.sql script in all your
 existing databases will work.
 See the <link linkend="soft_upgrade">soft upgrade</link> chapter
-for more informations.
+for more information.
 				</para>
 
 				<para>
@@ -5570,7 +5642,7 @@
 			<sect3>
 				<title>Bug fixes</title>
 <para>Fixed memory leak in polygonize()</para>
-<para>Fixed bug in lwgeom_as_anytype cast funcions</para>
+<para>Fixed bug in lwgeom_as_anytype cast functions</para>
 <para>
 Fixed USE_GEOS, USE_PROJ and USE_STATS elements of postgis_version()
 output to always reflect library state.
@@ -5693,7 +5765,7 @@
 			</para>
 
 			<note><para>
-Return code of shp2pgsl changed from previous releases to conform to unix
+Return code of shp2pgsql changed from previous releases to conform to unix
 standards (return 0 on success).
 			</para></note>
 
@@ -5923,13 +5995,13 @@
 
 			<sect3>
 				<title>Library changes</title>
-	<para>BUGFIX in 3d computation of lenght_spheroid()</para>
+	<para>BUGFIX in 3d computation of length_spheroid()</para>
 	<para>BUGFIX in join selectivity estimator</para>
 			</sect3>
 
 			<sect3>
 				<title>Other changes/additions</title>
-	<para>BUGFIX in shp2pgql escape functions</para>
+	<para>BUGFIX in shp2pgsql escape functions</para>
 	<para>better support for concurrent postgis in multiple schemas</para>
 	<para>documentation fixes</para>
 	<para>jdbc2: compile with "-target 1.2 -source 1.2" by default</para>
@@ -6094,7 +6166,7 @@
 <para>BUGFIX in loader and dumper handling of MultiLine shapes</para>
 <para>BUGFIX in loader, skipping all but first hole of polygons.</para>
 <para>jdbc2: code cleanups, Makefile improvements</para>
-<para>FLEX and YACC variables set *after* pgsql Makefile.global is included and only if the pgsql *stripped* version evaulates to the empty string</para>
+<para>FLEX and YACC variables set *after* pgsql Makefile.global is included and only if the pgsql *stripped* version evaluates to the empty string</para>
 <para>Added already generated parser in release</para>
 <para>Build scripts refinements</para>
 <para>improved version handling, central Version.config</para>

Modified: packages/postgis/upstream/extras/WFS_locks/WFS_locks.sql.in
===================================================================
--- packages/postgis/upstream/extras/WFS_locks/WFS_locks.sql.in	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/extras/WFS_locks/WFS_locks.sql.in	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- 
--- $Id: WFS_locks.sql.in,v 1.4 2006/06/25 22:33:55 strk Exp $
+-- $Id: WFS_locks.sql.in 2394 2006-06-25 22:33:55Z strk $
 --
 -- PostGIS - Spatial Types for PostgreSQL
 -- http://postgis.refractions.net

Deleted: packages/postgis/upstream/extras/ogc_test_suite/.cvsignore
===================================================================
--- packages/postgis/upstream/extras/ogc_test_suite/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/extras/ogc_test_suite/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,2 +0,0 @@
-1_output.txt
-2_output.txt

Modified: packages/postgis/upstream/extras/ogc_test_suite/1_schema.sql
===================================================================
--- packages/postgis/upstream/extras/ogc_test_suite/1_schema.sql	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/extras/ogc_test_suite/1_schema.sql	2006-10-06 08:43:11 UTC (rev 561)
@@ -100,7 +100,12 @@
 -- create the spatial_ref_sys table or view via another mechanism.
 -- The size of the srtext VARCHAR exceeds that allowed on some systems.
 --
--- POSTGIS: This is already defined by postgis.sql so we comment it out.
+-- ---------------------
+-- !#@ ADAPTATION BEGIN
+-- This table is already defined by PostGIS so we comment it out here.
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 --CREATE TABLE spatial_ref_sys (
 --       srid       INTEGER NOT NULL PRIMARY KEY,
 --       auth_name  VARCHAR(256),
@@ -108,6 +113,10 @@
 --       srtext     VARCHAR(2048)
 --       srtext     VARCHAR(2000)
 --);
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 INSERT INTO spatial_ref_sys (SRID,AUTH_NAME,AUTH_SRID,SRTEXT) 
 VALUES (101, 'POSC', 32214, 
@@ -147,78 +156,208 @@
 --
 --
 --
--- POSTGIS: We break the schema creation into two steps, first create the 
--- POSTGIS: attribute table, second use the AddGeometryColumn() function 
--- POSTGIS: to create and register the geometry column.
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the 
+-- attribute table, second use the AddGeometryColumn() function 
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE lakes (
+--       fid               INTEGER NOT NULL PRIMARY KEY,
+--       name              VARCHAR(64),
+--       shore             POLYGON
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE lakes (
        fid               INTEGER NOT NULL PRIMARY KEY,
        name              VARCHAR(64)
---     shore             POLYGON
 );
 SELECT AddGeometryColumn('lakes','shore','101','POLYGON','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Road Segments
 --
 --
---
---
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE road_segments (
+--      fid               INTEGER NOT NULL PRIMARY KEY,
+--      name              VARCHAR(64),
+--      aliases           VARCHAR(64),
+--      num_lanes         INTEGER
+--      centerline        LINESTRING
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
+
 CREATE TABLE road_segments (
        fid               INTEGER NOT NULL PRIMARY KEY,
        name              VARCHAR(64),
        aliases           VARCHAR(64),
        num_lanes         INTEGER
---     centerline        LINESTRING
 );
 SELECT AddGeometryColumn('road_segments','centerline','101','LINESTRING','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Divided Routes
 --
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE divided_routes (
+--       fid               INTEGER NOT NULL PRIMARY KEY,
+--       name              VARCHAR(64),
+--       num_lanes         INTEGER
+--       centerlines       MULTILINESTRING
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE divided_routes (
        fid               INTEGER NOT NULL PRIMARY KEY,
        name              VARCHAR(64),
        num_lanes         INTEGER
---     centerlines       MULTILINESTRING
 );
 SELECT AddGeometryColumn('divided_routes','centerlines','101','MULTILINESTRING','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Forests
 --
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE forests (
+--       fid            INTEGER NOT NULL PRIMARY KEY,
+--       name           VARCHAR(64)
+--       boundary       MULTIPOLYGON
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE forests (
        fid            INTEGER NOT NULL PRIMARY KEY,
        name           VARCHAR(64)
---     boundary       MULTIPOLYGON
 );
 SELECT AddGeometryColumn('forests','boundary','101','MULTIPOLYGON','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Bridges
 --
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE bridges (
+--       fid           INTEGER NOT NULL PRIMARY KEY,
+--       name          VARCHAR(64)
+--       position      POINT
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE bridges (
        fid           INTEGER NOT NULL PRIMARY KEY,
        name          VARCHAR(64)
---     position      POINT
 );
 SELECT AddGeometryColumn('bridges','position','101','POINT','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
+
 --
 -- Streams
 --
 --
---
---
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE streams (
+--       fid             INTEGER NOT NULL PRIMARY KEY,
+--       name            VARCHAR(64)
+--       centerline      LINESTRING
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE streams (
        fid             INTEGER NOT NULL PRIMARY KEY,
        name            VARCHAR(64)
---     centerline      LINESTRING
 );
 SELECT AddGeometryColumn('streams','centerline','101','LINESTRING','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Buildings
 --
@@ -230,50 +369,138 @@
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE buildings (
+--     fid             INTEGER NOT NULL PRIMARY KEY,
+--     address         VARCHAR(64)
+--     position        POINT
+--     footprint       POLYGON
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE buildings (
        fid             INTEGER NOT NULL PRIMARY KEY,
        address         VARCHAR(64)
---     position        POINT
---     footprint       POLYGON
 );
 SELECT AddGeometryColumn('buildings','position','101','POINT','2');
 SELECT AddGeometryColumn('buildings','footprint','101','POLYGON','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Ponds
 --
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE ponds (
+--       fid             INTEGER NOT NULL PRIMARY KEY,
+--       name            VARCHAR(64),
+--       type            VARCHAR(64)
+--       shores          MULTIPOYLGON
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE ponds (
        fid             INTEGER NOT NULL PRIMARY KEY,
        name            VARCHAR(64),
        type            VARCHAR(64)
---     shores          MULTIPOYLGON
 );
 SELECT AddGeometryColumn('ponds','shores','101','MULTIPOLYGON','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 -- Named Places
 --
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+
+-- CREATE TABLE named_places (
+--       fid             INTEGER NOT NULL PRIMARY KEY,
+--       name            VARCHAR(64)
+--       boundary        POLYGON
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE named_places (
        fid             INTEGER NOT NULL PRIMARY KEY,
        name            VARCHAR(64)
---     boundary        POLYGON
 );
 SELECT AddGeometryColumn('named_places','boundary','101','POLYGON','2');
---
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 -- Map Neatline
 --
 --
 --
 --
+-- !#@ ADAPTATION BEGIN
+-- We break the schema creation into two steps, first create the
+-- attribute table, second use the AddGeometryColumn() function
+-- to create and register the geometry column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- CREATE TABLE map_neatlines (
+--     fid             INTEGER NOT NULL PRIMARY KEY
+--     neatline        POLYGON
+-- );
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 CREATE TABLE map_neatlines (
        fid             INTEGER NOT NULL PRIMARY KEY
---     neatline        POLYGON
 );
 SELECT AddGeometryColumn('map_neatlines','neatline','101','POLYGON','2');
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
 --
 --
 --

Modified: packages/postgis/upstream/extras/ogc_test_suite/2_queries.sql
===================================================================
--- packages/postgis/upstream/extras/ogc_test_suite/2_queries.sql	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/extras/ogc_test_suite/2_queries.sql	2006-10-06 08:43:11 UTC (rev 561)
@@ -210,9 +210,28 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script incorrectly references the 'lakes' table
+-- instead of the 'divided_routes' table where 'Route 75' 
+-- appears.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT GeometryType(centerlines) 
+-- FROM lakes 
+-- WHERE name = 'Route 75';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT GeometryType(centerlines) 
 FROM divided_routes 
 WHERE name = 'Route 75';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T8	
@@ -301,9 +320,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script includes extraneous parenthesis around the 
+-- 'boundary' column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT AsText(Boundary((boundary)) 
+-- FROM named_places 
+-- WHERE name = 'Goose Island';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(Boundary(boundary)) 
 FROM named_places 
 WHERE name = 'Goose Island';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T14	
@@ -314,9 +351,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script includes extraneous parenthesis around the
+-- 'boundary' column.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT AsText(Envelope((boundary)) 
+-- FROM named_places 
+-- WHERE name = 'Goose Island';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(Envelope(boundary)) 
 FROM named_places 
 WHERE name = 'Goose Island';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --
 --
@@ -335,9 +390,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script reference to 'Bridges' is not correct, the 
+-- attribute value is 'Cam Bridge'.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT X(position) 
+-- FROM bridges 
+-- WHERE name = 'Bridges';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT X(position) 
 FROM bridges 
 WHERE name = 'Cam Bridge';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T16	
@@ -597,9 +670,28 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script does not wrap a geometry-returning function in
+-- AsText(), so there is no guarantee that the return string
+-- will match the official answer.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT GeometryN(centerlines, 2)
+-- FROM divided_routes 
+-- WHERE name = 'Route 75';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(GeometryN(centerlines, 2))
 FROM divided_routes 
 WHERE name = 'Route 75';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --
 --
@@ -751,9 +843,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- The test script attempts to test the 'Touch' function, but the 
+-- specification document uses 'Touches' as the function name.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Touch(centerline, shore)
+-- FROM streams, lakes 
+-- WHERE streams.name = 'Cam Stream' AND lakes.name = 'Blue Lake';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Touches(centerline, shore)
 FROM streams, lakes 
 WHERE streams.name = 'Cam Stream' AND lakes.name = 'Blue Lake';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T40	
@@ -769,9 +879,29 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script reverses the correct order of arguments to 'Within()'. 
+-- Specification says 'Within(g1,g2) is 'TRUE if g1 is completely 
+-- contained in g2' and test explanation says we are checking if 
+-- the house (g1, footprint) is within Ashton (g2, boundary).
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Within(boundary, footprint)
+-- FROM named_places, buildings 
+-- WHERE named_places.name = 'Ashton' AND buildings.address = '215 Main Street';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Within(footprint, boundary)
 FROM named_places, buildings 
 WHERE named_places.name = 'Ashton' AND buildings.address = '215 Main Street';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T41	
@@ -787,9 +917,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script uses 'Overlap()' as the function name and specification
+-- gives 'Overlaps()' as the function name.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Overlap(forest.boundary, named_places.boundary)
+-- FROM forests, named_places 
+-- WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Overlaps(forests.boundary, named_places.boundary)
 FROM forests, named_places 
 WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T42	
@@ -805,9 +953,29 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script uses 'Cross()' as the function name and specification
+-- gives 'Crosses()' as the function name.
+-- Test script references 'road_segment' table and the correct table
+-- name is 'road_segments'.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Cross(road_segment.centerline, divided_routes.centerlines)
+-- FROM road_segment, divided_routes 
+-- WHERE road_segment.fid = 102 AND divided_routes.name = 'Route 75';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Crosses(road_segments.centerline, divided_routes.centerlines)
 FROM road_segments, divided_routes 
 WHERE road_segments.fid = 102 AND divided_routes.name = 'Route 75';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T43	
@@ -823,9 +991,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script references 'road_segment' table and the correct table
+-- name is 'road_segments'.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Intersects(road_segment.centerline, divided_routes.centerlines)
+-- FROM road_segment, divided_routes 
+-- WHERE road_segment.fid = 102 AND divided_routes.name = 'Route 75';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Intersects(road_segments.centerline, divided_routes.centerlines)
 FROM road_segments, divided_routes 
 WHERE road_segments.fid = 102 AND divided_routes.name = 'Route 75';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T44	
@@ -841,9 +1027,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script references 'forest' table and the correct table
+-- name is 'forests'.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Contains(forest.boundary, named_places.boundary)
+-- FROM forests, named_places 
+-- WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Contains(forests.boundary, named_places.boundary)
 FROM forests, named_places 
 WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T45	
@@ -859,9 +1063,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script references 'forest' table and the correct table
+-- name is 'forests'.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Relate(forest.boundary, named_places.boundary, 'TTTTTTTTT')
+-- FROM forests, named_places 
+-- WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT')
 FROM forests, named_places 
 WHERE forests.name = 'Green Forest' AND named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --
 --
@@ -902,9 +1124,28 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script does not wrap a geometry-returning function in
+-- AsText(), so there is no guarantee that the return string
+-- will match the official answer.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Intersection(centerline, shore)
+-- FROM streams, lakes 
+-- WHERE streams.name = 'Cam Stream' AND lakes.name = 'Blue Lake';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(Intersection(centerline, shore))
 FROM streams, lakes 
 WHERE streams.name = 'Cam Stream' AND lakes.name = 'Blue Lake';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T48	
@@ -917,9 +1158,30 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script does not wrap a geometry-returning function in
+-- AsText(), so there is no guarantee that the return string
+-- will match the official answer.
+-- Note that the return geometry is the same as the official
+-- answer but with a different start point.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Difference(named_places.boundary, forests.boundary)
+-- FROM named_places, forests 
+-- WHERE named_places.name = 'Ashton' AND forests.name = 'Green Forest';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(Difference(named_places.boundary, forests.boundary))
 FROM named_places, forests 
 WHERE named_places.name = 'Ashton' AND forests.name = 'Green Forest';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T49	
@@ -927,13 +1189,37 @@
 -- For this test we will determine the union of Blue Lake and Goose Island 
 --
 -- ANSWER: 'POLYGON((52 18,66 23,73 9,48 6,52 18))'
--- NOTE: The outer ring of BLue Lake is the answer.
+-- NOTE: The outer ring of Blue Lake is the answer.
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script does not wrap a geometry-returning function in
+-- AsText(), so there is no guarantee that the return string
+-- will match the official answer.
+-- Test script uses 'Ashton' as the place name where it means
+-- to use 'Goose Island'.
+-- Specification uses 'Union()' as a function name, but UNION
+-- is a SQL reserved work.  Function name adapted to 'GeomUnion()'
+-- for out implementation.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT Union(shore, boundary)
+-- FROM lakes, named_places 
+-- WHERE lakes.name = 'Blue Lake' AND named_places.name = Ashton';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(GeomUnion(shore, boundary))
 FROM lakes, named_places 
 WHERE lakes.name = 'Blue Lake' AND named_places.name = 'Goose Island';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T50	
@@ -942,13 +1228,34 @@
 -- and Goose Island 
 --
 -- ANSWER: 'POLYGON((52 18,66 23,73 9,48 6,52 18))'
--- NOTE: The outer ring of BLue Lake is the answer.
+-- NOTE: The outer ring of Blue Lake is the answer.
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script does not wrap a geometry-returning function in
+-- AsText(), so there is no guarantee that the return string
+-- will match the official answer.
+-- Test script uses 'Ashton' as the place name where it means
+-- to use 'Goose Island'.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT SymmetricDifference(shore, boundary)
+-- FROM lakes, named_places 
+-- WHERE lakes.name = 'Blue Lake' OR named_places.name = 'Ashton';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(SymmetricDifference(shore, boundary))
 FROM lakes, named_places 
 WHERE lakes.name = 'Blue Lake' AND named_places.name = 'Goose Island';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T51	
@@ -970,9 +1277,27 @@
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Our boolean function implementations return actual boolean values,
+-- so no further logical comparison (to 1 or 't') is required.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT count(*)
+-- FROM buildings, bridges
+-- WHERE Contains(Buffer(bridges.position, 15.0), buildings.footprint) = 1;
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT count(*)
 FROM buildings, bridges
 WHERE Contains(Buffer(bridges.position, 15.0), buildings.footprint);
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
 --
 --================================
 -- Conformance Item T52	
@@ -980,13 +1305,36 @@
 -- For this test we will determine the convex hull of Blue Lake 
 --
 -- ANSWER: 'POLYGON((52 18,66 23,73 9,48 6,52 18))'
--- NOTE: The outer ring of BLue Lake is the answer.
+-- NOTE: The outer ring of Blue Lake is the answer.
 --
 --================================
 --
+-- !#@ ADAPTATION BEGIN
+-- Test script does not wrap a geometry-returning function in
+-- AsText(), so there is no guarantee that the return string
+-- will match the official answer.
+-- Note that the return geometry is the same as the official
+-- answer but with a different start point.
+-- ---------------------
+-- -- BEGIN ORIGINAL SQL
+-- ---------------------
+-- SELECT ConvexHull(shore)
+-- FROM lakes
+-- WHERE lakes.name = 'Blue Lake';
+-- ---------------------
+-- -- END   ORIGINAL SQL
+-- ---------------------
+-- -- BEGIN ADAPTED  SQL
+-- ---------------------
 SELECT AsText(ConvexHull(shore))
 FROM lakes
 WHERE lakes.name = 'Blue Lake';
+-- ---------------------
+-- -- END   ADAPTED  SQL
+-- ---------------------
+-- -- !#@ ADAPTATION END
+
+
 --
 --
 --

Deleted: packages/postgis/upstream/extras/wkb_reader/.cvsignore
===================================================================
--- packages/postgis/upstream/extras/wkb_reader/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/extras/wkb_reader/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1 +0,0 @@
-readwkb

Added: packages/postgis/upstream/java/ejb2/CHANGES
===================================================================
--- packages/postgis/upstream/java/ejb2/CHANGES	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/CHANGES	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,6 @@
+PostGIS-EJB2-POC 1.0
+2006/08/29
+
+- Initial release!
+- EJB 2.x support
+- XDoclet code generation

Added: packages/postgis/upstream/java/ejb2/COPYING
===================================================================
--- packages/postgis/upstream/java/ejb2/COPYING	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/COPYING	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,341 @@
+
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.

Added: packages/postgis/upstream/java/ejb2/COPYING_LGPL
===================================================================
--- packages/postgis/upstream/java/ejb2/COPYING_LGPL	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/COPYING_LGPL	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,510 @@
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard.  To achieve this, non-free programs must
+be allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at least
+    three years, to give the same user the materials specified in
+    Subsection 6a, above, for a charge no more than the cost of
+    performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James
+  Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+

Added: packages/postgis/upstream/java/ejb2/README
===================================================================
--- packages/postgis/upstream/java/ejb2/README	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/README	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,177 @@
+Using PostGIS Geometry Types with EJB2 -- Proof of Concept
+----------------------------------------------------------
+Copyright (C) 2006 by the Geodetix s.r.l. Company. See
+http://www.geodetix.it/ for further information.
+
+Version 1.0.0 (2006/08/29)
+
+Table of Contents
+-----------------
+
+0. Licensing
+1. Introduction
+2. Directory Contents
+3. Software Requirements
+4. Installation
+5. Running
+6. Code Details
+
+
+0. Licensing
+------------
+The "Using PostGIS Geometry Types with EJB2 -- Proof of Concept" software is
+a short collection of examples related to the use of PostGIS Java API with
+the EJB 2.x technology.
+Copyright (C) 2006 by the Geodetix s.r.l. Company. See
+http://www.geodetix.it/ for further information.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+
+
+1. Introduction
+---------------
+Our software is a simple proof-of-concept application illustrating how the
+PostGIS provided Java geometric types could be integrated with a set of
+Enterprise Java Bean 2.x components.
+
+To achieve such a goal, an attribute of type org.postgis.Geometry has been 
+added to a BMP (Bean managed Persistence) Entity Bean. Furthermore, by using
+the DAO (Data Access Object) Pattern, the persistence code has been clearly 
+separated from the business logic.
+
+Not to add further complexity, some proper programming behaviours were omitted.
+For example the use of PostGIS geometric types directly inside the Entity Bean 
+code could be avoided by using a WKT compliant string attribute. Another issue
+is about security: table creational methods exposed in the 
+com.geodetix.geo.ejb.GeometryBean home interface should be protected by
+a proper role-base security policy, to avoid normal users deleting database 
+tables.
+
+Nevertheless our application, even if quite simple, still holds a lot of 
+generality and some of the implemented patterns or components are readily 
+usable in real-world applications.
+
+
+2. Directory Contents
+---------------------
+
+  ./            Build scripts (build.*), README and licensing information
+  ./src         Java source packages and files
+  ./resources   EJB specific configuration files
+  ./lib         JAR libraries needed to compile and run
+
+
+3. Software Requirements
+------------------------
+We here list all third-party libraries with their versions tested to work
+with the application.
+
+PostGIS JDBC driver version 1.1.3
+http://www.postgis.org/
+
+PostgreSQL JDBC driver version 8.1-404 jdbc3
+http://jdbc.postgresql.org/
+
+XDoclet lib version 1.2.3
+http://xdoclet.sourceforge.net
+
+Apache ANT version 1.6.5
+http://ant.apache.org/
+
+JBOSS Application Server version 4.0.4.GA-Patch1
+http://www.jboss.org/
+
+Note that our tool is application server agnostic and could be easily ported
+to any EJB 2.x compliant Container by modifying the provided deployment 
+ant file which is, in turn, written for the JBoss Application Server.
+
+
+4. Installation
+---------------
+After downloading (and compiling, if necessary) all of the required software,
+follow these steps:
+
+- copy the PostGIS driver (postgis_1.1.3.jar) into the ./lib/commonlib 
+directory
+
+- copy the PostgreSQL driver (postgresql-8.1-404.jdbc3.jar) into the 
+./lib/compiletimelib directory
+
+- copy the XDoclet libraries (contained in xdoclet-lib-1.2.3.tgz) into the 
+./lib/xdocletlib directory
+
+- install Apache ANT (follow the installation istructions provided 
+with the tool)
+
+- install the JBoss Application Server
+
+- make sure that your JBOSS_HOME environment variable correctly points to
+the JBoss installation directory (i.e. /opt/jboss-4.0.4.GA)
+
+- create a new PostGIS database according to what specified in the
+./resources/build.properties with the "database.name", "database.login",
+"database.password" properties (eventually change them to fit your needs).
+
+
+5. Running
+----------
+Start the JBoss application server with the provided scripts 
+(run.bat or run.sh).
+
+From the main application directory (./) execute these commands:
+
+> ant install-JDBC-driver
+This command installs the PostgreSQL driver into JBoss
+
+> ant install-DataSource
+This command installs the DataSource Connector into JBoss
+
+> ant javadoc
+This command generates the application API documentation into the ./javadoc
+directory (use index.html to start).
+
+> ant deploy
+Installs the application into JBoss
+
+> ant run-client
+Allows to test the installed application
+
+
+6. Code Details
+---------------
+The main components made available in the application are:
+
+- GeometryBean.java
+It is an entity bean containing a geometrical attribute of org.postgis.Geometry
+type which could contain every geometrical type (i.e. POINT, LINESTRING, etc.).
+The user can choose wether to create a NON-OpenGIS or an OpenGIS-compliant 
+bean. The first ones can contain different geometric types in the same table
+with undefined SRID (-1), while the second ones can only contain object of the 
+same type and SRID in one table;
+
+- PostgisGeometryDaoIml.java
+A DAO (Data Access Object) implementing persistence operations for the 
+GeometryBean EJB in a PostGIS database;
+
+- GeometryFacadeBean.java
+A stateless session bean implementing the interface between the geometric 
+entity beans and the client applications;
+
+- Client.java
+It is a simple client executing some tests thus illustrating the use of the 
+provided API.
+
+Further informations could be gathered from the source code and by reading the
+javadoc API documentation.

Added: packages/postgis/upstream/java/ejb2/build.xml
===================================================================
--- packages/postgis/upstream/java/ejb2/build.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/build.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project name="postgis-ejb2-poc" default="clean" basedir=".">
+  <description>Using PostGIS Geometry Types with EJB2 - Proof of Concept</description>
+
+  <!-- ENVIROMENT VARIABLES -->
+  <property environment="env"/>
+	
+  <!-- JBOSS PROPERTIES -->
+  <property name="jboss.home" value="${env.JBOSS_HOME}"/>
+  <property name="jboss.server.config" value="default"/>
+  <property name="jboss.server.lib" value="${jboss.home}/server/default/lib"/>
+  <property name="jboss.config.dir" value="${jboss.home}/server/default/conf"/>
+  <property name="jboss.deploy.dir" value="${jboss.home}/server/default/deploy"/>
+
+  <!-- REGULAR DIRECTORIES -->	
+  <property name="src.dir" value="src"/>
+  <property name="build.dir" value="build"/>
+  <property name="distro.dir" value="distro"/>
+  <property name="resources.dir" value="resources"/>
+  <property name="lib.dir" value="lib"/>
+  <property name="compiletime.lib.dir" value="${lib.dir}/compiletimelib"/>
+  <property name="common.jar.dir" value="common"/>
+  <property name="common.lib.dir" value="${lib.dir}/commonlib"/>
+  <property name="merge.dir" value="merge"/>
+  <property name="ejb.jar.dir" value="ejbjars"/>
+  <property name="javadoc.dir" value="javadoc"/>
+
+  <!-- GENERATED DIRECTORIES -->
+  <property name="gen.src.dir" value="gensrc"/>	
+  <property name="generated.dir" value="generated"/>
+  <property name="ejb.deployment.dir" value="${generated.dir}/ejbdeploy"/>
+	
+  <!-- WHERE TO DEPLOY THE FINISHED EAR FILE -->
+  <property name="deploy.path" value="${jboss.home}/server/${jboss.server.config}/deploy"/>
+
+  <!-- WHERE XDOCLET JARS ARE -->
+  <property name="xdoclet.lib.dir" value="${lib.dir}/xdocletlib"/>
+	  
+  <!-- PATH DEFINITION -->
+  <path id="classpath">   
+    <fileset dir="${lib.dir}" includes="*.jar"/>
+    <fileset dir="${compiletime.lib.dir}" includes="*.jar"/>
+    <fileset dir="${common.lib.dir}" includes="*.jar"/>
+    <fileset dir="${xdoclet.lib.dir}" includes="*.jar"/>
+    <fileset dir="${jboss.server.lib}" includes="*.jar"/>
+    <fileset dir="${jboss.home}/client" includes="**/*.jar"/>
+    <pathelement location="${resources.dir}/jndi"/>
+    <pathelement location="${build.dir}"/>
+  </path>
+	
+  <!-- LOAD USER DEFINED PROPERTIES -->
+  <!-- You can add your variables and/or properties in this file -->
+  <property file="${resources.dir}/build.properties" /> 
+
+  <!-- DATABASE RELATED PROPERTIES  -->
+  <property name="datasource.name" value="postgis-ejb2-ds"/>
+  <property name="datasource.file.name" value="postgis-ejb2-ds.xml"/>
+  <property name="database.connection.port" value="5432"/>
+  <property name="database.driver" value="org.postgresql.Driver"/>
+  <property name="database.connection.url" value="jdbc:postgresql://${database.host}:${database.connection.port}/${database.name}"/>
+
+  <!-- IMPORT RELATED BUILD FILES -->
+  <import file="${basedir}/prepare-jboss.xml" />
+	
+  
+  <target name="clean"  description="Delete all temporary directories and files created in the build.">
+    <echo message="Delete all temporary directories and files created in the build."/>
+
+    <delete dir="${gen.src.dir}"/>
+    <delete dir="${ejb.deployment.dir}"/>
+    <delete dir="${ejb.jar.dir}"/>
+    <delete dir="${common.jar.dir}"/>
+    <delete dir="${build.dir}"/>
+    <delete dir="${distro.dir}"/>
+    <delete dir="${generated.dir}"/>
+    <delete dir="${javadoc.dir}"/>
+
+    <delete>
+      <fileset dir="${basedir}" includes="**/*.bak"/>
+    </delete>		
+  </target>
+
+  
+  <target name="deploy" description="Deploy the application into JBOSS." depends="build-ear">
+    <echo message="Deploy EAR file."/>
+    <copy file="${distro.dir}/${ant.project.name}.ear"  todir="${deploy.path}"/>
+  </target>
+
+  
+  <target name="undeploy" description="Undeploy the Application." >
+    <echo message="Undeploy EAR file."/>
+    <delete file="${deploy.path}/${ant.project.name}.ear" />
+  </target>
+
+  
+  <target name="generate-ejb">
+    <echo message="Generate files with XDoclet."/>
+
+    <taskdef  name="ejbdoclet" 
+              classname="xdoclet.modules.ejb.EjbDocletTask"
+              classpathref="classpath"/>
+		
+    <!-- Generate EJB "stuff" -->
+    <ejbdoclet destdir="${gen.src.dir}" mergeDir="${merge.dir}" ejbSpec="2.1">
+      <packageSubstitution packages="ejb" substituteWith="interfaces"/>
+
+      <fileset dir="${src.dir}">
+        <include name="**/*Bean.java" />
+        <include name="**/*Service.java" />
+      </fileset>
+
+      <!-- Generate a deployment descriptor file, including all beans processed. -->
+      <deploymentdescriptor destdir="${ejb.deployment.dir}"/>
+
+      <!-- Generate JBOSS specific files  -->
+      <jboss destdir="${ejb.deployment.dir}" version="4.0" />
+
+      <!-- Generate all of the home and logical interfaces, unless told otherwise in the meta-information. -->
+      <homeinterface/>
+      <remoteinterface/>
+      <localinterface/>
+      <localhomeinterface/>
+
+      <!-- Generate a value object if the bean  has a @ejb.value-object tag.-->
+      <valueobject>
+        <packageSubstitution packages="ejb" 
+                             substituteWith="value"/>
+      </valueobject>
+
+      <!-- Generate a utility object for each EJB. -->
+      <utilobject includeGUID="true" 
+                  cacheHomes="true"
+                  kind="physical">
+        <packageSubstitution packages="ejb" 
+                             substituteWith="util"/>
+      </utilobject>
+
+      <!-- Generate complete entity and session classes (including ejbXXX() methods) based on the implementation class. -->
+      <entitybmp/>
+      <entitycmp/>
+      <session/>
+
+      <entitypk>
+        <packageSubstitution packages="ejb" 
+                             substituteWith="pk"/>
+      </entitypk>
+
+      <dao pattern="{0}Dao">
+        <packageSubstitution packages="ejb" 
+                             substituteWith="dao"/>
+      </dao>
+
+    </ejbdoclet>
+  </target>
+
+
+  <target name="build-common-jar" >
+    <mkdir dir="${common.jar.dir}"/>
+
+    <jar destfile="${common.jar.dir}/common.jar">
+      <fileset dir="${common.lib.dir}" includes="*.jar"/>
+    </jar>
+  </target>
+
+
+  <target name="build-ear" 
+          depends="build-ejb-jar,build-common-jar" 
+          description="Build .ear file and put it into distro dir.">
+    <mkdir dir="${distro.dir}"/>
+
+    <ear destfile="${distro.dir}/${ant.project.name}.ear" 
+         appxml="${resources.dir}/application.xml">
+      <fileset dir="${ejb.jar.dir}" includes="*.jar"/>
+      <fileset dir="${common.jar.dir}" includes="*.jar"/>
+    </ear>
+  </target>
+
+
+  <target name="build-ejb-jar" depends="compile" >
+    <mkdir dir="${ejb.jar.dir}"/>
+
+    <jar jarfile="${ejb.jar.dir}/ejb.jar">
+      <fileset dir="${build.dir}">
+        <include name="**/ejb/*.class"/>
+        <include name="**/exception/*.class"/>
+        <include name="**/util/*.class"/>
+        <include name="**/dao/*.class"/>
+        <include name="**/value/*.class"/>
+        <include name="**/interfaces/*.class"/>
+        <exclude name="**/client/*.class"/>
+      </fileset>  
+
+      <metainf dir="${ejb.deployment.dir}">
+        <include name="ejb-jar.xml"/>
+        <include name="jboss.xml"/>
+        <include name="jbosscmp-jdbc.xml"/> 
+      </metainf>
+    </jar>
+  </target> 
+
+
+  <target name="compile" depends="clean,generate-ejb" description="Compile EJB source code.">
+    <echo message="Compile source code."/>
+
+    <mkdir dir="${build.dir}"/>
+
+    <javac debug="on"
+           deprecation="on"
+           optimize="on"
+           encoding="iso-8859-1"
+           listfiles="no"
+           destdir="${build.dir}" 
+           classpathref="classpath">
+      <src path="${gen.src.dir};${src.dir}"/>
+      <exclude name="**/client/*.java"/>
+    </javac>
+  </target>
+
+
+  <target name="compile-client" depends="compile" description="Compile Client source code.">
+    <echo message="Compile Client source code."/>
+
+    <delete>
+      <fileset dir="${build.dir}" includes="**/client/*.*"/>
+    </delete>		
+
+    <mkdir dir="${build.dir}"/>
+
+    <javac debug="on"
+           deprecation="on"
+           optimize="on"
+           encoding="iso-8859-1"
+           listfiles="no"
+           destdir="${build.dir}" 
+           classpathref="classpath">
+      <src path="${gen.src.dir};${src.dir}"/>
+      <include name="**/client/*.java"/>
+    </javac>
+  </target>
+
+  
+  <target name="run-client"  description="Execute Client." depends="compile-client">
+    <java classname="com.geodetix.geo.client.Client" dir="." fork="true" classpathref="classpath" />
+  </target>
+
+
+  <target name="javadoc" 
+          depends="compile"
+          description="Create Project API documentation.">
+    <delete dir="${javadoc.dir}" />
+    <mkdir dir="${javadoc.dir}"/>
+    <javadoc destdir="${javadoc.dir}" sourcepath="${gen.src.dir};${src.dir}">
+      <classpath refid="classpath"/>
+      <packageset dir="${gen.src.dir}" defaultexcludes="yes">
+        <include name="**"/>   
+        <exclude name="**/ejb/**"/>   
+      </packageset>
+
+      <packageset dir="${src.dir}" defaultexcludes="yes">
+        <include name="**/exception/**"/> 
+        <include name="**/client/**"/> 
+        <include name="**/dao/**"/>     
+        <exclude name="**/ejb/**"/>
+      </packageset>
+
+      <doctitle><![CDATA[<h1>Using PostGIS Geometry Types with EJB2 <br> Proof of Concept</h1>]]></doctitle>
+      <bottom><![CDATA[<i>Copyright &#169; 2006 <a href="http://www.geodetix.it" target="_new">Geodetix S.r.l.</a> All Rights Reserved.</i>]]></bottom>
+    </javadoc>
+  </target>
+
+</project>

Added: packages/postgis/upstream/java/ejb2/prepare-jboss.xml
===================================================================
--- packages/postgis/upstream/java/ejb2/prepare-jboss.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/prepare-jboss.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project basedir=".">
+	
+  <!-- PROPERTY DEFINITIONS -->
+  <property name="tmp.dir" value="tmp"/>
+  
+  <target name="install-DataSource" description="Copy DataSource definition file into JBOSS deploy dir." >
+    <echo message="Copy DataSource definition file into JBOSS deploy dir"/> 
+
+    <copy file="${resources.dir}/${datasource.file.name}"  todir="${tmp.dir}"/>
+
+    <mkdir dir="${tmp.dir}"/>	
+
+    <replace  file="${tmp.dir}/${datasource.file.name}">
+      <replacefilter token="@datasource.name@" value="${datasource.name}"/>
+      <replacefilter token="@database.connection.url@" value="${database.connection.url}"/>
+      <replacefilter token="@database.driver@" value="${database.driver}"/>
+      <replacefilter token="@database.login@" value="${database.login}"/>
+      <replacefilter token="@database.password@" value="${database.password}"/>
+    </replace> 
+
+    <copy file="${tmp.dir}/${datasource.file.name}"  todir="${jboss.deploy.dir}"/>	
+
+    <delete dir="${tmp.dir}" />	 
+ </target>
+  
+  
+  <target name="install-JDBC-driver" description="Copy Postgresql JDBC Driver into JBOSS deploy dir." >
+    <echo message="Postgresql JDBC Driver into JBOSS deploy dir"/> 
+
+    <copy   todir="${jboss.deploy.dir}">
+      <fileset dir="${compiletime.lib.dir}"> 
+        <include name="postgres*.jar"/>
+      </fileset>
+    </copy>
+  </target>  
+  
+</project>

Added: packages/postgis/upstream/java/ejb2/resources/application.xml
===================================================================
--- packages/postgis/upstream/java/ejb2/resources/application.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/resources/application.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 
+                             'http://java.sun.com/dtd/application_1_3.dtd'>
+
+<application>
+
+  <display-name>postgis-ejb2-poc</display-name>
+
+  <description>Using PostGIS Geometry Types with EJB2 - Proof of Concept</description>
+
+  <module>
+    <ejb>ejb.jar</ejb>
+  </module>
+
+  <module>
+    <java>common.jar</java>
+  </module>
+
+</application>

Added: packages/postgis/upstream/java/ejb2/resources/build.properties
===================================================================
--- packages/postgis/upstream/java/ejb2/resources/build.properties	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/resources/build.properties	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,12 @@
+# You can change these properties to fit your environment.
+# This should be the only file to modify.
+# Note that you should NOT leave spaces after a property value
+
+# Name of the created database
+database.name=ejb2poc
+# User owner of the database tables
+database.login=CHANGEIT
+# Password for the db user
+database.password=CHANGEIT
+# IP or hostname of the machine running the database server
+database.host=127.0.0.1

Added: packages/postgis/upstream/java/ejb2/resources/jndi/jndi.properties
===================================================================
--- packages/postgis/upstream/java/ejb2/resources/jndi/jndi.properties	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/resources/jndi/jndi.properties	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+java.naming.provider.url=localhost

Added: packages/postgis/upstream/java/ejb2/resources/postgis-ejb2-ds.xml
===================================================================
--- packages/postgis/upstream/java/ejb2/resources/postgis-ejb2-ds.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/resources/postgis-ejb2-ds.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ================================================== -->
+<!--  Datasource config for Postgres                    -->
+<!--  DO NOT EDIT, it is a template configuration file! -->
+<!-- ================================================== -->
+
+
+<datasources>
+  <local-tx-datasource>
+    <jndi-name>@datasource.name@</jndi-name>
+    <connection-url>@database.connection.url@</connection-url>
+    <driver-class>@database.driver@</driver-class>
+    <user-name>@database.login@</user-name>
+    <password>@database.password@</password>
+  </local-tx-datasource>
+</datasources>
\ No newline at end of file

Added: packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/client/Client.java
===================================================================
--- packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/client/Client.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/client/Client.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,246 @@
+/*
+ * Client.java
+ *
+ * Using PostGIS Geometry Types with EJB2 - Proof of Concept
+ *
+ * Copyright 2006, Geodetix S.r.l. (http://www.geodetix.it)
+ * and individual contributors as indicated by the @authors tag.
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ *
+ */
+package com.geodetix.geo.client;
+
+import com.geodetix.geo.exception.ApplicationGeoLayerException;
+import com.geodetix.geo.interfaces.GeometryFacade;
+import com.geodetix.geo.interfaces.GeometryFacadeHome;
+
+import com.geodetix.geo.util.GeometryFacadeUtil;
+import com.geodetix.geo.value.GeometryValue;
+
+import java.rmi.RemoteException;
+
+import javax.naming.InitialContext;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+
+import java.util.*;
+import org.postgis.*;
+
+
+/**
+ * A client executing a simple Test Case and illustrating the Geometry Bean Usage.
+ * 
+ * @author  <a href="mailto:antonio.pace at geodetix.it">Antonio Pace</a>
+ */
+public class Client {
+    
+    
+    private GeometryFacade geometryFacade;
+    
+    private Point p1;
+    private Point p2;
+    private LineString fromP1toP2;
+    private Polygon searchPolygon;
+    
+    
+    /**
+     * Initializer method.
+     *
+     * @param geometryFacade the geometry facade object used to interact
+     * with the EJBs
+     */
+    public Client(GeometryFacade geometryFacade) {
+        
+        this.geometryFacade=geometryFacade;
+        
+        this.init();
+    }
+    
+    private void init(){
+        
+        // Create geometry stuff
+        
+        // City Stadium 
+        this.p1= new Point(16.23034006,39.31054320);
+        
+        // City Train Station
+        this.p2= new Point(16.26002601,39.31920668);
+        
+        this.fromP1toP2= new LineString(new Point[] {p1,p2});
+        
+        
+        // Create search polygon
+  
+        Point[] points = new Point[]{
+            
+            new Point(16.16399297, 39.40109388),
+            new Point(16.32368776, 39.39596998),
+            new Point(16.32397242, 39.25335486),
+            new Point(16.16399297, 39.25534748),
+            new Point(16.16399297, 39.40109388),
+        };
+        
+        LinearRing[] linearRings   = { new LinearRing(points) };
+       
+        // City Area Extension
+        this.searchPolygon = new Polygon(linearRings);
+    }
+    
+    
+    
+    private void executeNonOpenGisTest() throws ApplicationGeoLayerException, RemoteException {
+        
+        System.out.println("Execute some Tests on NON-OpenGIS Geometry EJBs");
+        
+        geometryFacade.createGeometryTable();
+        
+        System.out.println("create some geometry stuff...");
+        
+        this.showGeometry(p1);
+        GeometryValue gv1 = geometryFacade.createGeometry(p1,"[ City Stadium ]");
+        
+        this.showGeometry(p2);
+        GeometryValue gv2 = geometryFacade.createGeometry(p2,"[ City Train Station ]");
+        
+        this.showGeometry(fromP1toP2);
+        GeometryValue gv3 = geometryFacade.createGeometry(fromP1toP2,"Line from "
+                                                                     + gv1.getDescription()
+                                                                     + " to " 
+                                                                     + gv2.getDescription());
+        
+        System.out.println("Searching created geometries in City Area Perimeter: ");
+        this.showGeometry(searchPolygon);
+        
+        Collection<GeometryValue>  findResults = (Collection<GeometryValue>) geometryFacade.findByPolygon(searchPolygon);
+        
+        System.out.println("Search Results:");
+        
+        for (GeometryValue geometry  : findResults ) {
+            
+            this.showGeometry(geometry);
+        }
+        
+        geometryFacade.dropGeometryTable();
+    }
+    
+    
+    
+    
+    
+    private void executeOpenGisTest() throws ApplicationGeoLayerException, RemoteException {
+        
+        System.out.println("Execute some Tests on OpenGIS Geometry EJBs");
+        
+        geometryFacade.createGeometryTable("POINT",4326,2);
+        
+        System.out.println("Create some Points ....");
+        
+        // Setting SRID
+        this.p1.setSrid(4326);
+        this.p2.setSrid(4326);
+        this.searchPolygon.setSrid(4326);
+        
+        this.showGeometry(p1);
+        GeometryValue gv1 = geometryFacade.createGeometry(p1,"[ City Stadium ]");
+        
+        this.showGeometry(p2);
+        GeometryValue gv2 = geometryFacade.createGeometry(p2,"[ City Train Station ]");
+        
+        System.out.println();
+        System.out.println("Searching created Points in City Area Perimeter: ");
+        this.showGeometry(searchPolygon);
+        
+        // Note the use of geometricFacade finder method
+        Collection<GeometryValue>  findResults = (Collection<GeometryValue>) geometryFacade.findByPolygon(searchPolygon);
+        
+        System.out.println("Search Results:");
+        
+        for (GeometryValue geometry  : findResults ) {
+            
+            this.showGeometry(geometry);
+        }
+        
+        geometryFacade.dropGeometryTable();
+    }
+    
+    
+    
+    private void showGeometry(Geometry geometry) {
+        
+        System.out.println("Geometry: "+geometry.getTypeString()+geometry.getValue() + " SRID: "+geometry.getSrid());
+    }
+    
+    
+    private void showGeometry(GeometryValue geometryValue) {
+        
+        System.out.println("EJB Id: "+geometryValue.getId());
+        System.out.println("Description: "+geometryValue.getDescription());
+        
+        this.showGeometry(geometryValue.getGeometry());
+    }
+    
+    
+    /**
+     * Main client method.
+     *
+     * @param args arguments from the command line
+     */
+    public static void main(String [] args) {
+        
+        try {
+            
+            GeometryFacadeHome geometryFacadeHome= GeometryFacadeUtil.getHome();
+            
+            GeometryFacade geometryFacade= geometryFacadeHome.create();
+            
+            Client client = new Client(geometryFacade);
+            
+            System.out.println("===============================");
+            System.out.println("== TEST 1 =====================");
+            System.out.println("===============================");
+            client.executeNonOpenGisTest();
+            
+            System.out.println("===============================");
+            System.out.println("== TEST 2 =====================");
+            System.out.println("===============================");
+            client.executeOpenGisTest();
+            
+            System.out.println("===============================");
+            System.out.println("DONE.");
+            
+        } catch (ApplicationGeoLayerException ae) {
+            ae.printStackTrace();
+        } catch (java.rmi.RemoteException re) {
+            re.printStackTrace();
+        } catch (javax.naming.NamingException ne) {
+            ne.printStackTrace();
+        } catch (javax.ejb.CreateException ce) {
+            ce.printStackTrace();
+        }
+        
+    }
+    
+    
+    
+    private static Context getInitialContext()
+    throws javax.naming.NamingException {
+        
+        return new javax.naming.InitialContext();
+    }
+    
+}

Added: packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAO.java
===================================================================
--- packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAO.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAO.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,153 @@
+/*
+ * PostGisGeometryDAO.java
+ *
+ * Using PostGIS Geometry Types with EJB2 - Proof of Concept
+ *
+ * Copyright 2006, Geodetix S.r.l. (http://www.geodetix.it)
+ * and individual contributors as indicated by the @authors tag.
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ *
+ */
+package com.geodetix.geo.dao;
+
+
+/**
+ * This is the DAO (Data Access Object) interface customized for
+ * the PostGIS database which extends the XDoclet's auto-generated
+ * GeometryDao interface and contains all of the SQL query statements.
+ *
+ * @author <a href="mailto:antonio.pace at geodetix.it">Antonio Pace</a>
+ *
+ */
+public interface PostGisGeometryDAO extends GeometryDao {
+    
+    /* ========== Constants Definition ============ */
+    
+    /** DataSource Lookup String */
+    public static final String DATASOURCE_NAME = "java:/postgis-ejb2-ds";
+    
+    /* ========== SQL Queries Definition ============ */
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.ejb.GeometryBean#ejbCreate(org.postgis.Geometry, java.lang.String)}
+     * is called.
+     */
+    public static final String EJB_CREATE_STATEMENT = 
+            "INSERT INTO geometries (id,geometry,description) VALUES (?,?,?)";
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#findByPrimaryKey(java.lang.Integer)}
+     * is called.
+     */
+    public static final String FIND_BY_PRIMARY_KEY_STATEMENT = 
+            "SELECT id FROM geometries WHERE id = ?";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#findByPolygon(org.postgis.Polygon)}
+     * is called.
+     */
+    public static final String FIND_BY_POLYGON_STATEMENT = 
+            "SELECT id FROM geometries WHERE contains(?,geometry)";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable()}
+     * is called.
+     */
+    public static final String HOME_CREATE_NON_OPENGIS_TABLE_STATEMENT = 
+            "CREATE TABLE geometries (id INT PRIMARY KEY, description TEXT, geometry GEOMETRY)";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)}
+     * is called for create initial table.
+     */
+    public static final String HOME_CREATE_OPENGIS_TABLE_STATEMENT = 
+            "CREATE TABLE geometries (id INT PRIMARY KEY, description TEXT)";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)}
+     * is called for adding geometry column.
+     */
+    public static final String ADD_OPEN_GIS_GEOMETRY_COLUMN_STATEMENT = 
+            "SELECT AddGeometryColumn('','geometries','geometry',?,?,?)";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#dropDbTable()}
+     * is called for adding geometry column.
+     */
+    public static final String DROP_TABLE_STATEMENT = 
+            "DROP TABLE geometries";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.ejb.GeometryBMP#ejbLoad()}
+     * is called from the container.
+     */
+    public static final String EJB_LOAD_STATEMENT = 
+            "SELECT id,geometry,description FROM geometries WHERE id=?";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.ejb.GeometryBMP#ejbStore()}
+     * is called from the container.
+     */
+    public static final String EJB_STORE_STATEMENT = 
+            "UPDATE geometries SET geometry=?, description=? WHERE id=?";
+    
+    
+    /**
+     * Query executed from 
+     * {@link com.geodetix.geo.dao.PostGisGeometryDAOImpl}
+     * on PostGIS when the method 
+     * {@link com.geodetix.geo.ejb.GeometryBean#ejbRemove()}
+     * is called from the container.
+     */
+    public static final String EJB_REMOVE_STATEMENT = 
+            "DELETE FROM geometries WHERE id = ?";
+    
+} // end PostGisGeometryDAO

Added: packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAOImpl.java
===================================================================
--- packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAOImpl.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/dao/PostGisGeometryDAOImpl.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,579 @@
+/*
+ * PostGisGeometryDAOImpl.java
+ *
+ * Using PostGIS Geometry Types with EJB2 - Proof of Concept
+ *
+ * Copyright 2006, Geodetix S.r.l. (http://www.geodetix.it)
+ * and individual contributors as indicated by the @authors tag.
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ *
+ */
+package com.geodetix.geo.dao;
+
+import org.apache.commons.logging.*;
+
+import org.postgis.*;
+
+import java.sql.*;
+
+import java.util.*;
+
+import javax.ejb.*;
+
+import javax.naming.*;
+
+import javax.sql.*;
+
+import java.io.*;
+
+/**
+ *
+ * PostGis DAO Implementation for 
+ * {@link com.geodetix.geo.ejb.GeometryBean} BMP Persistence.
+ *
+ * @author  <a href="mailto:antonio.pace at geodetix.it">antonio.pace</a>
+ *
+ */
+public class PostGisGeometryDAOImpl implements PostGisGeometryDAO {
+    
+    
+    private DataSource  dataSource;
+    private Context     jndiCntx;
+    
+    /**
+     * Creates a new instance of PostGisPointDAO.
+     */
+    public PostGisGeometryDAOImpl() {}
+    
+    
+    
+    /** Initializes the bean. */
+    public void init() {
+        try {
+            
+            jndiCntx   = new InitialContext();
+            dataSource = (DataSource) jndiCntx.lookup(PostGisGeometryDAO.DATASOURCE_NAME);
+            
+        } catch (NamingException ne) {
+            throw new EJBException(ne);
+        }
+    }
+    
+    
+    
+    
+    /* =========== Create Methods ============ */
+    
+    
+    
+    /**
+     * PostGIS implementation of the 
+     * {@link com.geodetix.geo.ejb.GeometryBean#ejbCreate(org.postgis.Geometry, java.lang.String)}
+     * method.
+     * 
+     * @return the primary key of the persisted bean.
+     * @param ejb the bean to persist.
+     * @throws javax.ejb.CreateException launched if an EJB creation error is encountered.
+     * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
+     */
+    public java.lang.Integer create(com.geodetix.geo.ejb.GeometryBean ejb)
+    throws javax.ejb.CreateException, javax.ejb.EJBException {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        
+        
+        try {
+            con = this.dataSource.getConnection();
+            
+            pstm  = con.prepareStatement(PostGisGeometryDAO.EJB_CREATE_STATEMENT);
+            
+            pstm.setInt(1, ejb.getId());
+            pstm.setObject(2, new PGgeometry((Geometry)ejb.getGeometry()));
+            pstm.setString(3,ejb.getDescription());
+            
+            if (pstm.executeUpdate() != 1) {
+                throw new CreateException(
+                        "Failed to add EJB to database");
+            }
+            
+            return ejb.getId();
+            
+        } catch (SQLException se) {
+            throw new EJBException(se);
+            
+        } finally {
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+                
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    
+    
+    
+    
+    /* ============ Finder Methods ============== */
+    
+    
+    /**
+     * PostGIS implementation of the 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#findByPrimaryKey(java.lang.Integer)}
+     * method
+     * 
+     * 
+     * @return the found bean's prymary key.
+     * @param primaryKey primary key of searching bean.
+     * @throws javax.ejb.FinderException launched if an error occours during the search operation.
+     */
+    public java.lang.Integer findByPrimaryKey(java.lang.Integer primaryKey)
+    throws javax.ejb.FinderException {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        ResultSet        result = null;
+        
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            pstm  = con.prepareStatement(PostGisGeometryDAO.FIND_BY_PRIMARY_KEY_STATEMENT);
+            
+            pstm.setInt(1, primaryKey.intValue());
+            
+            result = pstm.executeQuery();
+            
+            if (!result.next()) {
+                throw new ObjectNotFoundException(
+                        "Cannot find Geometry Bean with id = " + primaryKey);
+            }
+            
+        } catch (SQLException se) {
+            throw new EJBException(se);
+        } finally {
+            try {
+                if (result != null) {
+                    result.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+            } catch (Exception e) {}
+        }
+        
+        return primaryKey;
+    }
+    
+    
+    
+    
+    /**
+     * PostGIS implementation of the  
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#findByPolygon(org.postgis.Polygon)}
+     * method
+     * 
+     * @return a collection of bean's primary key beeing found.
+     * @param polygon the {@link org.postgis.Polygon} to search in.
+     * @throws javax.ejb.FinderException launched if an error occours during the search operation.
+     */
+    public java.util.Collection findByPolygon(org.postgis.Polygon polygon)
+    throws javax.ejb.FinderException {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        ResultSet        result = null;
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            pstm  = con.prepareStatement(PostGisGeometryDAO.FIND_BY_POLYGON_STATEMENT);
+            
+            pstm.setObject(1, new PGgeometry(polygon));
+            
+            result = pstm.executeQuery();
+            
+            Vector keys = new Vector();
+            
+            while (result.next()) {
+                keys.addElement(result.getObject("id"));
+            }
+            
+            return keys;
+            
+        } catch (SQLException se) {
+            throw new EJBException(se);
+            
+        } finally {
+            try {
+                if (result != null) {
+                    result.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    
+    
+    /* =========== Bean's Life Cycle Methods ============= */
+    
+    
+    
+    /**
+     * PostGIS implementation of the entity bean's life cycle method 
+     * <code>ejbLoad()</code>.
+     * 
+     * @param pk the primary key of the bean to load.
+     * @param ejb the ejb whose data must be loaded.
+     * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
+     */
+    public void load(java.lang.Integer pk, com.geodetix.geo.ejb.GeometryBean ejb)
+    throws javax.ejb.EJBException {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        ResultSet        result = null;
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            pstm  = con.prepareStatement(PostGisGeometryDAO.EJB_LOAD_STATEMENT);
+            
+            pstm.setInt(1, pk.intValue());
+            
+            result = pstm.executeQuery();
+            
+            if (result.next()) {
+                ejb.setId(pk);
+                ejb.setGeometry(((PGgeometry) result.getObject("geometry")).getGeometry());
+                ejb.setDescription((String) result.getString("description"));
+                
+            } else {
+                
+                throw new EJBException("ejbLoad unable to load EJB.");
+            }
+            
+        } catch (SQLException se) {
+            throw new EJBException(se);
+            
+        } finally {
+            try {
+                if (result != null) {
+                    result.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    /**
+     * PostGIS implementation of the entity bean's lifecicle method 
+     * <code>ejbStore()</code>.
+     * 
+     * @param ejb the ejb whose data must be stored.
+     * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
+     */
+    public void store(com.geodetix.geo.ejb.GeometryBean ejb)
+    throws javax.ejb.EJBException {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            pstm  = con.prepareStatement(PostGisGeometryDAO.EJB_STORE_STATEMENT);
+            
+            pstm.setObject(1, new PGgeometry(ejb.getGeometry()));
+            pstm.setString(2,ejb.getDescription());
+            pstm.setInt(3, ejb.getId().intValue());
+            
+            if (pstm.executeUpdate() != 1) {
+                throw new EJBException("ejbStore unable to update EJB.");
+            }
+            
+        } catch (SQLException se) {
+            
+            throw new EJBException(se);
+            
+        } finally {
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+                
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    /**
+     * PostGIS implementation of the entity bean's lifecicle method 
+     * <code>ejbRemove()</code>.
+     * 
+     * 
+     * @param pk primary key of the bean that must be removed .
+     * @throws javax.ejb.RemoveException launched if an error during
+     *   EJB remove operation is encountered.
+     * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
+     */
+    public void remove(java.lang.Integer pk)
+    throws javax.ejb.RemoveException, javax.ejb.EJBException {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            pstm  = con.prepareStatement(PostGisGeometryDAO.EJB_REMOVE_STATEMENT);
+            
+            pstm.setInt(1, pk.intValue());
+            
+            if (pstm.executeUpdate() != 1) {
+                throw new EJBException("ejbRemove unable to remove EJB.");
+            }
+        } catch (SQLException se) {
+            
+            throw new EJBException(se);
+            
+        } finally {
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    
+    
+    
+    /* =========== Home Interface Utility Methods ============ */
+
+    
+    /**
+     * PostGIS implementation of the 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)}
+     * method creating a NON-OpenGis compliant table in the PostGIS database.
+     * The table will contain the geometry EJBs.
+     */
+    public void makeDbTable() {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            System.out.println("Creating non-OpenGIG Bean table... ");
+            
+            pstm = con.prepareStatement(PostGisGeometryDAO.HOME_CREATE_NON_OPENGIS_TABLE_STATEMENT);
+            pstm.execute();
+            
+            System.out.println("...done!");
+            
+        } catch (SQLException e) {
+            throw new EJBException(e);
+            
+        } finally {
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+                
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    
+    /**
+     * PostGIS implementation of the 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)}
+     * method creating an OpenGIS compliant table in the PostGIS database.
+     * The table will contain the geometry EJBs.
+     *
+     * @param gemetryType the string that rapresent a valid PostGIS 
+     * geometry type (i.e.: POINT, LINESTRING, POLYGON etc.).
+     * @param srid the SRID of the geometry.
+     * @param geometryDimension the dimension of the geometry.
+     */
+    public void makeDbTable(String gemetryType, int srid, int geometryDimension) {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            System.out.println("Creating OpenGIS Bean table...");
+            
+            pstm = con.prepareStatement(PostGisGeometryDAO.HOME_CREATE_OPENGIS_TABLE_STATEMENT);
+            pstm.execute();
+            
+            pstm = con.prepareStatement(PostGisGeometryDAO.ADD_OPEN_GIS_GEOMETRY_COLUMN_STATEMENT);
+            pstm.setInt(1,srid);
+            pstm.setString(2,gemetryType);
+            pstm.setInt(3,geometryDimension);
+            
+            pstm.execute();
+            
+            System.out.println("...done!");
+            
+        } catch (SQLException e) {
+            throw new EJBException(e);
+            
+        } finally {
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+                
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+    /**
+     * PostGIS implementation of the 
+     * {@link com.geodetix.geo.interfaces.GeometryLocalHome#dropDbTable()}
+     * method removing the table related to the EJBs.
+     */
+    public void dropDbTable() {
+        
+        PreparedStatement  pstm = null;
+        Connection          con = null;
+        
+        
+        try {
+            
+            con = this.dataSource.getConnection();
+            
+            System.out.println("Dropping Bean Table... ");
+            
+            pstm = con.prepareStatement(PostGisGeometryDAO.DROP_TABLE_STATEMENT);
+            pstm.execute();
+            
+            System.out.println("...done!");
+            
+        } catch (SQLException e) {
+            
+            throw new EJBException(e);
+            
+        } finally {
+            
+            try {
+                if (pstm != null) {
+                    pstm.close();
+                }
+            } catch (Exception e) {}
+            
+            try {
+                if (con != null) {
+                    con.close();
+                }
+                
+            } catch (Exception e) {}
+        }
+    }
+    
+    
+}
\ No newline at end of file

Added: packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryBean.java
===================================================================
--- packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryBean.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryBean.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,298 @@
+/*
+ * GeometryBean.java
+ *
+ * Using PostGIS Geometry Types with EJB2 - Proof of Concept
+ *
+ * Copyright 2006, Geodetix S.r.l. (http://www.geodetix.it)
+ * and individual contributors as indicated by the @authors tag.
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ *
+ */
+package com.geodetix.geo.ejb;
+
+
+import javax.ejb.*;
+
+import java.util.*;
+
+import org.postgis.*;
+
+import com.geodetix.geo.value.GeometryValue;
+
+/**
+ * This BMP (Bean Managed Persistence) entity bean stores information
+ * about geometrical description of a choosen entity in some application
+ * domain. It stores geometrical infos in the <code>geometry</code> attribute
+ * of type <code>org.postgis.Geometry</code>. Note that such an attribute could 
+ * even be implemented as a pure text (i.e. Java <code>String</code>) field 
+ * following the WKT format, thus leaving geometric details to the PostGIS 
+ * api classes (see <code>README</code> file for further details).
+ *
+ * @ejb.bean
+ *    name="Geometry"
+ *    jndi-name="geodetix/geo/Geometry"
+ *    local-jndi-name="geodetix/geo/GeometryLocal"
+ *    type="BMP"
+ *    view-type="local"
+ *    primkey-field="id"
+ *
+ * @ejb.dao
+ *     impl-class="com.geodetix.geo.dao.PostGisGeometryDAOImpl"
+ *
+ *
+ * @ejb.transaction
+ *     type="RequiresNew"
+ *
+ *
+ * @ejb.value-object
+ *     name="Geometry"
+ *     match="value"
+ *
+ * @author  <a href="mailto:antonio.pace at geodetix.it">Antonio Pace</a>
+ *
+ */
+public abstract class GeometryBean implements javax.ejb.EntityBean {
+    
+    
+    /* TEMPORARY (NOT FOR REAL WORLD) PRIMARY KEY GENERATOR */
+    private static final int SIMPLE_ID_GENERATOR = (int) System.currentTimeMillis();
+    private static int actualId = SIMPLE_ID_GENERATOR;
+    
+    
+    
+    /* BMP fields */
+    private Integer   id;
+    private String    description;
+    private Geometry  geometry;
+    
+    
+    
+    
+    /* CREATE METHODS */
+    
+    
+    /**
+     * Creates a new Geometry Bean.
+     * 
+     * @ejb.create-method 
+     *
+     * @param geometry the <code>org.postgis.Geometry</code> that has to be 
+     * included in this EJB.
+     * @param description the textual description of this bean.
+     * @throws CreateException lauched if an error occours during the 
+     * EJB creation.
+     * @return the EJB's primary key.
+     */
+    public Integer ejbCreate(org.postgis.Geometry geometry,String description)
+    throws CreateException {
+        
+        this.id    = (new Integer(actualId++));
+        this.geometry = geometry;
+        this.description=description;
+        
+        /* For now return null, this will be overrided in the DAO implementation of this method */
+        return null;
+    }
+    
+    /**
+     * This method is called by the container after the EJB creation.
+     *
+     * @param geometry the <code>org.postgis.Geometry</code> that has to be 
+     * included in this EJB.
+     */
+    public void ejbPostCreate(org.postgis.Geometry geometry) {
+        
+        // Do something with Relationship.
+    }
+    
+    
+    
+    
+    
+    /* ========== Finder Methods =========== */
+    
+    
+    /**
+     * Find a Geometry Bean from his primary key.
+     * 
+     * @param primaryKey the primary key of the bean to found.
+     * @throws FinderException lauched if an error occours during the 
+     * EJB search operation.
+     */
+    public abstract Integer ejbFindByPrimaryKey(Integer primaryKey)
+    throws FinderException;
+    
+    
+    
+    
+    /**
+     * Find all of the geometry beans contained in a <code>Polygon</code>.
+     *
+     * @param polygon the Polygon to search in.
+     */
+    public abstract Collection ejbFindByPolygon(org.postgis.Polygon polygon)
+    throws FinderException;
+    
+ 
+    
+    
+    
+    /* ============== BMP Fields Accessor Methods ============ */
+    
+    
+    /**
+     * Returns the EJB's id field.
+     *
+     * @ejb.pk-field
+     * @ejb.interface-method
+     * @ejb.value-object match="value"
+     */
+    public Integer getId() {
+        
+        return this.id;
+    }
+    
+    
+    /**
+     * Modifies the id field.
+     */
+    public void setId(Integer id) {
+        
+        this.id = id;
+        
+        this.makeDirty();
+    }
+    
+    
+    /**
+     * Returns the EJB's textual description.
+     *
+     * @ejb.interface-method
+     * @ejb.value-object match="value"
+     * @return the Geometry Bean description.
+     */
+    public String getDescription() {
+        
+        return this.description;
+    }
+    
+    /**
+     * Modifies the EJB's textual description.
+     *
+     * @ejb.interface-method
+     * @param description the Geometry Bean description.
+     */
+    public void setDescription(String description) {
+        
+        this.description = description;
+        
+        this.makeDirty();
+    }
+    
+    
+    
+    /**
+     * Returns the EJB's geometrical description.
+     *
+     * @ejb.interface-method
+     * @ejb.value-object match="value"
+     * @return the org.postgis.Geometry included in this bean.
+     */
+    public org.postgis.Geometry getGeometry() {
+        
+        return this.geometry;
+    }
+    
+    /**
+     * Modifies the EJB's geometrical description.
+     *
+     * @ejb.interface-method
+     * @param geometry the <code>org.postgis.Geometry</code> that has to 
+     * be included in this EJB.
+     */
+    public void setGeometry(org.postgis.Geometry geometry) {
+        
+        this.geometry = geometry;
+        
+        this.makeDirty();
+    }
+    
+    
+    
+    
+    
+    /* HOME INTERFACE BMP UTILITY METHODS */
+    
+    
+    /**
+     * Create a non-OpenGIS DataBase table, used to persist the Geometry Beans.
+     *
+     * @ejb.home-method
+     *
+     * @dao.call
+     */
+    public abstract void ejbHomeMakeDbTable();
+    
+    
+    
+    /**
+     * Create OpenGIS DataBase table, used to persist the Geometry Beans.
+     *
+     * @ejb.home-method
+     *
+     * @dao.call
+     */
+    public abstract void ejbHomeMakeDbTable(String gemetryType, int srid, int geometryDimension);
+    
+    
+    
+    /**
+     * Remove Bean's Persistence Teable of the DataBase.
+     *
+     * @ejb.home-method
+     *
+     * @dao.call
+     */
+    public abstract void ejbHomeDropDbTable();
+    
+    
+    
+    /* VALUE OBJECTS */
+    
+    /**
+     * This is an abstract method to allow XDoclet to expose
+     * value object functionalities in the local/remote interface.
+     *
+     * @ejb.interface-method
+     *
+     * @return a value object for this GeometryBean.
+     */
+    public abstract GeometryValue getGeometryValue();
+    
+    
+    
+    
+    
+    /* XDOCLET BMP METHODS RELATED STUFF */
+    
+    
+    /**
+     * @see com.geodetix.geo.ejb.GeometryBMP source.
+     */
+    protected abstract void makeDirty();
+    
+}

Added: packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryFacadeBean.java
===================================================================
--- packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryFacadeBean.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/ejb/GeometryFacadeBean.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,238 @@
+/*
+ * GeometryFacadeBean.java
+ *
+ * Using PostGIS Geometry Types with EJB2 - Proof of Concept
+ *
+ * Copyright 2006, Geodetix S.r.l. (http://www.geodetix.it)
+ * and individual contributors as indicated by the @authors tag.
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ *
+ */
+package com.geodetix.geo.ejb;
+
+
+import com.geodetix.geo.exception.ApplicationGeoLayerException;
+import com.geodetix.geo.interfaces.GeometryLocalHome;
+import com.geodetix.geo.interfaces.GeometryLocal;
+import com.geodetix.geo.util.GeometryUtil;
+import com.geodetix.geo.value.GeometryValue;
+
+import org.apache.commons.logging.*;
+
+import org.postgis.*;
+
+import java.rmi.*;
+
+import java.util.*;
+
+import javax.ejb.*;
+
+import javax.naming.*;
+
+
+/**
+ * A SessionFacade for managing Geometry beans.
+ *
+ * @ejb.bean
+ *     name="GeometryFacade"
+ *     jndi-name="geodetix/geo/GeometryFacade"
+ *     local-jndi-name="geodetix/geo/GeometryFacadeLocal"
+ *     type="Stateless"
+ *     view-type="both"
+ *     transaction-type="Container"
+ *
+ * @ejb.ejb-ref
+ *     ejb-name="Geometry"
+ *     view-type="local"
+ *     ref-name="ejb/GeometryLocal"
+ *
+ * @author  <a href="mailto:antonio.pace at geodetix.it">Antonio Pace</a>
+ */
+public abstract class GeometryFacadeBean implements SessionBean {
+    private SessionContext ctx;
+    
+    
+    /**
+     * EJB Initializer.
+     *
+     * @ejb.create-method
+     */
+    public void ejbCreate() throws CreateException {}
+    
+    /**
+     * Called after the EJB creation.
+     */
+    public void ejbPostCreate() throws CreateException {}
+    
+    /**
+     * Save the EJB session context.
+     */
+    public void setSessionContext(SessionContext ctx)
+    throws EJBException, RemoteException {
+        this.ctx = ctx;
+    }
+    
+    
+    
+  
+    /* ============ Finder Methods ============== */
+    
+    /**
+     * Find all of the geometry beans contained in a <code>Polygon</code>.
+     *
+     * @ejb.interface-method
+     *
+     * @param polygon The Polygon to search in.
+     */
+    public Collection findByPolygon(org.postgis.Polygon polygon)
+    throws ApplicationGeoLayerException {
+        try {
+            GeometryLocalHome geometryHome = GeometryUtil.getLocalHome();
+            Collection       geometries    = geometryHome.findByPolygon(polygon);
+            
+            List result = new ArrayList();
+            
+            for (Iterator iter = geometries.iterator(); iter.hasNext(); ) {
+                GeometryLocal geometry = (GeometryLocal) iter.next();
+                
+                result.add(geometry.getGeometryValue());
+            }
+            
+            return result;
+            
+        } catch (NamingException e) {
+            throw new ApplicationGeoLayerException(e);
+        } catch (FinderException e) {
+            throw new ApplicationGeoLayerException(e);
+        }
+    }
+    
+    
+    
+    
+    
+    /* =============== Business Iinterfaces Methods ============= */
+    
+    
+    /**
+     * Creates a new Geometry Bean.
+     *
+     * @ejb.interface-method
+     *
+     * @param geometry the <code>org.postgis.Geometry</code> that has to be 
+     * included in this EJB.
+     * @param description the textual description of this bean.
+     * @return a value object representing the created EJB.
+     */
+    public GeometryValue createGeometry(org.postgis.Geometry geometry, String description)
+    throws ApplicationGeoLayerException {
+        try {
+            GeometryLocalHome geometryHome  = GeometryUtil.getLocalHome();
+            GeometryLocal     geometryLocal =
+                    geometryHome.create(geometry,description);
+            
+            return geometryLocal.getGeometryValue();
+        } catch (NamingException e) {
+            throw new ApplicationGeoLayerException(e);
+        } catch (CreateException e) {
+            throw new ApplicationGeoLayerException(e);
+        }
+    }
+    
+    
+    
+    
+    
+    /* ================== BMP Utility Methods ================= */
+    
+    
+    
+    /**
+     * Create a non-OpenGIS DataBase table used to persist the Geometry Beans.
+     * <em>Note that in a real-world application this method should be protected
+     * by using a role-based security policy.</em>
+     *
+     * @ejb.interface-method
+     *
+     * @throws ApplicationGeoLayerException thrown if an error occours 
+     * during table creation.
+     */
+    public void createGeometryTable() throws ApplicationGeoLayerException {
+        try {
+            GeometryLocalHome geometryHome = GeometryUtil.getLocalHome();
+            
+            geometryHome.makeDbTable();
+        } catch (NamingException e) {
+            throw new ApplicationGeoLayerException(e);
+        } catch (Exception e) {
+            throw new ApplicationGeoLayerException(e);
+        }
+    }
+    
+    
+    /**
+     * Create an OpenGIS compliant database table used to persist the 
+     * Geometry Beans.
+     * <em>Note that in a real-world application this method should be protected
+     * by using a role-based security policy.</em>
+     *
+     * @ejb.interface-method
+     *
+     * @throws ApplicationGeoLayerException thrown if an error occours 
+     * during table creation.
+     */
+    public void createGeometryTable(String gemetryType, int srid, int geometryDimension )
+    throws ApplicationGeoLayerException {
+        try {
+            GeometryLocalHome geometryHome = GeometryUtil.getLocalHome();
+            
+            geometryHome.makeDbTable(gemetryType, srid,  geometryDimension);
+            
+        } catch (NamingException e) {
+            throw new ApplicationGeoLayerException(e);
+        } catch (Exception e) {
+            throw new ApplicationGeoLayerException(e);
+        }
+    }
+    
+    
+    
+    /**
+     * Remove the EJB's persistence table from the database.
+     * <em>Note that in a real-world application this method should be protected
+     * by using a role-based security policy.</em>
+     *
+     * @ejb.interface-method
+     *
+     * @throws ApplicationGeoLayerException thrown if an error occours 
+     * during table creation.
+     */
+    public void dropGeometryTable() throws ApplicationGeoLayerException {
+        try {
+            GeometryLocalHome geometryHome = GeometryUtil.getLocalHome();
+            
+            geometryHome.dropDbTable();
+        } catch (NamingException e) {
+            throw new ApplicationGeoLayerException(e);
+        } catch (Exception e) {
+            throw new ApplicationGeoLayerException(e);
+        }
+    }
+    
+    
+    
+}

Added: packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/exception/ApplicationGeoLayerException.java
===================================================================
--- packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/exception/ApplicationGeoLayerException.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb2/src/com/geodetix/geo/exception/ApplicationGeoLayerException.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,66 @@
+/*
+ * ApplicationGeoLayerException.java
+ *
+ * Using PostGIS Geometry Types with EJB2 - Proof of Concept
+ *
+ * Copyright 2006, Geodetix S.r.l. (http://www.geodetix.it)
+ * and individual contributors as indicated by the @authors tag.
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ *
+ */
+package com.geodetix.geo.exception;
+
+
+/**
+ * Generic Application Exception.
+ *
+ * @author <a href="mailto:antonio.pace at geodetix.it">Antonio Pace</a>
+ *
+ */
+public class ApplicationGeoLayerException extends Exception {
+    
+    /**
+     * Creates a new ApplicationGeoLayerException object.
+     */
+    public ApplicationGeoLayerException() {
+        super("unknown");
+        
+    } // end ApplicationGeoLayerException()
+    
+    
+    /**
+     * Creates a new ApplicationGeoLayerException object.
+     *
+     * @param e the wrapped Exception.
+     */
+    public ApplicationGeoLayerException(Exception e) {
+        super(e.getMessage());
+        
+    } // end ApplicationGeoLayerException()
+    
+    
+    /**
+     * Creates a new ApplicationGeoLayerException object.
+     *
+     * @param msg the wrapped Message.
+     */
+    public ApplicationGeoLayerException(String msg) {
+        super(msg);
+        
+    } // end ApplicationGeoLayerException()
+    
+} // end ApplicationGeoLayerException

Added: packages/postgis/upstream/java/ejb3/.classpath
===================================================================
--- packages/postgis/upstream/java/ejb3/.classpath	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/.classpath	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.jboss.ide.eclipse.jdt.aop.core.classpath.AOP_15_CONTAINER"/>
+	<classpathentry kind="con" path="org.jboss.ide.eclipse.jdt.ejb3.wizards.core.classpath.EJB3_CONTAINER/JBoss-4.0.4.GA"/>
+	<classpathentry kind="lib" path="C:/jboss-4.0.4.GA/server/default/lib/postgis_1.1.0.jar"/>
+	<classpathentry kind="lib" path="C:/jboss-4.0.4.GA/client/jbossws-client.jar"/>
+	<classpathentry kind="lib" path="C:/jboss-4.0.4.GA/client/jboss-jaxrpc.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: packages/postgis/upstream/java/ejb3/.project
===================================================================
--- packages/postgis/upstream/java/ejb3/.project	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/.project	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>PostGISTutorial</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.jboss.ide.eclipse.ejb3.wizards.core.EJB3ProjectNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: packages/postgis/upstream/java/ejb3/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- packages/postgis/upstream/java/ejb3/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/.settings/org.eclipse.jdt.core.prefs	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,7 @@
+#Mon Sep 18 15:14:48 BST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

Added: packages/postgis/upstream/java/ejb3/README.txt
===================================================================
--- packages/postgis/upstream/java/ejb3/README.txt	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/README.txt	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,27 @@
+$Id: README.txt 2489 2006-09-27 08:47:10Z mschaber $
+(This code was contributed by Norman Barker <nbarker at ittvis.com>)
+
+Spatial EJB3
+
+
+Spatial EJB3 is a quick investigation to see if it is possible to integrate the
+Java 5 annotation approach to mark a property of an object as spatial and to
+delegate to the EJB3 persistence model to store and retrieve this data. 
+
+The project utilises JBoss and PostGIS, future iterations will look to remove
+the dependency on JBoss and Hibernate to incorporate other Application
+Services. 
+
+Since it is useful to display screenshots in a tutorial this has been written
+as a PDF and the document and source are available here.
+
+
+COMPILING:
+
+Run "ant" to compile.
+
+The postgis.jar, pgjdbc.jar and the other needed libs have to 
+be put in the lib/ subdirectory.
+
+If your JBOSS is not installed in C:\jboss-4.0.4.GA, fix the
+path in the build.xml.

Added: packages/postgis/upstream/java/ejb3/build.xml
===================================================================
--- packages/postgis/upstream/java/ejb3/build.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/build.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,71 @@
+<!--
+ * build file
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - EJB3 Support
+ * 
+ * (C) 2006  Noarman Barker <nbarker at ittvis.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: build.xml 2476 2006-09-20 09:03:12Z mschaber $
+ -->
+<project name="PostGIS EJB3 Tutorial" default="compile" basedir=".">
+    <property name="build.dir" value="bin"/>
+    <property name="lib.dir" value="lib"/>
+    <property name="src.dir" value="src"/>
+    <property name="dist.dir" value="dist"/>
+    <property name="jboss.home" value="C:/jboss-4.0.4.GA"/>
+    <property name="jbossconf" value="jboss"/>
+
+    <path id="class.path">
+        <pathelement location="${build.dir}"/>
+        <fileset dir="${lib.dir}" includes="*.jar"/>
+        <fileset dir="${jboss.home}/client">
+            <include name="*.jar"/>
+        </fileset>
+        <fileset dir="${jboss.home}/server/default/lib" includes="hibernate3.jar"/>
+    </path>
+
+    <target name="clean" description="Removes all generated files">
+        <delete dir="${build.dir}"/>
+        <delete dir="${dist.dir}"/>
+    </target>
+
+    <target name="compile">
+        <mkdir dir="${build.dir}"/>
+        <javac destdir="${build.dir}" fork="true" classpathref="class.path" source="1.5" target="1.5">
+            <src path="${src.dir}"/>
+        </javac>
+        <copy todir="${build.dir}">
+            <fileset dir="${src.dir}"
+                includes="**/images/*,**/*.properties" excludes="**/.svn/*"/>  
+        </copy>
+    </target>
+    
+    <target name="dist" depends="clean, compile">
+        <mkdir dir="${dist.dir}"/>
+        <jar jarfile="${dist.dir}/ingest.jar" basedir="${build.dir}" includes="**/ejb/*, **/mdb/*, **/UserBean/*, **/hibernate/*">
+            <metainf dir="${src.dir}/META-INF" includes="*.xml"/>
+        </jar>
+    </target>
+
+    <target name="deploy" description="deploys the service to JBoss" depends="dist">
+      <copy todir="${jboss.home}/server/default/deploy">
+        <fileset dir="${dist.dir}" includes="ingest.jar, people.war"/>
+        <fileset dir="${jbossconf}" includes="*.xml"/>
+      </copy>
+    </target>
+    
+</project>

Added: packages/postgis/upstream/java/ejb3/ejb3spatial.pdf
===================================================================
(Binary files differ)


Property changes on: packages/postgis/upstream/java/ejb3/ejb3spatial.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: packages/postgis/upstream/java/ejb3/jboss/geodata-ds.xml
===================================================================
--- packages/postgis/upstream/java/ejb3/jboss/geodata-ds.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/jboss/geodata-ds.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<datasources>
+  <local-tx-datasource>
+    <jndi-name>GeoDataDS</jndi-name>
+    <connection-url>jdbc:postgresql://127.0.0.1:5432/geotest</connection-url>
+    <driver-class>org.postgis.DriverWrapper</driver-class>
+    <user-name>geo</user-name>
+    <password>geo</password>
+      <metadata>
+         <type-mapping>PostgreSQL 8.1</type-mapping>
+      </metadata>
+  </local-tx-datasource>
+</datasources>

Added: packages/postgis/upstream/java/ejb3/jboss/ingest-service.xml
===================================================================
--- packages/postgis/upstream/java/ejb3/jboss/ingest-service.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/jboss/ingest-service.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+  <mbean code="org.jboss.mq.server.jmx.Queue"
+	 name="jboss.mq.destination:service=Queue,name=ingestQueue">
+    <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+  </mbean>
+</server>
\ No newline at end of file

Added: packages/postgis/upstream/java/ejb3/src/META-INF/persistence.xml
===================================================================
--- packages/postgis/upstream/java/ejb3/src/META-INF/persistence.xml	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/META-INF/persistence.xml	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,5 @@
+<persistence>
+	<persistence-unit name="People">
+		<jta-data-source>java:/GeoDataDS</jta-data-source>
+	</persistence-unit>
+</persistence>
\ No newline at end of file

Added: packages/postgis/upstream/java/ejb3/src/jndi.properties
===================================================================
--- packages/postgis/upstream/java/ejb3/src/jndi.properties	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/jndi.properties	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+java.naming.provider.url=localhost:1099

Added: packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/PersonEntity.java
===================================================================
--- packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/PersonEntity.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/PersonEntity.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,96 @@
+/*
+ * PersonEntity.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - EJB3 Tutorial
+ * 
+ * (C) 2006  Noarman Barker <nbarker at ittvis.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PersonEntity.java 2476 2006-09-20 09:03:12Z mschaber $
+ */
+package org.postgis.ejb;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.hibernate.annotations.Type;
+import org.postgis.Geometry;
+
+ at Entity
+ at Table(name="people")
+ at NamedQuery(name="findPerson",
+		query="SELECT DISTINCT OBJECT(p) FROM PersonEntity p WHERE ((p.name = :name) AND (p.surname = :surname)) ORDER BY p.date")
+public class PersonEntity {
+	private long id;
+	private String name;
+	private String surname;
+	private Geometry location;
+	private Date date;
+	
+	@Id 
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	@Column(name="id")
+	public long getId() {
+		return id;
+	}
+	public void setId(long id) {
+		this.id = id;
+	}
+	
+	@Type(type = "org.postgis.hibernate.GeometryType")
+	@Column(name="location", columnDefinition="Geometry")
+	public Geometry getLocation() {
+		return location;
+	}
+	public void setLocation(Geometry location) {
+		this.location = location;
+	}
+	
+	@Column(name="name")
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	@Column(name="surname")
+	public String getSurname() {
+		return surname;
+	}
+	public void setSurname(String surname) {
+		this.surname = surname;
+	}
+	
+	@Column(name="ingested")
+	@Temporal(TemporalType.TIMESTAMP)
+	public Date getDate() {
+		return date;
+	}
+	
+	public void setDate(Date date) {
+		this.date = date;
+	}
+}

Added: packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBean.java
===================================================================
--- packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBean.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBean.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,124 @@
+/*
+ * UserBean.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - EJB3 Tutorial
+ * 
+ * (C) 2006  Noarman Barker <nbarker at ittvis.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: UserBean.java 2476 2006-09-20 09:03:12Z mschaber $
+ */
+package org.postgis.ejb;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.annotation.security.RunAs;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.jboss.annotation.security.SecurityDomain;
+
+ at Stateless
+ at WebService(
+		  name = "EndpointInterface", 
+		  targetNamespace = "http://org.postgis/ejb/UserBean", 
+		  serviceName = "PeopleFinder")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public class UserBean implements UserBeanRemote{
+	@PersistenceContext(unitName="People") private EntityManager entityManager;
+
+	@Resource(mappedName = "java:/ConnectionFactory")
+	private QueueConnectionFactory connectionFactory;
+	
+	@Resource(mappedName = "queue/ingestQueue")
+	private Queue queue;
+
+
+	@WebMethod
+	public void ingest(@WebParam(name = "name") String name, at WebParam(name = "surname") String surname, at WebParam(name = "lat") double lat, @WebParam(name = "lon") double lon){
+		// place message on a queue
+		try {
+			QueueConnection qConn = connectionFactory.createQueueConnection();
+			QueueSession qSession = qConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+			QueueSender qSender = qSession.createSender(queue);
+
+			// create a message
+			MapMessage message = qSession.createMapMessage();
+			message.setStringProperty("MessageFormat", "Person");
+			message.setString("NAME", name);
+			message.setString("SURNAME", surname);
+			message.setDouble("LAT", lat);
+			message.setDouble("LON", lon);
+			qSender.send(message);
+			qSession.close();
+			qConn.close();
+		} catch (JMSException e) {
+			throw new EJBException(e.getMessage());
+		}
+
+	}
+
+
+	@WebMethod
+	@WebResult(name="positions")
+	public String[] findPerson(@WebParam(name = "name") String name, @WebParam(name = "surname") String surname)
+	{
+		Query query = entityManager.createNamedQuery("findPerson");
+		query.setParameter("name", name);
+		query.setParameter("surname", surname);
+		List list = query.getResultList();
+		
+		if (list != null)
+		{
+			Iterator itr = list.iterator();
+			ArrayList<String> resultList = new ArrayList<String>();
+			
+			while (itr.hasNext())
+			{
+				PersonEntity person = (PersonEntity) itr.next();
+				resultList.add(person.getLocation().getValue() + "," + person.getDate() + "\r\n");
+			}
+			
+			String[] result = (String[])(resultList.toArray(new String[resultList.size()]));
+			return result;
+		}
+		else
+		{
+			return null;
+		}
+		
+	}
+
+}

Added: packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBeanRemote.java
===================================================================
--- packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBeanRemote.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/UserBeanRemote.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,35 @@
+/*
+ * UserBeanRemote.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - EJB3 Tutorial
+ * 
+ * (C) 2006  Noarman Barker <nbarker at ittvis.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: UserBeanRemote.java 2476 2006-09-20 09:03:12Z mschaber $
+ */
+package org.postgis.ejb;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.Remote;
+import javax.jws.WebParam;
+
+ at Remote
+public interface UserBeanRemote {
+	public void ingest(String name, String surname, double lat, double lon) throws RemoteException;
+	public String[] findPerson(String name, String surname) throws RemoteException;
+}

Added: packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/mdb/IngestMDB.java
===================================================================
--- packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/mdb/IngestMDB.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/org/postgis/ejb/mdb/IngestMDB.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,99 @@
+/*
+ * IngestMDB.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - EJB3 Tutorial
+ * 
+ * (C) 2006  Noarman Barker <nbarker at ittvis.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: IngestMDB.java 2476 2006-09-20 09:03:12Z mschaber $
+ */
+package org.postgis.ejb.mdb;
+
+import java.util.Date;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.postgis.Point;
+import org.postgis.ejb.PersonEntity;
+
+ at MessageDriven(activationConfig={
+		@ActivationConfigProperty(
+				propertyName="destinationType",
+				propertyValue="javax.jms.Queue"),
+		@ActivationConfigProperty(
+				propertyName="destination", 
+				propertyValue="queue/ingestQueue"),
+		@ActivationConfigProperty(
+				propertyName="messageSelector",
+				propertyValue="MessageFormat ='Person'"),
+		@ActivationConfigProperty(
+				propertyName="acknowledgeMode",
+				propertyValue="Auto-acknowledge")
+})
+/**
+ * implements a listener interface to ingest people data
+ */
+public class IngestMDB implements MessageListener {
+    
+	public static final String NAME = "NAME";
+	public static final String SURNAME = "SURNAME";
+	public static final String LATITUDE = "LAT";
+	public static final String LONGITUDE = "LON";
+	
+	@PersistenceContext(unitName="People") private EntityManager entityManager;
+
+	
+	/**
+	 * Implements a message listener for Person ingest requests
+	 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
+	 */
+	public void onMessage(Message msg) {
+		if (msg instanceof MapMessage)
+		{
+			try {
+				MapMessage m = (MapMessage)msg;
+				String name = m.getString(IngestMDB.NAME);
+				String surname = m.getString(IngestMDB.SURNAME);
+				Double lat = m.getDouble(IngestMDB.LATITUDE);
+				Double lon = m.getDouble(IngestMDB.LONGITUDE);
+				
+				PersonEntity person = new PersonEntity();
+				person.setName(name);
+				person.setSurname(surname);
+				person.setLocation(new Point(lon, lat));
+				person.setDate(new Date());
+				entityManager.persist(person);
+				
+				// for tutorial info
+				System.out.println("INGESTED " + name + " " + surname + " into PostGIS");
+			} catch (JMSException e) {
+				e.printStackTrace();
+			}
+			
+			
+		}
+		
+	}
+
+}

Added: packages/postgis/upstream/java/ejb3/src/org/postgis/hibernate/GeometryType.java
===================================================================
--- packages/postgis/upstream/java/ejb3/src/org/postgis/hibernate/GeometryType.java	                        (rev 0)
+++ packages/postgis/upstream/java/ejb3/src/org/postgis/hibernate/GeometryType.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,148 @@
+/*
+ * GeometryType.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - EJB3 Tutorial
+ * 
+ * (C) 2006  Noarman Barker <nbarker at ittvis.com>
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: GeometryType.java 2476 2006-09-20 09:03:12Z mschaber $
+ */
+package org.postgis.hibernate;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.sql.Blob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.HibernateException;
+import org.hibernate.usertype.UserType;
+import java.io.InputStream;
+import org.postgis.Geometry;
+import org.postgis.binary.BinaryParser;
+import org.postgis.binary.BinaryWriter;
+
+/**
+ * @author nbarker $date 16/8/06
+ */
+public class GeometryType implements UserType {
+	 private static final int[] SQL_TYPES = { Types.BLOB };
+	
+
+	/**
+	 * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
+	 */
+	public Object deepCopy(Object value) throws HibernateException {
+		return value;
+	}
+
+	/**
+	 * @see org.hibernate.usertype.UserType#equals(java.lang.Object, java.lang.Object)
+	 */
+	public boolean equals(Object x, Object y) throws HibernateException {
+		if (x == y) {
+			return true;
+		} else if (x == null || y == null) {
+			return false;
+		} else {
+			return x.equals(y);
+		}
+	}
+
+	/**
+	 * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
+	 */
+	public int hashCode(Object arg0) throws HibernateException {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	/**
+	 * @see org.hibernate.usertype.UserType#isMutable()
+	 */
+	public boolean isMutable() {
+		return false;
+	}
+
+	/**)
+	 * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object)
+	 */
+	public Object nullSafeGet(ResultSet resultSet, 
+		      String[] names, Object owner) throws HibernateException, SQLException {
+	    Geometry result = null;
+	    String geom = resultSet.getString(names[0]);
+	    BinaryParser parser = new BinaryParser();
+	    result = parser.parse(geom);
+	    return result;
+	}
+
+	/**
+	 * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
+	 */
+	public void nullSafeSet(PreparedStatement statement, 
+		      Object value, int index) throws HibernateException, SQLException {
+	    if (value == null) {
+	        statement.setBytes(index, null);
+	      } else {
+	    	BinaryWriter bw = new BinaryWriter();
+	    	
+	    	byte[] bytes = bw.writeBinary((Geometry)value);
+	        statement.setBytes(index, bytes);
+	      }
+	}
+
+	/* (non-Javadoc)
+	 * @see org.hibernate.usertype.UserType#replace(java.lang.Object, java.lang.Object, java.lang.Object)
+	 */
+	public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.hibernate.usertype.UserType#returnedClass()
+	 */
+	public Class returnedClass() {
+		return Geometry.class;
+	}
+
+	/**
+	 * @see org.hibernate.usertype.UserType#sqlTypes()
+	 */
+	public int[] sqlTypes() {
+		return GeometryType.SQL_TYPES;
+	}
+
+	/**
+	 * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable, java.lang.Object)
+	 */
+	public Object assemble(Serializable cached, Object owner) throws HibernateException {
+		return cached;
+	}
+	
+	/**
+	 * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
+	 */
+	public Serializable disassemble(Object value) throws HibernateException {
+		return (Serializable)value;
+	}
+
+}
+

Added: packages/postgis/upstream/java/jdbc/COPYING_LGPL
===================================================================
--- packages/postgis/upstream/java/jdbc/COPYING_LGPL	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/COPYING_LGPL	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,510 @@
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard.  To achieve this, non-free programs must
+be allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at least
+    three years, to give the same user the materials specified in
+    Subsection 6a, above, for a charge no more than the cost of
+    performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James
+  Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+

Added: packages/postgis/upstream/java/jdbc/Makefile
===================================================================
--- packages/postgis/upstream/java/jdbc/Makefile	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/Makefile	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,267 @@
+# PostGIS Makefile
+
+# (C) 2004 Paul Ramsey, pramsey at refractions.net
+# (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+# (C) 2005 Sandro Santilli, strk at refractions.net
+# (C) 2005 Alex Bodnaru, alexbodn at 012.net.il
+
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+# Following are some variable definitions that may have to be changed
+# according to your build environment. This can be done either by editing
+# this Makefile, or setting them via shell environment prior to calling make.
+
+### Config variable section starts ###
+
+# Configure the helper executables used during build.
+
+JAVAC?=javac -target 1.2 -source 1.2
+JAVA?=java
+JAR?=jar
+MKDIR?=mkdir -p
+DELETE?=rm -rvf
+CP?=cp
+
+# If you happen to be stuck with ancient jar implementations that do not
+# know about the -u option, but does not complain about duplicate directorys
+# with the same name (e. G. debian woody fastjar), set the DEBUGJAR below
+# variable to postgis_debug.fastjar and JAR (above) to fastjar.
+DEBUGJAR?=postgis_debug.jar
+
+# 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},)
+	POSTGIS_BUILD_CLASSPATH?=/usr/share/java/postgresql.jar
+else
+	POSTGIS_BUILD_CLASSPATH?=${CLASSPATH}
+endif
+
+# 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
+
+# Class path entry separator, this is : on Linux/Unix and ; on Windows
+CPSEP?=:
+
+# This are used for the online regression tests, override via environment
+# 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
+PGUSER?=psql
+PGPASS?=guess
+PGURL?=//$(PGHOST):$(PGPORT)/$(PGDATABASE)
+
+# Where to put the output from regression tests. If you want to have it on
+# stdout, set TESTOUT to the empty string. Be careful - this will be deleted
+# by "make clean".
+TESTOUTPUT?=test.log
+
+### Config variable section ends ###
+
+# build internal constants follow:
+SRCDIR=src
+EXAMPLES=examples
+BUILD=bin
+RUNCP=$(POSTGIS_BUILD_CLASSPATH)$(CPSEP)./postgis.jar
+BUILDCP=$(STUBBUILD)$(CPSEP)$(POSTGIS_BUILD_CLASSPATH)$(CPSEP)$(SRCDIR)
+
+# The pgjdbc 7.2/7.4/8.0 compatibility stub stuff
+STUBDIR=stubs
+STUBBUILD=stubbin/
+
+# What to put into the JAR files:
+JARCONTENTS=-C $(BUILD) org \
+		-C $(BUILD) examples \
+		-C $(SRCDIR) org/postgresql/driverconfig.properties \
+		-C . README COPYING_LGPL \
+		-C ../.. COPYING
+
+DEBUGJARCONTENTS=-C $(SRCDIR) org \
+		-C $(SRCDIR) examples
+
+# include version numbers
+include ../../Version.config
+
+# include configuration from central repository, only needed for install
+# and installdirs targets, not for building itsself.
+-include ../../Makefile.config
+
+VERSION=$(JDBC_MAJOR_VERSION).$(JDBC_MINOR_VERSION).$(JDBC_MICRO_VERSION)
+VERSIONPATH=$(BUILD)/org/postgis
+VERSIONTARGET=$(VERSIONPATH)/version.properties
+
+# Output redirect for tests
+TESTRD?= >>$(TESTOUTPUT) 
+
+# Preliminary jts support - not stable yet!
+JTSDIR=jtssrc
+JTSBUILD=jtsbin/
+
+JTSPATH=$(JTSBUILD)$(CPSEP)$(BUILD)$(CPSEP)$(RUNCP)
+
+# Get the list of all source files
+
+SRC = $(SRCDIR)/org/postgis/*.java $(SRCDIR)/org/postgis/*/*.java $(SRCDIR)/examples/*.java
+
+STUBSRC = $(STUBDIR)/org/postgresql/*.java
+
+JTSSRC = $(JTSDIR)/org/postgis/jts/*.java
+
+
+# Now the makefile targets that do the work:
+# The default target:
+all:	jar \
+	offlinetests
+
+# Packing the archives
+
+jar:	compile postgis.jar $(DEBUGJAR)
+	$(CP) postgis.jar postgis_$(VERSION).jar
+	$(CP) postgis_debug.jar postgis_debug_$(VERSION).jar
+
+postgis.jar: compile $(SRCDIR)/org/postgresql/driverconfig.properties
+	$(JAR) -cf postgis.jar $(JARCONTENTS)
+
+postgis_debug.jar: postgis.jar $(SRC)
+	$(CP) postgis.jar postgis_debug.jar
+	$(JAR) -uf postgis_debug.jar $(DEBUGJARCONTENTS)
+
+# See comment for DEBUGJAR above for this rule.
+postgis_debug.fastjar: compile $(SRC) $(SRCDIR)/org/postgresql/driverconfig.properties
+	$(JAR) -cf postgis_debug.jar $(JARCONTENTS) $(DEBUGJARCONTENTS)
+
+$(BUILD):
+	$(MKDIR) $(BUILD)
+
+$(STUBBUILD):
+	$(MKDIR) $(STUBBUILD)
+
+$(VERSIONPATH): $(BUILD)
+	$(MKDIR) $(VERSIONPATH)
+
+$(VERSIONTARGET): $(SRC) ../../Version.config $(VERSIONPATH)
+	$(CP) ../../Version.config $(VERSIONTARGET)
+
+stubcompile: $(STUBBUILD) $(SRCCONF) $(STUBSRC)
+	$(JAVAC) -d $(STUBBUILD) $(STUBSRC)
+	touch stubcompile
+
+compile: stubcompile $(BUILD) $(SRCCONF) $(SRC) $(VERSIONTARGET)
+	$(JAVAC) $(COMP_ADDCP) "$(BUILDCP)" -d $(BUILD) $(SRC) 
+	touch compile
+
+test:	postgis.jar
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/Test $(TESTRD) 
+
+jtest:	postgis.jar
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestServer $(TESTRD) \
+	 jdbc:postgresql:$(PGURL) $(PGUSER) $(PGPASS)
+
+ptestoffline: postgis.jar	
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestParser $(TESTRD) offline
+
+ptest: postgis.jar
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestParser $(TESTRD) \
+	 "jdbc:postgresql_postGIS:$(PGURL);jdbc:postgresql_autogis:$(PGURL)" \
+	 $(PGUSER) $(PGPASS)
+
+boxtestoffline: postgis.jar	
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestBoxes $(TESTRD) offline
+
+boxtest: postgis.jar
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestBoxes $(TESTRD) \
+	 jdbc:postgresql_postGIS:$(PGURL) $(PGUSER) $(PGPASS)
+
+autoregistertest: postgis.jar
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestAutoregister $(TESTRD) \
+	 jdbc:postgresql:$(PGURL) $(PGUSER) $(PGPASS)
+
+# Print all available versions
+versions: postgis.jar
+	$(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/VersionPrinter jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS)
+
+offlinetests: boxtestoffline ptestoffline test
+
+onlinetests: boxtest ptest jtest autoregistertest
+
+# boxtest and ptest include boxtestoffline and ptestoffline, so we only need
+# to run test in addition to the onlinetests
+alltests: onlinetests test
+
+# Cleaning
+clean:
+	echo cleaning...
+	$(DELETE) $(BUILD) bin stubbin postgis.jar postgis_debug.jar \
+		compile stubcompile jtscompile $(JTSBUILD) postgis_jts.jar \
+		$(TESTOUTPUT) \
+		postgis_$(VERSION).jar \
+		postgis_debug_$(VERSION).jar \
+		postgis_jts_$(VERSION).jar
+
+maintainer-clean: clean
+	$(DELETE) $(SRCCONF)
+
+
+install: jar installdirs
+	@echo Testing for successful inclusion of ../Makefile.config
+	test ../Makefile.config
+	$(INSTALL_DATA) postgis.jar $(DESTDIR)
+	$(INSTALL_DATA) postgis_debug.jar $(DESTDIR)
+
+installdirs:
+	@mkdir -p $(DESTDIR)
+
+# Preliminary JTS support
+
+postgis_jts: postgis_jts.jar jtstestoffline
+	@echo "Warning! This is beta code. Use at your own risk."
+
+$(JTSBUILD):
+	$(MKDIR) $(JTSBUILD)
+
+jtscompile: compile stubcompile $(JTSBUILD) $(SRCCONF) $(JTSSRC)
+	$(JAVAC) $(COMP_ADDCP) "$(BUILD)$(CPSEP)$(BUILDCP)" -d $(JTSBUILD) $(JTSSRC) 
+	touch jtscompile
+	
+jtstestoffline: jtscompile	
+	$(JAVA) $(EXEC_ADDCP) "$(JTSPATH)" $(EXAMPLES)/JtsTestParser $(TESTRD) offline
+
+jtstest: jtscompile
+	$(JAVA) $(EXEC_ADDCP) "$(JTSPATH)" $(EXAMPLES)/JtsTestParser $(TESTRD) \
+	jdbc:postgres_jts:$(PGURL) $(PGUSER) $(PGPASS)
+
+postgis_jts.jar: postgis.jar jtscompile $(SRCDIR)/org/postgresql/driverconfig.properties
+	$(CP) postgis.jar postgis_jts.jar
+	$(JAR) -uf postgis_jts.jar -C $(JTSBUILD) .
+	$(CP) postgis_jts.jar postgis_jts_$(VERSION).jar
+

Added: packages/postgis/upstream/java/jdbc/README
===================================================================
--- packages/postgis/upstream/java/jdbc/README	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/README	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,245 @@
+
+*** PostGIS JDBC Driver extension README / FAQ ***
+
+(C) 2005 Markus Schaber <markus.schaber at logix-tt.com>
+
+$Id $
+
+* What is it all about? *
+
+JDBC is an database driver specification for Java. Like ODBC in the C
+world, JDBC allows java applications to transparently use different
+JDBC compliant databases without any source code changes. PostgreSQL,
+the database PostGIS is written for, comes with a driver that
+follows this specification. For downloads and more info, see:
+http://jdbc.postgresql.org/download.html
+
+The purpose of the JDBC Driver extension is to give the PostgreSQL
+JDBC driver some understanding of the PostGIS data types (Geometry,
+Box3D, Box2D). Without this, the Application can only get byte arrays
+or strings (binary and text representation, rsp.) and has to parse it
+on its own. When registering this extension, the Application can
+simply call getObject(column) on the result of the query, and get a
+real java object that is modeled after the OpenGIS spec. It also can
+create or modify this objects itsself and then pass them into the
+database via the PreparedStatement.setObject() method.
+
+Currently, the code is tested with PostGIS 0.8.1, 0.9.1. 0.9.2 and
+1.0.0. It supports both the new hex-encoded EWKB canonical text
+representation used by PostGIS 1.0.0 lwgeom code, and the old, less
+efficient WKT like representation used by previous releases when
+reading data from the server. When sending data to the server, it
+currently always uses the latter form, which is compatible to all
+PostGIS versions.
+
+
+* Do I need it? *
+
+If you happen to write GIS applications, you can propably benefit.
+
+In case your applications are PostGIS specific, you can fully exploit
+the functionality, see "How to I use it" below for instructions and
+the src/examples directory for some code examples.
+
+If you rather prefer to stay OpenGIS compliant, then you cannot use
+the full driver embedding, as this is PostGIS specific functionality.
+But you can still use the geometry classes as a lightweight java
+geometry model if you do not want to use a full-blown GIS
+implementation like jts. Simply use the asText() and
+GeometryFromText() OpenGIS SQL functions against whichever OpenGIS
+compliant server you want, and use the WKT parsing constructors or
+PGgeometry.geomFromString() as well as Geometry.toString() to convert
+between WKT strings and geometry objects.
+
+
+* Is it free? *
+
+Yes. The actual Driver extension code is licensed under the GNU LGPL, 
+this allows everyone to include the code in his projects. You do not
+have to pay any license fees, and you can keep your own application 
+code proprietary, but you have to make the PostGIS source code available 
+to any receivers, including any modifications you apply to it. For 
+details, please see the license file COPYING_LGPL.
+
+The Build files and examples are licensed under GNU GPL, just like the
+rest of PostGIS is. This is not LGPL as applications usually do not
+link against those.
+
+
+* How do I build it? *
+
+You need a recent pgjdbc driver jar, see the download link from above.
+It is currently tested and supported with 7.2, 7.3, 7.4, 8.0 and 8.1 pgjdbc
+releases. Those are the same PostgreSQL releases that are supported by the
+PostGIS server-side C code, and apart from 7.2, the same as currently 
+supported by PostgreSQL server developers.
+
+The current PostGIS jdbc release is also reported to run (but not compile)
+against the postgresql jdbc7.1-1.2.jar, but this is not supported, as well as 
+current PostGIS backend itsself does not support 7.1 servers any more.
+
+Note that your pgjdbc driver version does not constrain the PostgreSQL 
+server version. As the JDBC drivers are downwards compatible against older 
+servers, and PostgreSQL servers typically accept older clients, you can 
+easily use e. G. a pgjdbc 8.0 against a PostgreSQL 7.3 server. To benefit
+from optimizations and bugfixes, it is generally suggested to use the 
+newest stable pgjdbc build that is documented to work against your 
+server release.
+
+Make shure the pgjdbc driver is available in your Java CLASSPATH,
+either by setting the environment variable, or by editing the
+Makefile.
+
+A "make jar" then compiles the code and creates two jar files. The
+"postgis.jar" is for normal usage and deployment, the
+"postgis_debug.jar" additionally includes the source code, for
+debugging purposes.
+
+
+* It is called jdbc2 - does it work with jdbc3, too? *
+
+To make it short: The naming does not refer to SUN jdbc standard releases 
+jdbc-1, jdbc-2 or jdbc-3. 
+
+The current naming is somehow unfortunate. The directory simply is named
+jdbc2 because it is the successor of Paul Ramsey's original jdbc directory,
+which used to exist parallel in the CVS repository. As CVS does its best
+to hinder useful version tracking across file renames, the name was kept
+even after removal of the original jdbc subproject. 
+
+Please note that the PostgreSQL JDBC driver itsself is released in
+several flavours for different JDBC relases and sun JDK releases, but
+currently, the same postgis.jar should work with all of them. If not,
+you clearly found a bug, and we kindly ask you to report it.
+
+If you run into troubles, make shure that you use the newest pgjdbc build.
+Especially pre releases are known to contain bugs (that's why they are pre
+releases), and e. G. 8.0 build 309 contained some problems that are fixed
+in 8.0 build 313.
+
+
+* How do I use it? *
+
+To use the PostGIS types, you need the postgis.jar and the pgjdbc
+driver in your classpath.
+
+The PostGIS extension must be registered within the JDBC driver.
+There are three ways to do this:
+
+- If you use pgjdbc 8.0, the org/postgresql/driverconfig.properties
+  file contained in the postgis.jar autoregisters the PostGIS
+  extension for the PostGIS data types (geometry, box2d, box3d)
+  within the pgjdbc driver.
+
+- You can use the org.postgis.DriverWrapper as replacement for the
+  jdbc driver. This class wraps the PostGreSQL Driver to
+  transparently add the PostGIS Object Classes. This method currently
+  works both with J2EE DataSources, and with the older DriverManager
+  framework. I's a thin wrapper around org.postgresql.Driver that
+  simply registers the extension on every new connection created.
+
+  To use it, you replace the "jdbc:postgresql:" with a
+  "jdbc:postgresql_postGIS" in the jdbc URL, and make your
+  environment aware of the new Driver class.
+
+  DriverManager users simply register org/postgis/DriverWrapper
+  instead of  (or in addition to) org.postgresql.Driver, see
+  examples/TestBoxes.connect()  for an working code.
+
+  DataSource users similarly have to configure their datasource to
+  use the different class. The following works for jboss, put it in
+  your-ds.xml: <driver-class>org.postgis.DriverWrapper</driver-class>
+
+- Of course, you can also manually register the Datatypes on your
+  pgjdbc connection. You have to cast your connection to PGConnection
+  and then call:
+
+        pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+        pgconn.addDataType("box3d", "org.postgis.PGbox3d");
+        pgconn.addDataType("box2d", "org.postgis.PGbox2d");
+
+  You may need to dig through some wrappers when running in an
+  appserver. E. G. for JBoss, The datasource actually gives you a
+  instance of org.jboss.resource.adapter.jdbc.WrappedConnection and
+  have to call getUnderlyingConnection() on it to get the
+  PGConnection instance.)
+
+  Also note that the above addDataType() methods known from earlier
+  pgjdbc versions are deprecated in pgjdbc 8.0 (but still work), see
+  the commented code variants in the DriverWrapper.addGisTypes()
+  method for an alternative.
+
+Note: Even using pgjdbc 8.0, you may still want to use the second or
+third approach if you have several pgjdbc extensions that
+autoregister for the same PostGIS types, as the driver cannot guess
+which extension it should actually use on which connection. The
+current pgjdbc implementation simply parses all
+org/postgresql/driverconfig.properties the classloader can find in his
+classpath, using the first definition found for each type.
+
+
+* How to I run the tests? Are they allowed to fail? *
+
+There are two types of tests provided, offline and online. Offline
+tests can run without a PostGIS server, the online tests need a
+PostGIS server to connect to.
+
+- Offline Tests
+
+  The easiest way to run the offline tests is "make offlinetests".
+
+  The offline tests should always complete without any failure. If
+  you happen to get a failure here, it is a bug in the PostGIS code
+  (or, very unlikely, in the JDK/JRE or Hardware you use). Please
+  contact the PostGIS developer list in this case.
+
+- Online tests
+
+  The online tests can be ran with "make onlinetests", but they need
+  a specially prepared database to connect against, and the pgjdbc
+  driver available in your classpath. The Makefile provides defaults
+  for PGHOST, PGPOR, PGDATABASE, PGUSER and PGPASS, you can override
+  them for your needs. For the jtest, the user needs to create and
+  drop table privileges, the two other tests do not use any table.
+  Make shure you have the PostGIS installed in the database.
+
+  None of the online tests should report any failure. However, some of the
+  tests are skipped against PostGix 0.X servers as 0.8.X and 0.9.X, those
+  are the box2d tests (because this datatype simply is missing on those
+  releases), as well as 22 skipped tests for some geometry representations
+  that those old releases do not support. This is a PostGIS server side
+  problem as the server fails to parse some OpenGIS compliant WKT
+  representations, and structurally (but not geometrically or topologically) 
+  mangles some other geometries. They are unlikely to be fixed in those
+  releases as users should migrate to PostGIS 1.0.
+  
+  The Autoregister Test needs a pgjdbc version 8.0 or newer, and will
+  simply do nothing with older pgjdbc versions.
+
+  If you get any failure messages in the online tests, check whether
+  your really fulfil the prerequisites above. If yes, please contact
+  the PostGIS developer list.
+
+
+* What about the JTS stuff *
+
+There's beta support for the JTS 1.6 geometry implementations instead of the
+native PostGIS classes on the java client side. Simply add jts_1.6.jar to your
+CLASSPATH, "make postgis_jts" and use at your own risk.
+
+
+* How can I contact you? *
+
+Well, the best place are the official PostGIS mailing lists for PostGIS,
+subscription information is linked at:
+  http://postgis.refractions.net/support.php
+  
+If you want to report errors, please try to send us all the details we need
+to reproduce your problem. A small, self-contained test case would be best.
+
+
+* Phew. That's all? *
+
+Yes. For now, at least.
+
+Happy Coding!

Added: packages/postgis/upstream/java/jdbc/jtssrc/examples/JtsTestParser.java
===================================================================
--- packages/postgis/upstream/java/jdbc/jtssrc/examples/JtsTestParser.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/jtssrc/examples/JtsTestParser.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,496 @@
+/*
+ * JtsTestParser.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: JtsTestParser.java 1730 2005-05-25 10:12:54Z mschaber $
+ */
+
+package examples;
+
+import org.postgis.binary.ValueSetter;
+import org.postgis.jts.JtsBinaryParser;
+import org.postgis.jts.JtsBinaryWriter;
+import org.postgis.jts.JtsGeometry;
+
+import org.postgresql.util.PGtokenizer;
+
+import com.vividsolutions.jts.geom.Geometry;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+
+public class JtsTestParser {
+
+    public static String ALL = "ALL", ONLY10 = "ONLY10", EQUAL10 = "EQUAL10";
+
+    /**
+     * Our set of geometries to test.
+     */
+    public static final String[][] testset = new String[][]{
+        {
+            ALL, // 2D
+            "POINT(10 10)"},
+        {
+            ALL, // 3D with 3rd coordinate set to 0
+            "POINT(10 10 0)"},
+        {
+            ALL, // 3D
+            "POINT(10 10 20)"},
+        {
+            ALL,
+            "MULTIPOINT(11 12, 20 20)"},
+        {
+            ALL,
+            "MULTIPOINT(11 12 13, 20 20 20)"},
+        {
+            ALL,
+            "LINESTRING(10 10,20 20,50 50,34 34)"},
+        {
+            ALL,
+            "LINESTRING(10 10 20,20 20 20,50 50 50,34 34 34)"},
+        {
+            ALL,
+            "POLYGON((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))"},
+        {
+            ALL,
+            "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))"},
+        {
+            ALL,
+            "MULTIPOLYGON(((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)),((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)))"},
+        {
+            ALL,
+            "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)))"},
+        {
+            ALL,
+            "MULTILINESTRING((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))"},
+        {
+            ALL,
+            "MULTILINESTRING((10 10 5,20 10 5,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10),POINT(20 20))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10 20),POINT(20 20 20))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(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)),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)))"},
+        {
+            ONLY10, // Cannot be parsed by 0.X servers
+            "GEOMETRYCOLLECTION(MULTIPOINT(10 10 10, 20 20 20),MULTIPOINT(10 10 10, 20 20 20))"},
+        {
+            EQUAL10, // PostGIs 0.X "flattens" this geometry, so it is not
+            // equal after reparsing.
+            "GEOMETRYCOLLECTION(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)))"},
+        {
+            EQUAL10,// PostGIs 0.X "flattens" this geometry, so it is not equal
+            // after reparsing.
+            "GEOMETRYCOLLECTION(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))),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))))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10 20),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),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)))"},
+        {
+            ONLY10, // Collections that contain both X and MultiX do not work on
+            // PostGIS 0.x
+            "GEOMETRYCOLLECTION(POINT(10 10 20),MULTIPOINT(10 10 10, 20 20 20),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),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)),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))),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)))"},
+        {
+            ALL,// new (correct) representation
+            "GEOMETRYCOLLECTION EMPTY"},
+    // end
+    };
+
+    /** The srid we use for the srid tests */
+    public static final int SRID = 4326;
+
+    /** The string prefix we get for the srid tests */
+    public static final String SRIDPREFIX = "SRID=" + SRID + ";";
+
+    /** How much tests did fail? */
+    public static int failcount = 0;
+
+    private static JtsBinaryParser bp = new JtsBinaryParser();
+    private static final JtsBinaryWriter bw = new JtsBinaryWriter();
+
+    /** The actual test method */
+    public static void test(String WKT, Connection[] conns, String flags) throws SQLException {
+        System.out.println("Original:  " + WKT);
+        Geometry geom = JtsGeometry.geomFromString(WKT);
+        String parsed = geom.toString();
+        System.out.println("Parsed:    " + parsed);
+        Geometry regeom = JtsGeometry.geomFromString(parsed);
+        String reparsed = regeom.toString();
+        System.out.println("Re-Parsed: " + reparsed);
+        if (!geom.equalsExact(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else if (!reparsed.equals(parsed)) {
+            System.out.println("--- Text Reps are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        String hexNWKT = bw.writeHexed(regeom, ValueSetter.NDR.NUMBER);
+        System.out.println("NDRHex:    " + hexNWKT);
+        regeom = JtsGeometry.geomFromString(hexNWKT);
+        System.out.println("ReNDRHex:  " + regeom.toString());
+        if (!geom.equalsExact(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        String hexXWKT = bw.writeHexed(regeom, ValueSetter.XDR.NUMBER);
+        System.out.println("XDRHex:    " + hexXWKT);
+        regeom = JtsGeometry.geomFromString(hexXWKT);
+        System.out.println("ReXDRHex:  " + regeom.toString());
+        if (!geom.equalsExact(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        byte[] NWKT = bw.writeBinary(regeom, ValueSetter.NDR.NUMBER);
+        regeom = bp.parse(NWKT);
+        System.out.println("NDR:       " + regeom.toString());
+        if (!geom.equalsExact(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        byte[] XWKT = bw.writeBinary(regeom, ValueSetter.XDR.NUMBER);
+        regeom = bp.parse(XWKT);
+        System.out.println("XDR:       " + regeom.toString());
+        if (!geom.equalsExact(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        for (int i = 0; i < conns.length; i++) {
+            Connection connection = conns[i];
+            Statement statement = connection.createStatement();
+            int serverPostgisMajor = TestAutoregister.getPostgisMajor(statement);
+
+            if ((flags == ONLY10) && serverPostgisMajor < 1) {
+                System.out.println("PostGIS server too old, skipping test on connection " + i
+                        + ": " + connection.getCatalog());
+            } else {
+                System.out.println("Testing on connection " + i + ": " + connection.getCatalog());
+                try {
+                    Geometry sqlGeom = viaSQL(WKT, statement);
+                    System.out.println("SQLin    : " + sqlGeom.toString());
+                    if (!geom.equalsExact(sqlGeom)) {
+                        System.out.println("--- Geometries after SQL are not equal!");
+                        if (flags == EQUAL10 && serverPostgisMajor < 1) {
+                            System.out.println("--- This is expected with PostGIS "
+                                    + serverPostgisMajor + ".X");
+                        } else {
+                            failcount++;
+                        }
+                    } else {
+                        System.out.println("Eq SQL in: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                try {
+                    Geometry sqlreGeom = viaSQL(parsed, statement);
+                    System.out.println("SQLout  :  " + sqlreGeom.toString());
+                    if (!geom.equalsExact(sqlreGeom)) {
+                        System.out.println("--- reparsed Geometries after SQL are not equal!");
+                        if (flags == EQUAL10 && serverPostgisMajor < 1) {
+                            System.out.println("--- This is expected with PostGIS "
+                                    + serverPostgisMajor + ".X");
+                        } else {
+                            failcount++;
+                        }
+                    } else {
+                        System.out.println("Eq SQLout: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                try {
+                    Geometry sqlreGeom = viaPrepSQL(geom, connection);
+                    System.out.println("Prepared:  " + sqlreGeom.toString());
+                    if (!geom.equalsExact(sqlreGeom)) {
+                        System.out.println("--- reparsed Geometries after prepared StatementSQL are not equal!");
+                        if (flags == EQUAL10 && serverPostgisMajor < 1) {
+                            System.out.println("--- This is expected with PostGIS "
+                                    + serverPostgisMajor + ".X");
+                        } else {
+                            failcount++;
+                        }
+                    } else {
+                        System.out.println("Eq Prep: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // asEWKT() function is not present on PostGIS 0.X, and the test
+                // is pointless as 0.X uses EWKT as canonical rep so the same
+                // functionality was already tested above.
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = ewktViaSQL(WKT, statement);
+                        System.out.println("asEWKT   : " + sqlGeom.toString());
+                        if (!geom.equalsExact(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKT SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal   : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // asEWKB() function is not present on PostGIS 0.X.
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = ewkbViaSQL(WKT, statement);
+                        System.out.println("asEWKB   : " + sqlGeom.toString());
+                        if (!geom.equalsExact(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // HexEWKB parsing is not present on PostGIS 0.X.
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = viaSQL(hexNWKT, statement);
+                        System.out.println("hexNWKT:   " + sqlGeom.toString());
+                        if (!geom.equalsExact(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = viaSQL(hexXWKT, statement);
+                        System.out.println("hexXWKT:   " + sqlGeom.toString());
+                        if (!geom.equalsExact(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // Canonical binary input is not present before 1.0
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = binaryViaSQL(NWKT, connection);
+                        System.out.println("NWKT:      " + sqlGeom.toString());
+                        if (!geom.equalsExact(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = binaryViaSQL(XWKT, connection);
+                        System.out.println("XWKT:      " + sqlGeom.toString());
+                        if (!geom.equalsExact(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+            }
+            statement.close();
+        }
+        System.out.println("***");
+    }
+
+    /** Pass a geometry representation through the SQL server */
+    private static Geometry viaSQL(String rep, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT geometry_in('" + rep + "')");
+        rs.next();
+        return ((JtsGeometry) rs.getObject(1)).getGeometry();
+    }
+
+    /**
+     * Pass a geometry representation through the SQL server via prepared
+     * statement
+     */
+    private static Geometry viaPrepSQL(Geometry geom, Connection conn) throws SQLException {
+        PreparedStatement prep = conn.prepareStatement("SELECT ?::geometry");
+        JtsGeometry wrapper = new JtsGeometry(geom);
+        prep.setObject(1, wrapper, Types.OTHER);
+        ResultSet rs = prep.executeQuery();
+        rs.next();
+        JtsGeometry resultwrapper = ((JtsGeometry) rs.getObject(1));
+        return resultwrapper.getGeometry();
+    }
+
+    /** Pass a geometry representation through the SQL server via EWKT */
+    private static Geometry ewktViaSQL(String rep, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT asEWKT(geometry_in('" + rep + "'))");
+        rs.next();
+        String resrep = rs.getString(1);
+        return JtsGeometry.geomFromString(resrep);
+    }
+
+    /** Pass a geometry representation through the SQL server via EWKB */
+    private static Geometry ewkbViaSQL(String rep, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT asEWKB(geometry_in('" + rep + "'))");
+        rs.next();
+        byte[] resrep = rs.getBytes(1);
+        return bp.parse(resrep);
+    }
+
+    /** Pass a EWKB geometry representation through the server */
+    private static Geometry binaryViaSQL(byte[] rep, Connection conn) throws SQLException {
+        PreparedStatement prep = conn.prepareStatement("SELECT ?::bytea::geometry");
+        prep.setBytes(1, rep);
+        ResultSet rs = prep.executeQuery();
+        rs.next();
+        JtsGeometry resultwrapper = ((JtsGeometry) rs.getObject(1));
+        return resultwrapper.getGeometry();
+    }
+
+    /**
+     * Connect to the databases
+     * 
+     * We use DriverWrapper here. For alternatives, see the DriverWrapper
+     * Javadoc
+     * 
+     * @param dbuser
+     * 
+     * @see org.postgis.DriverWrapper
+     * 
+     */
+    public static Connection connect(String url, String dbuser, String dbpass) throws SQLException {
+        Connection conn;
+        conn = DriverManager.getConnection(url, dbuser, dbpass);
+        return conn;
+    }
+
+    public static void loadDrivers() throws ClassNotFoundException {
+        Class.forName("org.postgis.jts.JtsWrapper");
+    }
+
+    /** Our apps entry point */
+    public static void main(String[] args) throws SQLException, ClassNotFoundException {
+        loadDrivers();
+
+        PGtokenizer dburls;
+        String dbuser = null;
+        String dbpass = null;
+
+        if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
+            System.out.println("Performing only offline tests");
+            dburls = new PGtokenizer("", ';');
+        } else if (args.length == 3) {
+            System.out.println("Performing offline and online tests");
+            dburls = new PGtokenizer(args[0], ';');
+
+            dbuser = args[1];
+            dbpass = args[2];
+        } else {
+            System.err.println("Usage: java examples/TestParser dburls user pass [tablename]");
+            System.err.println("   or: java examples/TestParser offline");
+            System.err.println();
+            System.err.println("dburls has one or more jdbc urls separated by ; in the following format");
+            System.err.println("jdbc:postgresql://HOST:PORT/DATABASENAME");
+            System.err.println("tablename is 'jdbc_test' by default.");
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        Connection[] conns;
+        conns = new Connection[dburls.getSize()];
+        for (int i = 0; i < dburls.getSize(); i++) {
+            System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+            conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
+        }
+
+        System.out.println("Performing tests...");
+        System.out.println("***");
+
+        for (int i = 0; i < testset.length; i++) {
+            test(testset[i][1], conns, testset[i][0]);
+            test(SRIDPREFIX + testset[i][1], conns, testset[i][0]);
+        }
+
+        System.out.print("cleaning up...");
+        for (int i = 0; i < conns.length; i++) {
+            conns[i].close();
+        }
+
+        System.out.println("Finished, " + failcount + " tests failed!");
+        System.err.println("Finished, " + failcount + " tests failed!");
+        System.exit(failcount);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryParser.java
===================================================================
--- packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryParser.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryParser.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,247 @@
+/*
+ * JtsBinaryParser.java
+ * 
+ * Binary Parser for JTS - relies on org.postgis V1.0.0+ package.
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: JtsBinaryParser.java 2407 2006-07-18 18:13:31Z mschaber $
+ */
+package org.postgis.jts;
+
+import org.postgis.binary.ByteGetter;
+import org.postgis.binary.ValueGetter;
+import org.postgis.binary.ByteGetter.BinaryByteGetter;
+import org.postgis.binary.ByteGetter.StringByteGetter;
+
+import com.vividsolutions.jts.geom.*;
+import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
+
+/**
+ * Parse binary representation of geometries. Currently, only text rep (hexed)
+ * implementation is tested.
+ * 
+ * It should be easy to add char[] and CharSequence ByteGetter instances,
+ * although the latter one is not compatible with older jdks.
+ * 
+ * I did not implement real unsigned 32-bit integers or emulate them with long,
+ * as both java Arrays and Strings currently can have only 2^31-1 elements
+ * (bytes), so we cannot even get or build Geometries with more than approx.
+ * 2^28 coordinates (8 bytes each).
+ * 
+ * @author Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ */
+public class JtsBinaryParser {
+
+    /**
+     * Get the appropriate ValueGetter for my endianness
+     * 
+     * @param bytes
+     *            The appropriate Byte Getter
+     * 
+     * @return the ValueGetter
+     */
+    public static ValueGetter valueGetterForEndian(ByteGetter bytes) {
+        if (bytes.get(0) == ValueGetter.XDR.NUMBER) { // XDR
+            return new ValueGetter.XDR(bytes);
+        } else if (bytes.get(0) == ValueGetter.NDR.NUMBER) {
+            return new ValueGetter.NDR(bytes);
+        } else {
+            throw new IllegalArgumentException("Unknown Endian type:" + bytes.get(0));
+        }
+    }
+
+    /**
+     * Parse a hex encoded geometry
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.)
+     */
+    public synchronized Geometry parse(String value) {
+        StringByteGetter bytes = new ByteGetter.StringByteGetter(value);
+        return parseGeometry(valueGetterForEndian(bytes));
+    }
+
+    /**
+     * Parse a binary encoded geometry.
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.)
+     */
+    public synchronized Geometry parse(byte[] value) {
+        BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value);
+        return parseGeometry(valueGetterForEndian(bytes));
+    }
+
+    /** Parse a geometry starting at offset. */
+    protected Geometry parseGeometry(ValueGetter data) {
+        return parseGeometry(data, 0, false);
+    }
+
+    /** Parse with a known geometry factory */
+    protected Geometry parseGeometry(ValueGetter data, int srid, boolean inheritSrid) {
+        byte endian = data.getByte(); // skip and test endian flag
+        if (endian != data.endian) {
+            throw new IllegalArgumentException("Endian inconsistency!");
+        }
+        int typeword = data.getInt();
+
+        int realtype = typeword & 0x1FFFFFFF; // cut off high flag bits
+
+        boolean haveZ = (typeword & 0x80000000) != 0;
+        boolean haveM = (typeword & 0x40000000) != 0;
+        boolean haveS = (typeword & 0x20000000) != 0;
+
+        if (haveS) {
+            int newsrid = data.getInt();
+            if (inheritSrid && newsrid != srid) {
+                throw new IllegalArgumentException("Inconsistent srids in complex geometry: " + srid + ", " + newsrid);
+            } else {
+                srid = newsrid;
+            }
+        } else if (!inheritSrid) {
+            srid = -1;
+        }
+       
+        Geometry result;
+        switch (realtype) {
+        case org.postgis.Geometry.POINT:
+            result = parsePoint(data, haveZ, haveM);
+            break;
+        case org.postgis.Geometry.LINESTRING:
+            result = parseLineString(data, haveZ, haveM);
+            break;
+        case org.postgis.Geometry.POLYGON:
+            result = parsePolygon(data, haveZ, haveM, srid);
+            break;
+        case org.postgis.Geometry.MULTIPOINT:
+            result = parseMultiPoint(data, srid);
+            break;
+        case org.postgis.Geometry.MULTILINESTRING:
+            result = parseMultiLineString(data, srid);
+            break;
+        case org.postgis.Geometry.MULTIPOLYGON:
+            result = parseMultiPolygon(data, srid);
+            break;
+        case org.postgis.Geometry.GEOMETRYCOLLECTION:
+            result = parseCollection(data, srid);
+            break;
+        default:
+            throw new IllegalArgumentException("Unknown Geometry Type!");
+        }
+        
+        result.setSRID(srid);
+        
+        return result;
+    }
+
+    private Point parsePoint(ValueGetter data, boolean haveZ, boolean haveM) {
+        double X = data.getDouble();
+        double Y = data.getDouble();
+        Point result;
+        if (haveZ) {
+            double Z = data.getDouble();
+            result = JtsGeometry.geofac.createPoint(new Coordinate(X, Y, Z));
+        } else {
+            result = JtsGeometry.geofac.createPoint(new Coordinate(X, Y));
+        }
+
+        if (haveM) { // skip M value
+            data.getDouble();
+        }
+        
+        return result;
+    }
+
+    /** Parse an Array of "full" Geometries */
+    private void parseGeometryArray(ValueGetter data, Geometry[] container, int srid) {
+        for (int i = 0; i < container.length; i++) {
+            container[i] = parseGeometry(data, srid, true);
+        }
+    }
+
+    /**
+     * Parse an Array of "slim" Points (without endianness and type, part of
+     * LinearRing and Linestring, but not MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private CoordinateSequence parseCS(ValueGetter data, boolean haveZ, boolean haveM) {
+        int count = data.getInt();
+        int dims = haveZ ? 3 : 2;
+        CoordinateSequence cs = new PackedCoordinateSequence.Double(count, dims);
+
+        for (int i = 0; i < count; i++) {
+            for (int d = 0; d < dims; d++) {
+                cs.setOrdinate(i, d, data.getDouble());
+            }
+            if (haveM) { // skip M value
+                data.getDouble();
+            }
+        }
+        return cs;
+    }
+
+    private MultiPoint parseMultiPoint(ValueGetter data, int srid) {
+        Point[] points = new Point[data.getInt()];
+        parseGeometryArray(data, points, srid);
+        return JtsGeometry.geofac.createMultiPoint(points);
+    }
+
+    private LineString parseLineString(ValueGetter data, boolean haveZ, boolean haveM) {
+        return JtsGeometry.geofac.createLineString(parseCS(data, haveZ, haveM));
+    }
+
+    private LinearRing parseLinearRing(ValueGetter data, boolean haveZ, boolean haveM) {
+        return JtsGeometry.geofac.createLinearRing(parseCS(data, haveZ, haveM));
+    }
+
+    private Polygon parsePolygon(ValueGetter data, boolean haveZ, boolean haveM, int srid) {
+        int holecount = data.getInt() - 1;
+        LinearRing[] rings = new LinearRing[holecount];
+        LinearRing shell = parseLinearRing(data, haveZ, haveM);
+        shell.setSRID(srid);
+        for (int i = 0; i < holecount; i++) {
+            rings[i] = parseLinearRing(data, haveZ, haveM);
+            rings[i].setSRID(srid);
+        }
+        return JtsGeometry.geofac.createPolygon(shell, rings);
+    }
+
+    private MultiLineString parseMultiLineString(ValueGetter data, int srid) {
+        int count = data.getInt();
+        LineString[] strings = new LineString[count];
+        parseGeometryArray(data, strings, srid);
+        return JtsGeometry.geofac.createMultiLineString(strings);
+    }
+
+    private MultiPolygon parseMultiPolygon(ValueGetter data, int srid) {
+        int count = data.getInt();
+        Polygon[] polys = new Polygon[count];
+        parseGeometryArray(data, polys, srid);
+        return JtsGeometry.geofac.createMultiPolygon(polys);
+    }
+
+    private GeometryCollection parseCollection(ValueGetter data, int srid) {
+        int count = data.getInt();
+        Geometry[] geoms = new Geometry[count];
+        parseGeometryArray(data, geoms, srid);
+        return JtsGeometry.geofac.createGeometryCollection(geoms);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryWriter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryWriter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsBinaryWriter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,387 @@
+/*
+ * JtsBinaryWriter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Writer
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: JtsBinaryWriter.java 2410 2006-07-19 13:31:18Z mschaber $
+ */
+package org.postgis.jts;
+
+import com.vividsolutions.jts.geom.CoordinateSequence;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryCollection;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.MultiLineString;
+import com.vividsolutions.jts.geom.MultiPoint;
+import com.vividsolutions.jts.geom.MultiPolygon;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+
+import org.postgis.binary.ByteSetter;
+import org.postgis.binary.ValueSetter;
+
+/**
+ * Create binary representation of geometries. Currently, only text rep (hexed)
+ * implementation is tested. Supports only 2 dimensional geometries.
+ * 
+ * It should be easy to add char[] and CharSequence ByteGetter instances,
+ * although the latter one is not compatible with older jdks.
+ * 
+ * I did not implement real unsigned 32-bit integers or emulate them with long,
+ * as both java Arrays and Strings currently can have only 2^31-1 elements
+ * (bytes), so we cannot even get or build Geometries with more than approx.
+ * 2^28 coordinates (8 bytes each).
+ * 
+ * @author markus.schaber at logi-track.com
+ * 
+ */
+public class JtsBinaryWriter {
+
+    /**
+     * Get the appropriate ValueGetter for my endianness
+     * 
+     * @param bytes
+     *            The appropriate Byte Getter
+     * 
+     * @return the ValueGetter
+     */
+    public static ValueSetter valueSetterForEndian(ByteSetter bytes, byte endian) {
+        if (endian == ValueSetter.XDR.NUMBER) { // XDR
+            return new ValueSetter.XDR(bytes);
+        } else if (endian == ValueSetter.NDR.NUMBER) {
+            return new ValueSetter.NDR(bytes);
+        } else {
+            throw new IllegalArgumentException("Unknown Endian type:" + endian);
+        }
+    }
+
+    /**
+     * Write a hex encoded geometry
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.) This is a
+     * TODO item.
+     * 
+     * Currently, geometries with more than 2 dimensions and measures are not
+     * cleanly supported, but SRID is honored.
+     */
+    public synchronized String writeHexed(Geometry geom, byte REP) {
+        int length = estimateBytes(geom);
+        ByteSetter.StringByteSetter bytes = new ByteSetter.StringByteSetter(length);
+        writeGeometry(geom, valueSetterForEndian(bytes, REP));
+        return bytes.result();
+    }
+
+    public synchronized String writeHexed(Geometry geom) {
+        return writeHexed(geom, ValueSetter.NDR.NUMBER);
+    }
+
+    /**
+     * Write a binary encoded geometry.
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.) This is a
+     * TODO item.
+     * 
+     * Currently, geometries with more than 2 dimensions and measures are not
+     * cleanly supported, but SRID is honored.
+     */
+    public synchronized byte[] writeBinary(Geometry geom, byte REP) {
+        int length = estimateBytes(geom);
+        ByteSetter.BinaryByteSetter bytes = new ByteSetter.BinaryByteSetter(length);
+        writeGeometry(geom, valueSetterForEndian(bytes, REP));
+        return bytes.result();
+    }
+
+    public synchronized byte[] writeBinary(Geometry geom) {
+        return writeBinary(geom, ValueSetter.NDR.NUMBER);
+    }
+
+    /** Parse a geometry starting at offset. */
+    protected void writeGeometry(Geometry geom, ValueSetter dest) {
+        final int dimension = getCoordDim(geom);
+        if (dimension < 2 || dimension > 4) {
+            throw new IllegalArgumentException("Unsupported geometry dimensionality: " + dimension);
+        }
+        // write endian flag
+        dest.setByte(dest.endian);
+
+        // write typeword
+        final int plaintype = getWKBType(geom);
+        int typeword = plaintype;
+        if (dimension == 3 || dimension == 4) {
+            typeword |= 0x80000000;
+        }
+        if (dimension == 4) {
+            typeword |= 0x40000000;
+        }
+        if (checkSrid(geom)) {
+            typeword |= 0x20000000;
+        }
+
+        dest.setInt(typeword);
+
+        if (checkSrid(geom)) {
+            dest.setInt(geom.getSRID());
+        }
+
+        switch (plaintype) {
+        case org.postgis.Geometry.POINT:
+            writePoint((Point) geom, dest);
+            break;
+        case org.postgis.Geometry.LINESTRING:
+            writeLineString((LineString) geom, dest);
+            break;
+        case org.postgis.Geometry.POLYGON:
+            writePolygon((Polygon) geom, dest);
+            break;
+        case org.postgis.Geometry.MULTIPOINT:
+            writeMultiPoint((MultiPoint) geom, dest);
+            break;
+        case org.postgis.Geometry.MULTILINESTRING:
+            writeMultiLineString((MultiLineString) geom, dest);
+            break;
+        case org.postgis.Geometry.MULTIPOLYGON:
+            writeMultiPolygon((MultiPolygon) geom, dest);
+            break;
+        case org.postgis.Geometry.GEOMETRYCOLLECTION:
+            writeCollection((GeometryCollection) geom, dest);
+            break;
+        default:
+            throw new IllegalArgumentException("Unknown Geometry Type: " + plaintype);
+        }
+    }
+
+    public static int getWKBType(Geometry geom) {
+        if (geom instanceof Point) {
+            return org.postgis.Geometry.POINT;
+        } else if (geom instanceof com.vividsolutions.jts.geom.LineString) {
+            return org.postgis.Geometry.LINESTRING;
+        } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) {
+            return org.postgis.Geometry.POLYGON;
+        } else if (geom instanceof MultiPoint) {
+            return org.postgis.Geometry.MULTIPOINT;
+        } else if (geom instanceof MultiLineString) {
+            return org.postgis.Geometry.MULTILINESTRING;
+        } else if (geom instanceof com.vividsolutions.jts.geom.MultiPolygon) {
+            return org.postgis.Geometry.MULTIPOLYGON;
+        } else if (geom instanceof com.vividsolutions.jts.geom.GeometryCollection) {
+            return org.postgis.Geometry.GEOMETRYCOLLECTION;
+        } else {
+            throw new IllegalArgumentException("Unknown Geometry Type: " + geom.getClass().getName());
+        }
+    }
+
+    /**
+     * Writes a "slim" Point (without endiannes, srid ant type, only the
+     * ordinates and measure. Used by writeGeometry.
+     */
+    private void writePoint(Point geom, ValueSetter dest) {
+        writeCoordinates(geom.getCoordinateSequence(), getCoordDim(geom), dest);
+    }
+
+    /**
+     * Write a Coordinatesequence, part of LinearRing and Linestring, but not
+     * MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private void writeCoordinates(CoordinateSequence seq, int dims, ValueSetter dest) {
+        for (int i = 0; i < seq.size(); i++) {
+            for (int d = 0; d < dims; d++) {
+                dest.setDouble(seq.getOrdinate(i, d));
+            }
+        }
+    }
+
+    private void writeMultiPoint(MultiPoint geom, ValueSetter dest) {
+        dest.setInt(geom.getNumPoints());
+        for (int i = 0; i < geom.getNumPoints(); i++) {
+            writeGeometry(geom.getGeometryN(i), dest);
+        }
+    }
+
+    private void writeLineString(LineString geom, ValueSetter dest) {
+        dest.setInt(geom.getNumPoints());
+        writeCoordinates(geom.getCoordinateSequence(), getCoordDim(geom), dest);
+    }
+
+    private void writePolygon(Polygon geom, ValueSetter dest) {
+        dest.setInt(geom.getNumInteriorRing() + 1);
+        writeLineString(geom.getExteriorRing(), dest);
+        for (int i = 0; i < geom.getNumInteriorRing(); i++) {
+            writeLineString(geom.getInteriorRingN(i), dest);
+        }
+    }
+
+    private void writeMultiLineString(MultiLineString geom, ValueSetter dest) {
+        writeGeometryArray(geom, dest);
+    }
+
+    private void writeMultiPolygon(MultiPolygon geom, ValueSetter dest) {
+        writeGeometryArray(geom, dest);
+    }
+
+    private void writeCollection(GeometryCollection geom, ValueSetter dest) {
+        writeGeometryArray(geom, dest);
+    }
+
+    private void writeGeometryArray(Geometry geom, ValueSetter dest) {
+        dest.setInt(geom.getNumGeometries());
+        for (int i = 0; i < geom.getNumGeometries(); i++) {
+            writeGeometry(geom.getGeometryN(i), dest);
+        }
+    }
+
+    /** Estimate how much bytes a geometry will need in WKB. */
+    protected int estimateBytes(Geometry geom) {
+        int result = 0;
+
+        // write endian flag
+        result += 1;
+
+        // write typeword
+        result += 4;
+
+        if (checkSrid(geom)) {
+            result += 4;
+        }
+
+        switch (getWKBType(geom)) {
+        case org.postgis.Geometry.POINT:
+            result += estimatePoint((Point) geom);
+            break;
+        case org.postgis.Geometry.LINESTRING:
+            result += estimateLineString((LineString) geom);
+            break;
+        case org.postgis.Geometry.POLYGON:
+            result += estimatePolygon((Polygon) geom);
+            break;
+        case org.postgis.Geometry.MULTIPOINT:
+            result += estimateMultiPoint((MultiPoint) geom);
+            break;
+        case org.postgis.Geometry.MULTILINESTRING:
+            result += estimateMultiLineString((MultiLineString) geom);
+            break;
+        case org.postgis.Geometry.MULTIPOLYGON:
+            result += estimateMultiPolygon((MultiPolygon) geom);
+            break;
+        case org.postgis.Geometry.GEOMETRYCOLLECTION:
+            result += estimateCollection((GeometryCollection) geom);
+            break;
+        default:
+            throw new IllegalArgumentException("Unknown Geometry Type: " + getWKBType(geom));
+        }
+        return result;
+    }
+
+    private boolean checkSrid(Geometry geom) {
+        final int srid = geom.getSRID();
+        // SRID is default 0 with jts geometries
+        return (srid != -1) && (srid != 0);
+    }
+
+    private int estimatePoint(Point geom) {
+        return 8 * getCoordDim(geom);
+    }
+
+    /** Write an Array of "full" Geometries */
+    private int estimateGeometryArray(Geometry container) {
+        int result = 0;
+        for (int i = 0; i < container.getNumGeometries(); i++) {
+            result += estimateBytes(container.getGeometryN(i));
+        }
+        return result;
+    }
+
+    /**
+     * Estimate an Array of "slim" Points (without endianness and type, part of
+     * LinearRing and Linestring, but not MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private int estimatePointArray(int length, Point example) {
+        // number of points
+        int result = 4;
+
+        // And the amount of the points itsself, in consistent geometries
+        // all points have equal size.
+        if (length > 0) {
+            result += length * estimatePoint(example);
+        }
+        return result;
+    }
+
+    /** Estimate an array of "fat" Points */
+    private int estimateMultiPoint(MultiPoint geom) {
+        // int size
+        int result = 4;
+        if (geom.getNumGeometries() > 0) {
+            // We can shortcut here, compared to estimateGeometryArray, as all
+            // subgeoms have the same fixed size
+            result += geom.getNumGeometries() * estimateBytes(geom.getGeometryN(0));
+        }
+        return result;
+    }
+
+    private int estimateLineString(LineString geom) {
+        if (geom == null || geom.getNumGeometries() == 0) {
+            return 0;
+        } else {
+            return estimatePointArray(geom.getNumPoints(), geom.getStartPoint());
+        }
+    }
+
+    private int estimatePolygon(Polygon geom) {
+        // int length
+        int result = 4;
+        result += estimateLineString(geom.getExteriorRing());
+        for (int i = 0; i < geom.getNumInteriorRing(); i++) {
+            result += estimateLineString(geom.getInteriorRingN(i));
+        }
+        return result;
+    }
+
+    private int estimateMultiLineString(MultiLineString geom) {
+        // 4-byte count + subgeometries
+        return 4 + estimateGeometryArray(geom);
+    }
+
+    private int estimateMultiPolygon(MultiPolygon geom) {
+        // 4-byte count + subgeometries
+        return 4 + estimateGeometryArray(geom);
+    }
+
+    private int estimateCollection(GeometryCollection geom) {
+        // 4-byte count + subgeometries
+        return 4 + estimateGeometryArray(geom);
+    }
+
+    public static final int getCoordDim(Geometry geom) {
+        // TODO: Fix geometries with more dimensions
+        // geom.getFactory().getCoordinateSequenceFactory()
+        if (geom == null) {
+            return 0;
+        } else {
+            return 2;
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGeometry.java
===================================================================
--- packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGeometry.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGeometry.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,159 @@
+/*
+ * JtsGeometry.java
+ * 
+ * Wrapper for PostgreSQL JDBC driver to allow transparent reading and writing
+ * of JTS geometries
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: JtsGeometry.java 2409 2006-07-19 09:45:53Z mschaber $
+ */
+
+package org.postgis.jts;
+
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryCollection;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Polygon;
+import com.vividsolutions.jts.geom.PrecisionModel;
+import com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory;
+import com.vividsolutions.jts.io.WKTReader;
+
+/**
+ * JTS Geometry SQL wrapper. Supports PostGIS 1.x (lwgeom hexwkb) for writing
+ * and both PostGIS 0.x (EWKT) and 1.x (lwgeom hexwkb) for reading.
+ * 
+ * @author Markus Schaber
+ */
+
+public class JtsGeometry extends PGobject {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    Geometry geom;
+
+    final static JtsBinaryParser bp = new JtsBinaryParser();
+
+    final static JtsBinaryWriter bw = new JtsBinaryWriter();
+
+    final static PrecisionModel prec = new PrecisionModel();
+
+    final static CoordinateSequenceFactory csfac = PackedCoordinateSequenceFactory.DOUBLE_FACTORY;
+
+    final static GeometryFactory geofac = new GeometryFactory(prec, 0, csfac);
+
+    static final WKTReader reader = new WKTReader(geofac);
+
+    /** Constructor called by JDBC drivers */
+    public JtsGeometry() {
+        setType("geometry");
+    }
+
+    public JtsGeometry(Geometry geom) {
+        this();
+        this.geom = geom;
+    }
+
+    public JtsGeometry(String value) throws SQLException {
+        this();
+        setValue(value);
+    }
+
+    public void setValue(String value) throws SQLException {
+        geom = geomFromString(value);
+    }
+
+    public static Geometry geomFromString(String value) throws SQLException {
+        try {
+            value = value.trim();
+            if (value.startsWith("00") || value.startsWith("01")) {
+                return bp.parse(value);
+            } else {
+                Geometry result;
+                // no srid := 0 in JTS world
+                int srid = 0;
+                // break up geometry into srid and wkt
+                if (value.startsWith("SRID=")) {
+                    String[] temp = value.split(";");
+                    value = temp[1].trim();
+                    srid = Integer.parseInt(temp[0].substring(5));
+                }
+
+                result = reader.read(value);
+                setSridRecurse(result, srid);
+                return result;
+            }
+        } catch (Exception E) {
+            E.printStackTrace();
+            throw new SQLException("Error parsing SQL data:" + E);
+        }
+    }
+
+    /** Recursively set a srid for the geometry and all subgeometries */
+    public static void setSridRecurse(final Geometry geom, final int srid) {
+        geom.setSRID(srid);
+        if (geom instanceof GeometryCollection) {
+            final int subcnt = geom.getNumGeometries();
+            for (int i = 0; i < subcnt; i++) {
+                setSridRecurse(geom.getGeometryN(i), srid);
+            }
+        } else if (geom instanceof Polygon) {
+            Polygon poly = (Polygon) geom;
+            poly.getExteriorRing().setSRID(srid);
+            final int subcnt = poly.getNumInteriorRing();
+            for (int i = 0; i < subcnt; i++) {
+                poly.getInteriorRingN(i).setSRID(srid);
+            }
+        }
+    }
+
+    public Geometry getGeometry() {
+        return geom;
+    }
+
+    public String toString() {
+        return geom.toString();
+    }
+
+    public String getValue() {
+        return bw.writeHexed(getGeometry());
+    }
+
+    public Object clone() {
+        JtsGeometry obj = new JtsGeometry(geom);
+        obj.setType(type);
+        return obj;
+    }
+
+    public boolean equals(Object obj) {
+        if ((obj != null) && (obj instanceof JtsGeometry)) {
+            Geometry other = ((JtsGeometry) obj).geom;
+            if (this.geom == other) { // handles identity as well as both
+                                        // ==null
+                return true;
+            } else if (this.geom != null && other != null) {
+                return other.equals(this.geom);
+            }
+        }
+        return false;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGisWrapper.java
===================================================================
--- packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGisWrapper.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsGisWrapper.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,155 @@
+/*
+ * JtsWrapper.java
+ * 
+ * Allows transparent usage of JTS Geometry classes via PostgreSQL JDBC driver
+ * connected to a PostGIS enabled PostgreSQL server.
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: JtsGisWrapper.java 1977 2005-10-20 15:58:52Z mschaber $
+ */
+
+package org.postgis.jts;
+
+import org.postgresql.Driver;
+import org.postgresql.PGConnection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * JtsGisWrapper
+ * 
+ * Wraps the PostGreSQL Driver to add the JTS/PostGIS Object Classes.
+ * 
+ * This method currently works with J2EE DataSource implementations, and with
+ * DriverManager framework.
+ * 
+ * Simply replace the "jdbc:postgresql:" with a "jdbc:postgresql_JTS" in the
+ * jdbc URL.
+ * 
+ * @author markus.schaber at logix-tt.com
+ * 
+ */
+public class JtsGisWrapper extends Driver {
+
+    private static final String POSTGRES_PROTOCOL = "jdbc:postgresql:";
+    private static final String POSTGIS_PROTOCOL = "jdbc:postgresql_JTS:";
+    public static final String REVISION = "$Revision: 1977 $";
+
+    public JtsGisWrapper() {
+        super();
+    }
+
+    static {
+        try {
+            // Analogy to org.postgresql.Driver
+            java.sql.DriverManager.registerDriver(new JtsGisWrapper());
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Creates a postgresql connection, and then adds the PostGIS data types to
+     * it calling addpgtypes()
+     * 
+     * @param url the URL of the database to connect to
+     * @param info a list of arbitrary tag/value pairs as connection arguments
+     * @return a connection to the URL or null if it isnt us
+     * @exception SQLException if a database access error occurs
+     * 
+     * @see java.sql.Driver#connect
+     * @see org.postgresql.Driver
+     */
+    public java.sql.Connection connect(String url, Properties info) throws SQLException {
+        url = mangleURL(url);
+        Connection result = super.connect(url, info);
+        addGISTypes((PGConnection) result);
+        return result;
+    }
+
+    /**
+     * adds the JTS/PostGIS Data types to a PG Connection.
+     * 
+     * @throws SQLException
+     */
+    public static void addGISTypes(PGConnection pgconn) throws SQLException {
+        pgconn.addDataType("geometry", org.postgis.jts.JtsGeometry.class);
+        pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
+        pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
+    }
+
+    /**
+     * Mangles the PostGIS URL to return the original PostGreSQL URL
+     */
+    public static String mangleURL(String url) throws SQLException {
+        if (url.startsWith(POSTGIS_PROTOCOL)) {
+            return POSTGRES_PROTOCOL + url.substring(POSTGIS_PROTOCOL.length());
+        } else {
+            throw new SQLException("Unknown protocol or subprotocol in url " + url);
+        }
+    }
+
+    /**
+     * Returns true if the driver thinks it can open a connection to the given
+     * URL. Typically, drivers will return true if they understand the
+     * subprotocol specified in the URL and false if they don't. Our protocols
+     * start with jdbc:postgresql_postGIS:
+     * 
+     * @see java.sql.Driver#acceptsURL
+     * @param url the URL of the driver
+     * @return true if this driver accepts the given URL
+     * @exception SQLException if a database-access error occurs (Dont know why
+     *                it would *shrug*)
+     */
+    public boolean acceptsURL(String url) throws SQLException {
+        try {
+            url = mangleURL(url);
+        } catch (SQLException e) {
+            return false;
+        }
+        return super.acceptsURL(url);
+    }
+
+    /**
+     * Gets the underlying drivers major version number
+     * 
+     * @return the drivers major version number
+     */
+
+    public int getMajorVersion() {
+        return super.getMajorVersion();
+    }
+
+    /**
+     * Get the underlying drivers minor version number
+     * 
+     * @return the drivers minor version number
+     */
+    public int getMinorVersion() {
+        return super.getMinorVersion();
+    }
+
+    /**
+     * Returns our own CVS version plus postgres Version
+     */
+    public static String getVersion() {
+        return "JtsGisWrapper " + REVISION + ", wrapping " + Driver.getVersion();
+    }
+}

Added: packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsWrapper.java
===================================================================
--- packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsWrapper.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/jtssrc/org/postgis/jts/JtsWrapper.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,156 @@
+/*
+ * JtsWrapper.java
+ * 
+ * Allows transparent usage of JTS Geometry classes via PostgreSQL JDBC driver
+ * connected to a PostGIS enabled PostgreSQL server.
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: JtsWrapper.java 1977 2005-10-20 15:58:52Z mschaber $
+ */
+
+package org.postgis.jts;
+
+import org.postgresql.Driver;
+import org.postgresql.PGConnection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * DriverWrapper
+ * 
+ * Wraps the PostGreSQL Driver to add the JTS/PostGIS Object Classes.
+ * 
+ * This method currently works with J2EE DataSource implementations, and with
+ * DriverManager framework.
+ * 
+ * Simply replace the "jdbc:postgresql:" with a "jdbc:postgres_jts:" in the jdbc
+ * URL.
+ * 
+ * When using the drivermanager, you need to initialize JtsWrapper instead of
+ * (or in addition to) org.postgresql.Driver. When using a J2EE DataSource
+ * implementation, set the driver class property in the datasource config, the
+ * following works for jboss:
+ * 
+ * &lt;driver-class&gt;org.postgis.jts.PostGisWrapper&lt;/driver-class&gt;
+ * 
+ * @author markus.schaber at logix-tt.com
+ * 
+ */
+public class JtsWrapper extends Driver {
+
+    private static final String POSTGRES_PROTOCOL = "jdbc:postgresql:";
+    private static final String POSTGIS_PROTOCOL = "jdbc:postgres_jts:";
+    public static final String REVISION = "$Revision: 1977 $";
+
+    public JtsWrapper() {
+        super();
+    }
+
+    static {
+        try {
+            // Try to register ourself to the DriverManager
+            java.sql.DriverManager.registerDriver(new JtsWrapper());
+        } catch (SQLException e) {
+            Driver.info("Error registering PostgreSQL Jts Wrapper Driver", e);
+        }
+    }
+
+    /**
+     * Creates a postgresql connection, and then adds the JTS GIS data types to
+     * it calling addpgtypes()
+     * 
+     * @param url the URL of the database to connect to
+     * @param info a list of arbitrary tag/value pairs as connection arguments
+     * @return a connection to the URL or null if it isnt us
+     * @exception SQLException if a database access error occurs
+     * 
+     * @see java.sql.Driver#connect
+     * @see org.postgresql.Driver
+     */
+    public java.sql.Connection connect(String url, Properties info) throws SQLException {
+        url = mangleURL(url);
+        Connection result = super.connect(url, info);
+        addGISTypes((PGConnection) result);
+        return result;
+    }
+
+    /**
+     * adds the JTS/PostGIS Data types to a PG Connection.
+     * @throws SQLException 
+     */
+    public static void addGISTypes(PGConnection pgconn) throws SQLException {
+        pgconn.addDataType("geometry", org.postgis.jts.JtsGeometry.class);
+    }
+
+    /**
+     * Mangles the PostGIS URL to return the original PostGreSQL URL
+     */
+    public static String mangleURL(String url) throws SQLException {
+        if (url.startsWith(POSTGIS_PROTOCOL)) {
+            return POSTGRES_PROTOCOL + url.substring(POSTGIS_PROTOCOL.length());
+        } else {
+            throw new SQLException("Unknown protocol or subprotocol in url " + url);
+        }
+    }
+
+    /**
+     * Check whether the driver thinks he can handle the given URL.
+     * 
+     * @see java.sql.Driver#acceptsURL
+     * @param url the URL of the driver
+     * @return true if this driver accepts the given URL
+     * @exception SQLException Passed through from the underlying PostgreSQL
+     *                driver, should not happen.
+     */
+    public boolean acceptsURL(String url) throws SQLException {
+        try {
+            url = mangleURL(url);
+        } catch (SQLException e) {
+            return false;
+        }
+        return super.acceptsURL(url);
+    }
+
+    /**
+     * Gets the underlying drivers major version number
+     * 
+     * @return the drivers major version number
+     */
+
+    public int getMajorVersion() {
+        return super.getMajorVersion();
+    }
+
+    /**
+     * Get the underlying drivers minor version number
+     * 
+     * @return the drivers minor version number
+     */
+    public int getMinorVersion() {
+        return super.getMinorVersion();
+    }
+
+    /**
+     * Returns our own CVS version plus postgres Version
+     */
+    public static String getVersion() {
+        return "JtsGisWrapper " + REVISION + ", wrapping " + Driver.getVersion();
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/Test.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/Test.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/Test.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,102 @@
+/*
+ * Test.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: Test.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package examples;
+
+import org.postgis.LineString;
+import org.postgis.LinearRing;
+import org.postgis.MultiLineString;
+import org.postgis.MultiPolygon;
+import org.postgis.PGgeometry;
+import org.postgis.Point;
+import org.postgis.Polygon;
+
+import java.sql.SQLException;
+
+public class Test {
+
+    public static void main(String[] args) throws SQLException {
+        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 lr_str = "(10 10 20,34 34 34, 23 19 23 , 10 10 11)";
+
+        System.out.println("LinearRing Test:");
+        System.out.println("\t" + lr_str);
+        LinearRing lr = new LinearRing(lr_str);
+        System.out.println("\t" + lr.toString());
+
+        System.out.println();
+
+        System.out.println("Point Test:");
+        System.out.println("\t" + ptg_str);
+        Point ptg = new Point(ptg_str);
+        System.out.println("\t" + ptg.toString());
+
+        System.out.println();
+
+        System.out.println("LineString Test:");
+        System.out.println("\t" + lng_str);
+        LineString lng = new LineString(lng_str);
+        System.out.println("\t" + lng.toString());
+
+        System.out.println();
+
+        System.out.println("Polygon Test:");
+        System.out.println("\t" + plg_str);
+        Polygon plg = new Polygon(plg_str);
+        System.out.println("\t" + plg.toString());
+
+        System.out.println();
+
+        System.out.println("MultiPolygon Test:");
+        System.out.println("\t" + mplg_str);
+        MultiPolygon mplg = new MultiPolygon(mplg_str);
+        System.out.println("\t" + mplg.toString());
+
+        System.out.println();
+
+        System.out.println("MultiLineString Test:");
+        System.out.println("\t" + mlng_str);
+        MultiLineString mlng = new MultiLineString(mlng_str);
+        System.out.println("\t" + mlng.toString());
+
+        System.out.println();
+
+        System.out.println("PG Test:");
+        System.out.println("\t" + mlng_str);
+        PGgeometry pgf = new PGgeometry(mlng_str);
+        System.out.println("\t" + pgf.toString());
+
+        System.out.println();
+
+        System.out.println("finished");
+        // If we reached here without any exception, we passed all tests.
+        System.err.println("Test.java finished without errors.");
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/TestAutoregister.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/TestAutoregister.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/TestAutoregister.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,179 @@
+/*
+ * TestAutoregister.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: TestAutoregister.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package examples;
+
+import org.postgis.PGbox2d;
+import org.postgis.PGbox3d;
+import org.postgis.PGgeometry;
+import org.postgresql.Driver;
+import org.postgresql.util.PGobject;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * This test program tests whether the autoregistration of PostGIS data types
+ * within the pgjdbc driver was successful. This is supposed to work with
+ * pgjdbc.jar version 8.0 and newer, and thus refuses to work with older pgjdbc
+ * versions. (But it will work fine against older servers.) It also checks for
+ * postgis version to know whether box2d is available.
+ */
+public class TestAutoregister {
+
+    public static void main(String[] args) {
+        String dburl = null;
+        String dbuser = null;
+        String dbpass = null;
+
+        if (args.length == 3) {
+            System.out.println("Testing proper auto-registration");
+            dburl = args[0];
+            dbuser = args[1];
+            dbpass = args[2];
+        } else {
+            System.err.println("Usage: java examples/TestParser dburl user pass");
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        System.out.println("Driver version: " + Driver.getVersion());
+        int major;
+        try {
+            major = new Driver().getMajorVersion();
+        } catch (Exception e) {
+            System.err.println("Cannot create Driver instance: " + e.getMessage());
+            System.exit(1);
+            return;
+        }
+
+        if (major < 8) {
+            System.err.println("Your pgdjbc " + major
+                    + ".X is too old, it does not support autoregistration!");
+            return;
+        }
+
+        System.out.println("Creating JDBC connection to " + dburl);
+        Connection conn = null;
+        Statement stat = null;
+        try {
+            conn = DriverManager.getConnection(dburl, dbuser, dbpass);
+            stat = conn.createStatement();
+        } catch (SQLException e) {
+            System.err.println("Connection initialization failed, aborting.");
+            e.printStackTrace();
+            System.exit(1);
+        }
+
+        int postgisServerMajor = 0;
+        try {
+            postgisServerMajor = getPostgisMajor(stat);
+        } catch (SQLException e) {
+            System.err.println("Error fetching PostGIS version: " + e.getMessage());
+            System.err.println("Is PostGIS really installed in the database?");
+            // Signal the compiler that code flow ends here.
+            System.exit(1);
+        }
+
+        System.out.println("PostGIS Version: " + postgisServerMajor);
+
+        PGobject result = null;
+
+        /* Test geometries */
+        try {
+            ResultSet rs = stat.executeQuery("SELECT 'POINT(1 2)'::geometry");
+            rs.next();
+            result = (PGobject) rs.getObject(1);
+            if (result instanceof PGgeometry) {
+                System.out.println("PGgeometry successful!");
+            } else {
+                System.out.println("PGgeometry failed!");
+            }
+        } catch (SQLException e) {
+            System.err.println("Selecting geometry failed: " + e.getMessage());
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        /* Test box3d */
+        try {
+            ResultSet rs = stat.executeQuery("SELECT 'BOX3D(1 2 3, 4 5 6)'::box3d");
+            rs.next();
+            result = (PGobject) rs.getObject(1);
+            if (result instanceof PGbox3d) {
+                System.out.println("Box3d successful!");
+            } else {
+                System.out.println("Box3d failed!");
+            }
+        } catch (SQLException e) {
+            System.err.println("Selecting box3d failed: " + e.getMessage());
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        /* Test box2d if appropriate */
+        if (postgisServerMajor < 1) {
+            System.out.println("PostGIS version is too old, skipping box2ed test");
+            System.err.println("PostGIS version is too old, skipping box2ed test");
+        } else {
+            try {
+                ResultSet rs = stat.executeQuery("SELECT 'BOX(1 2,3 4)'::box2d");
+                rs.next();
+                result = (PGobject) rs.getObject(1);
+                if (result instanceof PGbox2d) {
+                    System.out.println("Box2d successful!");
+                } else {
+                    System.out.println("Box2d failed! " + result.getClass().getName());
+                }
+            } catch (SQLException e) {
+                System.err.println("Selecting box2d failed: " + e.getMessage());
+                System.exit(1);
+                // Signal the compiler that code flow ends here.
+                return;
+            }
+        }
+
+        System.out.println("Finished.");
+        // If we finished up to here without exitting, we passed all tests.
+        System.err.println("TestAutoregister.java finished without errors.");
+    }
+
+    public static int getPostgisMajor(Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT postgis_version()");
+        rs.next();
+        String version = rs.getString(1);
+        if (version == null) {
+            throw new SQLException("postgis_version returned NULL!");
+        }
+        version = version.trim();
+        int idx = version.indexOf('.');
+        return Integer.parseInt(version.substring(0, idx));
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/TestBoxes.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/TestBoxes.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/TestBoxes.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,234 @@
+/*
+ * Test.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: TestBoxes.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package examples;
+
+import org.postgis.PGbox2d;
+import org.postgis.PGbox3d;
+import org.postgresql.util.PGobject;
+import org.postgresql.util.PGtokenizer;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class TestBoxes {
+
+    /** Our test candidates: */
+    public static final String[] BOXEN3D = new String[]{
+        "BOX3D(1 2 3,4 5 6)", // 3d variant
+        "BOX3D(1 2,4 5)"// 2d variant
+    };
+    public static final String[] BOXEN2D = new String[]{"BOX(1 2,3 4)"};
+
+    /** The srid we use for the srid tests */
+    public static final int SRID = 4326;
+
+    /** The string prefix we get for the srid tests */
+    public static final String SRIDPREFIX = "SRID=" + SRID + ";";
+
+    /** How much tests did fail? */
+    public static int failcount = 0;
+
+    /**
+     * The actual test method
+     */
+    public static void test(String orig, PGobject candidate, Connection[] conns,
+            boolean newPostgisOnly) throws SQLException {
+
+        System.out.println("Original:  " + orig);
+        String redone = candidate.toString();
+        System.out.println("Parsed:    " + redone);
+
+        if (!orig.equals(redone)) {
+            System.out.println("--- Recreated Text Rep not equal!");
+            failcount++;
+        }
+
+        // Let's simulate the way pgjdbc uses to create PGobjects
+        PGobject recreated;
+        try {
+            recreated = (PGobject) candidate.getClass().newInstance();
+        } catch (Exception e) {
+            System.out.println("--- pgjdbc instantiation failed!");
+            System.out.println("--- " + e.getMessage());
+            failcount++;
+            return;
+        }
+        recreated.setValue(redone);
+
+        String reparsed = recreated.toString();
+        System.out.println("Re-Parsed: " + reparsed);
+        if (!recreated.equals(candidate)) {
+            System.out.println("--- Recreated boxen are not equal!");
+            failcount++;
+        } else if (!reparsed.equals(orig)) {
+            System.out.println("--- 2nd generation text reps are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        for (int i = 0; i < conns.length; i++) {
+            System.out.println("Testing on connection " + i + ": " + conns[i].getCatalog());
+            Statement statement = conns[i].createStatement();
+            if (newPostgisOnly && TestAutoregister.getPostgisMajor(statement) < 1) {
+                System.out.println("PostGIS version is too old, not testing box2d");
+            } else {
+
+                try {
+                    PGobject sqlGeom = viaSQL(candidate, statement);
+                    System.out.println("SQLin    : " + sqlGeom.toString());
+                    if (!candidate.equals(sqlGeom)) {
+                        System.out.println("--- Geometries after SQL are not equal!");
+                        failcount++;
+                    } else {
+                        System.out.println("Eq SQL in: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                try {
+                    PGobject sqlreGeom = viaSQL(recreated, statement);
+                    System.out.println("SQLout  :  " + sqlreGeom.toString());
+                    if (!candidate.equals(sqlreGeom)) {
+                        System.out.println("--- reparsed Geometries after SQL are not equal!");
+                        failcount++;
+                    } else {
+                        System.out.println("Eq SQLout: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+            }
+            statement.close();
+        }
+        System.out.println("***");
+    }
+
+    /** Pass a geometry representation through the SQL server */
+    private static PGobject viaSQL(PGobject obj, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT '" + obj.toString() + "'::" + obj.getType());
+        rs.next();
+        return (PGobject) rs.getObject(1);
+    }
+
+    /**
+     * Connect to the databases
+     * 
+     * We use DriverWrapper here. For alternatives, see the DriverWrapper
+     * Javadoc
+     * 
+     * @param dbuser
+     * 
+     * @throws ClassNotFoundException
+     * 
+     * @see org.postgis.DriverWrapper
+     * 
+     */
+    public static Connection connect(String url, String dbuser, String dbpass) throws SQLException,
+            ClassNotFoundException {
+        Connection conn;
+        Class.forName("org.postgis.DriverWrapper");
+        conn = DriverManager.getConnection(url, dbuser, dbpass);
+        return conn;
+    }
+
+    /** Our apps entry point */
+    public static void main(String[] args) throws SQLException, ClassNotFoundException {
+        PGtokenizer dburls;
+        String dbuser = null;
+        String dbpass = null;
+
+        if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
+            System.out.println("Performing only offline tests");
+            dburls = new PGtokenizer("", ';');
+        } else if (args.length == 3) {
+            System.out.println("Performing offline and online tests");
+
+            dburls = new PGtokenizer(args[0], ';');
+            dbuser = args[1];
+            dbpass = args[2];
+        } else {
+            System.err.println("Usage: java examples/TestParser dburls user pass [tablename]");
+            System.err.println("   or: java examples/TestParser offline");
+            System.err.println();
+            System.err.println("dburls has one or more jdbc urls separated by ; in the following format");
+            System.err.println("jdbc:postgresql://HOST:PORT/DATABASENAME");
+            System.err.println("tablename is 'jdbc_test' by default.");
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        Connection[] conns;
+        conns = new Connection[dburls.getSize()];
+        for (int i = 0; i < dburls.getSize(); i++) {
+            System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+            conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
+        }
+
+        System.out.println("Performing tests...");
+        System.out.println("***");
+
+        for (int i = 0; i < BOXEN3D.length; i++) {
+            try {
+                PGbox3d candidate = new PGbox3d(BOXEN3D[i]);
+                test(BOXEN3D[i], candidate, conns, false);
+            } catch (SQLException e) {
+                System.out.println("--- Instantiation of " + BOXEN3D[i] + "failed:");
+                System.out.println("--- " + e.getMessage());
+                failcount++;
+            }
+        }
+
+        for (int i = 0; i < BOXEN2D.length; i++) {
+            try {
+                PGbox2d candidate = new PGbox2d(BOXEN2D[i]);
+                test(BOXEN2D[i], candidate, conns, true);
+            } catch (SQLException e) {
+                System.out.println("--- Instantiation of " + BOXEN2D[i] + "failed:");
+                System.out.println("--- " + e.getMessage());
+                failcount++;
+            }
+
+        }
+
+        System.out.print("cleaning up...");
+        for (int i = 0; i < conns.length; i++) {
+            conns[i].close();
+        }
+
+        System.out.println("Finished, " + failcount + " tests failed!");
+        System.err.println("Finished, " + failcount + " tests failed!");
+        System.exit(failcount);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/TestJava2d.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/TestJava2d.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/TestJava2d.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,178 @@
+/*
+ * Test.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: TestJava2d.java 2408 2006-07-18 18:13:57Z mschaber $
+ */
+
+package examples;
+
+import java.awt.*;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import org.postgis.java2d.Java2DWrapper;
+
+public class TestJava2d {
+    private static final boolean DEBUG = true;
+
+    public static final Shape[] SHAPEARRAY = new Shape[0];
+
+    static {
+        new Java2DWrapper(); // make shure our driver is initialized
+    }
+
+    public static void main(String[] args) throws ClassNotFoundException, SQLException {
+
+        if (args.length != 5) {
+            System.err.println("Usage: java examples/TestJava2D dburl user pass tablename column");
+            System.err.println();
+            System.err.println("dburl has the following format:");
+            System.err.println(Java2DWrapper.POSTGIS_PROTOCOL + "//HOST:PORT/DATABASENAME");
+            System.err.println("tablename is 'jdbc_test' by default.");
+            System.exit(1);
+        }
+
+        Shape[] geometries = read(args[0], args[1], args[2], "SELECT " + args[4] + " FROM "
+                + args[3]);
+
+        if (geometries.length == 0) {
+            System.err.println("No geometries were found.");
+            return;
+        }
+
+        System.err.println("Painting...");
+        Frame window = new Frame("PostGIS java2D demo");
+
+        Canvas CV = new GisCanvas(geometries);
+
+        window.add(CV);
+
+        window.setSize(500, 500);
+
+        window.addWindowListener(new EventHandler());
+
+        window.setVisible(true);
+    }
+
+    static Rectangle2D calcbbox(Shape[] geometries) {
+        Rectangle2D bbox = geometries[0].getBounds2D();
+        for (int i = 1; i < geometries.length; i++) {
+            bbox = bbox.createUnion(geometries[i].getBounds2D());
+        }
+        return bbox;
+    }
+
+    private static Shape[] read(String dburl, String dbuser, String dbpass, String query)
+            throws ClassNotFoundException, SQLException {
+        ArrayList geometries = new ArrayList();
+        System.out.println("Creating JDBC connection...");
+        Class.forName("org.postgresql.Driver");
+        Connection conn = DriverManager.getConnection(dburl, dbuser, dbpass);
+
+        System.out.println("fetching geometries");
+        ResultSet r = conn.createStatement().executeQuery(query);
+
+        while (r.next()) {
+            final Shape current = (Shape) r.getObject(1);
+            if (current != null) {
+                geometries.add(current);
+            }
+        }
+        conn.close();
+        return (Shape[]) geometries.toArray(SHAPEARRAY);
+    }
+
+    public static class GisCanvas extends Canvas {
+        /** Keep java 1.5 compiler happy */
+        private static final long serialVersionUID = 1L;
+
+        final Rectangle2D bbox;
+        final Shape[] geometries;
+
+        public GisCanvas(Shape[] geometries) {
+            this.geometries = geometries;
+            this.bbox = calcbbox(geometries);
+            setBackground(Color.GREEN);
+        }
+
+        public void paint(Graphics og) {
+            Graphics2D g = (Graphics2D) og;
+
+            final double scaleX = (super.getWidth() - 10) / bbox.getWidth();
+            final double scaleY = (super.getHeight() - 10) / bbox.getHeight();
+
+            AffineTransform at = new AffineTransform();
+            at.translate(super.getX() + 5, super.getY() + 5);
+            at.scale(scaleX, scaleY);
+            at.translate(-bbox.getX(), -bbox.getY());
+
+            if (DEBUG) {
+                System.err.println();
+                System.err.println("bbox:  " + bbox);
+                System.err.println("trans: " + at);
+                System.err.println("new:   " + at.createTransformedShape(bbox).getBounds2D());
+                System.err.println("visual:" + super.getBounds());
+            }
+            for (int i = 0; i < geometries.length; i++) {
+                g.setPaint(Color.BLUE);
+                final Shape shape = at.createTransformedShape(geometries[i]);
+                g.fill(shape);
+                g.setPaint(Color.ORANGE);
+                g.draw(shape);
+            }
+        }
+    }
+
+    public static class EventHandler implements WindowListener {
+
+        public void windowActivated(WindowEvent e) {//
+        }
+
+        public void windowClosed(WindowEvent e) {//
+        }
+
+        public void windowClosing(WindowEvent e) {
+            e.getWindow().setVisible(false);
+            System.exit(0);
+        }
+
+        public void windowDeactivated(WindowEvent e) {//
+        }
+
+        public void windowDeiconified(WindowEvent e) {//
+        }
+
+        public void windowIconified(WindowEvent e) {//
+        }
+
+        public void windowOpened(WindowEvent e) {//
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/TestParser.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/TestParser.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/TestParser.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,580 @@
+/*
+ * Test.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: TestParser.java 2340 2006-05-03 08:30:25Z mschaber $
+ */
+
+package examples;
+
+import org.postgis.Geometry;
+import org.postgis.PGgeometry;
+import org.postgis.binary.BinaryParser;
+import org.postgis.binary.BinaryWriter;
+import org.postgis.binary.ValueSetter;
+import org.postgresql.util.PGtokenizer;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+
+public class TestParser {
+
+    public static String ALL = "ALL", ONLY10 = "ONLY10", EQUAL10 = "EQUAL10";
+
+    /**
+     * Our set of geometries to test.
+     */
+    public static final String[][] testset = new String[][]{
+        {
+            ALL, // 2D
+            "POINT(10 10)"},
+        {
+            ALL, // 3D with 3rd coordinate set to 0
+            "POINT(10 10 0)"},
+        {
+            ALL, // 3D
+            "POINT(10 10 20)"},
+        {
+            ALL, // 3D with scientific notation
+            "POINT(1e100 1.2345e-100 -2e-5)"},
+        {
+            ONLY10, // 2D + Measures
+            "POINTM(10 10 20)"},
+        {
+            ONLY10, // 3D + Measures
+            "POINT(10 10 20 30)"},
+        {
+            ALL, // broken format, see http://lists.jump-project.org/pipermail/jts-devel/2006-April/001572.html
+            "MULTIPOINT(11 12, 20 20)"},
+        {
+            ALL,// broken format
+            "MULTIPOINT(11 12 13, 20 20 20)"},
+        {
+            ONLY10,// broken format
+            "MULTIPOINTM(11 12 13, 20 20 20)"},
+        {
+            ONLY10,// broken format
+            "MULTIPOINT(11 12 13 14,20 20 20 20)"},
+        {
+            ALL, // OGC conforming format
+            "MULTIPOINT((11 12), (20 20))"},
+        {
+            ALL,
+            "MULTIPOINT((11 12 13), (20 20 20))"},
+        {
+            ONLY10,
+            "MULTIPOINTM((11 12 13), (20 20 20))"},
+        {
+            ONLY10,
+            "MULTIPOINT((11 12 13 14),(20 20 20 20))"},            
+        {
+            ALL,
+            "LINESTRING(10 10,20 20,50 50,34 34)"},
+        {
+            ALL,
+            "LINESTRING(10 10 20,20 20 20,50 50 50,34 34 34)"},
+        {
+            ONLY10,
+            "LINESTRINGM(10 10 20,20 20 20,50 50 50,34 34 34)"},
+        {
+            ONLY10,
+            "LINESTRING(10 10 20 20,20 20 20 20,50 50 50 50,34 34 34 50)"},
+        {
+            ALL,
+            "POLYGON((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))"},
+        {
+            ALL,
+            "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))"},
+        {
+            ONLY10,
+            "POLYGONM((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))"},
+        {
+            ONLY10,
+            "POLYGON((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7))"},
+        {
+            ALL,
+            "MULTIPOLYGON(((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)),((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)))"},
+        {
+            ALL,
+            "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)))"},
+        {
+            ONLY10,
+            "MULTIPOLYGONM(((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)))"},
+        {
+            ONLY10,
+            "MULTIPOLYGON(((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7)),((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7)))"},
+        {
+            ALL,
+            "MULTILINESTRING((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))"},
+        {
+            ALL,
+            "MULTILINESTRING((10 10 5,20 10 5,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ONLY10,
+            "MULTILINESTRINGM((10 10 7,20 10 7,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ONLY10,
+            "MULTILINESTRING((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10),POINT(20 20))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10 20),POINT(20 20 20))"},
+        {
+            ONLY10,
+            "GEOMETRYCOLLECTIONM(POINT(10 10 20),POINT(20 20 20))"},
+        {
+            ONLY10,
+            "GEOMETRYCOLLECTION(POINT(10 10 20 7),POINT(20 20 20 7))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(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)),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)))"},
+        {
+            ONLY10, // Cannot be parsed by 0.X servers, broken format
+            "GEOMETRYCOLLECTION(MULTIPOINT(10 10 10, 20 20 20),MULTIPOINT(10 10 10, 20 20 20))"},
+        {
+            ONLY10, // Cannot be parsed by 0.X servers, OGC conformant
+            "GEOMETRYCOLLECTION(MULTIPOINT((10 10 10), (20 20 20)),MULTIPOINT((10 10 10), (20 20 20)))"},
+        {
+            EQUAL10, // PostGIs 0.X "flattens" this geometry, so it is not
+            // equal after reparsing.
+            "GEOMETRYCOLLECTION(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)))"},
+        {
+            EQUAL10,// PostGIs 0.X "flattens" this geometry, so it is not equal
+            // after reparsing.
+            "GEOMETRYCOLLECTION(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))),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))))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10 20),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),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)))"},
+        {
+            ONLY10, // Collections that contain both X and MultiX do not work on
+            // PostGIS 0.x, broken format
+            "GEOMETRYCOLLECTION(POINT(10 10 20),MULTIPOINT(10 10 10, 20 20 20),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),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)),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))),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)))"},
+        {
+            ONLY10, // Collections that contain both X and MultiX do not work on
+            // PostGIS 0.x, OGC conformant
+            "GEOMETRYCOLLECTION(POINT(10 10 20),MULTIPOINT((10 10 10), (20 20 20)),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),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)),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))),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)))"},
+        {
+            ALL, // Old (bad) PostGIS 0.X Representation
+            "GEOMETRYCOLLECTION(EMPTY)"},
+
+        {
+            ALL,// new (correct) representation
+            "GEOMETRYCOLLECTION EMPTY"},
+        {
+            ONLY10,// new (correct) representation - does not work on 0.X
+            "POINT EMPTY"},
+        {
+            ONLY10,// new (correct) representation - does not work on 0.X
+            "LINESTRING EMPTY"},
+        {
+            ONLY10,// new (correct) representation - does not work on 0.X
+            "POLYGON EMPTY"},
+        {
+            ONLY10,// new (correct) representation - does not work on 0.X
+            "MULTIPOINT EMPTY"},
+        {
+            ONLY10,// new (correct) representation - does not work on 0.X
+            "MULTILINESTRING EMPTY"},
+        {
+            ONLY10,// new (correct) representation - does not work on 0.X
+            "MULTIPOLYGON EMPTY"},
+    // end
+    };
+
+    /** The srid we use for the srid tests */
+    public static final int SRID = 4326;
+
+    /** The string prefix we get for the srid tests */
+    public static final String SRIDPREFIX = "SRID=" + SRID + ";";
+
+    /** How much tests did fail? */
+    public static int failcount = 0;
+
+    private static BinaryParser bp = new BinaryParser();
+    private static final BinaryWriter bw = new BinaryWriter();
+
+    /** The actual test method */
+    public static void test(String WKT, Connection[] conns, String flags) throws SQLException {
+        System.out.println("Original:  " + WKT);
+        Geometry geom = PGgeometry.geomFromString(WKT);
+        String parsed = geom.toString();
+        System.out.println("Parsed:    " + parsed);
+        Geometry regeom = PGgeometry.geomFromString(parsed);
+        String reparsed = regeom.toString();
+        System.out.println("Re-Parsed: " + reparsed);
+        if (!geom.equals(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else if (!reparsed.equals(parsed)) {
+            System.out.println("--- Text Reps are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        String hexNWKT = bw.writeHexed(regeom, ValueSetter.NDR.NUMBER);
+        System.out.println("NDRHex:    " + hexNWKT);
+        regeom = PGgeometry.geomFromString(hexNWKT);
+        System.out.println("ReNDRHex:  " + regeom.toString());
+        if (!geom.equals(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        String hexXWKT = bw.writeHexed(regeom, ValueSetter.XDR.NUMBER);
+        System.out.println("XDRHex:    " + hexXWKT);
+        regeom = PGgeometry.geomFromString(hexXWKT);
+        System.out.println("ReXDRHex:  " + regeom.toString());
+        if (!geom.equals(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        byte[] NWKT = bw.writeBinary(regeom, ValueSetter.NDR.NUMBER);
+        regeom = bp.parse(NWKT);
+        System.out.println("NDR:       " + regeom.toString());
+        if (!geom.equals(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        byte[] XWKT = bw.writeBinary(regeom, ValueSetter.XDR.NUMBER);
+        regeom = bp.parse(XWKT);
+        System.out.println("XDR:       " + regeom.toString());
+        if (!geom.equals(regeom)) {
+            System.out.println("--- Geometries are not equal!");
+            failcount++;
+        } else {
+            System.out.println("Equals:    yes");
+        }
+
+        for (int i = 0; i < conns.length; i++) {
+            Connection connection = conns[i];
+            Statement statement = connection.createStatement();
+            int serverPostgisMajor = TestAutoregister.getPostgisMajor(statement);
+
+            if ((flags == ONLY10) && serverPostgisMajor < 1) {
+                System.out.println("PostGIS server too old, skipping test on connection " + i
+                        + ": " + connection.getCatalog());
+            } else {
+                System.out.println("Testing on connection " + i + ": " + connection.getCatalog());
+                try {
+                    Geometry sqlGeom = viaSQL(WKT, statement);
+                    System.out.println("SQLin    : " + sqlGeom.toString());
+                    if (!geom.equals(sqlGeom)) {
+                        System.out.println("--- Geometries after SQL are not equal!");
+                        if (flags == EQUAL10 && serverPostgisMajor < 1) {
+                            System.out.println("--- This is expected with PostGIS "
+                                    + serverPostgisMajor + ".X");
+                        } else {
+                            failcount++;
+                        }
+                    } else {
+                        System.out.println("Eq SQL in: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                try {
+                    Geometry sqlreGeom = viaSQL(parsed, statement);
+                    System.out.println("SQLout  :  " + sqlreGeom.toString());
+                    if (!geom.equals(sqlreGeom)) {
+                        System.out.println("--- reparsed Geometries after SQL are not equal!");
+                        if (flags == EQUAL10 && serverPostgisMajor < 1) {
+                            System.out.println("--- This is expected with PostGIS "
+                                    + serverPostgisMajor + ".X");
+                        } else {
+                            failcount++;
+                        }
+                    } else {
+                        System.out.println("Eq SQLout: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                try {
+                    Geometry sqlreGeom = viaPrepSQL(geom, connection);
+                    System.out.println("Prepared:  " + sqlreGeom.toString());
+                    if (!geom.equals(sqlreGeom)) {
+                        System.out.println("--- reparsed Geometries after prepared StatementSQL are not equal!");
+                        if (flags == EQUAL10 && serverPostgisMajor < 1) {
+                            System.out.println("--- This is expected with PostGIS "
+                                    + serverPostgisMajor + ".X");
+                        } else {
+                            failcount++;
+                        }
+                    } else {
+                        System.out.println("Eq Prep: yes");
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // asEWKT() function is not present on PostGIS 0.X, and the test
+                // is pointless as 0.X uses EWKT as canonical rep so the same
+                // functionality was already tested above.
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = ewktViaSQL(WKT, statement);
+                        System.out.println("asEWKT   : " + sqlGeom.toString());
+                        if (!geom.equals(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKT SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal   : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // asEWKB() function is not present on PostGIS 0.X.
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = ewkbViaSQL(WKT, statement);
+                        System.out.println("asEWKB   : " + sqlGeom.toString());
+                        if (!geom.equals(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // HexEWKB parsing is not present on PostGIS 0.X.
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = viaSQL(hexNWKT, statement);
+                        System.out.println("hexNWKT:   " + sqlGeom.toString());
+                        if (!geom.equals(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = viaSQL(hexXWKT, statement);
+                        System.out.println("hexXWKT:   " + sqlGeom.toString());
+                        if (!geom.equals(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+                // Canonical binary input is not present before 1.0
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = binaryViaSQL(NWKT, connection);
+                        System.out.println("NWKT:      " + sqlGeom.toString());
+                        if (!geom.equals(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+                try {
+                    if (serverPostgisMajor >= 1) {
+                        Geometry sqlGeom = binaryViaSQL(XWKT, connection);
+                        System.out.println("XWKT:      " + sqlGeom.toString());
+                        if (!geom.equals(sqlGeom)) {
+                            System.out.println("--- Geometries after EWKB SQL are not equal!");
+                            failcount++;
+                        } else {
+                            System.out.println("equal    : yes");
+                        }
+                    }
+                } catch (SQLException e) {
+                    System.out.println("--- Server side error: " + e.toString());
+                    failcount++;
+                }
+
+            }
+            statement.close();
+        }
+        System.out.println("***");
+    }
+
+    /** Pass a geometry representation through the SQL server */
+    private static Geometry viaSQL(String rep, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT geometry_in('" + rep + "')");
+        rs.next();
+        return ((PGgeometry) rs.getObject(1)).getGeometry();
+    }
+
+    /**
+     * Pass a geometry representation through the SQL server via prepared
+     * statement
+     */
+    private static Geometry viaPrepSQL(Geometry geom, Connection conn) throws SQLException {
+        PreparedStatement prep = conn.prepareStatement("SELECT ?::geometry");
+        PGgeometry wrapper = new PGgeometry(geom);
+        prep.setObject(1, wrapper, Types.OTHER);
+        ResultSet rs = prep.executeQuery();
+        rs.next();
+        PGgeometry resultwrapper = ((PGgeometry) rs.getObject(1));
+        return resultwrapper.getGeometry();
+    }
+
+    /** Pass a geometry representation through the SQL server via EWKT */
+    private static Geometry ewktViaSQL(String rep, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT asEWKT(geometry_in('" + rep + "'))");
+        rs.next();
+        String resrep = rs.getString(1);
+        return PGgeometry.geomFromString(resrep);
+    }
+
+    /** Pass a geometry representation through the SQL server via EWKB */
+    private static Geometry ewkbViaSQL(String rep, Statement stat) throws SQLException {
+        ResultSet rs = stat.executeQuery("SELECT asEWKB(geometry_in('" + rep + "'))");
+        rs.next();
+        byte[] resrep = rs.getBytes(1);
+        return bp.parse(resrep);
+    }
+
+    /** Pass a EWKB geometry representation through the server */
+    private static Geometry binaryViaSQL(byte[] rep, Connection conn) throws SQLException {
+        PreparedStatement prep = conn.prepareStatement("SELECT ?::bytea::geometry");
+        prep.setBytes(1, rep);
+        ResultSet rs = prep.executeQuery();
+        rs.next();
+        PGgeometry resultwrapper = ((PGgeometry) rs.getObject(1));
+        return resultwrapper.getGeometry();
+    }
+
+    /**
+     * Connect to the databases
+     * 
+     * We use DriverWrapper here. For alternatives, see the DriverWrapper
+     * Javadoc
+     * 
+     * @param dbuser
+     * 
+     * @see org.postgis.DriverWrapper
+     * 
+     */
+    public static Connection connect(String url, String dbuser, String dbpass) throws SQLException {
+        Connection conn;
+        conn = DriverManager.getConnection(url, dbuser, dbpass);
+        return conn;
+    }
+
+    public static void loadDrivers() throws ClassNotFoundException {
+        Class.forName("org.postgis.DriverWrapper");
+        Class.forName("org.postgis.DriverWrapperAutoprobe");
+    }
+
+    /** Our apps entry point */
+    public static void main(String[] args) throws SQLException, ClassNotFoundException {
+        loadDrivers();
+
+        PGtokenizer dburls;
+        String dbuser = null;
+        String dbpass = null;
+
+        if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
+            System.out.println("Performing only offline tests");
+            dburls = new PGtokenizer("", ';');
+        } else if (args.length == 3) {
+            System.out.println("Performing offline and online tests");
+            dburls = new PGtokenizer(args[0], ';');
+
+            dbuser = args[1];
+            dbpass = args[2];
+        } else {
+            System.err.println("Usage: java examples/TestParser dburls user pass");
+            System.err.println("   or: java examples/TestParser offline");
+            System.err.println();
+            System.err.println("dburls has one or more jdbc urls separated by ; in the following format");
+            System.err.println("jdbc:postgresql://HOST:PORT/DATABASENAME");
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        Connection[] conns;
+        conns = new Connection[dburls.getSize()];
+        for (int i = 0; i < dburls.getSize(); i++) {
+            System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+            conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
+        }
+
+        System.out.println("Performing tests...");
+        System.out.println("***");
+
+        for (int i = 0; i < testset.length; i++) {
+            test(testset[i][1], conns, testset[i][0]);
+            test(SRIDPREFIX + testset[i][1], conns, testset[i][0]);
+        }
+
+        System.out.print("cleaning up...");
+        for (int i = 0; i < conns.length; i++) {
+            conns[i].close();
+        }
+
+        System.out.println("Finished, " + failcount + " tests failed!");
+        System.err.println("Finished, " + failcount + " tests failed!");
+        System.exit(failcount);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/TestServer.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/TestServer.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/TestServer.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,116 @@
+/*
+ * Test.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: TestServer.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package examples;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+public class TestServer {
+
+    public static void main(String[] args) {
+        if (args.length != 4 && args.length != 3) {
+            System.err.println("Usage: java examples/TestServer dburl user pass [tablename]");
+            System.err.println();
+            System.err.println("dburl has the following format:");
+            System.err.println("jdbc:postgresql://HOST:PORT/DATABASENAME");
+            System.err.println("tablename is 'jdbc_test' by default.");
+            System.exit(1);
+        }
+
+        Connection conn;
+
+        String dburl = args[0];
+        String dbuser = args[1];
+        String dbpass = args[2];
+
+        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");
+            conn = DriverManager.getConnection(dburl, dbuser, dbpass);
+            System.out.println("Adding geometric type entries...");
+            /*
+             * magic trickery to be pgjdbc 7.2 compatible
+             * 
+             * This works due to the late binding of data types in most java
+             * VMs. As this is more a demo source than a real-world app, we can
+             * risk breaking on exotic VMs here. Real-world apps usually do not
+             * suffer from this problem as they do not have to support such a
+             * wide range of different pgjdbc releases, or they can use the
+             * approach from org.postgis.DriverWrapper (which we do not use here
+             * intentionally to have a test for the other ways to do it).
+             */
+            if (conn.getClass().getName().equals("org.postgresql.jdbc2.Connection")) {
+                ((org.postgresql.Connection) conn).addDataType("geometry", "org.postgis.PGgeometry");
+                ((org.postgresql.Connection) conn).addDataType("box3d", "org.postgis.PGbox3d");
+            } else {
+                ((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) {
+                System.out.println("Error dropping old table: " + e.getMessage());
+            }
+            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) {
+            System.err.println("Aborted due to error:");
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/examples/VersionPrinter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/examples/VersionPrinter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/examples/VersionPrinter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,144 @@
+/*
+ * VersionPrinter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - example and test classes
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: VersionPrinter.java 1672 2005-04-26 07:01:29Z mschaber $
+ */
+
+package examples;
+
+import org.postgis.Version;
+import org.postgresql.Driver;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * Prints out as much version information as available.
+ */
+public class VersionPrinter {
+
+    public static String[] GISVERSIONS = {
+        "postgis_version",
+        "postgis_proj_version",
+        "postgis_scripts_installed",
+        "postgis_lib_version",
+        "postgis_scripts_released",
+        "postgis_uses_stats",
+        "postgis_geos_version",
+        "postgis_scripts_build_date",
+        "postgis_lib_build_date",
+        "postgis_full_version"};
+
+    public static void main(String[] args) {
+        Statement stat = null;
+        Driver d;
+
+    	// Print PostGIS version
+        printHeading("PostGIS jdbc client code");
+        printVersionString("getFullVersion", Version.getFullVersion());
+
+    	// Print PGJDBC Versions
+        printHeading("PGJDBC Driver");
+        printVersionString("getVersion", Driver.getVersion());
+        try {
+            d = new Driver();
+        } catch (Exception e) {
+            System.err.println("Cannot create Driver instance: " + e.getMessage());
+            System.exit(1);
+            return;
+        }	
+        printVersionString("getMajorVersion", d.getMajorVersion());
+        printVersionString("getMinorVersion", d.getMinorVersion());
+
+    	// Print PostgreSQL server versions
+        if (args.length == 3) {
+            Connection conn = null;
+            try {
+                conn = DriverManager.getConnection(args[0], args[1], args[2]);
+                stat = conn.createStatement();
+            } catch (SQLException e) {
+                System.err.println("Connection to database failed, aborting.");
+                System.err.println(e.getMessage());
+                System.exit(1);
+            }
+        } else if (args.length != 0) {
+            System.err.println("Usage: java examples/VersionPrinter dburl user pass");
+            System.exit(1);
+            // Signal the compiler that code flow ends here.
+            return;
+        }
+
+        if (stat == null) {
+            System.out.println("No online version available.");
+        }
+
+        printHeading("PostgreSQL Server");
+        printVersionString("version", stat);
+
+    	// Print PostGIS versions
+        printHeading("PostGIS Server");
+        for (int i = 0; i < GISVERSIONS.length; i++) {
+            printVersionString(GISVERSIONS[i], stat);
+        }
+
+    }
+
+    public static boolean makeemptyline = false;
+
+    private static void printHeading(String heading) {
+        if (makeemptyline) {
+            System.out.println();
+        }
+        System.out.println("** " + heading + " **");
+        makeemptyline = true;
+    }
+
+    public static void printVersionString(String function, int value) {
+        printVersionString(function, Integer.toString(value));
+    }
+
+    public static void printVersionString(String function, String value) {
+        System.out.println("\t" + function + ": " + value);
+    }
+
+    public static void printVersionString(String function, Statement stat) {
+        printVersionString(function, getVersionString(function, stat));
+    }
+
+    public static String getVersionString(String function, Statement stat) {
+        try {
+            ResultSet rs = stat.executeQuery("SELECT " + function + "()");
+            if (rs.next()==false) {
+                return "-- no result --";
+            }
+            String version = rs.getString(1);
+            if (version==null) {
+                return "-- null result --";
+            }
+            return version.trim();
+        } catch (SQLException e) {
+            return "-- unavailable -- ";
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/ComposedGeom.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/ComposedGeom.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/ComposedGeom.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,265 @@
+/*
+ * ComposedGeom.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: ComposedGeom.java 1839 2005-07-28 12:23:16Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.util.PGtokenizer;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+/**
+ * ComposedGeom - Abstract base class for all Geometries that are composed out
+ * of other Geometries.
+ * 
+ * In fact, this currently are all Geometry subclasses except Point.
+ * 
+ * @author markus.schaber at logix-tt.com
+ * 
+ * 
+ */
+public abstract class ComposedGeom extends Geometry {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public static final Geometry[] EMPTY = new Geometry[0];
+
+    /**
+     * The Array containing the geometries
+     * 
+     * This is only to be exposed by concrete subclasses, to retain type safety.
+     */
+    protected Geometry[] subgeoms = EMPTY;
+
+    /**
+     * @param type
+     */
+    public ComposedGeom(int type) {
+        super(type);
+    }
+
+    public Geometry getSubGeometry(int index) {
+        return subgeoms[index];
+    }
+
+    public int numGeoms() {
+        return subgeoms.length;
+    }
+
+    protected ComposedGeom(int type, Geometry[] geoms) {
+        this(type);
+        this.subgeoms = geoms;
+        if (geoms.length > 0) {
+            dimension = geoms[0].dimension;
+            haveMeasure = geoms[0].haveMeasure;
+        } else {
+            dimension = 0;
+        }
+    }
+
+    protected ComposedGeom(int type, String value, boolean haveM) throws SQLException {
+        super(type);
+        value = initSRID(value);
+
+        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.
+        ComposedGeom cother = (ComposedGeom) other;
+
+        if (cother.subgeoms == null && subgeoms == null) {
+            return true;
+        } else if (cother.subgeoms == null || subgeoms == null) {
+            return false;
+        } else if (cother.subgeoms.length != subgeoms.length) {
+            return false;
+        } else if (subgeoms.length == 0) {
+            return true;
+        } else {
+            for (int i = 0; i < subgeoms.length; i++) {
+                if (!cother.subgeoms[i].equalsintern(this.subgeoms[i])) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    public int numPoints() {
+        if ((subgeoms == null) || (subgeoms.length == 0)) {
+            return 0;
+        } else {
+            int result = 0;
+            for (int i = 0; i < subgeoms.length; i++) {
+                result += subgeoms[i].numPoints();
+            }
+            return result;
+        }
+    }
+
+    public Point getPoint(int n) {
+        if (n < 0) {
+            throw new ArrayIndexOutOfBoundsException("Negative index not allowed");
+        } else if ((subgeoms == null) || (subgeoms.length == 0)) {
+            throw new ArrayIndexOutOfBoundsException("Empty Geometry has no Points!");
+        } else {
+            for (int i = 0; i < subgeoms.length; i++) {
+
+                Geometry current = subgeoms[i];
+                int np = current.numPoints();
+                if (n < np) {
+                    return current.getPoint(n);
+                } else {
+                    n -= np;
+                }
+            }
+            throw new ArrayIndexOutOfBoundsException("Index too large!");
+        }
+    }
+
+    /**
+     * Optimized version
+     */
+    public Point getLastPoint() {
+        if ((subgeoms == null) || (subgeoms.length == 0)) {
+            throw new ArrayIndexOutOfBoundsException("Empty Geometry has no Points!");
+        } else {
+            return subgeoms[subgeoms.length - 1].getLastPoint();
+        }
+    }
+
+    /**
+     * Optimized version
+     */
+    public Point getFirstPoint() {
+        if ((subgeoms == null) || (subgeoms.length == 0)) {
+            throw new ArrayIndexOutOfBoundsException("Empty Geometry has no Points!");
+        } else {
+            return subgeoms[0].getFirstPoint();
+        }
+    }
+
+    public Iterator iterator() {
+        return java.util.Arrays.asList(subgeoms).iterator();
+    }
+
+    public boolean isEmpty() {
+        return (subgeoms == null) || (subgeoms.length == 0);
+    }
+
+    protected void mediumWKT(StringBuffer sb) {
+        if ((subgeoms == null) || (subgeoms.length == 0)) {
+            sb.append(" EMPTY");
+        } else {
+            sb.append('(');
+            innerWKT(sb);
+            sb.append(')');
+        }
+    }
+
+    protected void innerWKT(StringBuffer sb) {
+        subgeoms[0].mediumWKT(sb);
+        for (int i = 1; i < subgeoms.length; i++) {
+            sb.append(',');
+            subgeoms[i].mediumWKT(sb);
+        }
+    }
+
+    // Hashing - still buggy!
+    boolean nohash = true;
+    int hashcode = 0;
+
+    public int hashCode() {
+        if (nohash) {
+            hashcode = super.hashCode() ^ subgeoms.hashCode();
+            nohash = false;
+        }
+        return hashcode;
+    }
+
+    public boolean checkConsistency() {
+        if (super.checkConsistency()) {
+            if (isEmpty()) {
+                return true;
+            }
+            // cache to avoid getMember opcode
+            int _dimension = this.dimension;
+            boolean _haveMeasure = this.haveMeasure;
+            int _srid = this.srid;
+            for (int i = 0; i < subgeoms.length; i++) {
+                Geometry sub = subgeoms[i];
+                if (!(sub.checkConsistency() && sub.dimension == _dimension
+                        && sub.haveMeasure == _haveMeasure && sub.srid == _srid)) {
+                    return false;
+                }
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapper.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapper.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapper.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,317 @@
+/*
+ * DriverWrapper.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Wrapper utility class
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: DriverWrapper.java 1978 2005-10-20 16:04:03Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.Driver;
+import org.postgresql.PGConnection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * DriverWrapper
+ * 
+ * Wraps the PostGreSQL Driver to transparently add the PostGIS Object Classes.
+ * This avoids the need of explicit addDataType() calls from the driver users
+ * side.
+ * 
+ * This method currently works with J2EE DataSource implementations, and with
+ * DriverManager framework.
+ * 
+ * Simply replace the "jdbc:postgresql:" with a "jdbc:postgresql_postGIS:" in
+ * the jdbc URL.
+ * 
+ * When using the drivermanager, you need to initialize DriverWrapper instead of
+ * (or in addition to) org.postgresql.Driver. When using a J2EE DataSource
+ * implementation, set the driver class property in the datasource config, the
+ * following works for jboss:
+ * 
+ * <code>
+ * &lt;driver-class&gt;org.postgis.DriverWrapper&lt;/driver-class&gt;
+ * </code>
+ * If you don't like or want to use the DriverWrapper, you have two
+ * alternatives, see the README file.
+ * 
+ * Also note that the addDataType() methods known from earlier pgjdbc versions
+ * are deprecated in pgjdbc 8.0, see the commented code variants in the
+ * addGisTypes() method.
+ * 
+ * This wrapper always uses EWKT as canonical text representation, and thus
+ * works against PostGIS 1.x servers as well as 0.x (tested with 0.8, 0.9 and
+ * 1.0).
+ * 
+ * @author Markus Schaber <markus.schaber at logix-tt.com>
+ * @see DriverWrapperLW
+ * @see DriverWrapperAutoprobe
+ */
+public class DriverWrapper extends Driver {
+
+    public static final String POSTGRES_PROTOCOL = "jdbc:postgresql:";
+    public static final String POSTGIS_PROTOCOL = "jdbc:postgresql_postGIS:";
+    public static final String REVISION = "$Revision: 1978 $";
+    protected static TypesAdder ta72 = null;
+    protected static TypesAdder ta74 = null;
+    protected static TypesAdder ta80 = null;
+
+    protected TypesAdder typesAdder;
+
+    /**
+     * Default constructor.
+     * 
+     * This also loads the appropriate TypesAdder for our SQL Driver instance.
+     * 
+     * @throws SQLException
+     */
+    public DriverWrapper() throws SQLException {
+        super();
+        typesAdder = getTypesAdder(this);
+        // The debug method is @since 7.2
+        if (super.getMajorVersion() > 8 || super.getMinorVersion() > 1) {
+            Driver.debug(this.getClass().getName() + " loaded TypesAdder: "
+                    + typesAdder.getClass().getName());
+        }
+    }
+
+    protected static TypesAdder getTypesAdder(Driver d) throws SQLException {
+        if (d.getMajorVersion() == 7) {
+            if (d.getMinorVersion() >= 3) {
+                if (ta74 == null) {
+                    ta74 = loadTypesAdder("74");
+                }
+                return ta74;
+            } else {
+                if (ta72 == null) {
+                    ta72 = loadTypesAdder("72");
+                }
+                return ta72;
+            }
+        } else {
+            if (ta80 == null) {
+                ta80 = loadTypesAdder("80");
+            }
+            return ta80;
+        }
+    }
+
+    private static TypesAdder loadTypesAdder(String version) throws SQLException {
+        try {
+            Class klass = Class.forName("org.postgis.DriverWrapper$TypesAdder" + version);
+            return (TypesAdder) klass.newInstance();
+        } catch (Exception e) {
+            throw new SQLException("Cannot create TypesAdder instance! " + e.getMessage());
+        }
+    }
+
+    static {
+        try {
+            // Try to register ourself to the DriverManager
+            java.sql.DriverManager.registerDriver(new DriverWrapper());
+        } catch (SQLException e) {
+            Driver.info("Error registering PostGIS Wrapper Driver", e);
+        }
+    }
+
+    /**
+     * Creates a postgresql connection, and then adds the PostGIS data types to
+     * it calling addpgtypes()
+     * 
+     * @param url the URL of the database to connect to
+     * @param info a list of arbitrary tag/value pairs as connection arguments
+     * @return a connection to the URL or null if it isnt us
+     * @exception SQLException if a database access error occurs
+     * 
+     * @see java.sql.Driver#connect
+     * @see org.postgresql.Driver
+     */
+    public java.sql.Connection connect(String url, Properties info) throws SQLException {
+        url = mangleURL(url);
+        Connection result = super.connect(url, info);
+        typesAdder.addGT(result, useLW(result));
+        return result;
+    }
+
+    /**
+     * Do we have HexWKB as well known text representation - to be overridden by
+     * subclasses.
+     */
+    protected boolean useLW(Connection result) {
+        if (result == null) {
+            throw new IllegalArgumentException("null is no valid parameter");
+        }
+        return false;
+    }
+
+    /**
+     * Check whether the driver thinks he can handle the given URL.
+     * 
+     * @see java.sql.Driver#acceptsURL
+     * @param url the URL of the driver
+     * @return true if this driver accepts the given URL
+     * @exception SQLException Passed through from the underlying PostgreSQL
+     *                driver, should not happen.
+     */
+    public boolean acceptsURL(String url) throws SQLException {
+        try {
+            url = mangleURL(url);
+        } catch (SQLException e) {
+            return false;
+        }
+        return super.acceptsURL(url);
+    }
+
+    /**
+     * Returns our own CVS version plus postgres Version
+     */
+    public static String getVersion() {
+        return "PostGisWrapper " + REVISION + ", wrapping " + Driver.getVersion();
+    }
+
+    /*
+     * Here follows the addGISTypes() stuff. This is a little tricky because the
+     * pgjdbc people had several, partially incompatible API changes during 7.2
+     * and 8.0. We still want to support all those releases, however.
+     * 
+     */
+    /**
+     * adds the JTS/PostGIS Data types to a PG 7.3+ Connection. If you use
+     * PostgreSQL jdbc drivers V8.0 or newer, those methods are deprecated due
+     * to some class loader problems (but still work for now), and you may want
+     * to use the method below instead.
+     * 
+     * @throws SQLException
+     * 
+     */
+    public static void addGISTypes(PGConnection pgconn) throws SQLException {
+        loadTypesAdder("74").addGT((Connection) pgconn, false);
+    }
+
+    /**
+     * adds the JTS/PostGIS Data types to a PG 8.0+ Connection.
+     */
+    public static void addGISTypes80(PGConnection pgconn) throws SQLException {
+        loadTypesAdder("80").addGT((Connection) pgconn, false);
+    }
+
+    /**
+     * adds the JTS/PostGIS Data types to a PG 7.2 Connection.
+     * 
+     * @throws SQLException
+     */
+    public static void addGISTypes72(org.postgresql.Connection pgconn) throws SQLException {
+        loadTypesAdder("72").addGT((Connection) pgconn, false);
+    }
+
+    /**
+     * Mangles the PostGIS URL to return the original PostGreSQL URL
+     */
+    protected String mangleURL(String url) throws SQLException {
+        String myProgo = getProtoString();
+        if (url.startsWith(myProgo)) {
+            return POSTGRES_PROTOCOL + url.substring(myProgo.length());
+        } else {
+            throw new SQLException("Unknown protocol or subprotocol in url " + url);
+        }
+    }
+
+    protected String getProtoString() {
+        return POSTGIS_PROTOCOL;
+    }
+
+    /** Base class for the three typewrapper implementations */
+    protected abstract static class TypesAdder {
+        public final void addGT(java.sql.Connection conn, boolean lw) throws SQLException {
+            if (lw) {
+                addBinaryGeometries(conn);
+            } else {
+                addGeometries(conn);
+            }
+            addBoxen(conn);
+        }
+
+        public abstract void addGeometries(Connection conn) throws SQLException;
+
+        public abstract void addBoxen(Connection conn) throws SQLException;
+
+        public abstract void addBinaryGeometries(Connection conn) throws SQLException;
+    }
+
+    /** addGISTypes for V7.3 and V7.4 pgjdbc */
+    protected static final class TypesAdder74 extends TypesAdder {
+        public void addGeometries(Connection conn) {
+            PGConnection pgconn = (PGConnection) conn;
+            pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+        }
+
+        public void addBoxen(Connection conn) {
+            PGConnection pgconn = (PGConnection) conn;
+            pgconn.addDataType("box3d", "org.postgis.PGbox3d");
+            pgconn.addDataType("box2d", "org.postgis.PGbox2d");
+        }
+
+        public void addBinaryGeometries(Connection conn) {
+            PGConnection pgconn = (PGConnection) conn;
+            pgconn.addDataType("geometry", "org.postgis.PGgeometryLW");
+        }
+    }
+
+    /** addGISTypes for V7.2 pgjdbc */
+    protected static class TypesAdder72 extends TypesAdder {
+        public void addGeometries(Connection conn) {
+            org.postgresql.Connection pgconn = (org.postgresql.Connection) conn;
+            pgconn.addDataType("geometry", "org.postgis.PGgeometry");
+        }
+
+        public void addBoxen(Connection conn) {
+            org.postgresql.Connection pgconn = (org.postgresql.Connection) conn;
+            pgconn.addDataType("box3d", "org.postgis.PGbox3d");
+            pgconn.addDataType("box2d", "org.postgis.PGbox2d");
+        }
+
+        public void addBinaryGeometries(Connection conn) {
+            org.postgresql.Connection pgconn = (org.postgresql.Connection) conn;
+            pgconn.addDataType("geometry", "org.postgis.PGgeometryLW");
+        }
+    }
+
+    /** addGISTypes for V8.0 (and hopefully newer) pgjdbc */
+    protected static class TypesAdder80 extends TypesAdder {
+        public void addGeometries(Connection conn) throws SQLException {
+            PGConnection pgconn = (PGConnection) conn;
+            pgconn.addDataType("geometry", org.postgis.PGgeometry.class);
+        }
+
+        public void addBoxen(Connection conn) throws SQLException {
+            PGConnection pgconn = (PGConnection) conn;
+            pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
+            pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
+        }
+
+        public void addBinaryGeometries(Connection conn) throws SQLException {
+            PGConnection pgconn = (PGConnection) conn;
+            pgconn.addDataType("geometry", org.postgis.PGgeometryLW.class);
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperAutoprobe.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperAutoprobe.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperAutoprobe.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,109 @@
+/*
+ * DriverWrapperAutoprobe.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Wrapper utility class
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: DriverWrapperAutoprobe.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.Driver;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * DriverWrapperAutoprobe
+ * 
+ * Wraps the PostGreSQL Driver to transparently add the PostGIS Object Classes.
+ * This avoids the need of explicit addDataType() calls from the driver users
+ * side.
+ * 
+ * This DriverWrapper tries to autoprobe the installed PostGIS version to decide
+ * whether to use EWKT or hex encoded EWKB as canonical text representation. It
+ * uses the first PostGIS installation found in your namespace search path (aka
+ * schema search path) on the server side, and this works as long as you do not
+ * access incompatible PostGIS versions that reside in other schemas.
+ * 
+ * For usage notes, see DriverWrapper class, but use "jdbc:postgresql_autogis:"
+ * as JDBC url prefix and org.postgis.DriverWrapperAutoprobe as driver class.
+ * 
+ * @author Markus Schaber <markus.schaber at logix-tt.com>
+ * @see DriverWrapper
+ */
+public class DriverWrapperAutoprobe extends DriverWrapper {
+
+    public static final String POSTGIS_AUTOPROTOCOL = "jdbc:postgresql_autogis:";
+    public static final String REVISIONAUTO = "$Revision: 1622 $";
+
+    /**
+     * Default constructor.
+     */
+    public DriverWrapperAutoprobe() throws SQLException {
+        super();
+    }
+
+    static {
+        try {
+            // Try to register ourself to the DriverManager
+            java.sql.DriverManager.registerDriver(new DriverWrapperAutoprobe());
+        } catch (SQLException e) {
+            Driver.info("Error registering PostGIS LW Wrapper Driver", e);
+        }
+    }
+
+    protected String getProtoString() {
+        return POSTGIS_AUTOPROTOCOL;
+    }
+
+    protected boolean useLW(Connection conn) {
+        try {
+            return supportsEWKB(conn);
+        } catch (SQLException e) {
+            // fail safe default
+            return false;
+        }
+    }
+
+    /**
+     * Returns our own CVS version plus postgres Version
+     */
+    public static String getVersion() {
+        return "PostGisWrapperAutoprobe " + REVISIONAUTO + ", wrapping " + Driver.getVersion();
+    }
+
+    public static boolean supportsEWKB(Connection conn) throws SQLException {
+        Statement stat = conn.createStatement();
+        ResultSet rs = stat.executeQuery("SELECT postgis_version()");
+        rs.next();
+        String version = rs.getString(1);
+        rs.close();
+        stat.close();
+        if (version == null) {
+            throw new SQLException("postgis_version returned NULL!");
+        }
+        version = version.trim();
+        int idx = version.indexOf('.');
+        int majorVersion = Integer.parseInt(version.substring(0, idx));
+        return majorVersion >= 1;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperLW.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperLW.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/DriverWrapperLW.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,83 @@
+/*
+ * DriverWrapperLW.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Wrapper utility class
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: DriverWrapperLW.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.Driver;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * DriverWrapperLW
+ * 
+ * Wraps the PostGreSQL Driver to transparently add the PostGIS Object Classes.
+ * This avoids the need of explicit addDataType() calls from the driver users
+ * side.
+ * 
+ * This DriverWrapper subclass always uses hex encoded EWKB as canonical text
+ * representation, and thus only works against PostGIS 1.x servers and newer.
+ * 
+ * For usage notes, see DriverWrapper class, but use "jdbc:postgresql_lwgis:" as
+ * JDBC url prefix and org.postgis.DriverWrapperLW as driver class.
+ * 
+ * @author Markus Schaber <markus.schaber at logix-tt.com>
+ * @see DriverWrapper
+ */
+public class DriverWrapperLW extends DriverWrapper {
+
+    public static final String POSTGIS_LWPROTOCOL = "jdbc:postgresql_lwgis:";
+    public static final String REVISIONLW = "$Revision: 1622 $";
+
+    /**
+     * Default constructor.
+     */
+    public DriverWrapperLW() throws SQLException {
+        super();
+    }
+
+    static {
+        try {
+            // Try to register ourself to the DriverManager
+            java.sql.DriverManager.registerDriver(new DriverWrapperLW());
+        } catch (SQLException e) {
+            Driver.info("Error registering PostGIS LW Wrapper Driver", e);
+        }
+    }
+
+    protected String getProtoString() {
+        return POSTGIS_LWPROTOCOL;
+    }
+
+    protected boolean useLW(Connection result) {
+        return true;
+    }
+
+    /**
+     * Returns our own CVS version plus postgres Version
+     */
+    public static String getVersion() {
+        return "PostGisWrapperLW " + REVISIONLW + ", wrapping " + Driver.getVersion();
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/Geometry.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/Geometry.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/Geometry.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,325 @@
+/*
+ * Geometry.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: Geometry.java 2343 2006-05-09 13:06:56Z mschaber $
+ */
+
+package org.postgis;
+
+import java.io.Serializable;
+
+/** The base class of all geometries */
+public abstract class Geometry implements Serializable {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    // OpenGIS Geometry types as defined in the OGC WKB Spec
+    // (May we replace this with an ENUM as soon as JDK 1.5
+    // has gained widespread usage?)
+
+    /** Fake type for linear ring */
+    public static final int LINEARRING = 0;
+    /**
+     * 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.
+     */
+    public static final int GEOMETRYCOLLECTION = 7;
+
+    public static final String[] ALLTYPES = new String[]{
+        "", // internally used LinearRing does not have any text in front of it
+        "POINT",
+        "LINESTRING",
+        "POLYGON",
+        "MULTIPOINT",
+        "MULTILINESTRING",
+        "MULTIPOLYGON",
+        "GEOMETRYCOLLECTION"};
+
+    /**
+     * The Text representations of the geometry types
+     */
+    public static String getTypeString(int type) {
+        if (type >= 0 && type <= 7) {
+            return ALLTYPES[type];
+        } else {
+            throw new IllegalArgumentException("Unknown Geometry type" + type);
+        }
+    }
+
+    // Properties common to all geometries
+    /**
+     * The dimensionality of this feature (2,3)
+     */
+    public int dimension;
+
+    /**
+     * Do we have a measure (4th dimension)
+     */
+    public boolean haveMeasure = false;
+
+    /**
+     * The OGIS geometry type of this feature. this is final as it never
+     * changes, it is bound to the subclass of the instance.
+     */
+    public final int type;
+
+    /**
+     * The spacial reference system id of this geometry, default (no srid) is -1
+     */
+    public int srid = -1;
+
+    /**
+     * Constructor for subclasses
+     * 
+     * @param type has to be given by all subclasses.
+     */
+    protected Geometry(int type) {
+        this.type = type;
+    }
+
+    /**
+     * java.lang.Object hashCode implementation
+     */
+    public int hashCode() {
+        return dimension | (type * 4) | (srid * 32);
+    }
+
+    /**
+     * java.lang.Object equals implementation
+     */
+    public boolean equals(Object other) {
+        return (other != null) && (other instanceof Geometry) && equals((Geometry) other);
+    }
+
+    /**
+     * geometry specific equals implementation - only defined for non-null
+     * values
+     */
+    public boolean equals(Geometry other) {
+        boolean firstline = (other != null) && (this.dimension == other.dimension)
+                && (this.type == other.type);
+        boolean sridequals = (this.srid == other.srid);
+        boolean measEquals = (this.haveMeasure == other.haveMeasure);
+        boolean secondline = sridequals && measEquals;
+        boolean classequals = other.getClass().equals(this.getClass());
+        boolean equalsintern = this.equalsintern(other);
+        boolean result = firstline && secondline && classequals && equalsintern;
+        return result;
+    }
+
+    /**
+     * Whether test coordinates for geometry - subclass specific code
+     * 
+     * Implementors can assume that dimensin, type, srid and haveMeasure are
+     * equal, other != null and other is the same subclass.
+     */
+    protected abstract boolean equalsintern(Geometry other);
+
+    /**
+     * Return the number of Points of the geometry
+     */
+    public abstract int numPoints();
+
+    /**
+     * Get the nth Point of the geometry
+     * 
+     * @param n the index of the point, from 0 to numPoints()-1;
+     * @throws ArrayIndexOutOfBoundsException in case of an emtpy geometry or
+     *             bad index.
+     */
+    public abstract Point getPoint(int n);
+
+    /**
+     * Same as getPoint(0);
+     */
+    public abstract Point getFirstPoint();
+
+    /**
+     * Same as getPoint(numPoints()-1);
+     */
+    public abstract Point getLastPoint();
+
+    /**
+     * The OGIS geometry type number of this geometry.
+     */
+    public int getType() {
+        return this.type;
+    }
+
+    /**
+     * Return the Type as String
+     */
+    public String getTypeString() {
+        return getTypeString(this.type);
+    }
+
+    /** Returns whether we have a measure */
+    public boolean isMeasured() {
+        return haveMeasure;
+    }
+
+    /**
+     * Queries the number of geometric dimensions of this geometry. This does
+     * not include measures, as opposed to the server.
+     * 
+     * @return The dimensionality (eg, 2D or 3D) of this geometry.
+     */
+    public int getDimension() {
+        return this.dimension;
+    }
+
+    /**
+     * The OGIS geometry type number of this geometry.
+     */
+    public int getSrid() {
+        return this.srid;
+    }
+
+    /**
+     * Recursively sets the srid on this geometry and all contained
+     * subgeometries
+     */
+    public void setSrid(int srid) {
+        this.srid = srid;
+    }
+
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        if (srid != -1) {
+            sb.append("SRID=");
+            sb.append(srid);
+            sb.append(';');
+        }
+        outerWKT(sb, true);
+        return sb.toString();
+    }
+
+    /**
+     * Render the WKT version of this Geometry (without SRID) into the given
+     * StringBuffer.
+     */
+    public void outerWKT(StringBuffer sb, boolean putM) {
+        sb.append(getTypeString());
+        if (putM && haveMeasure && dimension == 2) {
+            sb.append('M');
+        }
+        mediumWKT(sb);
+    }
+
+    public final void outerWKT(StringBuffer sb) {
+        outerWKT(sb, true);
+    }
+
+    /**
+     * Render the WKT without the type name, but including the brackets into the
+     * StringBuffer
+     */
+    protected void mediumWKT(StringBuffer sb) {
+        sb.append('(');
+        innerWKT(sb);
+        sb.append(')');
+    }
+
+    /**
+     * Render the "inner" part of the WKT (inside the brackets) into the
+     * StringBuffer.
+     */
+    protected abstract void innerWKT(StringBuffer SB);
+
+    /**
+     * backwards compatibility method
+     */
+    public String getValue() {
+        StringBuffer sb = new StringBuffer();
+        mediumWKT(sb);
+        return sb.toString();
+    }
+
+    /**
+     * Do some internal consistency checks on the geometry.
+     * 
+     * Currently, all Geometries must have a valid dimension (2 or 3) and a
+     * valid type. 2-dimensional Points must have Z=0.0, as well as non-measured
+     * Points must have m=0.0. Composed geometries must have all equal SRID,
+     * dimensionality and measures, as well as that they do not contain NULL or
+     * inconsistent subgeometries.
+     * 
+     * BinaryParser and WKTParser should only generate consistent geometries.
+     * BinaryWriter may produce invalid results on inconsistent geometries.
+     * 
+     * @return true if all checks are passed.
+     */
+    public boolean checkConsistency() {
+        return (dimension >= 2 && dimension <= 3) && (type >= 0 && type <= 7);
+    }
+
+    /**
+     * Splits the SRID=4711; part of a EWKT rep if present and sets the srid.
+     * 
+     * @returns value without the SRID=4711; part
+     */
+    protected String initSRID(String value) {
+        value = value.trim();
+        if (value.startsWith("SRID=")) {
+            int index = value.indexOf(';', 5); // sridprefix length is 5
+            if (index == -1) {
+                throw new IllegalArgumentException(
+                        "Error parsing Geometry - SRID not delimited with ';' ");
+            } else {
+                this.srid = Integer.parseInt(value.substring(5, index));
+                return value.substring(index + 1).trim();
+            }
+        } else {
+            return value;
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/GeometryCollection.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/GeometryCollection.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/GeometryCollection.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,81 @@
+/*
+ * GeometryCollection.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: GeometryCollection.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+/**
+ * Geometry Collection class WARNING: Currently only implements empty
+ * collections
+ * 
+ * @author markus.schaber at logix-tt.com
+ * 
+ * $Id: GeometryCollection.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+public class GeometryCollection extends ComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public static final String GeoCollID = "GEOMETRYCOLLECTION";
+
+    public GeometryCollection() {
+        super(GEOMETRYCOLLECTION);
+    }
+
+    public GeometryCollection(Geometry[] geoms) {
+        super(GEOMETRYCOLLECTION, geoms);
+    }
+
+    public GeometryCollection(String value) throws SQLException {
+        this(value, false);
+    }
+
+    public GeometryCollection(String value, boolean haveM) throws SQLException {
+        super(GEOMETRYCOLLECTION, value, haveM);
+    }
+
+    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) {
+        subgeoms[0].outerWKT(SB, false);
+        for (int i = 1; i < subgeoms.length; i++) {
+            SB.append(',');
+            subgeoms[i].outerWKT(SB, false);
+        }
+    }
+
+    public Geometry[] getGeometries() {
+        return subgeoms;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/LineString.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/LineString.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/LineString.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,102 @@
+/*
+ * LineString.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: LineString.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+public class LineString extends PointComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    double len = -1.;
+
+    public LineString() {
+        super(LINESTRING);
+    }
+
+    public LineString(Point[] points) {
+        super(LINESTRING, points);
+    }
+
+    public LineString(String value) throws SQLException {
+        super(LINESTRING, value);
+    }
+
+    public LineString(String value, boolean haveM) throws SQLException {
+        super(LINESTRING, value, haveM);
+    }
+
+    public LineString reverse() {
+        Point[] points = this.getPoints();
+        int l = points.length;
+        int i, j;
+        Point[] p = new Point[l];
+        for (i = 0, j = l - 1; i < l; i++, j--) {
+            p[i] = points[j];
+        }
+        return new LineString(p);
+    }
+
+    public LineString concat(LineString other) {
+        Point[] points = this.getPoints();
+        Point[] opoints = other.getPoints();
+
+        boolean cutPoint = this.getLastPoint() == null
+                || this.getLastPoint().equals(other.getFirstPoint());
+        int count = points.length + points.length - (cutPoint ? 1 : 0);
+        Point[] p = new Point[count];
+
+        // Maybe we should use System.arrayCopy here?
+        int i, j;
+        for (i = 0; i < points.length; i++) {
+            p[i] = points[i];
+        }
+        if (!cutPoint) {
+            p[i++] = other.getFirstPoint();
+        }
+        for (j = 1; j < opoints.length; j++, i++) {
+            p[i] = opoints[j];
+        }
+        return new LineString(p);
+    }
+
+    public double length() {
+        if (len < 0) {
+            Point[] points = this.getPoints();
+            if ((points == null) || (points.length < 2)) {
+                len = 0;
+            } else {
+                double sum = 0;
+                for (int i = 1; i < points.length; i++) {
+                    sum += points[i - 1].distance(points[i]);
+                }
+                len = sum;
+            }
+        }
+        return len;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/LinearRing.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/LinearRing.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/LinearRing.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,75 @@
+/*
+ * LinearRing.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: LinearRing.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.util.PGtokenizer;
+
+import java.sql.SQLException;
+
+/**
+ * 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 PointComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public LinearRing(Point[] points) {
+        super(LINEARRING, points);
+    }
+
+    /**
+     * 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 {
+        this(value, false);
+    }
+
+    /**
+     * @param value The text representation of this LinearRing
+     * @param haveM Hint whether we have a measure. This is given to us by other
+     *            "parent" Polygon, and is passed further to our parent.
+     */
+
+    protected LinearRing(String value, boolean haveM) throws SQLException {
+        super(LINEARRING);
+        PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.trim()), ',');
+        int npoints = t.getSize();
+        Point[] points = new Point[npoints];
+        for (int p = 0; p < npoints; p++) {
+            points[p] = new Point(t.getToken(p), haveM);
+        }
+        this.dimension = points[0].dimension;
+        // fetch haveMeasure from subpoint because haveM does only work with
+        // 2d+M, not with 3d+M geometries
+        this.haveMeasure = points[0].haveMeasure;
+        this.subgeoms = points;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/MultiLineString.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/MultiLineString.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/MultiLineString.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,96 @@
+/*
+ * MultiLineString.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: MultiLineString.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+public class MultiLineString extends ComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    double len = -1;
+
+    public int hashCode() {
+        return super.hashCode() ^ (int) this.length();
+    }
+
+    public MultiLineString() {
+        super(MULTILINESTRING);
+    }
+
+    public MultiLineString(LineString[] lines) {
+        super(MULTILINESTRING, lines);
+    }
+
+    public MultiLineString(String value) throws SQLException {
+        this(value, false);
+    }
+
+    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() {
+        return subgeoms.length;
+    }
+
+    public LineString[] getLines() {
+        return (LineString[]) subgeoms.clone();
+    }
+
+    public LineString getLine(int idx) {
+        if (idx >= 0 & idx < subgeoms.length) {
+            return (LineString) subgeoms[idx];
+        } else {
+            return null;
+        }
+    }
+
+    public double length() {
+        if (len < 0) {
+            LineString[] lines = (LineString[]) subgeoms;
+            if (lines.length < 1) {
+                len = 0;
+            } else {
+                double sum = 0;
+                for (int i = 0; i < lines.length; i++) {
+                    sum += lines[i].length();
+                }
+                len = sum;
+            }
+        }
+        return len;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPoint.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPoint.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPoint.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,50 @@
+/*
+ * MultiPoint.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: MultiPoint.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+public class MultiPoint extends PointComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public MultiPoint() {
+        super(MULTIPOINT);
+    }
+
+    public MultiPoint(Point[] points) {
+        super(MULTIPOINT, points);
+    }
+
+    public MultiPoint(String value) throws SQLException {
+        this(value, false);
+    }
+
+    protected MultiPoint(String value, boolean haveM) throws SQLException {
+        super(MULTIPOINT, value, haveM);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPolygon.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPolygon.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/MultiPolygon.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,74 @@
+/*
+ * MultiPolygon.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: MultiPolygon.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+public class MultiPolygon extends ComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public MultiPolygon() {
+        super(MULTIPOLYGON);
+    }
+
+    public MultiPolygon(Polygon[] polygons) {
+        super(MULTIPOLYGON, polygons);
+    }
+
+    public MultiPolygon(String value) throws SQLException {
+        this(value, false);
+    }
+
+    protected MultiPolygon(String value, boolean haveM) throws SQLException {
+        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 subgeoms.length;
+    }
+
+    public Polygon getPolygon(int idx) {
+        if (idx >= 0 & idx < subgeoms.length) {
+            return (Polygon) subgeoms[idx];
+        } else {
+            return null;
+        }
+    }
+    
+    public Polygon[] getPolygons() {
+        return (Polygon[]) subgeoms;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox2d.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox2d.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox2d.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,66 @@
+/*
+ * PGbox2d.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - bounding box model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PGbox2d.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+public class PGbox2d extends PGboxbase {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public PGbox2d() {
+        super();
+    }
+
+    public PGbox2d(Point llb, Point urt) {
+        super(llb, urt);
+    }
+
+    public PGbox2d(String value) throws SQLException {
+        super(value);
+    }
+
+    public void setValue(String value) throws SQLException {
+        super.setValue(value);
+
+        if (llb.dimension != 2 || urt.dimension != 2) {
+            throw new SQLException("PGbox2d is only allowed to have 2 dimensions!");
+        }
+    }
+
+    public String getPrefix() {
+        return "BOX";
+    }
+
+    public String getPGtype() {
+        return "box2d";
+    }
+
+    protected PGboxbase newInstance() {
+        return new PGbox2d();
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox3d.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox3d.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/PGbox3d.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,59 @@
+/*
+ * PGbox3d.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - bounding box model
+ * 
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PGbox3d.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.sql.SQLException;
+
+public class PGbox3d extends PGboxbase {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    public PGbox3d() {
+        super();
+    }
+
+    public PGbox3d(Point llb, Point urt) {
+        super(llb, urt);
+    }
+
+    public PGbox3d(String value) throws SQLException {
+        super(value);
+    }
+
+    public String getPrefix() {
+        return ("BOX3D");
+    }
+
+    public String getPGtype() {
+        return ("box3d");
+    }
+
+    protected PGboxbase newInstance() {
+        return new PGbox3d();
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/PGboxbase.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/PGboxbase.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/PGboxbase.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,174 @@
+/*
+ * PGboxbase.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - bounding box model
+ * 
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PGboxbase.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.util.PGobject;
+import org.postgresql.util.PGtokenizer;
+
+import java.sql.SQLException;
+
+/*
+ * Updates Oct 2002 - data members made private - getLLB() and getURT() methods
+ * added
+ */
+
+public abstract class PGboxbase extends PGobject {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    /**
+     * The lower left bottom corner of the box.
+     */
+    protected Point llb;
+
+    /**
+     * The upper right top corner of the box.
+     */
+    protected Point urt;
+
+    /**
+     * The Prefix we have in WKT rep.
+     * 
+     * I use an abstract method here so we do not need to replicate the String
+     * object in every instance.
+     * 
+     */
+    public abstract String getPrefix();
+
+    /**
+     * The Postgres type we have (same construct as getPrefix())
+     */
+    public abstract String getPGtype();
+
+    public PGboxbase() {
+        this.setType(getPGtype());
+    }
+
+    public PGboxbase(Point llb, Point urt) {
+        this();
+        this.llb = llb;
+        this.urt = urt;
+    }
+
+    public PGboxbase(String value) throws SQLException {
+        this();
+        setValue(value);
+    }
+
+    public void setValue(String value) throws SQLException {
+        int srid = -1;
+        value = value.trim();
+        if (value.startsWith("SRID=")) {
+            String[] temp = PGgeometry.splitSRID(value);
+            value = temp[1].trim();
+            srid = Integer.parseInt(temp[0].substring(5));
+        }
+        String myPrefix = getPrefix();
+        if (value.startsWith(myPrefix)) {
+            value = value.substring(myPrefix.length()).trim();
+        }
+        PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
+        llb = new Point(t.getToken(0));
+        urt = new Point(t.getToken(1));
+        if (srid != -1) {
+            llb.setSrid(srid);
+            urt.setSrid(srid);
+        }
+    }
+
+    public String getValue() {
+        StringBuffer sb = new StringBuffer();
+        outerWKT(sb);
+        return sb.toString();
+    }
+
+    private void outerWKT(StringBuffer sb) {
+        sb.append(getPrefix());
+        sb.append('(');
+        llb.innerWKT(sb);
+        sb.append(',');
+        urt.innerWKT(sb);
+        sb.append(')');
+    }
+
+    /**
+     * Unlike geometries, toString() does _not_ contain the srid, as server-side
+     * PostGIS cannot parse this.
+     */
+    public String toString() {
+        return getValue();
+    }
+
+    /** 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;
+    }
+
+    public boolean equals(Object other) {
+        if (other instanceof PGboxbase) {
+            PGboxbase otherbox = (PGboxbase) other;
+            return (compareLazyDim(this.llb, otherbox.llb) && compareLazyDim(this.urt, otherbox.urt));
+        }
+        return false;
+    }
+
+    /**
+     * Compare two coordinates with lazy dimension checking.
+     * 
+     * As the Server always returns Box3D with three dimensions, z==0 equals
+     * dimensions==2
+     * 
+     */
+    protected static boolean compareLazyDim(Point first, Point second) {
+        return first.x == second.x
+                && first.y == second.y
+                && (((first.dimension == 2 || first.z == 0.0) && (second.dimension == 2 || second.z == 0)) || (first.z == second.z));
+    }
+
+    public Object clone() {
+        PGboxbase obj = newInstance();
+        obj.llb = this.llb;
+        obj.urt = this.urt;
+        obj.setType(type);
+        return obj;
+    }
+
+    /**
+     * We could have used this.getClass().newInstance() here, but this forces us
+     * dealing with InstantiationException and IllegalAccessException. Due to
+     * the PGObject.clone() brokennes that does not allow clone() to throw
+     * CloneNotSupportedException, we cannot even pass this exceptions down to
+     * callers in a sane way.
+     */
+    protected abstract PGboxbase newInstance();
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometry.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometry.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometry.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,169 @@
+/*
+ * PGgeometry.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - PGobject Geometry Wrapper
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PGgeometry.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgis.binary.BinaryParser;
+import org.postgresql.util.PGobject;
+
+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();
+
+    public PGgeometry() {
+        this.setType("geometry");
+    }
+
+    public PGgeometry(Geometry geom) {
+        this();
+        this.geom = geom;
+    }
+
+    public PGgeometry(String value) throws SQLException {
+        this();
+        setValue(value);
+    }
+
+    public void setValue(String value) throws SQLException {
+        geom = geomFromString(value, bp);
+    }
+
+    public static Geometry geomFromString(String value) throws SQLException {
+        return geomFromString(value, false);
+    }
+
+    public static Geometry geomFromString(String value, boolean haveM) throws SQLException {
+        BinaryParser bp = new BinaryParser();
+
+        return geomFromString(value, bp, haveM);
+    }
+
+    /**
+     * Maybe we could add more error checking here?
+     */
+    public static Geometry geomFromString(String value, BinaryParser bp) throws SQLException {
+        return geomFromString(value, bp, false);
+    }
+
+    public static Geometry geomFromString(String value, BinaryParser bp, boolean haveM)
+            throws SQLException {
+        value = value.trim();
+
+        int srid = -1;
+
+        if (value.startsWith(SRIDPREFIX)) {
+            // break up geometry into srid and wkt
+            String[] parts = PGgeometry.splitSRID(value);
+            value = parts[1].trim();
+            srid = Integer.parseInt(parts[0].substring(5));
+        }
+
+        Geometry result;
+        if (value.startsWith("00") || value.startsWith("01")) {
+            result = bp.parse(value);
+        } else if (value.endsWith("EMPTY")) {
+            // We have a standard conforming representation for an empty
+            // geometry which is to be parsed as an empty GeometryCollection.
+            result = new GeometryCollection();
+        } else if (value.startsWith("MULTIPOLYGON")) {
+            result = new MultiPolygon(value, haveM);
+        } else if (value.startsWith("MULTILINESTRING")) {
+            result = new MultiLineString(value, haveM);
+        } else if (value.startsWith("MULTIPOINT")) {
+            result = new MultiPoint(value, haveM);
+        } else if (value.startsWith("POLYGON")) {
+            result = new Polygon(value, haveM);
+        } else if (value.startsWith("LINESTRING")) {
+            result = new LineString(value, haveM);
+        } else if (value.startsWith("POINT")) {
+            result = new Point(value, haveM);
+        } else if (value.startsWith("GEOMETRYCOLLECTION")) {
+            result = new GeometryCollection(value, haveM);
+        } else {
+            throw new SQLException("Unknown type: " + value);
+        }
+
+        if (srid != -1) {
+            result.srid = srid;
+        }
+
+        return result;
+    }
+
+    public Geometry getGeometry() {
+        return geom;
+    }
+
+    public void setGeometry(Geometry newgeom) {
+        this.geom = newgeom;
+    }
+    
+    public int getGeoType() {
+        return geom.type;
+    }
+
+    public String toString() {
+        return geom.toString();
+    }
+
+    public String getValue() {
+        return geom.toString();
+    }
+
+    public Object clone() {
+        return new PGgeometry(geom);
+    }
+
+    /** The prefix that indicates SRID presence */
+    public static final String SRIDPREFIX = "SRID=";
+
+    /**
+     * Splits a String at the first occurrence of border charachter.
+     * 
+     * Poor man's String.split() replacement, as String.split() was invented at
+     * jdk1.4, and the Debian PostGIS Maintainer had problems building the woody
+     * backport of his package using DFSG-free compilers. In all the cases we
+     * used split() in the org.postgis package, we only needed to split at the
+     * first occurence, and thus this code could even be faster.
+     * 
+     * @throws SQLException
+     */
+    public static String[] splitSRID(String whole) throws SQLException {
+        int index = whole.indexOf(';', 5); // sridprefix length is 5
+        if (index == -1) {
+            throw new SQLException("Error parsing Geometry - SRID not delimited with ';' ");
+        } else {
+            return new String[]{
+                whole.substring(0, index),
+                whole.substring(index + 1)};
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometryLW.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometryLW.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/PGgeometryLW.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,66 @@
+/*
+ * PGgeometryLW.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - PGobject LWGeometry Wrapper
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PGgeometryLW.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgis.binary.BinaryWriter;
+
+import java.sql.SQLException;
+
+/**
+ * This is a subclas of PGgeometry that uses hex encoded EWKB to communicate
+ * with the backend, which is much more efficient, but only works with Lwgeom
+ * enabled PostGIS (1.0.0 and up).
+ */
+
+public class PGgeometryLW extends PGgeometry {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+    
+    BinaryWriter bw = new BinaryWriter();
+
+    public PGgeometryLW() {
+        super();
+    }
+
+    public PGgeometryLW(Geometry geom) {
+        super(geom);
+    }
+
+    public PGgeometryLW(String value) throws SQLException {
+        super(value);
+    }
+
+    public String toString() {
+        return geom.toString();
+    }
+
+    public String getValue() {
+        return bw.writeHexed(geom);
+    }
+
+    public Object clone() {
+        return new PGgeometryLW(geom);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/Point.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/Point.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/Point.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,288 @@
+/*
+ * Point.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: Point.java 2345 2006-05-10 10:47:35Z mschaber $
+ */
+
+package org.postgis;
+
+import org.postgresql.util.PGtokenizer;
+
+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;
+
+    public int hashCode() {
+        return super.hashCode() ^ hashCode(x) ^ hashCode(y) ^ hashCode(z) ^ hashCode(m);
+    }
+
+    public static int hashCode(double value) {
+        long v = Double.doubleToLongBits(value);
+        return (int) (v ^ (v >>> 32));
+    }
+
+    protected boolean equalsintern(Geometry otherg) {
+        Point other = (Point) otherg;
+        return equals(other);
+    }
+
+    public final boolean equals(Point other) {
+        boolean xequals = x == other.x;
+        boolean yequals = y == other.y;
+        boolean zequals = ((dimension == 2) || (z == other.z));
+        boolean mequals = ((haveMeasure == false) || (m == other.m));
+        boolean result = xequals && yequals && zequals && mequals;
+        return result;
+    }
+
+    public Point getPoint(int index) {
+        if (index == 0) {
+            return this;
+        } else {
+            throw new ArrayIndexOutOfBoundsException("Point only has a single Point! " + index);
+        }
+    }
+
+    /** Optimized versions for this special case */
+    public Point getFirstPoint() {
+        return this;
+    }
+
+    /** Optimized versions for this special case */
+    public Point getLastPoint() {
+        return this;
+    }
+
+    public int numPoints() {
+        return 1;
+    }
+
+    /**
+     * The X coordinate of the point.
+     * In most long/lat systems, this is the longitude.
+     */
+    public double x;
+
+    /**
+     * The Y coordinate of the point.
+     * In most long/lat systems, this is the latitude.
+     */
+    public double y;
+
+    /**
+     * The Z coordinate of the point.
+     * In most long/lat systems, this is a radius from the 
+     * center of the earth, or the height / elevation over
+     * the ground.
+     */
+    public double z;
+
+    /**
+     * The measure of the point.
+     */
+    public double m = 0.0;
+
+    public Point() {
+        super(POINT);
+    }
+
+    /** Constructs a new Point
+     * @param x the longitude / x ordinate
+     * @param y the latitude / y ordinate
+     * @param z the radius / height / elevation / z ordinate
+     */
+    public Point(double x, double y, double z) {
+        this();
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        dimension = 3;
+    }
+
+    /** Constructs a new Point
+     * @param x the longitude / x ordinate
+     * @param y the latitude / y ordinate
+     */
+    public Point(double x, double y) {
+        this();
+        this.x = x;
+        this.y = y;
+        this.z = 0.0;
+        dimension = 2;
+    }
+
+    /**
+     * Construct a Point from EWKT.
+     * 
+     * (3D and measures are legal, but SRID is not allowed).
+     */
+    public Point(String value) throws SQLException {
+        this(value, false);
+    }
+
+    /**
+     * Construct a Point
+     * 
+     * @param value The text representation of this point
+     * @param haveM Hint whether we have a measure. This is used by other
+     *            geometries parsing inner points where we only get "1 2 3 4"
+     *            like strings without the "POINT(" and ")" stuff. If there
+     *            acutally is a POINTM prefix, this overrides the given value.
+     *            However, POINT does not set it to false, as they can be
+     *            contained in measured collections, as in
+     *            "GEOMETRYCOLLECTIONM(POINT(0 0 0))".
+     */
+    protected Point(String value, boolean haveM) throws SQLException {
+        this();
+        value = initSRID(value);
+
+        if (value.indexOf("POINTM") == 0) {
+            haveM = true;
+            value = value.substring(6).trim();
+        } else if (value.indexOf("POINT") == 0) {
+            value = value.substring(5).trim();
+        }
+        PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ' ');
+        try {
+            x = Double.valueOf(t.getToken(0)).doubleValue();
+            y = Double.valueOf(t.getToken(1)).doubleValue();
+            haveM |= t.getSize() == 4;
+            if ((t.getSize() == 3 && !haveM) || (t.getSize() == 4)) {
+                z = Double.valueOf(t.getToken(2)).doubleValue();
+                dimension = 3;
+            } else {
+                dimension = 2;
+            }
+            if (haveM) {
+                m = Double.valueOf(t.getToken(dimension)).doubleValue();
+            }
+        } catch (NumberFormatException e) {
+            throw new SQLException("Error parsing Point: " + e.toString());
+        }
+        haveMeasure = haveM;
+    }
+
+    public void innerWKT(StringBuffer sb) {
+        sb.append(x);
+        if (CUTINTS)
+            cutint(sb);
+        sb.append(' ');
+        sb.append(y);
+        if (CUTINTS)
+            cutint(sb);
+        if (dimension == 3) {
+            sb.append(' ');
+            sb.append(z);
+            if (CUTINTS)
+                cutint(sb);
+        }
+        if (haveMeasure) {
+            sb.append(' ');
+            sb.append(m);
+            if (CUTINTS)
+                cutint(sb);
+        }
+    }
+
+    private static void cutint(StringBuffer sb) {
+        int l = sb.length() - 2;
+        if ((sb.charAt(l + 1) == '0') && (sb.charAt(l) == '.')) {
+            sb.setLength(l);
+        }
+    }
+
+    public double getX() {
+        return x;
+    }
+
+    public double getY() {
+        return y;
+    }
+
+    public double getZ() {
+        return z;
+    }
+
+    public double getM() {
+        return m;
+    }
+
+    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 setM(double m) {
+        haveMeasure = true;
+        this.m = m;
+    }
+
+    public void setX(int x) {
+        this.x = x;
+    }
+
+    public void setY(int y) {
+        this.y = y;
+    }
+
+    public void setZ(int z) {
+        this.z = z;
+    }
+
+    public double distance(Point other) {
+        double tx, ty, tz;
+        if (this.dimension != other.dimension) {
+            throw new IllegalArgumentException("Points have different dimensions!");
+        }
+        tx = this.x - other.x;
+        switch (this.dimension) {
+        case 1 :
+            return Math.sqrt(tx * tx);
+        case 2 :
+            ty = this.y - other.y;
+            return Math.sqrt(tx * tx + ty * ty);
+        case 3 :
+            ty = this.y - other.y;
+            tz = this.z - other.z;
+            return Math.sqrt(tx * tx + ty * ty + tz * tz);
+        default :
+            throw new IllegalArgumentException("Illegal dimension of Point" + this.dimension);
+        }
+    }
+
+    public boolean checkConsistency() {
+        return super.checkConsistency() && (this.dimension == 3 || this.z == 0.0)
+                && (this.haveMeasure || this.m == 0.0);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/PointComposedGeom.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/PointComposedGeom.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/PointComposedGeom.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,96 @@
+/*
+ * ComposedGeom.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PointComposedGeom.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+package org.postgis;
+
+import java.sql.SQLException;
+
+/**
+ * PointComposedGeom - base class for all composed geoms that contain only
+ * points.
+ * 
+ * @author markus.schaber at logix-tt.com
+ * 
+ */
+
+public abstract class PointComposedGeom extends ComposedGeom {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    protected PointComposedGeom(int type) {
+        super(type);
+    }
+
+    protected PointComposedGeom(int type, Point[] points) {
+        super(type, points);
+    }
+
+    public PointComposedGeom(int type, String value) throws SQLException {
+        this(type, value, false);
+    }
+
+    public PointComposedGeom(int type, String value, boolean haveM) throws SQLException {
+        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) {
+        subgeoms[0].innerWKT(sb);
+        for (int i = 1; i < subgeoms.length; i++) {
+            sb.append(',');
+            subgeoms[i].innerWKT(sb);
+        }
+    }
+
+    /**
+     * optimized version
+     */
+    public int numPoints() {
+        return subgeoms.length;
+    }
+
+    /**
+     * optimized version
+     */
+    public Point getPoint(int idx) {
+        if (idx >= 0 & idx < subgeoms.length) {
+            return (Point) subgeoms[idx];
+        } else {
+            return null;
+        }
+    }
+
+    /** Get the underlying Point array */
+    public Point[] getPoints() {
+        return (Point[]) subgeoms;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/Polygon.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/Polygon.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/Polygon.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,70 @@
+/*
+ * Polygon.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - geometry model
+ * 
+ * (C) 2004 Paul Ramsey, pramsey at refractions.net
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: Polygon.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+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(LinearRing[] rings) {
+        super(POLYGON, rings);
+    }
+
+    public Polygon(String value) throws SQLException {
+        this(value, false);
+    }
+
+    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() {
+        return subgeoms.length;
+    }
+
+    public LinearRing getRing(int idx) {
+        if (idx >= 0 & idx < subgeoms.length) {
+            return (LinearRing) subgeoms[idx];
+        } else {
+            return null;
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/Version.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/Version.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/Version.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,97 @@
+/*
+ * Version.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - current version identification
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: Version.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+/** Corresponds to the appropriate PostGIS that carried this source */
+public class Version {
+    /** We read our version information from this ressource... */
+    private static final String RESSOURCENAME = "org/postgis/version.properties";
+    
+    /** The major version */
+    public static final int MAJOR;
+
+    /** The minor version */
+    public static final int MINOR;
+
+    /**
+     * The micro version, usually a number including possibly textual suffixes
+     * like RC3.
+     */
+    public static final String MICRO;
+
+    static {
+        int major = -1;
+        int minor = -1;
+        String micro = "INVALID";
+        try {
+            ClassLoader loader = Version.class.getClassLoader();
+            URL ver = loader.getResource(RESSOURCENAME);
+            if (ver == null) {
+                throw new ExceptionInInitializerError(
+                        "Error initializing PostGIS JDBC version! Cause: Ressource "+RESSOURCENAME+" not found!");
+            }
+            BufferedReader rd = new BufferedReader(new InputStreamReader(ver.openStream()));
+
+            String line;
+            while ((line = rd.readLine()) != null) {
+                line = line.trim();
+                if (line.startsWith("JDBC_MAJOR_VERSION")) {
+                    major = Integer.parseInt(line.substring(19));
+                } else if (line.startsWith("JDBC_MINOR_VERSION")) {
+                    minor = Integer.parseInt(line.substring(19));
+                } else if (line.startsWith("JDBC_MICRO_VERSION")) {
+                    micro = line.substring(19);
+                } else {
+                    // ignore line
+                }
+            }
+            if (major == -1 || minor == -1 || micro.equals("INVALID")) {
+                throw new ExceptionInInitializerError("Error initializing PostGIS JDBC version! Cause: Ressource "+RESSOURCENAME+" incomplete!");
+            }
+        } catch (IOException e) {
+            throw new ExceptionInInitializerError("Error initializing PostGIS JDBC version! Cause: " + e.getMessage());
+        } finally {
+            MAJOR = major;
+            MINOR = minor;
+            MICRO = micro;
+        }
+    }
+
+    /** Full version for human reading - code should use the constants above */
+    public static final String FULL = "PostGIS JDBC V" + MAJOR + "." + MINOR + "." + MICRO;
+
+    public static void main(String[] args) {
+        System.out.println(FULL);
+    }
+
+    public static String getFullVersion() {
+        return FULL;
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryParser.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryParser.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryParser.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,233 @@
+/*
+ * BinaryParser.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Parser
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: BinaryParser.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+package org.postgis.binary;
+
+import org.postgis.Geometry;
+import org.postgis.GeometryCollection;
+import org.postgis.LineString;
+import org.postgis.LinearRing;
+import org.postgis.MultiLineString;
+import org.postgis.MultiPoint;
+import org.postgis.MultiPolygon;
+import org.postgis.Point;
+import org.postgis.Polygon;
+import org.postgis.binary.ByteGetter.BinaryByteGetter;
+import org.postgis.binary.ByteGetter.StringByteGetter;
+
+/**
+ * Parse binary representation of geometries.
+ * 
+ * It should be easy to add char[] and CharSequence ByteGetter instances,
+ * although the latter one is not compatible with older jdks.
+ * 
+ * I did not implement real unsigned 32-bit integers or emulate them with long,
+ * as both java Arrays and Strings currently can have only 2^31-1 elements
+ * (bytes), so we cannot even get or build Geometries with more than approx.
+ * 2^28 coordinates (8 bytes each).
+ * 
+ * @author Markus Schaber <markus.schaber at logix-tt.com>
+ *  
+ */
+public class BinaryParser {
+
+    /**
+     * Get the appropriate ValueGetter for my endianness
+     * 
+     * @param bytes The appropriate Byte Getter
+     * 
+     * @return the ValueGetter
+     */
+    public static ValueGetter valueGetterForEndian(ByteGetter bytes) {
+        if (bytes.get(0) == ValueGetter.XDR.NUMBER) { // XDR
+            return new ValueGetter.XDR(bytes);
+        } else if (bytes.get(0) == ValueGetter.NDR.NUMBER) {
+            return new ValueGetter.NDR(bytes);
+        } else {
+            throw new IllegalArgumentException("Unknown Endian type:" + bytes.get(0));
+        }
+    }
+
+    /**
+     * Parse a hex encoded geometry
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.)
+     */
+    public synchronized Geometry parse(String value) {
+        StringByteGetter bytes = new ByteGetter.StringByteGetter(value);
+        return parseGeometry(valueGetterForEndian(bytes));
+    }
+
+    /**
+     * Parse a binary encoded geometry.
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.)
+     */
+    public synchronized Geometry parse(byte[] value) {
+        BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value);
+        return parseGeometry(valueGetterForEndian(bytes));
+    }
+
+    /** Parse a geometry starting at offset. */
+    protected Geometry parseGeometry(ValueGetter data) {
+        byte endian = data.getByte(); // skip and test endian flag
+        if (endian != data.endian) {
+            throw new IllegalArgumentException("Endian inconsistency!");
+        }
+        int typeword = data.getInt();
+
+        int realtype = typeword & 0x1FFFFFFF; // cut off high flag bits
+
+        boolean haveZ = (typeword & 0x80000000) != 0;
+        boolean haveM = (typeword & 0x40000000) != 0;
+        boolean haveS = (typeword & 0x20000000) != 0;
+
+        int srid = -1;
+
+        if (haveS) {
+            srid = data.getInt();
+        }
+        Geometry result1;
+        switch (realtype) {
+        case Geometry.POINT :
+            result1 = parsePoint(data, haveZ, haveM);
+            break;
+        case Geometry.LINESTRING :
+            result1 = parseLineString(data, haveZ, haveM);
+            break;
+        case Geometry.POLYGON :
+            result1 = parsePolygon(data, haveZ, haveM);
+            break;
+        case Geometry.MULTIPOINT :
+            result1 = parseMultiPoint(data);
+            break;
+        case Geometry.MULTILINESTRING :
+            result1 = parseMultiLineString(data);
+            break;
+        case Geometry.MULTIPOLYGON :
+            result1 = parseMultiPolygon(data);
+            break;
+        case Geometry.GEOMETRYCOLLECTION :
+            result1 = parseCollection(data);
+            break;
+        default :
+            throw new IllegalArgumentException("Unknown Geometry Type: " + realtype);
+        }
+
+        Geometry result = result1;
+
+        if (haveS) {
+            result.setSrid(srid);
+        }
+        return result;
+    }
+
+    private Point parsePoint(ValueGetter data, boolean haveZ, boolean haveM) {
+        double X = data.getDouble();
+        double Y = data.getDouble();
+        Point result;
+        if (haveZ) {
+            double Z = data.getDouble();
+            result = new Point(X, Y, Z);
+        } else {
+            result = new Point(X, Y);
+        }
+
+        if (haveM) {
+            result.setM(data.getDouble());
+        }
+
+        return result;
+    }
+
+    /** Parse an Array of "full" Geometries */
+    private void parseGeometryArray(ValueGetter data, Geometry[] container) {
+        for (int i = 0; i < container.length; i++) {
+            container[i] = parseGeometry(data);
+        }
+    }
+
+    /**
+     * Parse an Array of "slim" Points (without endianness and type, part of
+     * LinearRing and Linestring, but not MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private Point[] parsePointArray(ValueGetter data, boolean haveZ, boolean haveM) {
+        int count = data.getInt();
+        Point[] result = new Point[count];
+        for (int i = 0; i < count; i++) {
+            result[i] = parsePoint(data, haveZ, haveM);
+        }
+        return result;
+    }
+
+    private MultiPoint parseMultiPoint(ValueGetter data) {
+        Point[] points = new Point[data.getInt()];
+        parseGeometryArray(data, points);
+        return new MultiPoint(points);
+    }
+
+    private LineString parseLineString(ValueGetter data, boolean haveZ, boolean haveM) {
+        Point[] points = parsePointArray(data, haveZ, haveM);
+        return new LineString(points);
+    }
+
+    private LinearRing parseLinearRing(ValueGetter data, boolean haveZ, boolean haveM) {
+        Point[] points = parsePointArray(data, haveZ, haveM);
+        return new LinearRing(points);
+    }
+
+    private Polygon parsePolygon(ValueGetter data, boolean haveZ, boolean haveM) {
+        int count = data.getInt();
+        LinearRing[] rings = new LinearRing[count];
+        for (int i = 0; i < count; i++) {
+            rings[i] = parseLinearRing(data, haveZ, haveM);
+        }
+        return new Polygon(rings);
+    }
+
+    private MultiLineString parseMultiLineString(ValueGetter data) {
+        int count = data.getInt();
+        LineString[] strings = new LineString[count];
+        parseGeometryArray(data, strings);
+        return new MultiLineString(strings);
+    }
+
+    private MultiPolygon parseMultiPolygon(ValueGetter data) {
+        int count = data.getInt();
+        Polygon[] polys = new Polygon[count];
+        parseGeometryArray(data, polys);
+        return new MultiPolygon(polys);
+    }
+
+    private GeometryCollection parseCollection(ValueGetter data) {
+        int count = data.getInt();
+        Geometry[] geoms = new Geometry[count];
+        parseGeometryArray(data, geoms);
+        return new GeometryCollection(geoms);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryWriter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryWriter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/binary/BinaryWriter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,364 @@
+/*
+ * BinaryWriter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Writer
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: BinaryWriter.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+package org.postgis.binary;
+
+import org.postgis.Geometry;
+import org.postgis.GeometryCollection;
+import org.postgis.LineString;
+import org.postgis.LinearRing;
+import org.postgis.MultiLineString;
+import org.postgis.MultiPoint;
+import org.postgis.MultiPolygon;
+import org.postgis.Point;
+import org.postgis.Polygon;
+
+/**
+ * Create binary representation of geometries. Currently, only text rep (hexed)
+ * implementation is tested.
+ * 
+ * It should be easy to add char[] and CharSequence ByteGetter instances,
+ * although the latter one is not compatible with older jdks.
+ * 
+ * I did not implement real unsigned 32-bit integers or emulate them with long,
+ * as both java Arrays and Strings currently can have only 2^31-1 elements
+ * (bytes), so we cannot even get or build Geometries with more than approx.
+ * 2^28 coordinates (8 bytes each).
+ * 
+ * @author markus.schaber at logi-track.com
+ * 
+ */
+public class BinaryWriter {
+
+    /**
+     * Get the appropriate ValueGetter for my endianness
+     * 
+     * @param bytes The appropriate Byte Getter
+     * 
+     * @return the ValueGetter
+     */
+    public static ValueSetter valueSetterForEndian(ByteSetter bytes, byte endian) {
+        if (endian == ValueSetter.XDR.NUMBER) { // XDR
+            return new ValueSetter.XDR(bytes);
+        } else if (endian == ValueSetter.NDR.NUMBER) {
+            return new ValueSetter.NDR(bytes);
+        } else {
+            throw new IllegalArgumentException("Unknown Endian type:" + endian);
+        }
+    }
+
+    /**
+     * Write a hex encoded geometry
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.) This is a
+     * TODO item.
+     * 
+     * The geometry you put in must be consistent, geom.checkConsistency() must
+     * return true. If not, the result may be invalid WKB.
+     * 
+     * @see Geometry#checkConsistency() the consistency checker
+     */
+    public synchronized String writeHexed(Geometry geom, byte REP) {
+        int length = estimateBytes(geom);
+        ByteSetter.StringByteSetter bytes = new ByteSetter.StringByteSetter(length);
+        writeGeometry(geom, valueSetterForEndian(bytes, REP));
+        return bytes.result();
+    }
+
+    public synchronized String writeHexed(Geometry geom) {
+        return writeHexed(geom, ValueSetter.NDR.NUMBER);
+    }
+
+    /**
+     * Write a binary encoded geometry.
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.) This is a
+     * TODO item.
+     * 
+     * The geometry you put in must be consistent, geom.checkConsistency() must
+     * return true. If not, the result may be invalid WKB.
+     * 
+     * @see Geometry#checkConsistency()
+     */
+    public synchronized byte[] writeBinary(Geometry geom, byte REP) {
+        int length = estimateBytes(geom);
+        ByteSetter.BinaryByteSetter bytes = new ByteSetter.BinaryByteSetter(length);
+        writeGeometry(geom, valueSetterForEndian(bytes, REP));
+        return bytes.result();
+    }
+
+    public synchronized byte[] writeBinary(Geometry geom) {
+        return writeBinary(geom, ValueSetter.NDR.NUMBER);
+    }
+
+    /** Parse a geometry starting at offset. */
+    protected void writeGeometry(Geometry geom, ValueSetter dest) {
+        // write endian flag
+        dest.setByte(dest.endian);
+
+        // write typeword
+        int typeword = geom.type;
+        if (geom.dimension == 3) {
+            typeword |= 0x80000000;
+        }
+        if (geom.haveMeasure) {
+            typeword |= 0x40000000;
+        }
+        if (geom.srid != -1) {
+            typeword |= 0x20000000;
+        }
+
+        dest.setInt(typeword);
+
+        if (geom.srid != -1) {
+            dest.setInt(geom.srid);
+        }
+
+        switch (geom.type) {
+        case Geometry.POINT :
+            writePoint((Point) geom, dest);
+            break;
+        case Geometry.LINESTRING :
+            writeLineString((LineString) geom, dest);
+            break;
+        case Geometry.POLYGON :
+            writePolygon((Polygon) geom, dest);
+            break;
+        case Geometry.MULTIPOINT :
+            writeMultiPoint((MultiPoint) geom, dest);
+            break;
+        case Geometry.MULTILINESTRING :
+            writeMultiLineString((MultiLineString) geom, dest);
+            break;
+        case Geometry.MULTIPOLYGON :
+            writeMultiPolygon((MultiPolygon) geom, dest);
+            break;
+        case Geometry.GEOMETRYCOLLECTION :
+            writeCollection((GeometryCollection) geom, dest);
+            break;
+        default :
+            throw new IllegalArgumentException("Unknown Geometry Type: " + geom.type);
+        }
+    }
+
+    /**
+     * Writes a "slim" Point (without endiannes, srid ant type, only the
+     * ordinates and measure. Used by writeGeometry as ell as writePointArray.
+     */
+    private void writePoint(Point geom, ValueSetter dest) {
+        dest.setDouble(geom.x);
+        dest.setDouble(geom.y);
+
+        if (geom.dimension == 3) {
+            dest.setDouble(geom.z);
+        }
+
+        if (geom.haveMeasure) {
+            dest.setDouble(geom.m);
+        }
+    }
+
+    /** Write an Array of "full" Geometries */
+    private void writeGeometryArray(Geometry[] container, ValueSetter dest) {
+        for (int i = 0; i < container.length; i++) {
+            writeGeometry(container[i], dest);
+        }
+    }
+
+    /**
+     * Write an Array of "slim" Points (without endianness, srid and type, part
+     * of LinearRing and Linestring, but not MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private void writePointArray(Point[] geom, ValueSetter dest) {
+        // number of points
+        dest.setInt(geom.length);
+        for (int i = 0; i < geom.length; i++) {
+            writePoint(geom[i], dest);
+        }
+    }
+
+    private void writeMultiPoint(MultiPoint geom, ValueSetter dest) {
+        dest.setInt(geom.numPoints());
+        writeGeometryArray(geom.getPoints(), dest);
+    }
+
+    private void writeLineString(LineString geom, ValueSetter dest) {
+        writePointArray(geom.getPoints(), dest);
+    }
+
+    private void writeLinearRing(LinearRing geom, ValueSetter dest) {
+        writePointArray(geom.getPoints(), dest);
+    }
+
+    private void writePolygon(Polygon geom, ValueSetter dest) {
+        dest.setInt(geom.numRings());
+        for (int i = 0; i < geom.numRings(); i++) {
+            writeLinearRing(geom.getRing(i), dest);
+        }
+    }
+
+    private void writeMultiLineString(MultiLineString geom, ValueSetter dest) {
+        dest.setInt(geom.numLines());
+        writeGeometryArray(geom.getLines(), dest);
+    }
+
+    private void writeMultiPolygon(MultiPolygon geom, ValueSetter dest) {
+        dest.setInt(geom.numPolygons());
+        writeGeometryArray(geom.getPolygons(), dest);
+    }
+
+    private void writeCollection(GeometryCollection geom, ValueSetter dest) {
+        dest.setInt(geom.numGeoms());
+        writeGeometryArray(geom.getGeometries(), dest);
+    }
+
+    /** Estimate how much bytes a geometry will need in WKB. */
+    protected int estimateBytes(Geometry geom) {
+        int result = 0;
+
+        // write endian flag
+        result += 1;
+
+        // write typeword
+        result += 4;
+
+        if (geom.srid != -1) {
+            result += 4;
+        }
+
+        switch (geom.type) {
+        case Geometry.POINT :
+            result += estimatePoint((Point) geom);
+            break;
+        case Geometry.LINESTRING :
+            result += estimateLineString((LineString) geom);
+            break;
+        case Geometry.POLYGON :
+            result += estimatePolygon((Polygon) geom);
+            break;
+        case Geometry.MULTIPOINT :
+            result += estimateMultiPoint((MultiPoint) geom);
+            break;
+        case Geometry.MULTILINESTRING :
+            result += estimateMultiLineString((MultiLineString) geom);
+            break;
+        case Geometry.MULTIPOLYGON :
+            result += estimateMultiPolygon((MultiPolygon) geom);
+            break;
+        case Geometry.GEOMETRYCOLLECTION :
+            result += estimateCollection((GeometryCollection) geom);
+            break;
+        default :
+            throw new IllegalArgumentException("Unknown Geometry Type: " + geom.type);
+        }
+        return result;
+    }
+
+    private int estimatePoint(Point geom) {
+        // x, y both have 8 bytes
+        int result = 16;
+        if (geom.dimension == 3) {
+            result += 8;
+        }
+
+        if (geom.haveMeasure) {
+            result += 8;
+        }
+        return result;
+    }
+
+    /** Write an Array of "full" Geometries */
+    private int estimateGeometryArray(Geometry[] container) {
+        int result = 0;
+        for (int i = 0; i < container.length; i++) {
+            result += estimateBytes(container[i]);
+        }
+        return result;
+    }
+
+    /**
+     * Write an Array of "slim" Points (without endianness and type, part of
+     * LinearRing and Linestring, but not MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private int estimatePointArray(Point[] geom) {
+        // number of points
+        int result = 4;
+
+        // And the amount of the points itsself, in consistent geometries
+        // all points have equal size.
+        if (geom.length > 0) {
+            result += geom.length * estimatePoint(geom[0]);
+        }
+        return result;
+    }
+
+    private int estimateMultiPoint(MultiPoint geom) {
+        // int size
+        int result = 4;
+        if (geom.numPoints() > 0) {
+            // We can shortcut here, as all subgeoms have the same fixed size
+            result += geom.numPoints() * estimateBytes(geom.getFirstPoint());
+        }
+        return result;
+    }
+
+    private int estimateLineString(LineString geom) {
+        return estimatePointArray(geom.getPoints());
+    }
+
+    private int estimateLinearRing(LinearRing geom) {
+        return estimatePointArray(geom.getPoints());
+    }
+
+    private int estimatePolygon(Polygon geom) {
+        // int length
+        int result = 4;
+        for (int i = 0; i < geom.numRings(); i++) {
+            result += estimateLinearRing(geom.getRing(i));
+        }
+        return result;
+    }
+
+    private int estimateMultiLineString(MultiLineString geom) {
+        // 4-byte count + subgeometries
+        return 4 + estimateGeometryArray(geom.getLines());
+    }
+
+    private int estimateMultiPolygon(MultiPolygon geom) {
+        // 4-byte count + subgeometries
+        return 4 + estimateGeometryArray(geom.getPolygons());
+    }
+
+    private int estimateCollection(GeometryCollection geom) {
+        // 4-byte count + subgeometries
+        return 4 + estimateGeometryArray(geom.getGeometries());
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteGetter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteGetter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteGetter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,74 @@
+/*
+ * ByteGetter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Parser
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: ByteGetter.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis.binary;
+
+public abstract class ByteGetter {
+    /**
+     * Get a byte.
+     * 
+     * @return The result is returned as Int to eliminate sign problems when
+     *         or'ing several values together.
+     */
+    public abstract int get(int index);
+
+    public static class BinaryByteGetter extends ByteGetter {
+        private byte[] array;
+
+        public BinaryByteGetter(byte[] array) {
+            this.array = array;
+        }
+
+        public int get(int index) {
+            return array[index] & 0xFF; // mask out sign-extended bits.
+        }
+    }
+
+    public static class StringByteGetter extends ByteGetter {
+        private String rep;
+
+        public StringByteGetter(String rep) {
+            this.rep = rep;
+        }
+
+        public int get(int index) {
+            index *= 2;
+            int high = unhex(rep.charAt(index));
+            int low = unhex(rep.charAt(index + 1));
+            return (high << 4) + low;
+        }
+
+        public static byte unhex(char c) {
+            if (c >= '0' && c <= '9') {
+                return (byte) (c - '0');
+            } else if (c >= 'A' && c <= 'F') {
+                return (byte) (c - 'A' + 10);
+            } else if (c >= 'a' && c <= 'f') {
+                return (byte) (c - 'a' + 10);
+            } else {
+                throw new IllegalArgumentException("No valid Hex char " + c);
+            }
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteSetter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteSetter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ByteSetter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,85 @@
+/*
+ * ByteGetter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Parser
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: ByteSetter.java 1729 2005-05-25 10:08:56Z mschaber $
+ */
+
+package org.postgis.binary;
+
+public abstract class ByteSetter {
+
+    /**
+     * Set a byte.
+     * 
+     */
+    public abstract void set(byte b, int index);
+
+    public static class BinaryByteSetter extends ByteSetter {
+        private byte[] array;
+
+        public BinaryByteSetter(int length) {
+            this.array = new byte[length];
+        }
+
+        public void set(byte b, int index) {
+            array[index] = b; // mask out sign-extended bits.
+        }
+
+        public byte[] result() {
+            return array;
+        }
+        
+        public String toString() {
+            char[] arr = new char[array.length];
+            for (int i=0; i<array.length; i++) {
+                arr[i] = (char)(array[i]&0xFF);
+            }
+            return new String(arr);
+        }
+    }
+
+    public static class StringByteSetter extends ByteSetter {
+        protected static final char[] hextypes = "0123456789ABCDEF".toCharArray();
+        private char[] rep;
+
+        public StringByteSetter(int length) {
+            this.rep = new char[length * 2];
+        }
+
+        public void set(byte b, int index) {
+            index *= 2;
+            rep[index] = hextypes[(b >>> 4) & 0xF];
+            rep[index + 1] = hextypes[b & 0xF];
+        }
+
+        public char[] resultAsArray() {
+            return rep;
+        }
+
+        public String result() {
+            return new String(rep);
+        }
+        
+        public String toString() {
+            return new String(rep);
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueGetter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueGetter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueGetter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,112 @@
+/*
+ * ValueGetter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Parser
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: ValueGetter.java 1622 2005-04-15 14:04:34Z mschaber $
+ */
+
+package org.postgis.binary;
+
+public abstract class ValueGetter {
+    ByteGetter data;
+    int position;
+    public final byte endian;
+
+    public ValueGetter(ByteGetter data, byte endian) {
+        this.data = data;
+        this.endian = endian;
+    }
+
+    /**
+     * Get a byte, should be equal for all endians
+     */
+    public byte getByte() {
+        return (byte) data.get(position++);
+    }
+
+    public int getInt() {
+        int res = getInt(position);
+        position += 4;
+        return res;
+    }
+
+    public long getLong() {
+        long res = getLong(position);
+        position += 8;
+        return res;
+    }
+
+    /** Get a 32-Bit integer */
+    protected abstract int getInt(int index);
+
+    /**
+     * Get a long value. This is not needed directly, but as a nice side-effect
+     * from GetDouble.
+     */
+    protected abstract long getLong(int index);
+
+    /**
+     * Get a double.
+     */
+    public double getDouble() {
+        long bitrep = getLong();
+        return Double.longBitsToDouble(bitrep);
+    }
+
+    public static class XDR extends ValueGetter {
+        public static final byte NUMBER = 0;
+
+        public XDR(ByteGetter data) {
+            super(data, NUMBER);
+        }
+
+        protected int getInt(int index) {
+            return (data.get(index) << 24) + (data.get(index + 1) << 16)
+                    + (data.get(index + 2) << 8) + data.get(index + 3);
+        }
+
+        protected long getLong(int index) {
+            return ((long) data.get(index) << 56) + ((long) data.get(index + 1) << 48)
+                    + ((long) data.get(index + 2) << 40) + ((long) data.get(index + 3) << 32)
+                    + ((long) data.get(index + 4) << 24) + ((long) data.get(index + 5) << 16)
+                    + ((long) data.get(index + 6) << 8) + ((long) data.get(index + 7) << 0);
+        }
+    }
+
+    public static class NDR extends ValueGetter {
+        public static final byte NUMBER = 1;
+
+        public NDR(ByteGetter data) {
+            super(data, NUMBER);
+        }
+
+        protected int getInt(int index) {
+            return (data.get(index + 3) << 24) + (data.get(index + 2) << 16)
+                    + (data.get(index + 1) << 8) + data.get(index);
+        }
+
+        protected long getLong(int index) {
+            return ((long) data.get(index + 7) << 56) + ((long) data.get(index + 6) << 48)
+                    + ((long) data.get(index + 5) << 40) + ((long) data.get(index + 4) << 32)
+                    + ((long) data.get(index + 3) << 24) + ((long) data.get(index + 2) << 16)
+                    + ((long) data.get(index + 1) << 8) + ((long) data.get(index) << 0);
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueSetter.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueSetter.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/binary/ValueSetter.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,130 @@
+/*
+ * ValueGetter.java
+ * 
+ * PostGIS extension for PostgreSQL JDBC driver - Binary Parser
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: ValueSetter.java 1774 2005-06-28 08:12:45Z mschaber $
+ */
+
+package org.postgis.binary;
+
+public abstract class ValueSetter {
+    ByteSetter data;
+    int position=0;
+    public final byte endian;
+
+    public ValueSetter(ByteSetter data, byte endian) {
+        this.data = data;
+        this.endian = endian;
+    }
+
+    /**
+     * Get a byte, should be equal for all endians
+     */
+    public void setByte(byte value) {
+        data.set(value, position);
+        position += 1;
+    }
+
+    public void setInt(int value) {
+        setInt(value, position);
+        position += 4;
+    }
+
+    public void setLong(long value) {
+        setLong(value, position);
+        position += 8;
+    }
+
+    /** Get a 32-Bit integer */
+    protected abstract void setInt(int value, int index);
+
+    /**
+     * Get a long value. This is not needed directly, but as a nice side-effect
+     * from GetDouble.
+     */
+    protected abstract void setLong(long data, int index);
+
+    /**
+     * Get a double.
+     */
+    public void setDouble(double data) {
+        long bitrep = Double.doubleToLongBits(data);
+        setLong(bitrep);
+    }
+
+    public String toString() {
+        String name = getClass().getName();
+        int pointpos = name.lastIndexOf('.');
+        String klsName = name.substring(pointpos+1);
+        return klsName+"('"+(data==null?"NULL":data.toString()+"')");
+    }
+    
+    public static class XDR extends ValueSetter {
+        public static final byte NUMBER = 0;
+
+        public XDR(ByteSetter data) {
+            super(data, NUMBER);
+        }
+
+        protected void setInt(int value, int index) {
+            data.set((byte) (value >>> 24), index);
+            data.set((byte) (value >>> 16), index + 1);
+            data.set((byte) (value >>> 8), index + 2);
+            data.set((byte) value, index + 3);
+        }
+
+        protected void setLong(long value, int index) {
+            data.set((byte) (value >>> 56), index);
+            data.set((byte) (value >>> 48), index + 1);
+            data.set((byte) (value >>> 40), index + 2);
+            data.set((byte) (value >>> 32), index + 3);
+            data.set((byte) (value >>> 24), index + 4);
+            data.set((byte) (value >>> 16), index + 5);
+            data.set((byte) (value >>> 8), index + 6);
+            data.set((byte) value, index + 7);
+        }
+    }
+
+    public static class NDR extends ValueSetter {
+        public static final byte NUMBER = 1;
+
+        public NDR(ByteSetter data) {
+            super(data, NUMBER);
+        }
+
+        protected void setInt(int value, int index) {
+            data.set((byte) (value >>> 24), index + 3);
+            data.set((byte) (value >>> 16), index + 2);
+            data.set((byte) (value >>> 8), index + 1);
+            data.set((byte) value, index);
+        }
+
+        protected void setLong(long value, int index) {
+            data.set((byte) (value >>> 56), index + 7);
+            data.set((byte) (value >>> 48), index + 6);
+            data.set((byte) (value >>> 40), index + 5);
+            data.set((byte) (value >>> 32), index + 4);
+            data.set((byte) (value >>> 24), index + 3);
+            data.set((byte) (value >>> 16), index + 2);
+            data.set((byte) (value >>> 8), index + 1);
+            data.set((byte) value, index);
+        }
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/Java2DWrapper.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/Java2DWrapper.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/Java2DWrapper.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,155 @@
+/*
+ * JtsWrapper.java
+ * 
+ * Allows transparent usage of JTS Geometry classes via PostgreSQL JDBC driver
+ * connected to a PostGIS enabled PostgreSQL server.
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: Java2DWrapper.java 1980 2005-10-20 18:07:37Z mschaber $
+ */
+
+package org.postgis.java2d;
+
+import org.postgresql.Driver;
+import org.postgresql.PGConnection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * Java2DWrapper
+ * 
+ * Wraps the PostGreSQL Driver to add transparent readonly support for PostGIS
+ * objects into java2d path objects.
+ * 
+ * This method currently works with J2EE DataSource implementations, and with
+ * DriverManager framework.
+ * 
+ * Simply replace the "jdbc:postgresql:" with a "jdbc:postgis_j2d" in the
+ * jdbc URL.
+ * 
+ * @author markus.schaber at logix-tt.com
+ * 
+ */
+public class Java2DWrapper extends Driver {
+
+    private static final String POSTGRES_PROTOCOL = "jdbc:postgresql:";
+    public static final String POSTGIS_PROTOCOL = "jdbc:postgis_j2d:";
+    public static final String REVISION = "$Revision: 1980 $";
+
+    public Java2DWrapper() {
+        super();
+    }
+
+    static {
+        try {
+            // Analogy to org.postgresql.Driver
+            java.sql.DriverManager.registerDriver(new Java2DWrapper());
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Creates a postgresql connection, and then adds the PostGIS data types to
+     * it calling addpgtypes()
+     * 
+     * @param url the URL of the database to connect to
+     * @param info a list of arbitrary tag/value pairs as connection arguments
+     * @return a connection to the URL or null if it isnt us
+     * @exception SQLException if a database access error occurs
+     * 
+     * @see java.sql.Driver#connect
+     * @see org.postgresql.Driver
+     */
+    public java.sql.Connection connect(String url, Properties info) throws SQLException {
+        url = mangleURL(url);
+        Connection result = super.connect(url, info);
+        addGISTypes((PGConnection) result);
+        return result;
+    }
+
+    /**
+     * adds the JTS/PostGIS Data types to a PG Connection.
+     * @throws SQLException 
+     */
+    public static void addGISTypes(PGConnection pgconn) throws SQLException {
+        pgconn.addDataType("geometry", PGShapeGeometry.class);
+        pgconn.addDataType("box3d", org.postgis.PGbox3d.class);
+        pgconn.addDataType("box2d", org.postgis.PGbox2d.class);
+    }
+
+    /**
+     * Mangles the PostGIS URL to return the original PostGreSQL URL
+     */
+    public static String mangleURL(String url) throws SQLException {
+        if (url.startsWith(POSTGIS_PROTOCOL)) {
+            return POSTGRES_PROTOCOL + url.substring(POSTGIS_PROTOCOL.length());
+        } else {
+            throw new SQLException("Unknown protocol or subprotocol in url " + url);
+        }
+    }
+
+    /**
+     * Returns true if the driver thinks it can open a connection to the given
+     * URL. Typically, drivers will return true if they understand the
+     * subprotocol specified in the URL and false if they don't. Our protocols
+     * start with jdbc:postgresql_postGIS:
+     * 
+     * @see java.sql.Driver#acceptsURL
+     * @param url the URL of the driver
+     * @return true if this driver accepts the given URL
+     * @exception SQLException if a database-access error occurs (Dont know why
+     *                it would *shrug*)
+     */
+    public boolean acceptsURL(String url) throws SQLException {
+        try {
+            url = mangleURL(url);
+        } catch (SQLException e) {
+            return false;
+        }
+        return super.acceptsURL(url);
+    }
+
+    /**
+     * Gets the underlying drivers major version number
+     * 
+     * @return the drivers major version number
+     */
+
+    public int getMajorVersion() {
+        return super.getMajorVersion();
+    }
+
+    /**
+     * Get the underlying drivers minor version number
+     * 
+     * @return the drivers minor version number
+     */
+    public int getMinorVersion() {
+        return super.getMinorVersion();
+    }
+
+    /**
+     * Returns our own CVS version plus postgres Version
+     */
+    public static String getVersion() {
+        return "Java2DWrapper " + REVISION + ", wrapping " + Driver.getVersion();
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/PGShapeGeometry.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/PGShapeGeometry.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/PGShapeGeometry.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,166 @@
+/*
+ * PGShapeGeometry.java
+ * 
+ * Allows PostGIS data to be read directly into a java2d shape
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: PGShapeGeometry.java 2077 2005-11-25 17:22:34Z mschaber $
+ */
+
+package org.postgis.java2d;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.geom.*;
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+/**
+ * PostGIS Java2D geometry implementation (read-only).
+ * 
+ * Supports PostGIS 1.x (lwgeom hexwkb).
+ * 
+ * As the java.awt.Shape methods currently are implemented by using a
+ * java.awt.geom.GeneralPath object, they have the same semantics.
+ * 
+ * BUG/TODO: MultiPoints or Points in a Geometry Collection currently don't work
+ * as expected, as some GeneralPath implementations throw away adjacent MoveTo
+ * commands as an optimization (e. G. sun 1.5 and ibm 1.5). Points thus are
+ * translated into MoveTo() followed by a closePath. This may change when we
+ * implement our own path logics. We have to evaluate whether Graphics2D renders
+ * a single MoveTo command as a single "brush tip", or we need the closePath()
+ * command nevertheless to get any drawing. Maybe we need a LineTo() to the same
+ * coordinages instead.
+ * 
+ * (Multi)LineStrings are translated into a sequence of a single MoveTo and
+ * multiple LineTo vertices, and Polygon rings into a sequence of a single
+ * MoveTo, multiple LineTo and a closePath command. To allow correct Polygon
+ * filling, our PathIterators have GeneralPath.WIND_EVEN_ODD as winding rule.
+ * 
+ * @see java.awt.geom.GeneralPath
+ * @see java.awt.Shape
+ * @see org.postgresql.util.PGobject
+ * 
+ * @author Markus Schaber
+ */
+
+public class PGShapeGeometry extends PGobject implements Shape {
+    /* JDK 1.5 Serialization */
+    private static final long serialVersionUID = 0x100;
+
+    final static ShapeBinaryParser parser = new ShapeBinaryParser();
+
+    private final GeneralPath path;
+
+    private int srid;
+
+    /**
+     * Constructor called by JDBC drivers. call setValue afterwards to fill with
+     * Geometry data.
+     * 
+     */
+    public PGShapeGeometry() {
+        setType("geometry");
+        path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
+    }
+
+    /** Construct directly from a General Path */
+    public PGShapeGeometry(GeneralPath path, int srid) {
+        setType("geometry");
+        this.path = path;
+        this.srid = srid;
+    }
+
+    /** Reads the HexWKB representation */
+    public PGShapeGeometry(String value) throws SQLException {
+        this();
+        setValue(value);
+    }
+
+    /**
+     * Reads the HexWKB representation - to be called by the jdbc drivers. Be
+     * shure to call this only once and if you used the PGShapeGeometry()
+     * constructor without parameters. In all other cases, behaviour is
+     * undefined.
+     */
+    public void setValue(String value) throws SQLException {
+        srid = parser.parse(value, path);
+    }
+
+    public String toString() {
+        return "PGShapeGeometry " + path.toString();
+    }
+
+    /** We currently have read-only support, so this method returns null */
+    public String getValue() {
+        return null;
+    }
+
+    public boolean equals(Object obj) {
+        if (obj instanceof PGShapeGeometry)
+            return ((PGShapeGeometry) obj).path.equals(path);
+        return false;
+    }
+
+    /** Return the SRID or -1 if none was available */
+    public int getSRID() {
+        return srid;
+    }
+
+    // following are the java2d Shape method implementations...
+    public boolean contains(double x, double y) {
+        return path.contains(x, y);
+    }
+
+    public boolean contains(double x, double y, double w, double h) {
+        return path.contains(x, y, w, h);
+    }
+
+    public boolean intersects(double x, double y, double w, double h) {
+        return path.intersects(x, y, w, h);
+    }
+
+    public Rectangle getBounds() {
+        return path.getBounds();
+    }
+
+    public boolean contains(Point2D p) {
+        return path.contains(p);
+    }
+
+    public Rectangle2D getBounds2D() {
+        return path.getBounds2D();
+    }
+
+    public boolean contains(Rectangle2D r) {
+        return path.contains(r);
+    }
+
+    public boolean intersects(Rectangle2D r) {
+        return path.intersects(r);
+    }
+
+    public PathIterator getPathIterator(AffineTransform at) {
+        return path.getPathIterator(at);
+    }
+
+    public PathIterator getPathIterator(AffineTransform at, double flatness) {
+        return path.getPathIterator(at, flatness);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/ShapeBinaryParser.java
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/ShapeBinaryParser.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgis/java2d/ShapeBinaryParser.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,224 @@
+/*
+ * JtsBinaryParser.java
+ * 
+ * Binary Parser for JTS - relies on org.postgis V1.0.0+ package.
+ * 
+ * (C) 2005 Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation, either version 2.1 of the License.
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
+ * http://www.gnu.org.
+ * 
+ * $Id: ShapeBinaryParser.java 2077 2005-11-25 17:22:34Z mschaber $
+ */
+package org.postgis.java2d;
+
+import java.awt.geom.GeneralPath;
+
+import org.postgis.binary.ByteGetter;
+import org.postgis.binary.ValueGetter;
+import org.postgis.binary.ByteGetter.BinaryByteGetter;
+import org.postgis.binary.ByteGetter.StringByteGetter;
+
+/**
+ * Parse binary representation of geometries. Currently, only text rep (hexed)
+ * implementation is tested.
+ * 
+ * It should be easy to add char[] and CharSequence ByteGetter instances,
+ * although the latter one is not compatible with older jdks.
+ * 
+ * I did not implement real unsigned 32-bit integers or emulate them with long,
+ * as both java Arrays and Strings currently can have only 2^31-1 elements
+ * (bytes), so we cannot even get or build Geometries with more than approx.
+ * 2^28 coordinates (8 bytes each).
+ * 
+ * @author Markus Schaber, markus.schaber at logix-tt.com
+ * 
+ */
+public class ShapeBinaryParser {
+
+    /**
+     * Get the appropriate ValueGetter for my endianness
+     * 
+     * @param bytes The appropriate Byte Getter
+     * 
+     * @return the ValueGetter
+     */
+    public static ValueGetter valueGetterForEndian(ByteGetter bytes) {
+        if (bytes.get(0) == ValueGetter.XDR.NUMBER) { // XDR
+            return new ValueGetter.XDR(bytes);
+        } else if (bytes.get(0) == ValueGetter.NDR.NUMBER) {
+            return new ValueGetter.NDR(bytes);
+        } else {
+            throw new IllegalArgumentException("Unknown Endian type:" + bytes.get(0));
+        }
+    }
+
+    /**
+     * Parse a hex encoded geometry
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.)
+     * 
+     * @returns a potential SRID or -1 if not present
+     */
+    public synchronized int parse(String value, GeneralPath path) {
+        StringByteGetter bytes = new ByteGetter.StringByteGetter(value);
+        return parseGeometry(valueGetterForEndian(bytes), path);
+    }
+
+    /**
+     * Parse a binary encoded geometry.
+     * 
+     * Is synchronized to protect offset counter. (Unfortunately, Java does not
+     * have neither call by reference nor multiple return values.)
+     * 
+     * @returns a potential SRID or -1 if not present
+     */
+    public synchronized int parse(byte[] value, GeneralPath path) {
+        BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value);
+        return parseGeometry(valueGetterForEndian(bytes), path);
+    }
+
+    /**
+     * Parse a geometry starting at offset.
+     * 
+     * @param path
+     */
+    protected int parseGeometry(ValueGetter data, GeneralPath path) {
+        byte endian = data.getByte(); // skip and test endian flag
+        if (endian != data.endian) {
+            throw new IllegalArgumentException("Endian inconsistency!");
+        }
+        int typeword = data.getInt();
+
+        int realtype = typeword & 0x1FFFFFFF; // cut off high flag bits
+
+        boolean haveZ = (typeword & 0x80000000) != 0;
+        boolean haveM = (typeword & 0x40000000) != 0;
+        boolean haveS = (typeword & 0x20000000) != 0;
+
+        int srid = -1;
+
+        if (haveS) {
+            srid = data.getInt();
+        }
+
+        switch (realtype) {
+            case org.postgis.Geometry.POINT :
+                parsePoint(data, haveZ, haveM, path);
+                break;
+            case org.postgis.Geometry.LINESTRING :
+                parseLineString(data, haveZ, haveM, path);
+                break;
+            case org.postgis.Geometry.POLYGON :
+                parsePolygon(data, haveZ, haveM, path);
+                break;
+            case org.postgis.Geometry.MULTIPOINT :
+                parseMultiPoint(data, path);
+                break;
+            case org.postgis.Geometry.MULTILINESTRING :
+                parseMultiLineString(data, path);
+                break;
+            case org.postgis.Geometry.MULTIPOLYGON :
+                parseMultiPolygon(data, path);
+                break;
+            case org.postgis.Geometry.GEOMETRYCOLLECTION :
+                parseCollection(data, path);
+                break;
+            default :
+                throw new IllegalArgumentException("Unknown Geometry Type!");
+        }
+        return srid;
+    }
+
+    private void parsePoint(ValueGetter data, boolean haveZ, boolean haveM, GeneralPath path) {
+        path.moveTo((float) data.getDouble(), (float) data.getDouble());
+        path.closePath();
+        skipZM(data, haveZ, haveM);
+    }
+
+    private void skipZM(ValueGetter data, boolean haveZ, boolean haveM) {
+        if (haveZ) { // skip Z value
+            data.getDouble();
+        }
+        if (haveM) { // skip M value
+            data.getDouble();
+        }
+    }
+
+    /** Parse an Array of "full" Geometries */
+    private void parseGeometryArray(ValueGetter data, int count, GeneralPath path) {
+        for (int i = 0; i < count; i++) {
+            parseGeometry(data, path);
+        }
+    }
+
+    /**
+     * Parse an Array of "slim" Points (without endianness and type, part of
+     * LinearRing and Linestring, but not MultiPoint!
+     * 
+     * @param haveZ
+     * @param haveM
+     */
+    private void parseCS(ValueGetter data, boolean haveZ, boolean haveM, GeneralPath path) {
+        int count = data.getInt();
+        if (count > 0) {
+            path.moveTo((float) data.getDouble(), (float) data.getDouble());
+            skipZM(data, haveZ, haveM);
+            for (int i = 1; i < count; i++) {
+                path.lineTo((float) data.getDouble(), (float) data.getDouble());
+                skipZM(data, haveZ, haveM);
+            }
+        }
+    }
+
+
+    private void parseMultiPoint(ValueGetter data, GeneralPath path) {
+        parseGeometryArray(data, data.getInt(), path);
+    }
+
+    private void parseLineString(ValueGetter data, boolean haveZ, boolean haveM, GeneralPath path) {
+        parseCS(data, haveZ, haveM, path);
+    }
+
+    private void parseLinearRing(ValueGetter data, boolean haveZ, boolean haveM, GeneralPath path) {
+        parseCS(data, haveZ, haveM, path);
+        path.closePath();
+    }
+
+    private void parsePolygon(ValueGetter data, boolean haveZ, boolean haveM, GeneralPath path) {
+        int holecount = data.getInt() - 1;
+        // parse shell
+        parseLinearRing(data, haveZ, haveM, path);
+        // parse inner rings
+        for (int i = 0; i < holecount; i++) {
+            parseLinearRing(data, haveZ, haveM, path);
+        }
+    }
+
+    private void parseMultiLineString(ValueGetter data, GeneralPath path) {
+        int count = data.getInt();
+        parseGeometryArray(data, count, path);
+    }
+
+    private void parseMultiPolygon(ValueGetter data, GeneralPath path) {
+        int count = data.getInt();
+        parseGeometryArray(data, count, path);
+    }
+
+    private void parseCollection(ValueGetter data, GeneralPath path) {
+        int count = data.getInt();
+        parseGeometryArray(data, count, path);
+    }
+}

Added: packages/postgis/upstream/java/jdbc/src/org/postgresql/driverconfig.properties
===================================================================
--- packages/postgis/upstream/java/jdbc/src/org/postgresql/driverconfig.properties	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/src/org/postgresql/driverconfig.properties	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,8 @@
+#
+# This property file is included in the postgis jar and autoregisters the
+# PostGIS datatypes within the jdbc driver.
+#
+
+datatype.geometry=org.postgis.PGgeometry
+datatype.box3d=org.postgis.PGbox3d
+datatype.box2d=org.postgis.PGbox2d

Added: packages/postgis/upstream/java/jdbc/stubs/LICENSE
===================================================================
--- packages/postgis/upstream/java/jdbc/stubs/LICENSE	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/stubs/LICENSE	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,26 @@
+Copyright (c) 1997-2005, PostgreSQL Global Development Group
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+3. Neither the name of the PostgreSQL Global Development Group nor the names
+   of its contributors may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.

Added: packages/postgis/upstream/java/jdbc/stubs/org/postgresql/Connection.java
===================================================================
--- packages/postgis/upstream/java/jdbc/stubs/org/postgresql/Connection.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/stubs/org/postgresql/Connection.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,20 @@
+/*-------------------------------------------------------------------------
+ * Derived from org.postgresql.PGConnection Source from jdbc8.0 as well as 
+ * the pgjdbc 7.2 binary jar which both are licensed under BSD license.
+ *
+ * Copyright (c) 2003-2005, PostgreSQL Global Development Group
+ * Copyright (c) 2005 Markus Schaber <markus.schaber at logix-tt.com>
+ *
+ * IDENTIFICATION
+ *   $PostgreSQL: pgjdbc/org/postgresql/PGConnection.java,v 1.13 2005/01/17 09:51:40 jurka Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+package org.postgresql;
+
+/**
+ * Stub to compile postgis jdbc against
+ */
+public abstract class Connection {
+    public abstract void addDataType(String type, String name);
+}

Added: packages/postgis/upstream/java/jdbc/stubs/org/postgresql/PGConnection.java
===================================================================
--- packages/postgis/upstream/java/jdbc/stubs/org/postgresql/PGConnection.java	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/stubs/org/postgresql/PGConnection.java	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,25 @@
+/*-------------------------------------------------------------------------
+ * Derived from org.postgresql.PGConnection from jdbc8.0 which is licensed
+ * under BSD license.
+ *
+ * Copyright (c) 2003-2005, PostgreSQL Global Development Group
+ * Copyright (c) 2005 Markus Schaber <markus.schaber at logix-tt.com>
+ *
+ * IDENTIFICATION
+ *   $PostgreSQL: pgjdbc/org/postgresql/PGConnection.java,v 1.13 2005/01/17 09:51:40 jurka Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+package org.postgresql;
+
+import java.sql.SQLException;
+
+/**
+ * Stub to compile postgis jdbc against
+ */
+public interface PGConnection {
+    public void addDataType(String type, String name);
+
+    public void addDataType(String type, Class klass) throws SQLException;
+}
+

Added: packages/postgis/upstream/java/jdbc/todo.txt
===================================================================
--- packages/postgis/upstream/java/jdbc/todo.txt	                        (rev 0)
+++ packages/postgis/upstream/java/jdbc/todo.txt	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,22 @@
+Todo for PostGIS 1.0 compatible JDBC classes
+$Id: todo.txt 1622 2005-04-15 14:04:34Z mschaber $
+
+- even more Testing, especialy against different postgis, 
+  pgjdbc and postgresql releases.
+
+- Handling of length() - esp. with modifying the geometries
+
+- Handling of hashCode() - esp. with modifying the geometries
+
+- Test correctness of toString() and getValue() for compatibility reasons
+
+- See where the code can be cleaned and leaned.
+
+- Finish JTS support
+
+- Creating a sane extension interface for pgjdbc that allows binary
+  transfers and convince upstream to use it, then create support for it.
+
+- Possibly adding server side code to support plJava
+  http://gborg.postgresql.org/project/pljava/projdisplay.php
+

Deleted: packages/postgis/upstream/loader/.cvsignore
===================================================================
--- packages/postgis/upstream/loader/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/loader/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,2 +0,0 @@
-pgsql2shp
-shp2pgsql

Modified: packages/postgis/upstream/loader/dbfopen.c
===================================================================
--- packages/postgis/upstream/loader/dbfopen.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/loader/dbfopen.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id: dbfopen.c,v 1.8 2006/01/16 10:42:57 strk Exp $
+ * $Id: dbfopen.c 2472 2006-09-09 16:32:57Z pramsey $
  *
  * Project:  Shapelib
  * Purpose:  Implementation of .dbf access API documented in dbf_api.html.
@@ -33,7 +33,7 @@
  * DEALINGS IN THE SOFTWARE.
  ******************************************************************************
  *
- * $Log: dbfopen.c,v $
+ * $Log$
  * Revision 1.8  2006/01/16 10:42:57  strk
  * Added support for Bool and Date DBF<=>PGIS mapping
  *
@@ -204,7 +204,7 @@
  */
 
 static char rcsid[] = 
-  "$Id: dbfopen.c,v 1.8 2006/01/16 10:42:57 strk Exp $";
+  "$Id: dbfopen.c 2472 2006-09-09 16:32:57Z pramsey $";
 
 #include "shapefil.h"
 
@@ -919,7 +919,7 @@
 
       case 'D':
         /* NULL date fields have value "00000000" */
-        return strncmp(pszValue,"00000000",8) == 0;
+        return (strncmp(pszValue,"00000000",8) == 0 || strlen(pszValue) == 0);
 
       case 'L':
         /* NULL boolean fields have value "?" */ 

Modified: packages/postgis/upstream/loader/pgsql2shp.c
===================================================================
--- packages/postgis/upstream/loader/pgsql2shp.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/loader/pgsql2shp.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: pgsql2shp.c,v 1.85 2006/06/16 14:12:16 strk Exp $
+ * $Id: pgsql2shp.c 2486 2006-09-27 08:24:08Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -19,7 +19,7 @@
  **********************************************************************/
 
 static char rcsid[] =
-  "$Id: pgsql2shp.c,v 1.85 2006/06/16 14:12:16 strk Exp $";
+  "$Id: pgsql2shp.c 2486 2006-09-27 08:24:08Z strk $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,6 +34,8 @@
 #include "shapefil.h"
 #include "getopt.h"
 #include "compat.h"
+#include <sys/types.h> // for getpid()
+#include <unistd.h> // for getpid()
 
 #ifdef __CYGWIN__
 #include <sys/param.h>       
@@ -52,6 +54,7 @@
  * Verbosity:
  *   set to 1 to see record fetching progress
  *   set to 2 to see also shapefile creation progress
+ *   set to 3 for debugging
  */
 #define VERBOSE 1
 
@@ -69,6 +72,7 @@
 /* Global data */
 PGconn *conn;
 int rowbuflen;
+char temptablename[256];
 char *geo_col_name, *table, *shp_file, *schema, *usrquery;
 int type_ary[256];
 char *main_scan_query;
@@ -2505,7 +2509,6 @@
 		return 0;
 	}
 
-
 	/* Get geometry oid */
 	geo_oid = getGeometryOID(conn);
 	if ( geo_oid == -1 )
@@ -3240,7 +3243,15 @@
 	if ( strstr(spec, "SELECT ") || strstr(spec, "select ") )
 	{
 		usrquery = spec;
-		table = "__pgsql2shp_tmp_table";
+
+		/*
+		 * encode pid in table name to reduce 
+		 * clashes probability (see bug#115)
+		 */
+		sprintf(temptablename,
+			"__pgsql2shp%lu_tmp_table",
+			(long)getpid());
+		table = temptablename; 
 	}
 	else
 	{
@@ -3341,7 +3352,7 @@
 }
 
 /**********************************************************************
- * $Log: pgsql2shp.c,v $
+ * $Log$
  * Revision 1.85  2006/06/16 14:12:16  strk
  *         - BUGFIX in pgsql2shp successful return code.
  *         - BUGFIX in shp2pgsql handling of MultiLine WKT.

Modified: packages/postgis/upstream/loader/shapefil.h
===================================================================
--- packages/postgis/upstream/loader/shapefil.h	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/loader/shapefil.h	2006-10-06 08:43:11 UTC (rev 561)
@@ -2,7 +2,7 @@
 #define _SHAPEFILE_H_INCLUDED
 
 /******************************************************************************
- * $Id: shapefil.h,v 1.5 2006/01/16 10:42:58 strk Exp $
+ * $Id: shapefil.h 2280 2006-01-16 10:42:58Z strk $
  *
  * Project:  Shapelib
  * Purpose:  Primary include file for Shapelib.
@@ -36,7 +36,7 @@
  * DEALINGS IN THE SOFTWARE.
  ******************************************************************************
  *
- * $Log: shapefil.h,v $
+ * $Log$
  * Revision 1.5  2006/01/16 10:42:58  strk
  * Added support for Bool and Date DBF<=>PGIS mapping
  *

Modified: packages/postgis/upstream/loader/shp2pgsql.c
===================================================================
--- packages/postgis/upstream/loader/shp2pgsql.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/loader/shp2pgsql.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: shp2pgsql.c,v 1.108 2006/06/16 14:12:17 strk Exp $
+ * $Id: shp2pgsql.c 2383 2006-06-16 14:12:17Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -137,7 +137,7 @@
 static void print_wkb_double(double val);
 
 static char rcsid[] =
-  "$Id: shp2pgsql.c,v 1.108 2006/06/16 14:12:17 strk Exp $";
+  "$Id: shp2pgsql.c 2383 2006-06-16 14:12:17Z strk $";
 
 void *safe_malloc(size_t size)
 {
@@ -1697,7 +1697,7 @@
 #endif /* defined USE_ICONV */
 
 /**********************************************************************
- * $Log: shp2pgsql.c,v $
+ * $Log$
  * Revision 1.108  2006/06/16 14:12:17  strk
  *         - BUGFIX in pgsql2shp successful return code.
  *         - BUGFIX in shp2pgsql handling of MultiLine WKT.

Modified: packages/postgis/upstream/loader/shpopen.c
===================================================================
--- packages/postgis/upstream/loader/shpopen.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/loader/shpopen.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id: shpopen.c,v 1.5 2003/12/01 20:52:00 strk Exp $
+ * $Id: shpopen.c 398 2003-12-01 20:52:00Z strk $
  *
  * Project:  Shapelib
  * Purpose:  Implementation of core Shapefile read/write functions.
@@ -33,7 +33,7 @@
  * DEALINGS IN THE SOFTWARE.
  ******************************************************************************
  *
- * $Log: shpopen.c,v $
+ * $Log$
  * Revision 1.5  2003/12/01 20:52:00  strk
  * shapelib put in sync with gdal cvs
  *
@@ -174,7 +174,7 @@
  */
 
 static char rcsid[] = 
-  "$Id: shpopen.c,v 1.5 2003/12/01 20:52:00 strk Exp $";
+  "$Id: shpopen.c 398 2003-12-01 20:52:00Z strk $";
 
 #include "shapefil.h"
 

Deleted: packages/postgis/upstream/lwgeom/.cvsignore
===================================================================
--- packages/postgis/upstream/lwgeom/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +0,0 @@
-liblwgeom.so*
-lwgeom.sql
-y.output
-lwpostgis.sql
-postgis_geos_version.h

Modified: packages/postgis/upstream/lwgeom/lex.yy.c
===================================================================
--- packages/postgis/upstream/lwgeom/lex.yy.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lex.yy.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -20,7 +20,7 @@
 /* A lexical scanner generated by flex */
 
 /* Scanner skeleton version:
- * $Header: /home/cvs/postgis/postgis/lwgeom/lex.yy.c,v 1.7 2006/05/04 15:19:50 strk Exp $
+ * $Header$
  */
 
 #define FLEX_SCANNER

Modified: packages/postgis/upstream/lwgeom/long_xact.sql
===================================================================
--- packages/postgis/upstream/lwgeom/long_xact.sql	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/long_xact.sql	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- 
--- $Id: long_xact.sql,v 1.1 2006/06/25 23:59:32 strk Exp $
+-- $Id: long_xact.sql 2406 2006-07-07 13:56:52Z strk $
 --
 -- PostGIS - Spatial Types for PostgreSQL
 -- http://postgis.refractions.net
@@ -286,7 +286,7 @@
 			''n.nspname as schema, '' ||
 #endif
 			''c.relname as table, trim('' ||
-			quote_literal(''\\\\000'') ||
+			quote_literal(chr(92) || ''000'') ||
 			'' from t.tgargs) as id_column '' ||
 			''FROM pg_trigger t, pg_class c, pg_proc p '' ||
 #ifdef HAS_SCHEMAS

Modified: packages/postgis/upstream/lwgeom/lwcollection.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwcollection.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwcollection.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwcollection.c,v 1.32 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwcollection.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwgeom.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom.c,v 1.33 2006/05/30 08:47:00 strk Exp $
+ * $Id: lwgeom.c 2370 2006-05-30 08:47:00Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwgeom_box2dfloat4.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_box2dfloat4.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_box2dfloat4.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,520 +1,523 @@
-#include <math.h>
-#include <float.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "postgres.h"
-#include "access/gist.h"
-#include "access/itup.h"
-#include "fmgr.h"
-#include "utils/elog.h"
-#include "utils/geo_decls.h"
-
-#include "lwgeom_pg.h"
-#include "liblwgeom.h"
-#include "stringBuffer.h"
-
-
-/* #define PGIS_DEBUG */
-
-/* forward defs */
-Datum BOX2DFLOAT4_in(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_out(PG_FUNCTION_ARGS);
-Datum LWGEOM_to_BOX2DFLOAT4(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_expand(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_to_BOX3D(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_combine(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_to_LWGEOM(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_construct(PG_FUNCTION_ARGS);
-
-/* parser - "BOX(xmin ymin,xmax ymax)" */
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_in);
-Datum BOX2DFLOAT4_in(PG_FUNCTION_ARGS)
-{
-	char *str = PG_GETARG_CSTRING(0);
-	int nitems;
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
-
-
-
-/*printf( "box3d_in gets '%s'\n",str); */
-
-	if (strstr(str,"BOX(") !=  str )
-	{
-		 pfree(box);
-		 elog(ERROR,"BOX2DFLOAT4 parser - doesnt start with BOX(");
-		 PG_RETURN_NULL();
-	}
-	nitems = sscanf(str,"BOX(%f %f,%f %f)", &box->xmin,&box->ymin,&box->xmax,&box->ymax);
-	if (nitems != 4)
-	{
-		 pfree(box);
-		 elog(ERROR,"BOX2DFLOAT4 parser - couldnt parse.  It should look like: BOX(xmin ymin,xmax ymax)");
-		 PG_RETURN_NULL();
-	}
-
-	if (box->xmin > box->xmax)
-	{
-		float tmp = box->xmin;
-		box->xmin = box->xmax;
-		box->xmax = tmp;
-	}
-	if (box->ymin > box->ymax)
-	{
-		float tmp = box->ymin;
-		box->ymin = box->ymax;
-		box->ymax = tmp;
-	}
-	PG_RETURN_POINTER(box);
-}
-
-/*writer  "BOX(xmin ymin,xmax ymax)" */
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_out);
-Datum BOX2DFLOAT4_out(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	char tmp[500]; /* big enough */
-	char *result;
-	int size;
-
-	size  = sprintf(tmp,"BOX(%.15g %.15g,%.15g %.15g)",
-		box->xmin, box->ymin, box->xmax, box->ymax);
-
-	result= palloc(size+1); /* +1= null term */
-
-	memcpy(result,tmp,size+1);
-	PG_RETURN_CSTRING(result);
-}
-
-
-/*convert a PG_LWGEOM to BOX2D */
-PG_FUNCTION_INFO_V1(LWGEOM_to_BOX2DFLOAT4);
-Datum LWGEOM_to_BOX2DFLOAT4(PG_FUNCTION_ARGS)
-{
-	PG_LWGEOM *lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-	BOX2DFLOAT4 *result;
-
-	result = palloc(sizeof(BOX2DFLOAT4));
-	if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), result) )
-	{
-		PG_RETURN_NULL(); /* must be the empty geometry */
-	}
-
-	PG_RETURN_POINTER(result);
-}
-
-/*----------------------------------------------------------
- *	Relational operators for BOXes.
- *		<, >, <=, >=, and == are based on box area.
- *---------------------------------------------------------*/
-
-/*
- * box_same - are two boxes identical?
- */
-PG_FUNCTION_INFO_V1(BOX2D_same);
-Datum BOX2D_same(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPeq(box1->xmax, box2->xmax) &&
-				   FPeq(box1->xmin, box2->xmin) &&
-				   FPeq(box1->ymax, box2->ymax) &&
-				   FPeq(box1->ymin, box2->ymin));
-}
-
-/*
- * box_overlap - does box1 overlap box2?
- */
-PG_FUNCTION_INFO_V1(BOX2D_overlap);
-Datum BOX2D_overlap(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-	bool       result;
-
-
-	result = ((FPge(box1->xmax, box2->xmax) &&
-			 FPle(box1->xmin, box2->xmax)) ||
-			(FPge(box2->xmax, box1->xmax) &&
-			 FPle(box2->xmin, box1->xmax)))
-		&&
-		((FPge(box1->ymax, box2->ymax) &&
-		  FPle(box1->ymin, box2->ymax)) ||
-		 (FPge(box2->ymax, box1->ymax) &&
-		  FPle(box2->ymin, box1->ymax)));
-
-	PG_RETURN_BOOL(result);
-}
-
-
-/*
- * box_overleft - is the right edge of box1 to the left of
- *                the right edge of box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_overleft);
-Datum BOX2D_overleft(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4 *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPle(box1->xmax, box2->xmax));
-}
-
-/* 
- * box_left - is box1 strictly left of box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_left);
-Datum BOX2D_left(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPlt(box1->xmax, box2->xmin));
-}
-
-/*
- * box_right - is box1 strictly right of box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_right);
-Datum BOX2D_right(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPgt(box1->xmin, box2->xmax));
-}
-
-/* 
- * box_overright - is the left edge of box1 to the right of
- *                 the left edge of box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_overright);
-Datum BOX2D_overright(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPge(box1->xmin, box2->xmin));
-}
-
-/* 
- * box_overbelow - is the bottom edge of box1 below
- *                 the bottom edge of box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_overbelow);
-Datum BOX2D_overbelow(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPle(box1->ymin, box2->ymin));
-}
-
-/*
- * box_below - is box1 strictly below box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_below);
-Datum BOX2D_below(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPlt(box1->ymax, box2->ymin));
-}
-
-/*
- * box_above - is box1 strictly above box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_above);
-Datum BOX2D_above(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPgt(box1->ymin, box2->ymax));
-}
-
-/*
- * box_overabove - the top edge of box1 above
- *                 the top edge of box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_overabove);
-Datum BOX2D_overabove(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPge(box1->ymax, box2->ymax));
-}
-
-/*
- * box_contained - is box1 contained by box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_contained);
-Datum BOX2D_contained(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 =(BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPle(box1->xmax, box2->xmax) &&
-				   FPge(box1->xmin, box2->xmin) &&
-				   FPle(box1->ymax, box2->ymax) &&
-				   FPge(box1->ymin, box2->ymin));
-}
-
-/*
- * box_contain - does box1 contain box2?
- */
- PG_FUNCTION_INFO_V1(BOX2D_contain);
-Datum BOX2D_contain(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-
-	PG_RETURN_BOOL(FPge(box1->xmax, box2->xmax) &&
-				   FPle(box1->xmin, box2->xmin) &&
-				   FPge(box1->ymax, box2->ymax) &&
-				   FPle(box1->ymin, box2->ymin));
-
-}
-
-PG_FUNCTION_INFO_V1(BOX2D_intersects);
-Datum BOX2D_intersects(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *a = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4 *b = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
-	BOX2DFLOAT4 *n;
-
-
-	n = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
-
-	n->xmax = LWGEOM_Minf(a->xmax, b->xmax);
-	n->ymax = LWGEOM_Minf(a->ymax, b->ymax);
-	n->xmin = LWGEOM_Maxf(a->xmin, b->xmin);
-	n->ymin = LWGEOM_Maxf(a->ymin, b->ymin);
-
-
-	if (n->xmax < n->xmin || n->ymax < n->ymin)
-	{
-		pfree(n);
-		/* Indicate "no intersection" by returning NULL pointer */
-		n = NULL;
-	}
-
-	PG_RETURN_POINTER(n);
-}
-
-
-/*
- * union of two BOX2Ds
- */
-PG_FUNCTION_INFO_V1(BOX2D_union);
-Datum BOX2D_union(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *a = (BOX2DFLOAT4*) PG_GETARG_POINTER(0);
-	BOX2DFLOAT4 *b = (BOX2DFLOAT4*) PG_GETARG_POINTER(1);
-	BOX2DFLOAT4 *n;
-
-	n = (BOX2DFLOAT4 *) lwalloc(sizeof(BOX2DFLOAT4));
-	if ( ! box2d_union_p(a,b,n) ) PG_RETURN_NULL();
-	PG_RETURN_POINTER(n);
-}
-
-
-/*
- * min(a,b)
- */
-float LWGEOM_Minf(float a, float b)
-{
-	if (a<b)
-		return a;
-	return b;
-}
-
-/*
- * max(a,b)
- */
-float LWGEOM_Maxf(float a, float b)
-{
-	if (b>a) return b;
-	return a;
-}
-
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_expand);
-Datum BOX2DFLOAT4_expand(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	double d = PG_GETARG_FLOAT8(1);
-	BOX2DFLOAT4 *result = (BOX2DFLOAT4 *)palloc(sizeof(BOX2DFLOAT4));
-
-	memcpy(result, box, sizeof(BOX2DFLOAT4));
-	expand_box2d(result, d);
-
-	PG_RETURN_POINTER(result);
-}
-
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_to_BOX3D);
-Datum BOX2DFLOAT4_to_BOX3D(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	BOX3D *result = palloc(sizeof(BOX3D));
-
-	box2df_to_box3d_p(box, result);
-
-	PG_RETURN_POINTER(result);
-}
-
-
-#define KEEP_OBSOLETED_FUNX 1
-#if KEEP_OBSOLETED_FUNX
-Datum BOX2DFLOAT4_xmin(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_ymin(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_xmax(PG_FUNCTION_ARGS);
-Datum BOX2DFLOAT4_ymax(PG_FUNCTION_ARGS);
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_xmin);
-Datum BOX2DFLOAT4_xmin(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	PG_RETURN_FLOAT4(box->xmin);
-}
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_ymin);
-Datum BOX2DFLOAT4_ymin(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	PG_RETURN_FLOAT4(box->ymin);
-}
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_xmax);
-Datum BOX2DFLOAT4_xmax(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	PG_RETURN_FLOAT4(box->xmax);
-}
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_ymax);
-Datum BOX2DFLOAT4_ymax(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	PG_RETURN_FLOAT4(box->ymax);
-}
-#endif
-
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_combine);
-Datum BOX2DFLOAT4_combine(PG_FUNCTION_ARGS)
-{
-	Pointer box2d_ptr = PG_GETARG_POINTER(0);
-	Pointer geom_ptr = PG_GETARG_POINTER(1);
-	BOX2DFLOAT4 *a,*b;
-	PG_LWGEOM *lwgeom;
-	BOX2DFLOAT4 box, *result;
-
-	if  ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
-	{
-		PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
-	}
-
-	result = (BOX2DFLOAT4 *)palloc(sizeof(BOX2DFLOAT4));
-
-	if (box2d_ptr == NULL)
-	{
-		lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-		/* empty geom would make getbox2d_p return NULL */
-		if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), &box) ) PG_RETURN_NULL();
-		memcpy(result, &box, sizeof(BOX2DFLOAT4));
-		PG_RETURN_POINTER(result);
-	}
-
-	/* combine_bbox(BOX3D, null) => BOX3D */
-	if (geom_ptr == NULL)
-	{
-		memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX2DFLOAT4));
-		PG_RETURN_POINTER(result);
-	}
-
-	/*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
-
-	lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-	if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), &box) )
-	{
-		/* must be the empty geom */
-		memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX2DFLOAT4));
-		PG_RETURN_POINTER(result);
-	}
-
-	a = (BOX2DFLOAT4 *)PG_GETARG_DATUM(0);
-	b = &box;
-
-	result->xmax = LWGEOM_Maxf(a->xmax, b->xmax);
-	result->ymax = LWGEOM_Maxf(a->ymax, b->ymax);
-	result->xmin = LWGEOM_Minf(a->xmin, b->xmin);
-	result->ymin = LWGEOM_Minf(a->ymin, b->ymin);
-
-	PG_RETURN_POINTER(result);
-}
-
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_to_LWGEOM);
-Datum BOX2DFLOAT4_to_LWGEOM(PG_FUNCTION_ARGS)
-{
-	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
-	POINT2D *pts = palloc(sizeof(POINT2D)*5);
-	POINTARRAY *pa[1];
-	LWPOLY *poly;
-	int wantbbox = 0;
-	PG_LWGEOM *result;
-	uchar *ser;
-
-	/* Assign coordinates to POINT2D array */
-	pts[0].x = box->xmin; pts[0].y = box->ymin;
-	pts[1].x = box->xmin; pts[1].y = box->ymax;
-	pts[2].x = box->xmax; pts[2].y = box->ymax;
-	pts[3].x = box->xmax; pts[3].y = box->ymin;
-	pts[4].x = box->xmin; pts[4].y = box->ymin;
-
-	/* Construct point array */
-	pa[0] = palloc(sizeof(POINTARRAY));
-	pa[0]->serialized_pointlist = (uchar *)pts;
-	TYPE_SETZM(pa[0]->dims, 0, 0);
-	pa[0]->npoints = 5;
-
-	/* Construct polygon */
-	poly = lwpoly_construct(-1, NULL, 1, pa);
-
-	/* Serialize polygon */
-	ser = lwpoly_serialize(poly);
-
-	/* Construct PG_LWGEOM  */
-	result = PG_LWGEOM_construct(ser, -1, wantbbox);
-	
-	PG_RETURN_POINTER(result);
-}
-
-PG_FUNCTION_INFO_V1(BOX2DFLOAT4_construct);
-Datum BOX2DFLOAT4_construct(PG_FUNCTION_ARGS)
-{
-	PG_LWGEOM *min = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-	PG_LWGEOM *max = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-	BOX2DFLOAT4 *result = palloc(sizeof(BOX2DFLOAT4));
-	LWGEOM *minpoint, *maxpoint;
-	POINT2D minp, maxp;
-
-	minpoint = lwgeom_deserialize(SERIALIZED_FORM(min));
-	maxpoint = lwgeom_deserialize(SERIALIZED_FORM(max));
-
-	if ( TYPE_GETTYPE(minpoint->type) != POINTTYPE ||
-		TYPE_GETTYPE(maxpoint->type) != POINTTYPE )
-	{
-		elog(ERROR, "BOX2DFLOAT4_construct: args must be points");
-		PG_RETURN_NULL();
-	}
-	getPoint2d_p(((LWPOINT *)minpoint)->point, 0, &minp);
-	getPoint2d_p(((LWPOINT *)maxpoint)->point, 0, &maxp);
-
-	result->xmax = maxp.x;
-	result->ymax = maxp.y;
-
-	result->xmin = minp.x;
-	result->ymin = minp.y;
-
-	PG_RETURN_POINTER(result);
-}
-
+#include <math.h>
+#include <float.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "postgres.h"
+#include "access/gist.h"
+#include "access/itup.h"
+#include "fmgr.h"
+#include "utils/elog.h"
+#include "utils/geo_decls.h"
+
+#include "lwgeom_pg.h"
+#include "liblwgeom.h"
+#include "stringBuffer.h"
+
+
+/* #define PGIS_DEBUG */
+
+/* forward defs */
+Datum BOX2DFLOAT4_in(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_out(PG_FUNCTION_ARGS);
+Datum LWGEOM_to_BOX2DFLOAT4(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_expand(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_to_BOX3D(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_combine(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_to_LWGEOM(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_construct(PG_FUNCTION_ARGS);
+
+/* parser - "BOX(xmin ymin,xmax ymax)" */
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_in);
+Datum BOX2DFLOAT4_in(PG_FUNCTION_ARGS)
+{
+	char *str = PG_GETARG_CSTRING(0);
+	int nitems;
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
+
+
+
+/*printf( "box3d_in gets '%s'\n",str); */
+
+	if (strstr(str,"BOX(") !=  str )
+	{
+		 pfree(box);
+		 elog(ERROR,"BOX2DFLOAT4 parser - doesnt start with BOX(");
+		 PG_RETURN_NULL();
+	}
+	nitems = sscanf(str,"BOX(%f %f,%f %f)", &box->xmin,&box->ymin,&box->xmax,&box->ymax);
+	if (nitems != 4)
+	{
+		 pfree(box);
+		 elog(ERROR,"BOX2DFLOAT4 parser - couldnt parse.  It should look like: BOX(xmin ymin,xmax ymax)");
+		 PG_RETURN_NULL();
+	}
+
+	if (box->xmin > box->xmax)
+	{
+		float tmp = box->xmin;
+		box->xmin = box->xmax;
+		box->xmax = tmp;
+	}
+	if (box->ymin > box->ymax)
+	{
+		float tmp = box->ymin;
+		box->ymin = box->ymax;
+		box->ymax = tmp;
+	}
+	PG_RETURN_POINTER(box);
+}
+
+/*writer  "BOX(xmin ymin,xmax ymax)" */
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_out);
+Datum BOX2DFLOAT4_out(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	char tmp[500]; /* big enough */
+	char *result;
+	int size;
+
+	size  = sprintf(tmp,"BOX(%.15g %.15g,%.15g %.15g)",
+		box->xmin, box->ymin, box->xmax, box->ymax);
+
+	result= palloc(size+1); /* +1= null term */
+
+	memcpy(result,tmp,size+1);
+	PG_RETURN_CSTRING(result);
+}
+
+
+/*convert a PG_LWGEOM to BOX2D */
+PG_FUNCTION_INFO_V1(LWGEOM_to_BOX2DFLOAT4);
+Datum LWGEOM_to_BOX2DFLOAT4(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+	BOX2DFLOAT4 *result;
+
+	result = palloc(sizeof(BOX2DFLOAT4));
+	if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), result) )
+	{
+		PG_RETURN_NULL(); /* must be the empty geometry */
+	}
+
+	PG_RETURN_POINTER(result);
+}
+
+/*----------------------------------------------------------
+ *	Relational operators for BOXes.
+ *		<, >, <=, >=, and == are based on box area.
+ *---------------------------------------------------------*/
+
+/*
+ * box_same - are two boxes identical?
+ */
+PG_FUNCTION_INFO_V1(BOX2D_same);
+Datum BOX2D_same(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPeq(box1->xmax, box2->xmax) &&
+				   FPeq(box1->xmin, box2->xmin) &&
+				   FPeq(box1->ymax, box2->ymax) &&
+				   FPeq(box1->ymin, box2->ymin));
+}
+
+/*
+ * box_overlap - does box1 overlap box2?
+ */
+PG_FUNCTION_INFO_V1(BOX2D_overlap);
+Datum BOX2D_overlap(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+	bool       result;
+
+
+	result = ((FPge(box1->xmax, box2->xmax) &&
+			 FPle(box1->xmin, box2->xmax)) ||
+			(FPge(box2->xmax, box1->xmax) &&
+			 FPle(box2->xmin, box1->xmax)))
+		&&
+		((FPge(box1->ymax, box2->ymax) &&
+		  FPle(box1->ymin, box2->ymax)) ||
+		 (FPge(box2->ymax, box1->ymax) &&
+		  FPle(box2->ymin, box1->ymax)));
+
+	PG_RETURN_BOOL(result);
+}
+
+
+/*
+ * box_overleft - is the right edge of box1 to the left of
+ *                the right edge of box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_overleft);
+Datum BOX2D_overleft(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4 *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPle(box1->xmax, box2->xmax));
+}
+
+/* 
+ * box_left - is box1 strictly left of box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_left);
+Datum BOX2D_left(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPlt(box1->xmax, box2->xmin));
+}
+
+/*
+ * box_right - is box1 strictly right of box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_right);
+Datum BOX2D_right(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPgt(box1->xmin, box2->xmax));
+}
+
+/* 
+ * box_overright - is the left edge of box1 to the right of
+ *                 the left edge of box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_overright);
+Datum BOX2D_overright(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPge(box1->xmin, box2->xmin));
+}
+
+/* 
+ * box_overbelow - is the bottom edge of box1 below
+ *                 the bottom edge of box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_overbelow);
+Datum BOX2D_overbelow(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPle(box1->ymin, box2->ymin));
+}
+
+/*
+ * box_below - is box1 strictly below box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_below);
+Datum BOX2D_below(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPlt(box1->ymax, box2->ymin));
+}
+
+/*
+ * box_above - is box1 strictly above box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_above);
+Datum BOX2D_above(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPgt(box1->ymin, box2->ymax));
+}
+
+/*
+ * box_overabove - the top edge of box1 above
+ *                 the top edge of box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_overabove);
+Datum BOX2D_overabove(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPge(box1->ymax, box2->ymax));
+}
+
+/*
+ * box_contained - is box1 contained by box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_contained);
+Datum BOX2D_contained(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 =(BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPle(box1->xmax, box2->xmax) &&
+				   FPge(box1->xmin, box2->xmin) &&
+				   FPle(box1->ymax, box2->ymax) &&
+				   FPge(box1->ymin, box2->ymin));
+}
+
+/*
+ * box_contain - does box1 contain box2?
+ */
+ PG_FUNCTION_INFO_V1(BOX2D_contain);
+Datum BOX2D_contain(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4		   *box1 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4		   *box2 = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(FPge(box1->xmax, box2->xmax) &&
+				   FPle(box1->xmin, box2->xmin) &&
+				   FPge(box1->ymax, box2->ymax) &&
+				   FPle(box1->ymin, box2->ymin));
+
+}
+
+PG_FUNCTION_INFO_V1(BOX2D_intersects);
+Datum BOX2D_intersects(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *a = (BOX2DFLOAT4 *) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4 *b = (BOX2DFLOAT4 *) PG_GETARG_POINTER(1);
+	BOX2DFLOAT4 *n;
+
+
+	n = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
+
+	n->xmax = LWGEOM_Minf(a->xmax, b->xmax);
+	n->ymax = LWGEOM_Minf(a->ymax, b->ymax);
+	n->xmin = LWGEOM_Maxf(a->xmin, b->xmin);
+	n->ymin = LWGEOM_Maxf(a->ymin, b->ymin);
+
+
+	if (n->xmax < n->xmin || n->ymax < n->ymin)
+	{
+		pfree(n);
+		/* Indicate "no intersection" by returning NULL pointer */
+		n = NULL;
+	}
+
+	PG_RETURN_POINTER(n);
+}
+
+
+/*
+ * union of two BOX2Ds
+ */
+PG_FUNCTION_INFO_V1(BOX2D_union);
+Datum BOX2D_union(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *a = (BOX2DFLOAT4*) PG_GETARG_POINTER(0);
+	BOX2DFLOAT4 *b = (BOX2DFLOAT4*) PG_GETARG_POINTER(1);
+	BOX2DFLOAT4 *n;
+
+	n = (BOX2DFLOAT4 *) lwalloc(sizeof(BOX2DFLOAT4));
+	if ( ! box2d_union_p(a,b,n) ) PG_RETURN_NULL();
+	PG_RETURN_POINTER(n);
+}
+
+
+/*
+ * min(a,b)
+ */
+float LWGEOM_Minf(float a, float b)
+{
+	if (a<b)
+		return a;
+	return b;
+}
+
+/*
+ * max(a,b)
+ */
+float LWGEOM_Maxf(float a, float b)
+{
+	if (b>a) return b;
+	return a;
+}
+
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_expand);
+Datum BOX2DFLOAT4_expand(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	double d = PG_GETARG_FLOAT8(1);
+	BOX2DFLOAT4 *result = (BOX2DFLOAT4 *)palloc(sizeof(BOX2DFLOAT4));
+
+	memcpy(result, box, sizeof(BOX2DFLOAT4));
+	expand_box2d(result, d);
+
+	PG_RETURN_POINTER(result);
+}
+
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_to_BOX3D);
+Datum BOX2DFLOAT4_to_BOX3D(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	BOX3D *result = palloc(sizeof(BOX3D));
+
+	box2df_to_box3d_p(box, result);
+
+	PG_RETURN_POINTER(result);
+}
+
+
+#define KEEP_OBSOLETED_FUNX 1
+#if KEEP_OBSOLETED_FUNX
+Datum BOX2DFLOAT4_xmin(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_ymin(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_xmax(PG_FUNCTION_ARGS);
+Datum BOX2DFLOAT4_ymax(PG_FUNCTION_ARGS);
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_xmin);
+Datum BOX2DFLOAT4_xmin(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	PG_RETURN_FLOAT4(box->xmin);
+}
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_ymin);
+Datum BOX2DFLOAT4_ymin(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	PG_RETURN_FLOAT4(box->ymin);
+}
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_xmax);
+Datum BOX2DFLOAT4_xmax(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	PG_RETURN_FLOAT4(box->xmax);
+}
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_ymax);
+Datum BOX2DFLOAT4_ymax(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	PG_RETURN_FLOAT4(box->ymax);
+}
+#endif
+
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_combine);
+Datum BOX2DFLOAT4_combine(PG_FUNCTION_ARGS)
+{
+	Pointer box2d_ptr = PG_GETARG_POINTER(0);
+	Pointer geom_ptr = PG_GETARG_POINTER(1);
+	BOX2DFLOAT4 *a,*b;
+	PG_LWGEOM *lwgeom;
+	BOX2DFLOAT4 box, *result;
+
+	if  ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
+	{
+		PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
+	}
+
+	result = (BOX2DFLOAT4 *)palloc(sizeof(BOX2DFLOAT4));
+
+	if (box2d_ptr == NULL)
+	{
+		lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+		/* empty geom would make getbox2d_p return NULL */
+		if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), &box) ) PG_RETURN_NULL();
+		memcpy(result, &box, sizeof(BOX2DFLOAT4));
+		PG_RETURN_POINTER(result);
+	}
+
+	/* combine_bbox(BOX3D, null) => BOX3D */
+	if (geom_ptr == NULL)
+	{
+		memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX2DFLOAT4));
+		PG_RETURN_POINTER(result);
+	}
+
+	/*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
+
+	lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+	if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), &box) )
+	{
+		/* must be the empty geom */
+		memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX2DFLOAT4));
+		PG_RETURN_POINTER(result);
+	}
+
+	a = (BOX2DFLOAT4 *)PG_GETARG_DATUM(0);
+	b = &box;
+
+	result->xmax = LWGEOM_Maxf(a->xmax, b->xmax);
+	result->ymax = LWGEOM_Maxf(a->ymax, b->ymax);
+	result->xmin = LWGEOM_Minf(a->xmin, b->xmin);
+	result->ymin = LWGEOM_Minf(a->ymin, b->ymin);
+
+	PG_RETURN_POINTER(result);
+}
+
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_to_LWGEOM);
+Datum BOX2DFLOAT4_to_LWGEOM(PG_FUNCTION_ARGS)
+{
+	BOX2DFLOAT4 *box = (BOX2DFLOAT4 *)PG_GETARG_POINTER(0);
+	POINT2D *pts = palloc(sizeof(POINT2D)*5);
+	POINTARRAY *pa[1];
+	LWPOLY *poly;
+	int wantbbox = 0;
+	PG_LWGEOM *result;
+	uchar *ser;
+
+	/* Assign coordinates to POINT2D array */
+	pts[0].x = box->xmin; pts[0].y = box->ymin;
+	pts[1].x = box->xmin; pts[1].y = box->ymax;
+	pts[2].x = box->xmax; pts[2].y = box->ymax;
+	pts[3].x = box->xmax; pts[3].y = box->ymin;
+	pts[4].x = box->xmin; pts[4].y = box->ymin;
+
+	/* Construct point array */
+	pa[0] = palloc(sizeof(POINTARRAY));
+	pa[0]->serialized_pointlist = (uchar *)pts;
+	TYPE_SETZM(pa[0]->dims, 0, 0);
+	pa[0]->npoints = 5;
+
+	/* Construct polygon */
+	poly = lwpoly_construct(-1, NULL, 1, pa);
+
+	/* Serialize polygon */
+	ser = lwpoly_serialize(poly);
+
+	/* Construct PG_LWGEOM  */
+	result = PG_LWGEOM_construct(ser, -1, wantbbox);
+	
+	PG_RETURN_POINTER(result);
+}
+
+PG_FUNCTION_INFO_V1(BOX2DFLOAT4_construct);
+Datum BOX2DFLOAT4_construct(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *min = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+	PG_LWGEOM *max = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+	BOX2DFLOAT4 *result = palloc(sizeof(BOX2DFLOAT4));
+	LWGEOM *minpoint, *maxpoint;
+	POINT2D minp, maxp;
+
+	minpoint = lwgeom_deserialize(SERIALIZED_FORM(min));
+	maxpoint = lwgeom_deserialize(SERIALIZED_FORM(max));
+
+	if ( TYPE_GETTYPE(minpoint->type) != POINTTYPE ||
+		TYPE_GETTYPE(maxpoint->type) != POINTTYPE )
+	{
+		elog(ERROR, "BOX2DFLOAT4_construct: args must be points");
+		PG_RETURN_NULL();
+	}
+
+	errorIfSRIDMismatch(minpoint->SRID, maxpoint->SRID);
+
+	getPoint2d_p(((LWPOINT *)minpoint)->point, 0, &minp);
+	getPoint2d_p(((LWPOINT *)maxpoint)->point, 0, &maxp);
+
+	result->xmax = maxp.x;
+	result->ymax = maxp.y;
+
+	result->xmin = minp.x;
+	result->ymin = minp.y;
+
+	PG_RETURN_POINTER(result);
+}
+

Modified: packages/postgis/upstream/lwgeom/lwgeom_box3d.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_box3d.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_box3d.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -354,10 +354,12 @@
 	if ( TYPE_GETTYPE(minpoint->type) != POINTTYPE ||
 		TYPE_GETTYPE(maxpoint->type) != POINTTYPE )
 	{
-		elog(ERROR, "BOX2DFLOAT4_construct: args must be points");
+		elog(ERROR, "BOX3D_construct: args must be points");
 		PG_RETURN_NULL();
 	}
 
+	errorIfSRIDMismatch(minpoint->SRID, maxpoint->SRID);
+
 	getPoint3dz_p(((LWPOINT *)minpoint)->point, 0, &minp);
 	getPoint3dz_p(((LWPOINT *)maxpoint)->point, 0, &maxp);
 

Modified: packages/postgis/upstream/lwgeom/lwgeom_btree.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_btree.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_btree.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 /***********************************************************
  *
- * $Id: lwgeom_btree.c,v 1.9 2006/01/09 15:55:55 strk Exp $
+ * $Id: lwgeom_btree.c 2273 2006-01-09 15:55:55Z strk $
  *
  * Comparision function for use in Binary Tree searches
  * (ORDER BY, GROUP BY, DISTINCT)
@@ -458,7 +458,7 @@
 
 /***********************************************************
  *
- * $Log: lwgeom_btree.c,v $
+ * $Log$
  * Revision 1.9  2006/01/09 15:55:55  strk
  * ISO C90 comments (finished in lwgeom/)
  *

Modified: packages/postgis/upstream/lwgeom/lwgeom_chip.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_chip.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_chip.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -711,10 +711,10 @@
 	 * CHIP units
 	 */
 
-	PIXEL p;
-
 	switch ( op )
 	{
+		PIXEL p;
+
 		case PIXELOP_OVERWRITE:
 			chip_setPixel(chip, x, y, pixel);
 			break;
@@ -1098,9 +1098,10 @@
 		state->x < state->chip->width )
 	{
 		char buf[256];
+		PIXEL p;
 
 		if ( ! state->chip ) lwerror("state->chip corrupted");
-		PIXEL p = chip_getPixel(state->chip, state->x, state->y);
+		p = chip_getPixel(state->chip, state->x, state->y);
 		pixel_writeval(&p, buf, 255);
 
 		sprintf(state->values[0], "%d", state->x);

Modified: packages/postgis/upstream/lwgeom/lwgeom_dump.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_dump.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_dump.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -271,13 +271,14 @@
 	while (state->ringnum < state->poly->nrings )
 	{
 		LWPOLY* poly = state->poly;
+		POINTARRAY *ring;
 
 		/* Switch to an appropriate memory context for POINTARRAY
 		 * cloning and hexwkb allocation */
 		oldcontext = MemoryContextSwitchTo(newcontext);
 
 		/* We need a copy of input ring here */
-		POINTARRAY *ring = ptarray_clone(poly->rings[state->ringnum]);
+		ring = ptarray_clone(poly->rings[state->ringnum]);
 
 		/* Construct another polygon with shell only */
 		LWGEOM* ringgeom = (LWGEOM*)lwpoly_construct(

Modified: packages/postgis/upstream/lwgeom/lwgeom_estimate.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_estimate.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_estimate.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_estimate.c,v 1.39 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwgeom_estimate.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -2629,7 +2629,7 @@
 
 
 /**********************************************************************
- * $Log: lwgeom_estimate.c,v $
+ * $Log$
  * Revision 1.39  2006/05/30 08:38:58  strk
  * Added some missing copyright headers.
  *

Modified: packages/postgis/upstream/lwgeom/lwgeom_functions_analytic.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_functions_analytic.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_functions_analytic.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_functions_analytic.c,v 1.33 2006/01/29 13:54:38 strk Exp $
+ * $Id: lwgeom_functions_analytic.c 2298 2006-01-29 13:54:38Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwgeom_functions_basic.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_functions_basic.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_functions_basic.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_functions_basic.c,v 1.143 2006/06/26 00:41:24 strk Exp $
+ * $Id: lwgeom_functions_basic.c 2461 2006-07-28 13:07:06Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -1622,6 +1622,7 @@
 	LWGEOM *lwgeoms[2], *outlwg;
 	unsigned int type1, type2, outtype;
 	BOX2DFLOAT4 *box=NULL;
+	int SRID;
 
 	/* return null if both geoms are null */
 	if ( (geom1_ptr == NULL) && (geom2_ptr == NULL) )
@@ -1651,12 +1652,17 @@
 	elog(NOTICE, "LWGEOM_collect(%s, %s): call", lwgeom_typename(TYPE_GETTYPE(pglwgeom1->type)), lwgeom_typename(TYPE_GETTYPE(pglwgeom2->type)));
 #endif
 	
+#if 0
 	if ( pglwgeom_getSRID(pglwgeom1) != pglwgeom_getSRID(pglwgeom2) )
 	{
 		elog(ERROR, "Operation on two GEOMETRIES with different SRIDs\n");
 		PG_RETURN_NULL();
 	}
+#endif
 
+	SRID = pglwgeom_getSRID(pglwgeom1);
+	errorIfSRIDMismatch(SRID, pglwgeom_getSRID(pglwgeom2));
+
 	lwgeoms[0] = lwgeom_deserialize(SERIALIZED_FORM(pglwgeom1));
 	lwgeoms[1] = lwgeom_deserialize(SERIALIZED_FORM(pglwgeom2));
 
@@ -1686,7 +1692,7 @@
 	lwgeom_dropSRID(lwgeoms[1]);
 
 	outlwg = (LWGEOM *)lwcollection_construct(
-		outtype, lwgeoms[0]->SRID,
+		outtype, SRID,
 		box, 2, lwgeoms);
 
 	result = pglwgeom_serialize(outlwg);
@@ -2001,7 +2007,7 @@
 	LWMPOINT *mpoint;
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE, "LWGEOM_makeline called");
+	elog(NOTICE, "LWGEOM_line_from_mpoint called");
 #endif
 
 	/* Get input PG_LWGEOM and deserialize it */
@@ -2168,11 +2174,7 @@
 		PG_RETURN_NULL();
 	}
 
-	if ( pglwgeom_getSRID(pglwg1) != pglwgeom_getSRID(pglwg2) )
-	{
-		elog(ERROR, "Operation with two geometries with different SRIDs\n");
-		PG_RETURN_NULL();
-	}
+	errorIfSRIDMismatch(pglwgeom_getSRID(pglwg1), pglwgeom_getSRID(pglwg2));
 
 	lwpoints[0] = lwpoint_deserialize(SERIALIZED_FORM(pglwg1));
 	lwpoints[1] = lwpoint_deserialize(SERIALIZED_FORM(pglwg2));

Modified: packages/postgis/upstream/lwgeom/lwgeom_functions_lrs.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_functions_lrs.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_functions_lrs.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_functions_lrs.c,v 1.5 2005/12/01 19:09:04 strk Exp $
+ * $Id: lwgeom_functions_lrs.c 2124 2005-12-01 19:09:04Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwgeom_gist.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_gist.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_gist.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -544,7 +544,11 @@
 
 			gistentryinit(*retval, PointerGetDatum(rr),
 				entry->rel, entry->page,
+#if USE_VERSION >= 82
+				entry->offset,
+#else
 				entry->offset, sizeof(BOX2DFLOAT4),
+#endif
 				FALSE);
 
 		}
@@ -554,7 +558,11 @@
 		elog(NOTICE,"GIST: LWGEOM_gist_compress got a NULL key");
 #endif
 			gistentryinit(*retval, (Datum) 0, entry->rel,
+#if USE_VERSION >= 82
+				entry->page, entry->offset, FALSE);
+#else
 				entry->page, entry->offset, 0, FALSE);
+#endif
 		}
 
 	}

Modified: packages/postgis/upstream/lwgeom/lwgeom_gml.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_gml.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_gml.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_gml.c,v 1.13 2006/01/09 15:55:55 strk Exp $
+ * $Id: lwgeom_gml.c 2273 2006-01-09 15:55:55Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -504,7 +504,7 @@
 }
 
 /**********************************************************************
- * $Log: lwgeom_gml.c,v $
+ * $Log$
  * Revision 1.13  2006/01/09 15:55:55  strk
  * ISO C90 comments (finished in lwgeom/)
  *

Modified: packages/postgis/upstream/lwgeom/lwgeom_ogc.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_ogc.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_ogc.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_ogc.c,v 1.49 2005/12/30 17:40:37 strk Exp $
+ * $Id: lwgeom_ogc.c 2243 2005-12-30 17:40:37Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwgeom_spheroid.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_spheroid.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_spheroid.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_spheroid.c,v 1.14 2006/01/09 15:12:02 strk Exp $
+ * $Id: lwgeom_spheroid.c 2272 2006-01-09 15:12:02Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwgeom_svg.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_svg.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_svg.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_svg.c,v 1.11 2006/01/09 15:55:55 strk Exp $
+ * $Id: lwgeom_svg.c 2273 2006-01-09 15:55:55Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -279,7 +279,7 @@
 
 
 /**********************************************************************
- * $Log: lwgeom_svg.c,v $
+ * $Log$
  * Revision 1.11  2006/01/09 15:55:55  strk
  * ISO C90 comments (finished in lwgeom/)
  *

Modified: packages/postgis/upstream/lwgeom/lwgeom_transform.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwgeom_transform.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwgeom_transform.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwgeom_transform.c,v 1.31 2006/01/09 15:55:55 strk Exp $
+ * $Id: lwgeom_transform.c 2273 2006-01-09 15:55:55Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwline.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwline.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwline.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwline.c,v 1.32 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwline.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwmline.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwmline.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwmline.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwmline.c,v 1.14 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwmline.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwmpoint.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwmpoint.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwmpoint.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwmpoint.c,v 1.14 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwmpoint.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwmpoly.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwmpoly.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwmpoly.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwmpoly.c,v 1.15 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwmpoly.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwpoint.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwpoint.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwpoint.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwpoint.c,v 1.23 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwpoint.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwpoly.c
===================================================================
--- packages/postgis/upstream/lwgeom/lwpoly.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwpoly.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: lwpoly.c,v 1.23 2006/05/30 08:38:58 strk Exp $
+ * $Id: lwpoly.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/lwpostgis.sql.in
===================================================================
--- packages/postgis/upstream/lwgeom/lwpostgis.sql.in	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/lwpostgis.sql.in	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- 
--- $Id: lwpostgis.sql.in,v 1.159 2006/06/25 23:59:32 strk Exp $
+-- $Id: lwpostgis.sql.in 2406 2006-07-07 13:56:52Z strk $
 --
 -- PostGIS - Spatial Types for PostgreSQL
 -- http://postgis.refractions.net
@@ -2041,7 +2041,7 @@
 		table_name || ''.'' || column_name ||
 		'' SRID:'' || new_srid ||
 		'' TYPE:'' || new_type || 
-		'' DIMS:'' || new_dim || ''\n ''; 
+		'' DIMS:'' || new_dim || chr(10) || '' ''; 
 END;
 '
 LANGUAGE 'plpgsql' _VOLATILE_STRICT; -- WITH (isstrict);
@@ -2623,7 +2623,7 @@
 -- Do not modify this w/out also changing postgis_proc_upgrade.pl
 --
 CREATEFUNCTION postgis_scripts_installed() RETURNS text
-        AS 'SELECT \'@POSTGIS_SCRIPTS_VERSION@\'::text AS version'
+        AS 'SELECT ''@POSTGIS_SCRIPTS_VERSION@''::text AS version'
         LANGUAGE 'sql' _IMMUTABLE;
 
 CREATEFUNCTION postgis_lib_version() RETURNS text
@@ -2648,7 +2648,7 @@
 	LANGUAGE 'C' _IMMUTABLE;
 
 CREATEFUNCTION postgis_scripts_build_date() RETURNS text
-        AS 'SELECT \'@POSTGIS_BUILD_DATE@\'::text AS version'
+        AS 'SELECT ''@POSTGIS_BUILD_DATE@''::text AS version'
         LANGUAGE 'sql' _IMMUTABLE;
 
 CREATEFUNCTION postgis_lib_build_date() RETURNS text
@@ -2677,29 +2677,29 @@
 	SELECT postgis_scripts_installed() INTO dbproc;
 	SELECT postgis_scripts_released() INTO relproc;
 
-	fullver = \'POSTGIS="\' || libver || \'"\';
+	fullver = ''POSTGIS="'' || libver || ''"'';
 
 	IF  geosver IS NOT NULL THEN
-		fullver = fullver || \' GEOS="\' || geosver || \'"\';
+		fullver = fullver || '' GEOS="'' || geosver || ''"'';
 	END IF;
 
 	IF  jtsver IS NOT NULL THEN
-		fullver = fullver || \' JTS="\' || jtsver || \'"\';
+		fullver = fullver || '' JTS="'' || jtsver || ''"'';
 	END IF;
 
 	IF  projver IS NOT NULL THEN
-		fullver = fullver || \' PROJ="\' || projver || \'"\';
+		fullver = fullver || '' PROJ="'' || projver || ''"'';
 	END IF;
 
 	IF usestats THEN
-		fullver = fullver || \' USE_STATS\';
+		fullver = fullver || '' USE_STATS'';
 	END IF;
 
-	-- fullver = fullver || \' DBPROC="\' || dbproc || \'"\';
-	-- fullver = fullver || \' RELPROC="\' || relproc || \'"\';
+	-- fullver = fullver || '' DBPROC="'' || dbproc || ''"'';
+	-- fullver = fullver || '' RELPROC="'' || relproc || ''"'';
 
 	IF dbproc != relproc THEN
-		fullver = fullver || \' (procs from \' || dbproc || \' need upgrade)\';
+		fullver = fullver || '' (procs from '' || dbproc || '' need upgrade)'';
 	END IF;
 
 	RETURN fullver;

Modified: packages/postgis/upstream/lwgeom/measures.c
===================================================================
--- packages/postgis/upstream/lwgeom/measures.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/measures.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: measures.c,v 1.11 2006/05/30 08:38:58 strk Exp $
+ * $Id: measures.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/ptarray.c
===================================================================
--- packages/postgis/upstream/lwgeom/ptarray.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/ptarray.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: ptarray.c,v 1.31 2006/05/30 08:38:58 strk Exp $
+ * $Id: ptarray.c 2369 2006-05-30 08:38:58Z strk $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net

Modified: packages/postgis/upstream/lwgeom/stringBuffer.h
===================================================================
--- packages/postgis/upstream/lwgeom/stringBuffer.h	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/stringBuffer.h	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,14 +1,14 @@
-
-typedef struct {
-	char * string;
-	int length; /* length of string, EXCLUDING null termination */
-	int size;   /* size of buffer -can be longer than */
-} STRBUFF;
-
-
-extern STRBUFF * new_strBUFF(int size);
-extern void delete_StrBUFF(STRBUFF* buff);
-extern char* to_CString(STRBUFF * buffer);
-extern void add_str_simple(STRBUFF* buffer, char* str);
-extern void catenate(STRBUFF *buffer, char* str, int length);
-extern int getSize(int buffer_size, int buffer_length, int strLength);
+
+typedef struct {
+	char * string;
+	int length; /* length of string, EXCLUDING null termination */
+	int size;   /* size of buffer -can be longer than */
+} STRBUFF;
+
+
+extern STRBUFF * new_strBUFF(int size);
+extern void delete_StrBUFF(STRBUFF* buff);
+extern char* to_CString(STRBUFF * buffer);
+extern void add_str_simple(STRBUFF* buffer, char* str);
+extern void catenate(STRBUFF *buffer, char* str, int length);
+extern int getSize(int buffer_size, int buffer_length, int strLength);

Modified: packages/postgis/upstream/lwgeom/wktparse.h
===================================================================
--- packages/postgis/upstream/lwgeom/wktparse.h	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/wktparse.h	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,88 +1,88 @@
-/*
- * Written by Ralph Mason ralph.mason<at>telogis.com
- *
- * Copyright Telogis 2004
- * www.telogis.com
- *
- */
-
-#ifndef _WKTPARSE_H
-#define _WKTPARSE_H
-
-#include <stdlib.h>
-
-
-#ifndef _LIBLWGEOM_H
-typedef unsigned char uchar;
-#endif
-typedef void* (*allocator)(size_t size);
-typedef void  (*freeor)(void* mem);
-typedef void  (*report_error)(const char* string, ...);
-
-/*typedef unsigned long int4;*/
-
-/* How much memory is allocated at a time(bytes) for tuples */
-#define ALLOC_CHUNKS 8192
-
-/* to shrink ints less than 0x7f to 1 byte */
-/* #define SHRINK_INTS */
-
-#define	POINTTYPE	1
-#define	LINETYPE	2
-#define	POLYGONTYPE	3
-#define	MULTIPOINTTYPE	4
-#define	MULTILINETYPE	5
-#define	MULTIPOLYGONTYPE	6
-#define	COLLECTIONTYPE	7
-
-/* Extended lwgeom integer types */
-#define POINTTYPEI    10
-#define LINETYPEI     11
-#define POLYGONTYPEI  12
-
-extern int srid;
-
-/*
-
-   These functions are used by  the
-   generated parser and are not meant
-   for public use
-
-*/
-
-void set_srid(double srid);
-void alloc_lwgeom(int srid);
-
-void alloc_point_2d(double x,double y);
-void alloc_point_3d(double x,double y,double z);
-void alloc_point_4d(double x,double y,double z,double m);
-
-void alloc_point(void);
-void alloc_linestring(void);
-void alloc_polygon(void);
-void alloc_multipoint(void);
-void alloc_multilinestring(void);
-void alloc_multipolygon(void);
-void alloc_geomertycollection(void);
-void alloc_empty();
-void alloc_counter(void);
-
-
-void pop(void);
-void popc(void);
-
-void alloc_wkb(const char* parser);
-
-/*
-	Use these functions to parse and unparse lwgeoms
-	You are responsible for freeing the returned memory.
-*/
-
-uchar* parse_lwg(const char* wkt,allocator allocfunc,report_error errfunc);
-uchar* parse_lwgi(const char* wkt,allocator allocfunc,report_error errfunc);
-char* unparse_WKT(uchar* serialized, allocator alloc,freeor free);
-char* unparse_WKB(uchar* serialized, allocator alloc,freeor free, char endian, size_t *outsize, uchar hexform);
-int lwg_parse_yyparse(void);
-int lwg_parse_yyerror(char* s);
-
-#endif /* _WKTPARSE_H */
+/*
+ * Written by Ralph Mason ralph.mason<at>telogis.com
+ *
+ * Copyright Telogis 2004
+ * www.telogis.com
+ *
+ */
+
+#ifndef _WKTPARSE_H
+#define _WKTPARSE_H
+
+#include <stdlib.h>
+
+
+#ifndef _LIBLWGEOM_H
+typedef unsigned char uchar;
+#endif
+typedef void* (*allocator)(size_t size);
+typedef void  (*freeor)(void* mem);
+typedef void  (*report_error)(const char* string, ...);
+
+/*typedef unsigned long int4;*/
+
+/* How much memory is allocated at a time(bytes) for tuples */
+#define ALLOC_CHUNKS 8192
+
+/* to shrink ints less than 0x7f to 1 byte */
+/* #define SHRINK_INTS */
+
+#define	POINTTYPE	1
+#define	LINETYPE	2
+#define	POLYGONTYPE	3
+#define	MULTIPOINTTYPE	4
+#define	MULTILINETYPE	5
+#define	MULTIPOLYGONTYPE	6
+#define	COLLECTIONTYPE	7
+
+/* Extended lwgeom integer types */
+#define POINTTYPEI    10
+#define LINETYPEI     11
+#define POLYGONTYPEI  12
+
+extern int srid;
+
+/*
+
+   These functions are used by  the
+   generated parser and are not meant
+   for public use
+
+*/
+
+void set_srid(double srid);
+void alloc_lwgeom(int srid);
+
+void alloc_point_2d(double x,double y);
+void alloc_point_3d(double x,double y,double z);
+void alloc_point_4d(double x,double y,double z,double m);
+
+void alloc_point(void);
+void alloc_linestring(void);
+void alloc_polygon(void);
+void alloc_multipoint(void);
+void alloc_multilinestring(void);
+void alloc_multipolygon(void);
+void alloc_geomertycollection(void);
+void alloc_empty();
+void alloc_counter(void);
+
+
+void pop(void);
+void popc(void);
+
+void alloc_wkb(const char* parser);
+
+/*
+	Use these functions to parse and unparse lwgeoms
+	You are responsible for freeing the returned memory.
+*/
+
+uchar* parse_lwg(const char* wkt,allocator allocfunc,report_error errfunc);
+uchar* parse_lwgi(const char* wkt,allocator allocfunc,report_error errfunc);
+char* unparse_WKT(uchar* serialized, allocator alloc,freeor free);
+char* unparse_WKB(uchar* serialized, allocator alloc,freeor free, char endian, size_t *outsize, uchar hexform);
+int lwg_parse_yyparse(void);
+int lwg_parse_yyerror(char* s);
+
+#endif /* _WKTPARSE_H */

Modified: packages/postgis/upstream/lwgeom/wktunparse.c
===================================================================
--- packages/postgis/upstream/lwgeom/wktunparse.c	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/lwgeom/wktunparse.c	2006-10-06 08:43:11 UTC (rev 561)
@@ -4,7 +4,7 @@
  * Copyright Telogis 2004
  * www.telogis.com
  *
- * $Id: wktunparse.c,v 1.23 2006/02/06 11:12:22 strk Exp $
+ * $Id: wktunparse.c 2305 2006-02-06 11:12:22Z strk $
  */
 
 
@@ -612,7 +612,7 @@
 
 
 /******************************************************************
- * $Log: wktunparse.c,v $
+ * $Log$
  * Revision 1.23  2006/02/06 11:12:22  strk
  * uint32_t typedef moved back from wktparse.h to lwgparse.c and wktunparse.c
  *

Modified: packages/postgis/upstream/regress/Makefile
===================================================================
--- packages/postgis/upstream/regress/Makefile	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/regress/Makefile	2006-10-06 08:43:11 UTC (rev 561)
@@ -26,7 +26,8 @@
 	affine \
 	wkt \
 	measures \
-	long_xact
+	long_xact \
+	ctors
 
 ifeq ($(USE_GEOS),1)
 	TESTS += regress_ogc regress_bdpoly

Added: packages/postgis/upstream/regress/ctors.sql
===================================================================
--- packages/postgis/upstream/regress/ctors.sql	                        (rev 0)
+++ packages/postgis/upstream/regress/ctors.sql	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,14 @@
+-- postgis-users/2006-July/012764.html
+SELECT SRID(collect('SRID=32749;POINT(0 0)', 'SRID=32749;POINT(1 1)'));
+
+SELECT collect('SRID=32749;POINT(0 0)', 'SRID=32740;POINT(1 1)');
+
+select asewkt(makeline('SRID=3;POINT(0 0)', 'SRID=3;POINT(1 1)'));
+select makeline('POINT(0 0)', 'SRID=3;POINT(1 1)');
+
+-- postgis-users/2006-July/012788.html
+select makebox2d('SRID=3;POINT(0 0)', 'SRID=3;POINT(1 1)');
+select makebox2d('POINT(0 0)', 'SRID=3;POINT(1 1)');
+
+select makebox3d('SRID=3;POINT(0 0)', 'SRID=3;POINT(1 1)');
+select makebox3d('POINT(0 0)', 'SRID=3;POINT(1 1)');

Added: packages/postgis/upstream/regress/ctors_expected
===================================================================
--- packages/postgis/upstream/regress/ctors_expected	                        (rev 0)
+++ packages/postgis/upstream/regress/ctors_expected	2006-10-06 08:43:11 UTC (rev 561)
@@ -0,0 +1,8 @@
+32749
+ERROR:  Operation on mixed SRID geometries
+SRID=3;LINESTRING(0 0,1 1)
+ERROR:  Operation on mixed SRID geometries
+BOX(0 0,1 1)
+ERROR:  Operation on mixed SRID geometries
+BOX3D(0 0 0,1 1 0)
+ERROR:  Operation on mixed SRID geometries

Modified: packages/postgis/upstream/regress/loader/Arc.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/ArcM.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/MultiPoint.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/MultiPointM.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/MultiPointZ.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/Point.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/PointM.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/PointZ.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/Polygon.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/PolygonM.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/loader/PolygonZ.dbf
===================================================================
(Binary files differ)

Modified: packages/postgis/upstream/regress/regress_index.sql
===================================================================
--- packages/postgis/upstream/regress/regress_index.sql	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/regress/regress_index.sql	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,16 +1,16 @@
---- build a larger database
-\i regress_lots_of_points.sql
-
---- test some of the searching capabilities
-
--- GiST index
-
-CREATE INDEX quick_gist on test using gist (the_geom gist_geometry_ops);
-
- select num,astext(the_geom) from test where the_geom && 'BOX3D(125 125,135 135)'::box3d order by num;
-
-set enable_seqscan = off;
-
- select num,astext(the_geom) from test where the_geom && 'BOX3D(125 125,135 135)'::box3d  order by num;
-
-DROP TABLE test;
+--- build a larger database
+\i regress_lots_of_points.sql
+
+--- test some of the searching capabilities
+
+-- GiST index
+
+CREATE INDEX quick_gist on test using gist (the_geom gist_geometry_ops);
+
+ select num,astext(the_geom) from test where the_geom && 'BOX3D(125 125,135 135)'::box3d order by num;
+
+set enable_seqscan = off;
+
+ select num,astext(the_geom) from test where the_geom && 'BOX3D(125 125,135 135)'::box3d  order by num;
+
+DROP TABLE test;

Modified: packages/postgis/upstream/regress/regress_ogc.sql
===================================================================
--- packages/postgis/upstream/regress/regress_ogc.sql	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/regress/regress_ogc.sql	2006-10-06 08:43:11 UTC (rev 561)
@@ -8,7 +8,7 @@
 SELECT 'buffer', astext(SnapToGrid(buffer('POINT(0 0)', 1, 2), 1.0e-6));
 
 SELECT 'geomunion', astext(geomunion('POINT(0 0)', 'POINT(1 1)'));
-SELECT 'unite_garray', astext(unite_garray(geom_accum('{POINT(0 0)}', 'POINT(2 3)')));
+SELECT 'unite_garray', equals(unite_garray(geom_accum('{POINT(0 0)}', 'POINT(2 3)')), 'MULTIPOINT(2 3,0 0)');
 SELECT 'convexhull', asewkt(convexhull('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(2 2, 2 4, 4 4, 4 2, 2 2))'));
 SELECT 'relate', relate('POINT(0 0)', 'LINESTRING(0 0, 1 1)');
 SELECT 'relate', relate('POINT(0 0)', 'LINESTRING(0 0, 1 1)', 'F0FFFF*02');

Modified: packages/postgis/upstream/regress/regress_ogc_expected
===================================================================
--- packages/postgis/upstream/regress/regress_ogc_expected	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/regress/regress_ogc_expected	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 buffer|POLYGON((1 0,0.707107 -0.707107,0 -1,-0.707107 -0.707107,-1 0,-0.707107 0.707107,0 1,0.707107 0.707107,1 0))
 geomunion|MULTIPOINT(0 0,1 1)
-unite_garray|MULTIPOINT(2 3,0 0)
+unite_garray|t
 convexhull|POLYGON((0 0,0 10,10 10,10 0,0 0))
 relate|F0FFFF102
 relate|t

Deleted: packages/postgis/upstream/topology/.cvsignore
===================================================================
--- packages/postgis/upstream/topology/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/topology/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1 +0,0 @@
-topology.sql

Deleted: packages/postgis/upstream/topology/ER/.cvsignore
===================================================================
--- packages/postgis/upstream/topology/ER/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/topology/ER/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1 +0,0 @@
-topology.png

Deleted: packages/postgis/upstream/topology/test/.cvsignore
===================================================================
--- packages/postgis/upstream/topology/test/.cvsignore	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/topology/test/.cvsignore	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,2 +0,0 @@
-geom_predicates.sql
-topo_predicates.sql

Modified: packages/postgis/upstream/topology/topology.sql.in
===================================================================
--- packages/postgis/upstream/topology/topology.sql.in	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/topology/topology.sql.in	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- 
--- $Id: topology.sql.in,v 1.5 2005/11/01 11:56:20 strk Exp $
+-- $Id: topology.sql.in 2469 2006-09-06 11:16:59Z strk $
 --
 -- PostGIS - Spatial Types for PostgreSQL
 -- http://postgis.refractions.net
@@ -702,12 +702,6 @@
 '
 LANGUAGE 'sql' _VOLATILE;
 
-CREATEFUNCTION topology.AddTopoGeometryColumn(varchar, varchar, varchar, varchar, varchar)
-	RETURNS integer
-AS '
-	SELECT topology.AddTopoGeometryColumn($1, $2, $3, $4, $5, NULL);
-'
-LANGUAGE 'sql' _VOLATILE;
 --
 --} AddTopoGeometryColumn
 

Modified: packages/postgis/upstream/utils/profile_intersects.pl
===================================================================
--- packages/postgis/upstream/utils/profile_intersects.pl	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/utils/profile_intersects.pl	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# $Id: profile_intersects.pl,v 1.4 2004/09/27 08:23:45 strk Exp $
+# $Id: profile_intersects.pl 895 2004-09-27 08:23:45Z strk $
 # 
 # TODO:
 #
@@ -379,7 +379,7 @@
 }
 
 # 
-# $Log: profile_intersects.pl,v $
+# $Log$
 # Revision 1.4  2004/09/27 08:23:45  strk
 # Added USE_GIST variable on top of file. Changed true values report
 # as fraction of total rows.

Modified: packages/postgis/upstream/utils/test_estimation.pl
===================================================================
--- packages/postgis/upstream/utils/test_estimation.pl	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/utils/test_estimation.pl	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# $Id: test_estimation.pl,v 1.9 2005/04/18 13:30:25 strk Exp $
+# $Id: test_estimation.pl 1631 2005-04-18 13:30:25Z strk $
 # 
 # TODO:
 #
@@ -285,7 +285,7 @@
 }
 
 # 
-# $Log: test_estimation.pl,v $
+# $Log$
 # Revision 1.9  2005/04/18 13:30:25  strk
 # Fixed to work against LWGEOM installations
 #

Modified: packages/postgis/upstream/utils/test_joinestimation.pl
===================================================================
--- packages/postgis/upstream/utils/test_joinestimation.pl	2006-09-13 15:08:26 UTC (rev 560)
+++ packages/postgis/upstream/utils/test_joinestimation.pl	2006-10-06 08:43:11 UTC (rev 561)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# $Id: test_joinestimation.pl,v 1.3 2005/04/18 13:50:14 strk Exp $
+# $Id: test_joinestimation.pl 1633 2005-04-18 13:50:14Z strk $
 # 
 # TODO:
 #
@@ -255,7 +255,7 @@
 }
 
 # 
-# $Log: test_joinestimation.pl,v $
+# $Log$
 # Revision 1.3  2005/04/18 13:50:14  strk
 # Fixed bug in table2 schema parsing.
 #




More information about the Pkg-grass-devel mailing list