[DebianGIS-dev] r485 - in packages/postgis/trunk: . doc doc/html extras extras/WFS_locks extras/ogc_test_suite extras/rpm/spec extras/wkb_reader jdbc2 jdbc2/jtssrc/org/postgis/jts jdbc2/src/examples jdbc2/src/org/postgis loader lwgeom regress topology topology/ER topology/test

Fabio Tranchitella kobold at costa.debian.org
Thu Jul 20 16:49:54 UTC 2006


Author: kobold
Date: 2006-07-20 16:49:42 +0000 (Thu, 20 Jul 2006)
New Revision: 485

Added:
   packages/postgis/trunk/.cvsignore
   packages/postgis/trunk/HOWTO_RELEASE
   packages/postgis/trunk/autom4te.cache/
   packages/postgis/trunk/doc/.cvsignore
   packages/postgis/trunk/doc/README
   packages/postgis/trunk/doc/html/.cvsignore
   packages/postgis/trunk/doc/html/apa.html
   packages/postgis/trunk/doc/html/ch01.html
   packages/postgis/trunk/doc/html/ch02.html
   packages/postgis/trunk/doc/html/ch03.html
   packages/postgis/trunk/doc/html/ch04.html
   packages/postgis/trunk/doc/html/ch05.html
   packages/postgis/trunk/doc/html/ch06.html
   packages/postgis/trunk/doc/html/ch07.html
   packages/postgis/trunk/doc/html/index.html
   packages/postgis/trunk/doc/long_xact.xml
   packages/postgis/trunk/extras/WFS_locks/test.sql
   packages/postgis/trunk/extras/ogc_test_suite/.cvsignore
   packages/postgis/trunk/extras/template_gis/
   packages/postgis/trunk/extras/wkb_reader/.cvsignore
   packages/postgis/trunk/jdbc2/.cvsignore
   packages/postgis/trunk/loader/.cvsignore
   packages/postgis/trunk/lwgeom/.cvsignore
   packages/postgis/trunk/lwgeom/long_xact.c
   packages/postgis/trunk/lwgeom/long_xact.sql
   packages/postgis/trunk/make_dist.sh
   packages/postgis/trunk/regress/loader/
   packages/postgis/trunk/regress/long_xact.sql
   packages/postgis/trunk/regress/long_xact_expected
   packages/postgis/trunk/regress/measures.sql
   packages/postgis/trunk/regress/measures_expected
   packages/postgis/trunk/regress/wkt.sql
   packages/postgis/trunk/regress/wkt_expected
   packages/postgis/trunk/topology/.cvsignore
   packages/postgis/trunk/topology/ER/.cvsignore
   packages/postgis/trunk/topology/test/.cvsignore
Removed:
   packages/postgis/trunk/doc/html/postgis.html
Modified:
   packages/postgis/trunk/CHANGES
   packages/postgis/trunk/GNUmakefile
   packages/postgis/trunk/Makefile
   packages/postgis/trunk/Makefile.config.in
   packages/postgis/trunk/README.postgis
   packages/postgis/trunk/TODO
   packages/postgis/trunk/Version.config
   packages/postgis/trunk/configure
   packages/postgis/trunk/configure.in
   packages/postgis/trunk/doc/Makefile
   packages/postgis/trunk/doc/postgis.xml
   packages/postgis/trunk/extras/WFS_locks/Makefile
   packages/postgis/trunk/extras/WFS_locks/README
   packages/postgis/trunk/extras/WFS_locks/WFS_locks.c
   packages/postgis/trunk/extras/WFS_locks/WFS_locks.sql.in
   packages/postgis/trunk/extras/rpm/spec/postgis.spec
   packages/postgis/trunk/jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java
   packages/postgis/trunk/jdbc2/src/examples/TestParser.java
   packages/postgis/trunk/jdbc2/src/org/postgis/Geometry.java
   packages/postgis/trunk/jdbc2/src/org/postgis/Point.java
   packages/postgis/trunk/loader/pgsql2shp.c
   packages/postgis/trunk/loader/shp2pgsql.c
   packages/postgis/trunk/lwgeom/Makefile
   packages/postgis/trunk/lwgeom/lex.yy.c
   packages/postgis/trunk/lwgeom/liblwgeom.c
   packages/postgis/trunk/lwgeom/liblwgeom.h
   packages/postgis/trunk/lwgeom/lwcollection.c
   packages/postgis/trunk/lwgeom/lwgeom.c
   packages/postgis/trunk/lwgeom/lwgeom_chip.c
   packages/postgis/trunk/lwgeom/lwgeom_dump.c
   packages/postgis/trunk/lwgeom/lwgeom_estimate.c
   packages/postgis/trunk/lwgeom/lwgeom_functions_basic.c
   packages/postgis/trunk/lwgeom/lwgeom_geos_c.c
   packages/postgis/trunk/lwgeom/lwgeom_inout.c
   packages/postgis/trunk/lwgeom/lwgeom_jts.c
   packages/postgis/trunk/lwgeom/lwgeom_pg.c
   packages/postgis/trunk/lwgeom/lwline.c
   packages/postgis/trunk/lwgeom/lwmline.c
   packages/postgis/trunk/lwgeom/lwmpoint.c
   packages/postgis/trunk/lwgeom/lwmpoly.c
   packages/postgis/trunk/lwgeom/lwpoint.c
   packages/postgis/trunk/lwgeom/lwpoly.c
   packages/postgis/trunk/lwgeom/lwpostgis.sql.in
   packages/postgis/trunk/lwgeom/measures.c
   packages/postgis/trunk/lwgeom/ptarray.c
   packages/postgis/trunk/lwgeom/wktparse.lex
   packages/postgis/trunk/lwgeom/wktparse.tab.c
   packages/postgis/trunk/lwgeom/wktparse.y
   packages/postgis/trunk/regress/Makefile
   packages/postgis/trunk/regress/affine.sql
   packages/postgis/trunk/regress/affine_expected
   packages/postgis/trunk/regress/regress.sql
   packages/postgis/trunk/regress/regress_expected
   packages/postgis/trunk/regress/run_test
   packages/postgis/trunk/topology/test/Makefile
   packages/postgis/trunk/topology/test/load_topology.sql
Log:
Merged trunk with upstream (postgis-1.1.3).


Copied: packages/postgis/trunk/.cvsignore (from rev 484, packages/postgis/upstream/.cvsignore)

Modified: packages/postgis/trunk/CHANGES
===================================================================
--- packages/postgis/trunk/CHANGES	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/CHANGES	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,29 @@
+PostGIS 1.1.3
+2006/06/30
+
+	- NEW Long Transactions support.
+	- Can run the regress tests with 'make check' now.
+	- New regress test support for loader/dumper.
+	- BUGFIX in pgsql2shp successful return code.
+	- BUGFIX in shp2pgsql handling of MultiLine WKT.
+	- BUGFIX in affine() failing to update bounding box.
+	- WKT parser: forbidden construction of multigeometries with
+	  EMPTY elements (still supported for GEOMETRYCOLLECTION).
+	- Added --with-proj-libdir and --with-geos-libdir configure
+	  switches.
+	- JDBC:
+	    - Improved regression tests: MultiPoint and scientific ordinates
+	    - Fixed some minor bugs in jdbc code
+	    - Added proper accessor functions for all fields in preparation of
+	      making those fields private later
+	- Support for build Tru64 build.
+	- Use Jade for generating documentation.
+	- NEW DumpRings() function.
+	- BUGFIX in distance(poly,poly) giving wrong results.
+	- NEW AsHEXEWKB(geom, XDR|NDR) function.
+	- Don't link pgsql2shp to more libs then required.
+	- Initial support for PostgreSQL 8.2.
+
 PostGIS 1.1.2
 2006/03/30
 

Modified: packages/postgis/trunk/GNUmakefile
===================================================================
--- packages/postgis/trunk/GNUmakefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/GNUmakefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -29,7 +29,7 @@
 	$(MAKE) distclean
 	rm -f configure
 
-test: 
+test check: 
 	$(MAKE) -C regress test
 
 test-clean:

Copied: packages/postgis/trunk/HOWTO_RELEASE (from rev 484, packages/postgis/upstream/HOWTO_RELEASE)

Modified: packages/postgis/trunk/Makefile
===================================================================
--- packages/postgis/trunk/Makefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/Makefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -2,7 +2,7 @@
 # this file copied and adapted from PostgreSQL source
 # to allow easy build on BSD systems
 
-all install uninstall clean distclean maintainer-clean test docs docs-install docs-uninstall utils:
+all install uninstall clean distclean maintainer-clean test check docs docs-install docs-uninstall utils:
 	@IFS=':' ; \
 	 for dir in $$PATH; do \
 	   for prog in gmake gnumake make; do \

Modified: packages/postgis/trunk/Makefile.config.in
===================================================================
--- packages/postgis/trunk/Makefile.config.in	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/Makefile.config.in	2006-07-20 16:49:42 UTC (rev 485)
@@ -17,6 +17,7 @@
 #
 USE_PROJ=@USE_PROJ@
 PROJ_DIR=@PROJ_DIR@
+PROJ_LIBDIR=@PROJ_LIBDIR@
 
 #
 # Set USE_GEOS to 1 for GEOS spatial predicate and operator
@@ -32,6 +33,7 @@
 #
 USE_GEOS=@USE_GEOS@
 GEOS_DIR=@GEOS_DIR@
+GEOS_LDFLAGS=@GEOS_LDFLAGS@
 # EXPERIMENTAL! use geos C-API (only available with GEOS-2.2.x and up)
 USE_GEOS_CAPI=@USE_GEOS_CAPI@
 
@@ -85,6 +87,7 @@
 XSLBASE=@XSLBASE@
 XSLTPROC=@XSLTPROC@
 PDFXMLTEX=@PDFXMLTEX@
+DB2PDF=@DB2PDF@
 JW=@JW@
 DOC_RULE=@DOC_RULE@
 
@@ -103,6 +106,7 @@
 YACC=@YACC@
 LN_S=@LN_S@
 INSTALL=@INSTALL@ -c
+PWDREGRESS=@PWDREGRESS@
 INSTALL_DATA=$(INSTALL) -m 644
 INSTALL_BIN=$(INSTALL) -m 755
 INSTALL_LIB=$(INSTALL) -m 755

Modified: packages/postgis/trunk/README.postgis
===================================================================
--- packages/postgis/trunk/README.postgis	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/README.postgis	2006-07-20 16:49:42 UTC (rev 485)
@@ -99,7 +99,7 @@
 You want to run regress tests before installation.
 To do so, as postgres run:
 
-	make test
+	make check
 
 Final lines of output contain a summary of test results:
 run, succeeded, failed. If you have any failure please

Modified: packages/postgis/trunk/TODO
===================================================================
--- packages/postgis/trunk/TODO	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/TODO	2006-07-20 16:49:42 UTC (rev 485)
@@ -9,14 +9,6 @@
 - casts between PostGIS and PostgreSQL geometry classes
 
 ======================================
-2005/12/16 - PostGIS 1.1.0 closeup
-======================================
-
-- TEST TEST TEST (upgrades mainly)
-
-- Remove type-punned warnings given by gcc-3.3 ?
-
-======================================
 2005/12/14 - other random items 
 ======================================
 
@@ -31,7 +23,7 @@
 
 - LineMerge and Polygonize* interfaces for JTS
 
-- More LRS functions
+- More LRS functions ?
 
 - Selectivity estimation code merge (+- pgsql-8.0.0)
 	

Modified: packages/postgis/trunk/Version.config
===================================================================
--- packages/postgis/trunk/Version.config	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/Version.config	2006-07-20 16:49:42 UTC (rev 485)
@@ -4,9 +4,9 @@
 # shared library / release version
 SO_MAJOR_VERSION=1
 SO_MINOR_VERSION=1
-SO_MICRO_VERSION=2
+SO_MICRO_VERSION=3
 
 # JDBC code version
 JDBC_MAJOR_VERSION=1
 JDBC_MINOR_VERSION=1
-JDBC_MICRO_VERSION=0
+JDBC_MICRO_VERSION=3

Copied: packages/postgis/trunk/autom4te.cache (from rev 484, packages/postgis/upstream/autom4te.cache)

Modified: packages/postgis/trunk/configure
===================================================================
--- packages/postgis/trunk/configure	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/configure	2006-07-20 16:49:42 UTC (rev 485)
@@ -309,7 +309,7 @@
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX LN_S USE_ICONV ICONV_LDFLAGS CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os PGCONFIG PGFEINCLUDES PGBEINCLUDES PGFELIBS PGBELIBS PGBIN PGTEMPLATE LPATH USE_GEOS GEOS_DIR USE_GEOS_CAPI GEOSCONFIG USE_PROJ PROJ_DIR PROJ USE_JTS JTS_INCLUDES JTS_LIBDIR JTSCONFIG FLEX DLLWRAP DLLTOOL YACC INSTALL PERL docdir XSLBASE XSLTPROC PDFXMLTEX JW DOC_RULE PORTNAME DLSUFFIX DLFLAGS EXE HOST_OS ELF_SYS LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX LN_S USE_ICONV ICONV_LDFLAGS CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os PGCONFIG PGFEINCLUDES PGBEINCLUDES PGFELIBS PGBELIBS PGBIN PGTEMPLATE LPATH PWDREGRESS USE_GEOS GEOS_DIR GEOS_LDFLAGS USE_GEOS_CAPI GEOSCONFIG USE_PROJ PROJ_DIR PROJ_LIBDIR PROJ USE_JTS JTS_INCLUDES JTS_LIBDIR JTSCONFIG FLEX DLLWRAP DLLTOOL YACC INSTALL PERL docdir XSLBASE XSLTPROC PDFXMLTEX DB2PDF JW DOC_RULE PORTNAME DLSUFFIX DLFLAGS EXE HOST_OS ELF_SYS LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -857,7 +857,10 @@
                           [ARG=path to pg_config]
   --with-geos[=ARG]       enable spatial predicates and operators using GEOS
                           [ARG=path to geos-config]
+  --with-geos-libdir=PATH path to GEOS libdir
+                          [taken from geos-config by default]
   --with-proj[=DIR]       enable reprojection support
+  --with-proj-libdir=PATH path to PROJ4 libdir
   --with-jts[=ARG]        use JTS for spatial predicates and operators
                           [ARG=path to jts-config]
   --with-docdir=DIR       install the documentation in DIR [PREFIX/share/doc]
@@ -2697,6 +2700,75 @@
 		ICONV_LDFLAGS=-liconv
 
 else
+  echo "$as_me:$LINENO: checking for libiconv_open in -liconv" >&5
+echo $ECHO_N "checking for libiconv_open in -liconv... $ECHO_C" >&6
+if test "${ac_cv_lib_iconv_libiconv_open+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-liconv  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char libiconv_open ();
+int
+main ()
+{
+libiconv_open ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_iconv_libiconv_open=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_iconv_libiconv_open=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_iconv_libiconv_open" >&5
+echo "${ECHO_T}$ac_cv_lib_iconv_libiconv_open" >&6
+if test $ac_cv_lib_iconv_libiconv_open = yes; then
+  USE_ICONV=1
+			ICONV_LDFLAGS=-liconv
+
+else
   echo "$as_me:$LINENO: checking for iconv_open in -lc" >&5
 echo $ECHO_N "checking for iconv_open in -lc... $ECHO_C" >&6
 if test "${ac_cv_lib_c_iconv_open+set}" = set; then
@@ -2773,8 +2845,11 @@
 
 fi
 
+
 fi
 
+fi
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3566,18 +3641,33 @@
 
 
 PGFEINCLUDES="-I"`${PGCONFIG} --includedir`
-PGFELIBS="-L"`${PGCONFIG} --libdir`" -lpq "`${PGCONFIG} --libs 2> /dev/null`
+PGFELIBS="-L"`${PGCONFIG} --libdir`" -lpq " #(1)# `${PGCONFIG} --libs 2> /dev/null`
+#(1)#
+# We don't really want to link to more libs then required, see:
+# http://postgis.refractions.net/pipermail/postgis-devel/2006-May/002124.html
 PGBELIBS="-L"`${PGCONFIG} --libdir`" -lpostgres"
 PGBEINCLUDES="-I"`${PGCONFIG} --includedir-server`
 PGBIN=`${PGCONFIG} --bindir`
 
+case $host_os in
+	*mingw*)
+		PWDREGRESS="pwd -W"
+		;;
+	*)
+		PWDREGRESS="pwd"
+		;;
+esac
 
 
 
 
+
+
+
 USE_GEOS=0
 USE_GEOS_CAPI=0
 GEOS_DIR=
+GEOS_LDFLAGS=
 
 # Extract the first word of "geos-config", so it can be a program name with args.
 set dummy geos-config; ac_word=$2
@@ -3645,6 +3735,7 @@
 
 if test $USE_GEOS -gt 0; then
 	GEOS_DIR=`$GEOSCONFIG --prefix`
+	GEOS_LDFLAGS=`$GEOSCONFIG --ldflags`
 	GEOS_MAJOR=`$GEOSCONFIG --version | cut -d. -f1`
 	if test "$GEOS_MAJOR" = "@GEOS_VERSION@"; then
 		GEOS_MAJOR=1
@@ -3660,10 +3751,32 @@
 fi
 
 
+# Check whether --with-geos-libdir or --without-geos-libdir was given.
+if test "${with_geos_libdir+set}" = set; then
+  withval="$with_geos_libdir"
 
+case "$with_geos_libdir" in
+	no|yes)
+		{ { echo "$as_me:$LINENO: error: Invalid argument to --with-geos-libdir" >&5
+echo "$as_me: error: Invalid argument to --with-geos-libdir" >&2;}
+   { (exit 1); exit 1; }; }
+		;;
+	*)
+		GEOS_LDFLAGS=-L${with_geos_libdir}
+		;;
+esac
 
+else
+  with_geos_libdir=no
+fi;
+
+
+
+
+
 USE_PROJ=0
 PROJ_DIR=
+PROJ_LIBDIR=
 # Extract the first word of "proj", so it can be a program name with args.
 set dummy proj; ac_word=$2
 echo "$as_me:$LINENO: checking for $ac_word" >&5
@@ -3728,11 +3841,32 @@
 echo "$as_me: error: Can't find proj dir." >&2;}
    { (exit 1); exit 1; }; };
 	fi
+	PROJ_LIBDIR=${PROJ_DIR}/lib
 fi
 
 
+# Check whether --with-proj-libdir or --without-proj-libdir was given.
+if test "${with_proj_libdir+set}" = set; then
+  withval="$with_proj_libdir"
 
+case "$with_proj_libdir" in
+	no|yes)
+		{ { echo "$as_me:$LINENO: error: Invalid argument to --with-proj-libdir" >&5
+echo "$as_me: error: Invalid argument to --with-proj-libdir" >&2;}
+   { (exit 1); exit 1; }; }
+		;;
+	*)
+		PROJ_LIBDIR=${with_proj_libdir}
+		;;
+esac
 
+else
+  with_proj_libdir=no
+fi;
+
+
+
+
 USE_JTS=0
 JTS_INCLUDES=
 JTS_INCLUDES=
@@ -3932,38 +4066,35 @@
 fi
 
 
-
-# Extract the first word of "yacc", so it can be a program name with args.
-set dummy yacc; ac_word=$2
+for ac_prog in 'bison -y' byacc
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
 echo "$as_me:$LINENO: checking for $ac_word" >&5
 echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
-if test "${ac_cv_path_YACC+set}" = set; then
+if test "${ac_cv_prog_YACC+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  case $YACC in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_YACC="$YACC" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  if test -n "$YACC"; then
+  ac_cv_prog_YACC="$YACC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
   if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_YACC="$as_dir/$ac_word$ac_exec_ext"
+    ac_cv_prog_YACC="$ac_prog"
     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
 done
 
-  ;;
-esac
 fi
-YACC=$ac_cv_path_YACC
-
+fi
+YACC=$ac_cv_prog_YACC
 if test -n "$YACC"; then
   echo "$as_me:$LINENO: result: $YACC" >&5
 echo "${ECHO_T}$YACC" >&6
@@ -3972,6 +4103,10 @@
 echo "${ECHO_T}no" >&6
 fi
 
+  test -n "$YACC" && break
+done
+test -n "$YACC" || YACC="yacc"
+
 if test -z "$YACC"; then
 	{ { echo "$as_me:$LINENO: error: Can't find 'yacc'" >&5
 echo "$as_me: error: Can't find 'yacc'" >&2;}
@@ -4136,6 +4271,45 @@
 echo "${ECHO_T}no" >&6
 fi
 
+# Extract the first word of "db2pdf", so it can be a program name with args.
+set dummy db2pdf; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_path_DB2PDF+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  case $DB2PDF in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DB2PDF="$DB2PDF" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DB2PDF="$as_dir/$ac_word$ac_exec_ext"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+  ;;
+esac
+fi
+DB2PDF=$ac_cv_path_DB2PDF
+
+if test -n "$DB2PDF"; then
+  echo "$as_me:$LINENO: result: $DB2PDF" >&5
+echo "${ECHO_T}$DB2PDF" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
 # Extract the first word of "jw", so it can be a program name with args.
 set dummy jw; ac_word=$2
 echo "$as_me:$LINENO: checking for $ac_word" >&5
@@ -5082,12 +5256,15 @@
 s, at PGBIN@,$PGBIN,;t t
 s, at PGTEMPLATE@,$PGTEMPLATE,;t t
 s, at LPATH@,$LPATH,;t t
+s, at PWDREGRESS@,$PWDREGRESS,;t t
 s, at USE_GEOS@,$USE_GEOS,;t t
 s, at GEOS_DIR@,$GEOS_DIR,;t t
+s, at GEOS_LDFLAGS@,$GEOS_LDFLAGS,;t t
 s, at USE_GEOS_CAPI@,$USE_GEOS_CAPI,;t t
 s, at GEOSCONFIG@,$GEOSCONFIG,;t t
 s, at USE_PROJ@,$USE_PROJ,;t t
 s, at PROJ_DIR@,$PROJ_DIR,;t t
+s, at PROJ_LIBDIR@,$PROJ_LIBDIR,;t t
 s, at PROJ@,$PROJ,;t t
 s, at USE_JTS@,$USE_JTS,;t t
 s, at JTS_INCLUDES@,$JTS_INCLUDES,;t t
@@ -5103,6 +5280,7 @@
 s, at XSLBASE@,$XSLBASE,;t t
 s, at XSLTPROC@,$XSLTPROC,;t t
 s, at PDFXMLTEX@,$PDFXMLTEX,;t t
+s, at DB2PDF@,$DB2PDF,;t t
 s, at JW@,$JW,;t t
 s, at DOC_RULE@,$DOC_RULE,;t t
 s, at PORTNAME@,$PORTNAME,;t t
@@ -5627,10 +5805,12 @@
 		echo "$as_me:$LINENO: result:     GEOS: $GEOSCONFIG" >&5
 echo "${ECHO_T}    GEOS: $GEOSCONFIG" >&6
 	fi
+        echo "$as_me:$LINENO: result:           (ldflags: $GEOS_LDFLAGS)" >&5
+echo "${ECHO_T}          (ldflags: $GEOS_LDFLAGS)" >&6
 fi
 if test $USE_PROJ -gt 0; then
-	echo "$as_me:$LINENO: result:     PROJ: dir=$PROJ_DIR" >&5
-echo "${ECHO_T}    PROJ: dir=$PROJ_DIR" >&6
+	echo "$as_me:$LINENO: result:     PROJ: prefix=$PROJ_DIR libdir=$PROJ_LIBDIR" >&5
+echo "${ECHO_T}    PROJ: prefix=$PROJ_DIR libdir=$PROJ_LIBDIR" >&6
 fi
 echo "$as_me:$LINENO: result:    ICONV: $USE_ICONV $ICONV_LDFLAGS" >&5
 echo "${ECHO_T}   ICONV: $USE_ICONV $ICONV_LDFLAGS" >&6

Modified: packages/postgis/trunk/configure.in
===================================================================
--- packages/postgis/trunk/configure.in	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/configure.in	2006-07-20 16:49:42 UTC (rev 485)
@@ -37,10 +37,15 @@
 		USE_ICONV=1
 		ICONV_LDFLAGS=-liconv
 		,
-		AC_CHECK_LIB(c, iconv_open,
+		AC_CHECK_LIB(iconv, libiconv_open,
 			USE_ICONV=1
+			ICONV_LDFLAGS=-liconv
 			,
-			USE_ICONV=0
+			AC_CHECK_LIB(c, iconv_open,
+				USE_ICONV=1
+				,
+				USE_ICONV=0
+			)
 		)
 	)
 fi
@@ -83,21 +88,40 @@
 AC_SUBST(PGTEMPLATE)
 AC_SUBST(LPATH)
 PGFEINCLUDES="-I"`${PGCONFIG} --includedir`
-PGFELIBS="-L"`${PGCONFIG} --libdir`" -lpq "`${PGCONFIG} --libs 2> /dev/null`
+PGFELIBS="-L"`${PGCONFIG} --libdir`" -lpq " #(1)# `${PGCONFIG} --libs 2> /dev/null`
+#(1)#
+# We don't really want to link to more libs then required, see:
+# http://postgis.refractions.net/pipermail/postgis-devel/2006-May/002124.html
 PGBELIBS="-L"`${PGCONFIG} --libdir`" -lpostgres"
 PGBEINCLUDES="-I"`${PGCONFIG} --includedir-server`
 PGBIN=`${PGCONFIG} --bindir`
 
 dnl
+dnl MingW requires use of pwd -W to give proper Windows (not MingW) paths
+dnl for in-place regression tests
+dnl
+case $host_os in
+	*mingw*)
+		PWDREGRESS="pwd -W"
+		;;
+	*)
+		PWDREGRESS="pwd"
+		;;
+esac
+AC_SUBST(PWDREGRESS)
+
+dnl
 dnl Test for GEOS
 dnl
 
 AC_SUBST(USE_GEOS)
 AC_SUBST(GEOS_DIR)
+AC_SUBST(GEOS_LDFLAGS)
 AC_SUBST(USE_GEOS_CAPI)
 USE_GEOS=0
 USE_GEOS_CAPI=0
 GEOS_DIR=
+GEOS_LDFLAGS=
 
 AC_PATH_PROG([GEOSCONFIG], [geos-config])
 if test -n "$GEOSCONFIG"; then
@@ -123,6 +147,7 @@
 
 if test $USE_GEOS -gt 0; then
 	GEOS_DIR=`$GEOSCONFIG --prefix`
+	GEOS_LDFLAGS=`$GEOSCONFIG --ldflags`
 	GEOS_MAJOR=`$GEOSCONFIG --version | cut -d. -f1`
 	if test "$GEOS_MAJOR" = "@GEOS_VERSION@"; then
 		GEOS_MAJOR=1
@@ -137,6 +162,20 @@
 	fi
 fi
 
+AC_ARG_WITH(geos-libdir,
+[  --with-geos-libdir=PATH path to GEOS libdir
+                          [[taken from geos-config by default]]],
+[
+case "$with_geos_libdir" in
+	no|yes)
+		AC_MSG_ERROR([Invalid argument to --with-geos-libdir])
+		;;
+	*)
+		GEOS_LDFLAGS=-L${with_geos_libdir}
+		;;
+esac
+], with_geos_libdir=no)
+
 dnl AC_ARG_WITH(geos-capi, 
 dnl [  --with-geos-capi        enable use of GEOS C API ],
 dnl 	if test "$with_geos_capi" != "no"; then
@@ -146,8 +185,10 @@
 
 AC_SUBST(USE_PROJ)
 AC_SUBST(PROJ_DIR)
+AC_SUBST(PROJ_LIBDIR)
 USE_PROJ=0
 PROJ_DIR=
+PROJ_LIBDIR=
 AC_PATH_PROG([PROJ], [proj])
 if test -n "$PROJ"; then
 	USE_PROJ=1
@@ -169,8 +210,22 @@
 	if test ! -f $PROJ_DIR/include/projects.h; then
 		AC_MSG_ERROR([Can't find proj dir.]);
 	fi
+	PROJ_LIBDIR=${PROJ_DIR}/lib
 fi
 
+AC_ARG_WITH(proj-libdir,
+[  --with-proj-libdir=PATH path to PROJ4 libdir],
+[
+case "$with_proj_libdir" in
+	no|yes)
+		AC_MSG_ERROR([Invalid argument to --with-proj-libdir])
+		;;
+	*)
+		PROJ_LIBDIR=${with_proj_libdir}
+		;;
+esac
+], with_proj_libdir=no)
+
 AC_SUBST(USE_JTS)
 AC_SUBST(JTS_INCLUDES)
 AC_SUBST(JTS_LIBDIR)
@@ -216,8 +271,9 @@
 AC_SUBST(DLLTOOL)
 AC_PATH_PROG([DLLTOOL], [dlltool])
 
-AC_SUBST(YACC)
-AC_PATH_PROG([YACC], [yacc])
+dnl AC_SUBST(YACC)
+dnl AC_PATH_PROG([YACC], [yacc])
+AC_PROG_YACC
 if test -z "$YACC"; then
 	AC_MSG_ERROR(Can't find 'yacc');
 fi
@@ -275,6 +331,7 @@
 dnl
 AC_PATH_PROG([XSLTPROC], [xsltproc])
 AC_PATH_PROG([PDFXMLTEX], [pdfxmltex])
+AC_PATH_PROG([DB2PDF], [db2pdf])
 AC_PATH_PROG([JW], [jw])
 AC_SUBST(XSLTPROC)
 AC_SUBST(PDFXMLTEX)
@@ -535,9 +592,10 @@
 	else
 		AC_MSG_RESULT([    GEOS: $GEOSCONFIG])
 	fi
+        AC_MSG_RESULT([          (ldflags: $GEOS_LDFLAGS)])
 fi
 if test $USE_PROJ -gt 0; then
-	AC_MSG_RESULT([    PROJ: dir=$PROJ_DIR])
+	AC_MSG_RESULT([    PROJ: prefix=$PROJ_DIR libdir=$PROJ_LIBDIR])
 fi
 AC_MSG_RESULT([   ICONV: $USE_ICONV $ICONV_LDFLAGS])
 dnl AC_MSG_RESULT([  FLEX:  path=$FLEX])

Copied: packages/postgis/trunk/doc/.cvsignore (from rev 484, packages/postgis/upstream/doc/.cvsignore)

Modified: packages/postgis/trunk/doc/Makefile
===================================================================
--- packages/postgis/trunk/doc/Makefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/doc/Makefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -3,13 +3,19 @@
 
 LAST_RELEASE_VERSION = $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION).$(SO_MICRO_VERSION)
 
-COMMONOPTS = -f docbook -b html -e no-valid
-XSLTPROC_COMMONOPTS = --param section.autolabel 1 \
+JW_COMMONOPTS = -f docbook -b html -e no-valid
+
+XSLTPROC_COMMONOPTS = \
+	--param section.autolabel 1 \
 	--param section.label.includes.component.label 1 \
 	--param chunk.section.depth 0 
+
 XSLTPROC_HTMLOPTS = \
 	--stringparam html.stylesheet style.css \
 
+HTML_DOCBOOK_XSL=$(XSLBASE)/html/docbook.xsl 
+CHUNK_HTML_DOCBOOK_XSL=$(XSLBASE)/html/chunk.xsl 
+FO_DOCBOOK_XSL=$(XSLBASE)/fo/docbook.xsl
 
 all: $(DOC_RULE)
 
@@ -22,20 +28,20 @@
 	@echo "  http://postgis.refractions.net/docs"
 	@echo
 
-postgis-out.xml: postgis.xml ../Version.config
+postgis-out.xml: postgis.xml long_xact.xml ../Version.config
 	cat $< | sed "s/@@LAST_RELEASE_VERSION@@/$(LAST_RELEASE_VERSION)/g" > $@
 
 chunked-html: postgis-out.xml
 	$(XSLTPROC) $(XSLTPROC_COMMONOPTS) $(XSLTPROC_HTMLOPTS) \
 		--output html/ \
 		--stringparam saxon.character.representation decimal \
-		$(XSLBASE)/html/chunk.xsl \
+		$(CHUNK_HTML_DOCBOOK_XSL) \
 		$<
 
 html/postgis.html: postgis-out.xml
-	$(XSLTPROC) $(XSLTPROC_COMMONOPTS) \
+	$(XSLTPROC) $(XSLTPROC_COMMONOPTS) $(XSLTPROC_HTMLOPTS) \
 		--output html/postgis.html \
-		$(XSLBASE)/html/docbook.xsl \
+		$(HTML_DOCBOOK_XSL) \
 		$<
 
 postgis.fo: postgis-out.xml
@@ -46,12 +52,26 @@
 
 html: html/postgis.html
 
-postgis.pdf: postgis.fo
-	$(PDFXMLTEX) $< > /dev/null ; \
-	$(PDFXMLTEX) $< > /dev/null
+postgis.pdf: postgis-out.xml
+	@if test x"$(DB2PDF)" = x; then \
+	   echo "Error: db2pdf not found, can't build posgis.pdf"; \
+	   echo "       try installing docbook-utils package"; \
+	   false; \
+	else \
+	   $(DB2PDF) $< && mv postgis-out.pdf postgis.pdf; \
+	fi
 
+# this is broken
+_postgis.pdf: postgis.fo
+	@if test x"$(PDFXMLTEX)" = x; then \
+	   echo "Error: pdfxmltex not found, can't build posgis.pdf"; \
+	   false; \
+	else \
+	   $(PDFXMLTEX) $<;  \
+	fi
+
 jw: postgis-out.xml
-	$(JW) $(COMMONOPTS) -o html/ postgis-out.xml
+	$(JW) $(JW_COMMONOPTS) -o html/ postgis-out.xml
 
 clean:
 	@rm -f \

Copied: packages/postgis/trunk/doc/README (from rev 484, packages/postgis/upstream/doc/README)

Copied: packages/postgis/trunk/doc/html/.cvsignore (from rev 484, packages/postgis/upstream/doc/html/.cvsignore)

Copied: packages/postgis/trunk/doc/html/apa.html (from rev 484, packages/postgis/upstream/doc/html/apa.html)

Copied: packages/postgis/trunk/doc/html/ch01.html (from rev 484, packages/postgis/upstream/doc/html/ch01.html)

Copied: packages/postgis/trunk/doc/html/ch02.html (from rev 484, packages/postgis/upstream/doc/html/ch02.html)

Copied: packages/postgis/trunk/doc/html/ch03.html (from rev 484, packages/postgis/upstream/doc/html/ch03.html)

Copied: packages/postgis/trunk/doc/html/ch04.html (from rev 484, packages/postgis/upstream/doc/html/ch04.html)

Copied: packages/postgis/trunk/doc/html/ch05.html (from rev 484, packages/postgis/upstream/doc/html/ch05.html)

Copied: packages/postgis/trunk/doc/html/ch06.html (from rev 484, packages/postgis/upstream/doc/html/ch06.html)

Copied: packages/postgis/trunk/doc/html/ch07.html (from rev 484, packages/postgis/upstream/doc/html/ch07.html)

Copied: packages/postgis/trunk/doc/html/index.html (from rev 484, packages/postgis/upstream/doc/html/index.html)

Deleted: packages/postgis/trunk/doc/html/postgis.html
===================================================================
--- packages/postgis/trunk/doc/html/postgis.html	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/doc/html/postgis.html	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,1981 +0,0 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>PostGIS Manual</title><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.2"></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="id2686101"></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.2</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="#id2687796">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="#id2685716">1.2. More Information</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id2685832">2. Installation</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2685838">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="#id2687189">2.2.2. Common Problems</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2747398">2.3. JDBC</a></span></dt><dt><span class="sect1"><a href="#id2747474">2.4. Loader/Dumper</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id2747513">3. Frequently Asked Questions</a></span></dt><dt><span class="chapter"><a href="#id2747968">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="#id2747995">4.1.1. OpenGIS WKB and WKT</a></span></dt><dt><span class="sect2"><a href="#id2748107">4.1.2. PostGIS EWKB, EWKT and Canonical Forms</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2748263">4.2. Using OpenGIS Standards</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2748296">4.2.1. The SPATIAL_REF_SYS Table</a></span></dt><dt><span class="sect2"><a href="#id2748498">4.2.2. The GEOMETRY_COLUMNS Table</a></span></dt><dt><span class="sect2"><a href="#id2748632">4.2.3. Creating a Spatial Table</a></span></dt><dt><span class="sect2"><a href="#id2748738">4.2.4. Ensuring OpenGIS compliancy of geometries</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2748828">4.3. Loading GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2748842">4.3.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2748897">4.3.2. Using the Loader</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2749127">4.4. Retrieving GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2749140">4.4.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2685584">4.4.2. Using the Dumper</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2749611">4.5. Building Indexes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2749664">4.5.1. GiST Indexes</a></span></dt><dt><span class="sect2"><a href="#id2749738">4.5.2. Using Indexes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2749856">4.6. Complex Queries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2749875">4.6.1. Taking Advantage of Indexes</a></span></dt><dt><span class="sect2"><a href="#id2749970">4.6.2. Examples of Spatial SQL</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2750286">4.7. Using Mapserver</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2750329">4.7.1. Basic Usage</a></span></dt><dt><span class="sect2"><a href="#id2750577">4.7.2. Frequently Asked Questions</a></span></dt><dt><span class="sect2"><a href="#id2750744">4.7.3. Advanced Usage</a></span></dt><dt><span class="sect2"><a href="#id2750903">4.7.4. Examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2751001">4.8. Java Clients (JDBC)</a></span></dt><dt><span class="sect1"><a href="#id2751108">4.9. C Clients (libpq)</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2751117">4.9.1. Text Cursors</a></span></dt><dt><span class="sect2"><a href="#id2751127">4.9.2. Binary Cursors</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#id2751140">5. Performance tips</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2751145">5.1. Small tables of large geometries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2751151">5.1.1. Problem description</a></span></dt><dt><span class="sect2"><a href="#id2751203">5.1.2. Workarounds</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2751264">5.2. CLUSTERing on geometry indices</a></span></dt><dt><span class="sect1"><a href="#id2751319">5.3. Avoiding dimension conversion</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id2751363">6. PostGIS Reference</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2751375">6.1. OpenGIS Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2751381">6.1.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2751471">6.1.2. Geometry Relationship Functions</a></span></dt><dt><span class="sect2"><a href="#id2751848">6.1.3. Geometry Processing Functions</a></span></dt><dt><span class="sect2"><a href="#id2752174">6.1.4. Geometry Accessors</a></span></dt><dt><span class="sect2"><a href="#id2752660">6.1.5. Geometry Constructors</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2753262">6.2. Postgis Extensions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2753268">6.2.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2753593">6.2.2. Operators</a></span></dt><dt><span class="sect2"><a href="#id2753800">6.2.3. Measurement Functions</a></span></dt><dt><span class="sect2"><a href="#id2754089">6.2.4. Geometry Outputs</a></span></dt><dt><span class="sect2"><a href="#id2754182">6.2.5. Geometry Constructors</a></span></dt><dt><span class="sect2"><a href="#id2754500">6.2.6. Geometry Editors</a></span></dt><dt><span class="sect2"><a href="#id2755096">6.2.7. Linear Referencing</a></span></dt><dt><span class="sect2"><a href="#id2755316">6.2.8. Misc</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#id2755691">7. Reporting Bugs</a></span></dt><dt><span class="appendix"><a href="#release_notes">A. Release Notes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2755763">A.1. Release 1.1.2</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2755781">A.1.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2755831">A.1.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2755853">A.1.3. New functionalities</a></span></dt><dt><span class="sect2"><a href="#id2755881">A.1.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2755898">A.2. Release 1.1.1</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2755926">A.2.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2755972">A.2.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756007">A.2.3. New functionalities</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756028">A.3. Release 1.1.0</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756055">A.3.1. Credits</a></span></dt><dt><span class="sect2"><a href="#id2756082">A.3.2. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756135">A.3.3. New functions</a></span></dt><dt><span class="sect2"><a href="#id2756199">A.3.4. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756219">A.3.5. Function semantic changes</a></span></dt><dt><span class="sect2"><a href="#id2756235">A.3.6. Performance improvements</a></span></dt><dt><span class="sect2"><a href="#id2756251">A.3.7. JDBC2 works</a></span></dt><dt><span class="sect2"><a href="#id2756294">A.3.8. Other new things</a></span></dt><dt><span class="sect2"><a href="#id2756321">A.3.9. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756353">A.4. Release 1.0.6</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756367">A.4.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756411">A.4.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756446">A.4.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756462">A.5. Release 1.0.5</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756483">A.5.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756527">A.5.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2756554">A.5.3. Loader changes</a></span></dt><dt><span class="sect2"><a href="#id2756577">A.5.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756594">A.6. Release 1.0.4</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756609">A.6.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756653">A.6.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756685">A.6.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#rel_1.0.3_upgrading">A.7. Release 1.0.3</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756738">A.7.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756786">A.7.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756812">A.7.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756840">A.8. Release 1.0.2</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756854">A.8.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756881">A.8.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756903">A.8.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756919">A.9. Release 1.0.1</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756933">A.9.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756960">A.9.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2756975">A.9.3. Other changes/additions</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757019">A.10. Release 1.0.0</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757034">A.10.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757061">A.10.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757081">A.10.3. Other changes/additions</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757118">A.11. Release 1.0.0RC6</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757132">A.11.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757151">A.11.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757165">A.11.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757176">A.11.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757191">A.12. Release 1.0.0RC5</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757206">A.12.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757232">A.12.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757248">A.12.3. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757264">A.13. Release 1.0.0RC4</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757278">A.13.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757296">A.13.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757331">A.13.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757347">A.13.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757388">A.14. Release 1.0.0RC3</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757403">A.14.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757421">A.14.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757462">A.14.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757486">A.14.4. JDBC changes</a></span></dt><dt><span class="sect2"><a href="#id2757527">A.14.5. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757560">A.15. Release 1.0.0RC2</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757574">A.15.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757593">A.15.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757628">A.15.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757643">A.15.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757658">A.16. Release 1.0.0RC1</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757674">A.16.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757692">A.16.2. Changes</a></span></dt></dl></dd></dl></dd></dl></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2687796"></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="#id2685716">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, 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="id2685716"></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="id2685832"></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="#id2685838">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="#id2687189">2.2.2. Common Problems</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2747398">2.3. JDBC</a></span></dt><dt><span class="sect1"><a href="#id2747474">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="id2685838"></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.2
-      <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.2 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.2.tar.gz" target="_top">http://postgis.refractions.net/postgis-1.1.2.tar.gz</a>.
-          Uncompress and untar the archive.
-	  </p><pre class="programlisting"># gzip -d -c postgis-1.1.2.tar.gz | tar xvf -</pre></li><li><p>Enter the postgis-1.1.2 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. Release Notes">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="id2687189"></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="id2747398"></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="id2747474"></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.2/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="id2747513"></a>Chapter 3. Frequently Asked Questions</h2></div></div><div></div></div><div class="qandaset"><dl><dt>3.1. <a href="#id2747521">What kind of geometric objects can I store?</a></dt><dt>3.2. <a href="#id2747541">How do I insert a GIS object into the database?</a></dt><dt>3.3. <a href="#id2747637">How do I construct a spatial query?</a></dt><dt>3.4. <a href="#id2747702">How do I speed up spatial queries on large tables?</a></dt><dt>3.5. <a href="#id2747784">Why aren't PostgreSQL R-Tree indexes supported?</a></dt><dt>3.6. <a href="#id2747836">Why should I use the AddGeometryColumn()
-          function and all the other OpenGIS stuff?</a></dt><dt>3.7. <a href="#id2747884">What is the best way to find all objects within a radius of
-          another object?</a></dt><dt>3.8. <a href="#id2747936">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="id2747521"></a><a name="id2747523"></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="id2747541"></a><a name="id2747543"></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="id2747637"></a><a name="id2747639"></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="id2747702"></a><a name="id2747704"></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="id2747784"></a><a name="id2747786"></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="id2747836"></a><a name="id2747839"></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="id2747884"></a><a name="id2747886"></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="id2747936"></a><a name="id2747938"></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="id2747968"></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="#id2747995">4.1.1. OpenGIS WKB and WKT</a></span></dt><dt><span class="sect2"><a href="#id2748107">4.1.2. PostGIS EWKB, EWKT and Canonical Forms</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2748263">4.2. Using OpenGIS Standards</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2748296">4.2.1. The SPATIAL_REF_SYS Table</a></span></dt><dt><span class="sect2"><a href="#id2748498">4.2.2. The GEOMETRY_COLUMNS Table</a></span></dt><dt><span class="sect2"><a href="#id2748632">4.2.3. Creating a Spatial Table</a></span></dt><dt><span class="sect2"><a href="#id2748738">4.2.4. Ensuring OpenGIS compliancy of geometries</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2748828">4.3. Loading GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2748842">4.3.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2748897">4.3.2. Using the Loader</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2749127">4.4. Retrieving GIS Data</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2749140">4.4.1. Using SQL</a></span></dt><dt><span class="sect2"><a href="#id2685584">4.4.2. Using the Dumper</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2749611">4.5. Building Indexes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2749664">4.5.1. GiST Indexes</a></span></dt><dt><span class="sect2"><a href="#id2749738">4.5.2. Using Indexes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2749856">4.6. Complex Queries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2749875">4.6.1. Taking Advantage of Indexes</a></span></dt><dt><span class="sect2"><a href="#id2749970">4.6.2. Examples of Spatial SQL</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2750286">4.7. Using Mapserver</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2750329">4.7.1. Basic Usage</a></span></dt><dt><span class="sect2"><a href="#id2750577">4.7.2. Frequently Asked Questions</a></span></dt><dt><span class="sect2"><a href="#id2750744">4.7.3. Advanced Usage</a></span></dt><dt><span class="sect2"><a href="#id2750903">4.7.4. Examples</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2751001">4.8. Java Clients (JDBC)</a></span></dt><dt><span class="sect1"><a href="#id2751108">4.9. C Clients (libpq)</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2751117">4.9.1. Text Cursors</a></span></dt><dt><span class="sect2"><a href="#id2751127">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="id2747995"></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="id2748107"></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="id2748263"></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="id2748296"></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="id2748498"></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="id2748632"></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="id2748738"></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="id2748828"></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="id2748842"></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="id2748897"></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="id2749127"></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="id2749140"></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="id2685584"></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="id2749611"></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="id2749664"></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="id2749738"></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="id2749856"></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="id2749875"></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="id2749970"></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="#id2750017">What is the total length of all roads, expressed in
-                kilometers?</a></dt><dt>4.6.2.2. <a href="#id2750044">How large is the city of Prince George, in
-                hectares?</a></dt><dt>4.6.2.3. <a href="#id2750073">What is the largest municipality in the province, by
-                area?</a></dt><dt>4.6.2.4. <a href="#id2750115">What is the length of roads fully contained within each
-                municipality?</a></dt><dt>4.6.2.5. <a href="#id2750177">Create a new table with all the roads within the city of
-                Prince George.</a></dt><dt>4.6.2.6. <a href="#id2750216">What is the length in kilometers of "Douglas St" in
-                Victoria?</a></dt><dt>4.6.2.7. <a href="#id2750250">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="id2750017"></a><a name="id2750019"></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="id2750044"></a><a name="id2750046"></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="id2750073"></a><a name="id2750075"></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="id2750115"></a><a name="id2750117"></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="id2750177"></a><a name="id2750179"></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="id2750216"></a><a name="id2750218"></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="id2750250"></a><a name="id2750252"></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="id2750286"></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="id2750329"></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="id2750577"></a>4.7.2. Frequently Asked Questions</h3></div></div><div></div></div><div class="qandaset"><dl><dt>4.7.2.1. <a href="#id2750585">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="#id2750619">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="#id2750648">My PostGIS layer draws much slower than my Shape file
-                layer, is this normal?</a></dt><dt>4.7.2.4. <a href="#id2750686">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="id2750585"></a><a name="id2750587"></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="id2750619"></a><a name="id2750621"></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="id2750648"></a><a name="id2750650"></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="id2750686"></a><a name="id2750688"></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="id2750744"></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="id2750903"></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="id2751001"></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="id2751108"></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="id2751117"></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="id2751127"></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="id2751140"></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="#id2751145">5.1. Small tables of large geometries</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2751151">5.1.1. Problem description</a></span></dt><dt><span class="sect2"><a href="#id2751203">5.1.2. Workarounds</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2751264">5.2. CLUSTERing on geometry indices</a></span></dt><dt><span class="sect1"><a href="#id2751319">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="id2751145"></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="id2751151"></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="id2751203"></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="id2751264"></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="id2751319"></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="id2751363"></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="#id2751375">6.1. OpenGIS Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2751381">6.1.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2751471">6.1.2. Geometry Relationship Functions</a></span></dt><dt><span class="sect2"><a href="#id2751848">6.1.3. Geometry Processing Functions</a></span></dt><dt><span class="sect2"><a href="#id2752174">6.1.4. Geometry Accessors</a></span></dt><dt><span class="sect2"><a href="#id2752660">6.1.5. Geometry Constructors</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2753262">6.2. Postgis Extensions</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2753268">6.2.1. Management Functions</a></span></dt><dt><span class="sect2"><a href="#id2753593">6.2.2. Operators</a></span></dt><dt><span class="sect2"><a href="#id2753800">6.2.3. Measurement Functions</a></span></dt><dt><span class="sect2"><a href="#id2754089">6.2.4. Geometry Outputs</a></span></dt><dt><span class="sect2"><a href="#id2754182">6.2.5. Geometry Constructors</a></span></dt><dt><span class="sect2"><a href="#id2754500">6.2.6. Geometry Editors</a></span></dt><dt><span class="sect2"><a href="#id2755096">6.2.7. Linear Referencing</a></span></dt><dt><span class="sect2"><a href="#id2755316">6.2.8. Misc</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="id2751375"></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="id2751381"></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="id2751471"></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="id2751848"></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="id2752174"></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="id2752660"></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="id2753262"></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="id2753268"></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="id2753593"></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="id2753800"></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 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="id2754089"></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">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="id2754182"></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 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="#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 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>NOTE: this function is not available for
-		    builds against PostgreSQL 7.2.x</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2754500"></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 [multi]polygon having no ring 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="id2755096"></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="#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="id2755316"></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></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2755691"></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="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="release_notes"></a>Appendix A. Release Notes</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#id2755763">A.1. Release 1.1.2</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2755781">A.1.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2755831">A.1.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2755853">A.1.3. New functionalities</a></span></dt><dt><span class="sect2"><a href="#id2755881">A.1.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2755898">A.2. Release 1.1.1</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2755926">A.2.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2755972">A.2.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756007">A.2.3. New functionalities</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756028">A.3. Release 1.1.0</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756055">A.3.1. Credits</a></span></dt><dt><span class="sect2"><a href="#id2756082">A.3.2. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756135">A.3.3. New functions</a></span></dt><dt><span class="sect2"><a href="#id2756199">A.3.4. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756219">A.3.5. Function semantic changes</a></span></dt><dt><span class="sect2"><a href="#id2756235">A.3.6. Performance improvements</a></span></dt><dt><span class="sect2"><a href="#id2756251">A.3.7. JDBC2 works</a></span></dt><dt><span class="sect2"><a href="#id2756294">A.3.8. Other new things</a></span></dt><dt><span class="sect2"><a href="#id2756321">A.3.9. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756353">A.4. Release 1.0.6</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756367">A.4.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756411">A.4.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756446">A.4.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756462">A.5. Release 1.0.5</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756483">A.5.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756527">A.5.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2756554">A.5.3. Loader changes</a></span></dt><dt><span class="sect2"><a href="#id2756577">A.5.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756594">A.6. Release 1.0.4</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756609">A.6.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756653">A.6.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756685">A.6.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#rel_1.0.3_upgrading">A.7. Release 1.0.3</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756738">A.7.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756786">A.7.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756812">A.7.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756840">A.8. Release 1.0.2</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756854">A.8.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756881">A.8.2. Bug fixes</a></span></dt><dt><span class="sect2"><a href="#id2756903">A.8.3. Improvements</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2756919">A.9. Release 1.0.1</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2756933">A.9.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2756960">A.9.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2756975">A.9.3. Other changes/additions</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757019">A.10. Release 1.0.0</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757034">A.10.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757061">A.10.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757081">A.10.3. Other changes/additions</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757118">A.11. Release 1.0.0RC6</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757132">A.11.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757151">A.11.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757165">A.11.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757176">A.11.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757191">A.12. Release 1.0.0RC5</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757206">A.12.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757232">A.12.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757248">A.12.3. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757264">A.13. Release 1.0.0RC4</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757278">A.13.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757296">A.13.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757331">A.13.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757347">A.13.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757388">A.14. Release 1.0.0RC3</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757403">A.14.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757421">A.14.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757462">A.14.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757486">A.14.4. JDBC changes</a></span></dt><dt><span class="sect2"><a href="#id2757527">A.14.5. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757560">A.15. Release 1.0.0RC2</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757574">A.15.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757593">A.15.2. Library changes</a></span></dt><dt><span class="sect2"><a href="#id2757628">A.15.3. Scripts changes</a></span></dt><dt><span class="sect2"><a href="#id2757643">A.15.4. Other changes</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id2757658">A.16. Release 1.0.0RC1</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id2757674">A.16.1. Upgrading</a></span></dt><dt><span class="sect2"><a href="#id2757692">A.16.2. Changes</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="id2755763"></a>A.1. Release 1.1.2</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2755781"></a>A.1.1. Upgrading</h3></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.7. 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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2755831"></a>A.1.2. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2755853"></a>A.1.3. New functionalities</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2755881"></a>A.1.4. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2755898"></a>A.2. Release 1.1.1</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2755926"></a>A.2.1. Upgrading</h3></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.7. 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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2755972"></a>A.2.2. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756007"></a>A.2.3. New functionalities</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2756028"></a>A.3. Release 1.1.0</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756055"></a>A.3.1. Credits</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756082"></a>A.3.2. Upgrading</h3></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 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="#rel_1.0.3_upgrading" title="A.7. 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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756135"></a>A.3.3. New functions</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756199"></a>A.3.4. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756219"></a>A.3.5. Function semantic changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756235"></a>A.3.6. Performance improvements</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756251"></a>A.3.7. JDBC2 works</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756294"></a>A.3.8. Other new things</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756321"></a>A.3.9. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2756353"></a>A.4. Release 1.0.6</h2></div></div><div></div></div><p>Release date: 2005/12/06</p><p>
-Contains a few bug fixes and improvements.
-			</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756367"></a>A.4.1. Upgrading</h3></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.7. 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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756411"></a>A.4.2. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756446"></a>A.4.3. Improvements</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2756462"></a>A.5. Release 1.0.5</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756483"></a>A.5.1. Upgrading</h3></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.7. 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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756527"></a>A.5.2. Library changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756554"></a>A.5.3. Loader changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756577"></a>A.5.4. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2756594"></a>A.6. Release 1.0.4</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756609"></a>A.6.1. Upgrading</h3></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.7. 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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756653"></a>A.6.2. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756685"></a>A.6.3. Improvements</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="rel_1.0.3_upgrading"></a>A.7. Release 1.0.3</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756738"></a>A.7.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756786"></a>A.7.2. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756812"></a>A.7.3. Improvements</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2756840"></a>A.8. Release 1.0.2</h2></div></div><div></div></div><p>Release date: 2005/07/04</p><p>
-			Contains a few bug fixes and improvements.
-			</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756854"></a>A.8.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756881"></a>A.8.2. Bug fixes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756903"></a>A.8.3. Improvements</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2756919"></a>A.9. Release 1.0.1</h2></div></div><div></div></div><p>Release date: 2005/05/24</p><p>
-			Contains a few bug fixes and some improvements.
-			</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756933"></a>A.9.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756960"></a>A.9.2. Library changes</h3></div></div><div></div></div><p>BUGFIX in 3d computation of lenght_spheroid()</p><p>BUGFIX in join selectivity estimator</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2756975"></a>A.9.3. Other changes/additions</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757019"></a>A.10. Release 1.0.0</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757034"></a>A.10.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757061"></a>A.10.2. Library changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757081"></a>A.10.3. Other changes/additions</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757118"></a>A.11. Release 1.0.0RC6</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757132"></a>A.11.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757151"></a>A.11.2. Library changes</h3></div></div><div></div></div><p>BUGFIX in multi()</p><p>early return [when noop] from multi()</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757165"></a>A.11.3. Scripts changes</h3></div></div><div></div></div><p>dropped {x,y}{min,max}(box2d) functions</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757176"></a>A.11.4. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757191"></a>A.12. Release 1.0.0RC5</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757206"></a>A.12.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757232"></a>A.12.2. Library changes</h3></div></div><div></div></div><p>BUGFIX (segfaulting) in box3d computation (yes, another!).</p><p>BUGFIX (segfaulting) in estimated_extent().</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757248"></a>A.12.3. Other changes</h3></div></div><div></div></div><p>Small build scripts and utilities refinements.</p><p>Additional performance tips documented.</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757264"></a>A.13. Release 1.0.0RC4</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757278"></a>A.13.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757296"></a>A.13.2. Library changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757331"></a>A.13.3. Scripts changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757347"></a>A.13.4. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757388"></a>A.14. Release 1.0.0RC3</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757403"></a>A.14.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757421"></a>A.14.2. Library changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757462"></a>A.14.3. Scripts changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757486"></a>A.14.4. JDBC changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757527"></a>A.14.5. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757560"></a>A.15. Release 1.0.0RC2</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757574"></a>A.15.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757593"></a>A.15.2. Library changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757628"></a>A.15.3. Scripts changes</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757643"></a>A.15.4. Other changes</h3></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="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2757658"></a>A.16. Release 1.0.0RC1</h2></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757674"></a>A.16.1. Upgrading</h3></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="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2757692"></a>A.16.2. Changes</h3></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></body></html>

Copied: packages/postgis/trunk/doc/long_xact.xml (from rev 484, packages/postgis/upstream/doc/long_xact.xml)

Modified: packages/postgis/trunk/doc/postgis.xml
===================================================================
--- packages/postgis/trunk/doc/postgis.xml	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/doc/postgis.xml	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+  <!ENTITY long_xact SYSTEM "long_xact.xml">
+]>
 <book>
   <title>PostGIS Manual</title>
 
@@ -101,7 +103,8 @@
           <listitem>
             <para>
 		In alphabetical order: 
-		Alex Bodnaru, Alex Mayrhofer, Bernhard Reiter, 
+		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,
@@ -4392,6 +4395,13 @@
 			</varlistentry>
 
 			<varlistentry>
+				<term>AsHEXEWKB(geometry, {'NDR'|'XDR'})</term>
+				<listitem>
+					<para>Returns a Geometry in HEXEWKB format (as text) using either little-endian (NDR) or big-endian (XDR) encoding.</para>
+				</listitem>
+			</varlistentry>
+
+			<varlistentry>
 				<term>AsSVG(geometry, [rel], [precision])</term>
 				<listitem>
 					<para>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.</para>
@@ -4578,11 +4588,35 @@
 		    of the component inside the collection.
 		    </para>
 
-              	    <para>NOTE: this function is not available for
-		    builds against PostgreSQL 7.2.x</para>
+		<para>
+		    Availability: PostGIS 1.0.0RC1.
+		    Requires PostgreSQL 7.3 or higher.
+		</para>
+
 		  </listitem>
 		</varlistentry>
 
+		<varlistentry>
+		  <term>DumpRings(geometry)</term>
+
+		  <listitem>
+		    <para>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.
+		    </para>
+
+		<para>
+		    Availability: PostGIS 1.1.3.
+		    Requires PostgreSQL 7.3 or higher.
+		</para>
+
+		  </listitem>
+		</varlistentry>
+
 	  </variablelist>
       </sect2>
 
@@ -4901,7 +4935,7 @@
           <term>Segmentize(geometry, maxlength)</term>
 
           <listitem>
-            <para>Return a modified [multi]polygon having no ring segment
+            <para>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.</para>
@@ -5229,8 +5263,8 @@
         </variablelist>
       </sect2>
 
+      &long_xact;
 
-
     </sect1>
   </chapter>
 
@@ -5272,9 +5306,83 @@
 	</chapter>
 
 	<appendix id="release_notes">
+	<title>Appendix</title>
+
+	<sect1>
+
 		<title>Release Notes</title>
 
-    		<sect1>
+    		<sect2>
+			<title>Release 1.1.3</title>
+			<para>Release date: 2006/06/30</para>
+
+			<para>
+This is an bugfix release including also some new functionalities (most notably long transaction support) and portability enhancements.
+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 / correctness</title>
+<para> BUGFIX in distance(poly,poly) giving wrong results. </para>
+<para> BUGFIX in pgsql2shp successful return code. </para>
+<para> BUGFIX in shp2pgsql handling of MultiLine WKT. </para>
+<para> BUGFIX in affine() failing to update bounding box. </para>
+<para> WKT parser: forbidden construction of multigeometries with 
+	  EMPTY elements (still supported for GEOMETRYCOLLECTION). </para>
+			</sect3>
+
+			<sect3>
+				<title>New functionalities</title>
+<para> NEW Long Transactions support. </para>
+<para> NEW DumpRings() function. </para>
+<para> NEW AsHEXEWKB(geom, XDR|NDR) function. </para>
+			</sect3>
+
+			<sect3>
+				<title>JDBC changes</title>
+<para> Improved regression tests: MultiPoint and scientific ordinates </para>
+<para> Fixed some minor bugs in jdbc code </para>
+<para>
+Added proper accessor functions for all fields in preparation of 
+making those fields private later
+</para>
+			</sect3>
+
+			<sect3>
+				<title>Other changes</title>
+<para> NEW regress test support for loader/dumper. </para>
+<para> Added --with-proj-libdir and --with-geos-libdir configure switches. </para>
+<para> Support for build Tru64 build. </para>
+<para> Use Jade for generating documentation. </para>
+<para> Don't link pgsql2shp to more libs then required. </para>
+<para> Initial support for PostgreSQL 8.2. </para>
+			</sect3>
+
+		</sect2>
+
+    		<sect2>
 			<title>Release 1.1.2</title>
 			<para>Release date: 2006/03/30</para>
 
@@ -5283,7 +5391,7 @@
 Upgrade is <emphasis>encouraged</emphasis>.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>
@@ -5302,34 +5410,34 @@
 Upgrade from any release prior to 1.0.0RC6 requires an
 <link linkend="hard_upgrade">hard upgrade</link>.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 <para>BUGFIX in SnapToGrid() computation of output bounding box</para>
 <para>BUGFIX in EnforceRHR() </para>
 <para>jdbc2 SRID handling fixes in JTS code</para>
 <para>Fixed support for 64bit archs</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>New functionalities</title>
 <para>Regress tests can now be run *before* postgis intallation</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>
 <para>Embedded access control in estimated_extent() for builds against pgsql >= 8.0.0</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 <para>More portable ./configure script</para>
 <para>Changed ./run_test script to have more sane default behaviour</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.1.1</title>
 			<para>Release date: 2006/01/23</para>
 
@@ -5342,7 +5450,7 @@
 to be used in topological operations.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>
@@ -5361,9 +5469,9 @@
 Upgrade from any release prior to 1.0.0RC6 requires an
 <link linkend="hard_upgrade">hard upgrade</link>.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 <para>Fixed a premature exit in postgis_restore.pl </para>
 <para>BUGFIX in geometrycollection handling of GEOS-CAPI connector</para>
@@ -5372,17 +5480,17 @@
 <para>Fixed handling of postgresql paths</para>
 <para>BUGFIX in line_substring()</para>
 <para>Added support for localized cluster in regress tester</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>New functionalities</title>
 <para>New Z and M interpolation in line_substring()</para>
 <para>New Z and M interpolation in line_interpolate_point()</para>
 <para>added NumInteriorRing() alias due to OpenGIS ambiguity</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
-    		<sect1>
+		</sect2>
+    		<sect2>
 			<title>Release 1.1.0</title>
 			<para>Release date: 2005/12/21</para>
 
@@ -5399,7 +5507,7 @@
 require a rebuild of the PostGIS library.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Credits</title>
 
 				<para>
@@ -5413,9 +5521,9 @@
 the new area building functions.
 See the <link linkend="credits">credits</link> section for more names.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>
@@ -5438,9 +5546,9 @@
 Upgrade from any release prior to 1.0.0RC6 requires an
 <link linkend="hard_upgrade">hard upgrade</link>.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>New functions</title>
 <para>scale() and transscale() companion methods to translate()</para>
 <para>line_substring() </para>
@@ -5457,9 +5565,9 @@
 <para>OGC BdMPolyFromText(linestring_wkt, srid)</para>
 <para>RemovePoint(linestring, offset)</para>
 <para>ReplacePoint(linestring, offset, point)</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 <para>Fixed memory leak in polygonize()</para>
 <para>Fixed bug in lwgeom_as_anytype cast funcions</para>
@@ -5467,15 +5575,15 @@
 Fixed USE_GEOS, USE_PROJ and USE_STATS elements of postgis_version()
 output to always reflect library state.
 </para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Function semantic changes</title>
 <para>SnapToGrid doesn't discard higher dimensions</para>
 <para>Changed Z() function to return NULL if requested dimension is not available</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Performance improvements</title>
 <para>
 Much faster transform() function, caching proj4 objects
@@ -5484,9 +5592,9 @@
 Removed automatic call to fix_geometry_columns() in
 AddGeometryColumns() and update_geometry_stats()
 </para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>JDBC2 works</title>
 <para>Makefile improvements</para>
 <para>JTS support improvements</para>
@@ -5497,9 +5605,9 @@
 <para>fix compile problems in ValueSetter for ancient jdk releases.</para>
 <para>fix EWKT constructors to accept SRID=4711; representation</para>
 <para>added preliminary read-only support for java2d geometries</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other new things</title>
 <para>
 Full autoconf-based configuration, with PostgreSQL source dependency relief
@@ -5508,9 +5616,9 @@
 <para>Initial support for topology modelling</para>
 <para>Debian and RPM specfiles</para>
 <para>New lwpostgis_upgrade.sql script</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 <para>JTS support improvements</para>
 <para>Stricter mapping between DBF and SQL integer and string attributes</para>
@@ -5518,11 +5626,11 @@
 <para>old jdbc code removed from release</para>
 <para>obsoleted direct use of postgis_proc_upgrade.pl</para>
 <para>scripts version unified with release version</para>
-			</sect2>
+			</sect3>
 
 
-		</sect1>
-    		<sect1>
+		</sect2>
+    		<sect2>
 			<title>Release 1.0.6</title>
 			<para>Release date: 2005/12/06</para>
 
@@ -5530,7 +5638,7 @@
 Contains a few bug fixes and improvements.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5552,9 +5660,9 @@
 				requires an <link linkend="hard_upgrade">hard
 				upgrade</link>.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 	<para>Fixed palloc(0) call in collection deserializer (only gives problem with --enable-cassert)</para>
 	<para>Fixed bbox cache handling bugs</para>
@@ -5563,19 +5671,19 @@
 	<para>Fixed short-allocation in lwcollection_clone()</para>
 	<para>Fixed bug in segmentize()</para>
 	<para>Fixed bbox computation of SnapToGrid output</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Improvements</title>
 	<para>Initial support for postgresql 8.2</para>
 	<para>Added missing SRID mismatch checks in GEOS ops</para>
 
-			</sect2>
+			</sect3>
 
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.5</title>
 			<para>Release date: 2005/11/25</para>
 
@@ -5589,7 +5697,7 @@
 standards (return 0 on success).
 			</para></note>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5611,35 +5719,35 @@
 				requires an <link linkend="hard_upgrade">hard
 				upgrade</link>.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 	<para>Fixed memory alignment problems</para>
 	<para>Fixed computation of null values fraction in analyzer</para>
 	<para>Fixed a small bug in the getPoint4d_p() low-level function</para>
 	<para>Speedup of serializer functions</para>
 	<para>Fixed a bug in force_3dm(), force_3dz() and force_4d()</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Loader changes</title>
 	<para>Fixed return code of shp2pgsql</para>
 	<para>Fixed back-compatibility issue in loader (load of null shapefiles)</para>
 	<para>Fixed handling of trailing dots in dbf numerical attributes</para>
 	<para>Segfault fix in shp2pgsql (utf8 encoding)</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 	<para>Schema aware postgis_proc_upgrade.pl, support for pgsql 7.2+</para>
 	<para>New "Reporting Bugs" chapter in manual</para>
-			</sect2>
+			</sect3>
 
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.4</title>
 			<para>Release date: 2005/09/09</para>
 
@@ -5649,7 +5757,7 @@
 for large spatial tables.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5671,9 +5779,9 @@
 				requires an <link linkend="hard_upgrade">hard
 				upgrade</link>.
 				</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 	<para>Memory leak plugged in GiST indexing</para>
 	<para>Segfault fix in transform() handling of proj4 errors</para>
@@ -5681,9 +5789,9 @@
 	<para>Loader: fixed string functions usage, reworked NULL objects check, fixed segfault on MULTILINESTRING input.</para>
 	<para>Fixed bug in MakeLine dimension handling</para>
 	<para>Fixed bug in translate() corrupting output bounding box</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Improvements</title>
 	<para>Documentation improvements</para>
 	<para>More robust selectivity estimator </para>
@@ -5691,11 +5799,11 @@
 	<para>Minor cleanups </para>
 	<para>GiST indexing cleanup</para>
 	<para>Looser syntax acceptance in box3d parser</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1 id="rel_1.0.3_upgrading">
+    		<sect2 id="rel_1.0.3_upgrading">
 			<title>Release 1.0.3</title>
 			<para>Release date: 2005/08/08</para>
 
@@ -5704,7 +5812,7 @@
 correctness of stored geometries</emphasis> - and a few improvements.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>
@@ -5731,29 +5839,29 @@
 				</para>
 
 
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 	<para>Severe bugfix in lwgeom's 2d bounding box computation</para>
 	<para>Bugfix in WKT (-w) POINT handling in loader</para>
 	<para>Bugfix in dumper on 64bit machines</para>
 	<para>Bugfix in dumper handling of user-defined queries </para>
 	<para>Bugfix in create_undef.pl script</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Improvements</title>
 	<para>Small performance improvement in canonical input function</para>
 	<para>Minor cleanups in loader</para>
 	<para>Support for multibyte field names in loader</para>
 	<para>Improvement in the postgis_restore.pl script</para>
 	<para>New rebuild_bbox_caches.pl util script</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.2</title>
 			<para>Release date: 2005/07/04</para>
 
@@ -5761,7 +5869,7 @@
 			Contains a few bug fixes and improvements.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5773,25 +5881,25 @@
 				See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Bug fixes</title>
 	<para>Fault tolerant btree ops</para>
 	<para>Memory leak plugged in pg_error</para>
 	<para>Rtree index fix</para>
 	<para>Cleaner build scripts (avoided mix of CFLAGS and CXXFLAGS)</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Improvements</title>
 	<para>New index creation capabilities in loader (-I switch)</para>
 	<para>Initial support for postgresql 8.1dev</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.1</title>
 			<para>Release date: 2005/05/24</para>
 
@@ -5799,7 +5907,7 @@
 			Contains a few bug fixes and some improvements.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5811,15 +5919,15 @@
 				See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 	<para>BUGFIX in 3d computation of lenght_spheroid()</para>
 	<para>BUGFIX in join selectivity estimator</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes/additions</title>
 	<para>BUGFIX in shp2pgql escape functions</para>
 	<para>better support for concurrent postgis in multiple schemas</para>
@@ -5830,11 +5938,11 @@
 	<para>BUGFIX in pgsql2shp attribute names unicity enforcement</para>
 	<para>BUGFIX in Paris projections definitions</para>
 	<para>postgis_restore.pl cleanups</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0</title>
 			<para>Release date: 2005/04/19</para>
 
@@ -5844,7 +5952,7 @@
 			postgis versions), and more docs.
 			</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5856,16 +5964,16 @@
 				See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 	<para>BUGFIX in transform() releasing random memory address</para>
 	<para>BUGFIX in force_3dm() allocating less memory then required</para>
 	<para>BUGFIX in join selectivity estimator (defaults, leaks, tuplecount, sd)</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes/additions</title>
 	<para>BUGFIX in shp2pgsql escape of values starting with tab or single-quote</para>
 	<para>NEW manual pages for loader/dumper</para>
@@ -5874,54 +5982,54 @@
 	<para>NEW manual chapter about OGC compliancy enforcement</para>
 	<para>NEW autoconf support for JTS lib</para>
 	<para>BUGFIX in estimator testers (support for LWGEOM and schema parsing)</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0RC6</title>
 			<para>Release date: 2005/03/30</para>
 
 			<para>Sixth release candidate for 1.0.0.
 			Contains a few bug fixes and cleanups.</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 				<para>You need a dump/reload to upgrade
 				from precedent releases. See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 	<para>BUGFIX in multi()</para>
 	<para>early return [when noop] from multi()</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Scripts changes</title>
 	<para>dropped {x,y}{min,max}(box2d) functions</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 	<para>BUGFIX in postgis_restore.pl scrip</para>
 	<para>BUGFIX in dumper's 64bit support</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0RC5</title>
 			<para>Release date: 2005/03/25</para>
 
 			<para>Fifth release candidate for 1.0.0.
 			Contains a few bug fixes and a improvements.</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>If you are upgrading from
@@ -5933,38 +6041,38 @@
 				See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 	<para>BUGFIX (segfaulting) in box3d computation (yes, another!).</para>
 	<para>BUGFIX (segfaulting) in estimated_extent().</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 	<para>Small build scripts and utilities refinements.</para>
         <para>Additional performance tips documented.</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0RC4</title>
 			<para>Release date: 2005/03/18</para>
 
 			<para>Fourth release candidate for 1.0.0.
 			Contains bug fixes and a few improvements.</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 				<para>You need a dump/reload to upgrade
 				from precedent releases. See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 <para>BUGFIX (segfaulting) in geom_accum().</para>
 <para>BUGFIX in 64bit architectures support.</para>
@@ -5973,15 +6081,15 @@
 <para>Early return from force_collection.</para>
 <para>Consistency check fix in SnapToGrid().</para>
 <para>Box2d output changed back to 15 significant digits.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Scripts changes</title>
 <para>NEW distance_sphere() function.</para>
 <para>Changed get_proj4_from_srid implementation to use PL/PGSQL instead of SQL.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 <para>BUGFIX in loader and dumper handling of MultiLine shapes</para>
 <para>BUGFIX in loader, skipping all but first hole of polygons.</para>
@@ -5991,26 +6099,26 @@
 <para>Build scripts refinements</para>
 <para>improved version handling, central Version.config</para>
 <para>improvements in postgis_restore.pl</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0RC3</title>
 			<para>Release date: 2005/02/24</para>
 
 			<para>Third release candidate for 1.0.0.
 			Contains many bug fixes and improvements.</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 				<para>You need a dump/reload to upgrade
 				from precedent releases. See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 	<para>BUGFIX in transform(): missing SRID, better error handling.</para>
 	<para>BUGFIX in memory alignment handling</para>
@@ -6020,18 +6128,18 @@
 	<para>prefixed DEBUG macros with PGIS_ to avoid clash with pgsql one</para>
 	<para>plugged a leak in GEOS2POSTGIS converter</para>
 	<para>Reduced memory usage by early releasing query-context palloced one.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Scripts changes</title>
 	<para>BUGFIX in 72 index bindings.</para>
 	<para>BUGFIX in probe_geometry_columns() to work with PG72 and support multiple geometry columns in a single table</para>
 	<para>NEW bool::text cast</para>
 	<para>Some functions made IMMUTABLE from STABLE, for performance
 	improvement.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>JDBC changes</title>
 	<para>jdbc2: small patches, box2d/3d tests, revised docs and license.</para>
 	<para>jdbc2: bug fix and testcase in for pgjdbc 8.0 type autoregistration</para>
@@ -6041,9 +6149,9 @@
 	<para>jdbc2: added BETA support for jts geometry classes</para>
 	<para>jdbc2: Skip known-to-fail tests against older PostGIS servers.</para>
 	<para>jdbc2: Fixed handling of measured geometries in EWKT.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 	<para>new performance tips chapter in manual</para>
 	<para>documentation updates: pgsql72 requirement, lwpostgis.sql</para>
@@ -6053,27 +6161,27 @@
 	database.</para>
 	<para>spatial_ref_sys: changed Paris entries to match the ones
 	distributed with 0.x.</para>
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0RC2</title>
 			<para>Release date: 2005/01/26</para>
 
 			<para>Second release candidate for 1.0.0
 			containing bug fixes and a few improvements.</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 	
 				<para>You need a dump/reload to upgrade
 				from precedent releases. See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Library changes</title>
 
 <para>BUGFIX in pointarray box3d computation</para>
@@ -6084,27 +6192,27 @@
 <para>Faster binary outputs</para>
 <para>Stricter OGC WKB/WKT constructors</para>
 
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Scripts changes</title>
 
 <para>More correct STABLE, IMMUTABLE, STRICT uses in lwpostgis.sql</para>
 <para>stricter OGC WKB/WKT constructors</para>
 
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Other changes</title>
 
 <para>Faster and more robust loader (both i18n and not)</para>
 <para>Initial autoconf script</para>
 
-			</sect2>
+			</sect3>
 
-		</sect1>
+		</sect2>
 
-    		<sect1>
+    		<sect2>
 			<title>Release 1.0.0RC1</title>
 			<para>Release date: 2005/01/13</para>
 
@@ -6113,16 +6221,16 @@
 			storage of postgis types redesigned to be smaller
 			and faster on indexed queries.</para>
 
-			<sect2>
+			<sect3>
 				<title>Upgrading</title>
 
 				<para>You need a dump/reload to upgrade
 				from precedent releases. See the <link
 				linkend="upgrading">upgrading</link>
 				chapter for more informations.</para>
-			</sect2>
+			</sect3>
 
-			<sect2>
+			<sect3>
 				<title>Changes</title>
 
 				<para>
@@ -6169,7 +6277,8 @@
 				UTF8 support in loader.
 				</para>
 
-			</sect2>
-		</sect1>
+			</sect3>
+		</sect2>
+	</sect1>
 	</appendix>
 </book>

Modified: packages/postgis/trunk/extras/WFS_locks/Makefile
===================================================================
--- packages/postgis/trunk/extras/WFS_locks/Makefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/extras/WFS_locks/Makefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,4 +1,4 @@
-CFLAGS += -I$(shell pg_config --includedir-server)
+CFLAGS += -g -Wall -O2 -pedantic -Wno-long-long -I$(shell pg_config --includedir-server)
 CC = gcc
 MODULE_FILENAME = $(PWD)/libWFS_locks.so
 

Modified: packages/postgis/trunk/extras/WFS_locks/README
===================================================================
--- packages/postgis/trunk/extras/WFS_locks/README	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/extras/WFS_locks/README	2006-07-20 16:49:42 UTC (rev 485)
@@ -12,6 +12,12 @@
 
   Usage:
 	
+	-- Enable long transaction support
+	SELECT EnableLongTransactions();
+
+	-- Disable long transaction support
+	SELECT DisableLongTransactions();
+
 	-- Check updates and deletes of rows in
 	-- given table for being authorized.
 	-- Identify rows using <column> value.

Modified: packages/postgis/trunk/extras/WFS_locks/WFS_locks.c
===================================================================
--- packages/postgis/trunk/extras/WFS_locks/WFS_locks.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/extras/WFS_locks/WFS_locks.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -3,8 +3,10 @@
 #include "commands/trigger.h"   /* ... and triggers */
 #include "utils/lsyscache.h"	/* for get_namespace_name() */
 
-//#define PGIS_DEBUG 1
+/*#define PGIS_DEBUG 1*/
 
+#define ABORT_ON_AUTH_FAILURE 1
+
 Datum check_authorization(PG_FUNCTION_ARGS);
 
 /*
@@ -20,7 +22,8 @@
 {
 	TriggerData *trigdata = (TriggerData *) fcinfo->context;
 	char *colname;
-	HeapTuple rettuple;
+	HeapTuple rettuple_ok;
+	HeapTuple rettuple_fail;
 	TupleDesc tupdesc;
 	int SPIcode;
 	char query[1024];
@@ -29,17 +32,41 @@
 	HeapTuple tuple;
 	char *lockcode;
 	char *authtable = "authorization_table";
+	const char *op;
+#define ERRMSGLEN 256
+	char errmsg[ERRMSGLEN];
 
 
 	/* Make sure trigdata is pointing at what I expect */
-	if (!CALLED_AS_TRIGGER(fcinfo))
+	if ( ! CALLED_AS_TRIGGER(fcinfo) )
+	{
 		elog(ERROR,"check_authorization: not fired by trigger manager");
+	}
 
-	if (! (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event) ||
-		TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) )
+	if ( ! TRIGGER_FIRED_BEFORE(trigdata->tg_event) )
+	{
+		elog(ERROR,"check_authorization: not fired *before* event");
+	}
+
+	if ( TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event) )
+	{
+		rettuple_ok = trigdata->tg_newtuple;
+		rettuple_fail = NULL;
+		op = "UPDATE";
+	}
+	else if ( TRIGGER_FIRED_BY_DELETE(trigdata->tg_event) )
+	{
+		rettuple_ok = trigdata->tg_trigtuple;
+		rettuple_fail = NULL;
+		op = "DELETE";
+	}
+	else
+	{
 		elog(ERROR,"check_authorization: not fired by update or delete");
+		PG_RETURN_NULL();
+	}
 
-	rettuple = trigdata->tg_newtuple;
+
 	tupdesc = trigdata->tg_relation->rd_att;
 
 	/* Connect to SPI manager */
@@ -56,8 +83,7 @@
 		SPI_fnumber(tupdesc, colname));
 
 #if PGIS_DEBUG
-	elog(NOTICE,"check_authorization(%s.%s.%s=%s)",
-		nspname, relname, colname, pk_id);
+	elog(NOTICE,"check_authorization called");
 #endif
 
 	sprintf(query,"SELECT authid FROM \"%s\" WHERE expires >= now() AND toid = '%d' AND rid = '%s'", authtable, trigdata->tg_relation->rd_id, pk_id);
@@ -73,42 +99,37 @@
 	if (!SPI_processed )
 	{
 #if PGIS_DEBUG
-		elog(NOTICE,"there is NOT a lock on row '%s'", pk_id);
+		elog(NOTICE,"there is NO lock on row '%s'", pk_id);
 #endif
 		SPI_finish();
-		return PointerGetDatum(trigdata->tg_trigtuple);
+		return PointerGetDatum(rettuple_ok);
 	}
 
-	// there is a lock - check to see if I have rights to it!
+	/* there is a lock - check to see if I have rights to it! */
 
 	tuptable = SPI_tuptable;
-	tupdesc = SPI_tuptable->tupdesc;
+	tupdesc = tuptable->tupdesc;
 	tuple = tuptable->vals[0];
 	lockcode = SPI_getvalue(tuple, tupdesc, 1);
 
 #if PGIS_DEBUG
-	elog(NOTICE,"there is a lock on this row!");
+	elog(NOTICE, "there is a lock on row '%s' (auth: '%s').", pk_id, lockcode);
 #endif
 
-	// check to see if temp_lock_have_table table exists
-	// (it might not exist if they own no locks
+	/*
+	 * check to see if temp_lock_have_table table exists
+	 * (it might not exist if they own no locks)
+	 */
 	sprintf(query,"SELECT * FROM pg_class WHERE relname = 'temp_lock_have_table'");
 	SPIcode = SPI_exec(query,0);
 	if (SPIcode != SPI_OK_SELECT )
 		elog(ERROR,"couldnt execute to test for lockkey temp table :%s",query);
 	if (SPI_processed==0)
 	{
-		SPI_finish();
-
-		elog(ERROR,"Unauthorized modification (requires auth: '%s')",
-			lockcode);
-		elog(NOTICE,"Modificaton of row '%s' requires authorization '%s'",
-			pk_id, lockcode);
-		// ignore requested delete or update
-		return PointerGetDatum(trigdata->tg_trigtuple);
+		goto fail;
 	}
 
-	sprintf(query, "SELECT * FROM temp_lock_have_table WHERE lockcode ='%s'",lockcode);
+	sprintf(query, "SELECT * FROM temp_lock_have_table WHERE xideq( transid, getTransactionID() ) AND lockcode ='%s'", lockcode);
 
 #if PGIS_DEBUG
 	elog(NOTICE,"about to execute :%s", query);
@@ -116,7 +137,7 @@
 
 	SPIcode = SPI_exec(query,0);
 	if (SPIcode != SPI_OK_SELECT )
-		elog(ERROR,"couldnt execute to test for lock aquire: %s", query);
+		elog(ERROR, "couldnt execute to test for lock aquire: %s", query);
 
 	if (SPI_processed >0)
 	{
@@ -124,16 +145,30 @@
 		elog(NOTICE,"I own the lock - I can modify the row");
 #endif
 		SPI_finish();
-		return PointerGetDatum(rettuple);
+		return PointerGetDatum(rettuple_ok);
 	}
 
+	fail:
+
+	snprintf(errmsg, ERRMSGLEN, "%s where \"%s\" = '%s' requires authorization '%s'",
+		op, colname, pk_id, lockcode);
+	errmsg[ERRMSGLEN-1] = '\0';
+
+#ifdef ABORT_ON_AUTH_FAILURE
+	elog(ERROR, "%s", errmsg);
+#else
+	elog(NOTICE, "%s", errmsg);
+#endif
+
 	SPI_finish();
+	return PointerGetDatum(rettuple_fail);
 
-	elog(ERROR,"Unauthorized modification (requires auth: '%s')",
-		lockcode);
-	elog(NOTICE,"Modificaton of row '%s' requires authorization '%s'",
-		pk_id, lockcode);
-	// ignore the command
-	return PointerGetDatum(trigdata->tg_trigtuple);
 
 }
+
+PG_FUNCTION_INFO_V1(getTransactionID);
+Datum getTransactionID(PG_FUNCTION_ARGS)
+{
+    TransactionId xid = GetCurrentTransactionId();
+    PG_RETURN_DATUM( TransactionIdGetDatum(xid) );
+}

Modified: packages/postgis/trunk/extras/WFS_locks/WFS_locks.sql.in
===================================================================
--- packages/postgis/trunk/extras/WFS_locks/WFS_locks.sql.in	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/extras/WFS_locks/WFS_locks.sql.in	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,6 +1,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- 
--- $Id: WFS_locks.sql.in,v 1.1 2005/04/15 15:09:20 strk Exp $
+-- $Id: WFS_locks.sql.in,v 1.4 2006/06/25 22:33:55 strk Exp $
 --
 -- PostGIS - Spatial Types for PostgreSQL
 -- http://postgis.refractions.net
@@ -31,7 +31,11 @@
 # define _STRICT with(isstrict)
 #endif 
 
+#if USE_VERSION >= 73
+# define HAS_SCHEMAS 1
+#endif
 
+
 -----------------------------------------------------------------------
 -- LONG TERM LOCKING
 -----------------------------------------------------------------------
@@ -45,6 +49,11 @@
 DECLARE
 	ret int;
 BEGIN
+
+	IF NOT LongTransactionsEnabled() THEN
+		RAISE EXCEPTION ''Long transaction support disabled, use EnableLongTransaction() to enable.'';
+	END IF;
+
 	EXECUTE ''DELETE FROM authorization_table where authid = '' ||
 		quote_literal($1);
 
@@ -71,12 +80,22 @@
 	myrec RECORD;
 	
 BEGIN
+
+	IF NOT LongTransactionsEnabled() THEN
+		RAISE EXCEPTION ''Long transaction support disabled, use EnableLongTransaction() to enable.'';
+	END IF;
+
 	EXECUTE ''DELETE FROM authorization_table WHERE expires < now()''; 
 
+#ifdef HAS_SCHEMAS
 	SELECT c.oid INTO mytoid FROM pg_class c, pg_namespace n
 		WHERE c.relname = mytable
 		AND c.relnamespace = n.oid
 		AND n.nspname = myschema;
+#else
+	SELECT c.oid INTO mytoid FROM pg_class c
+		WHERE c.relname = mytable;
+#endif
 
 	-- RAISE NOTICE ''toid: %'', mytoid;
 
@@ -112,7 +131,7 @@
 CREATEFUNCTION LockRow(text, text, text)
 	RETURNS int
 	AS
-#if USE_VERSION >= 73
+#ifdef HAS_SCHEMAS
 'SELECT LockRow(current_schema(), $1, $2, $3, now()::timestamp+''1:00'');'
 #else
 'SELECT LockRow('''', $1, $2, $3, now()::timestamp+''1:00'');'
@@ -123,7 +142,7 @@
 CREATEFUNCTION LockRow(text, text, text, timestamp)
 	RETURNS int
 	AS
-#if USE_VERSION >= 73
+#ifdef HAS_SCHEMAS
 'SELECT LockRow(current_schema(), $1, $2, $3, $4);'
 #else
 'SELECT LockRow('''', $1, $2, $3, $4);'
@@ -146,14 +165,18 @@
 		okay := ''t'';
 	END LOOP; 
 	IF (okay <> ''t'') THEN 
-		CREATE TEMP TABLE temp_lock_have_table (lockcode text)
-			ON COMMIT DELETE ROWS;
+		CREATE TEMP TABLE temp_lock_have_table (transid xid, lockcode text);
+			-- this will only work from pgsql7.4 up
+			-- ON COMMIT DELETE ROWS;
 	END IF;
 
 	--  INSERT INTO mylock VALUES ( $1)
-	EXECUTE ''INSERT INTO temp_lock_have_table VALUES ( ''||
-		quote_literal(lockid) ||'')'';
+--	EXECUTE ''INSERT INTO temp_lock_have_table VALUES ( ''||
+--		quote_literal(getTransactionID()) || '','' ||
+--		quote_literal(lockid) ||'')'';
 
+	INSERT INTO temp_lock_have_table VALUES (getTransactionID(), lockid);
+
 	RETURN true::boolean;
 END;
 '
@@ -161,14 +184,22 @@
  
 
 -- CheckAuth( <schema>, <table>, <ridcolumn> )
+--
+-- Returns 0
+--
 CREATEFUNCTION CheckAuth(text, text, text)
 	RETURNS INT
 	AS '
 DECLARE
+#ifdef HAS_SCHEMAS
 	schema text;
+#endif
 BEGIN
+	IF NOT LongTransactionsEnabled() THEN
+		RAISE EXCEPTION ''Long transaction support disabled, use EnableLongTransaction() to enable.'';
+	END IF;
 
-#if USE_VERSION >= 73
+#ifdef HAS_SCHEMAS
 	if ( $1 != '''' ) THEN
 		schema = $1;
 	ELSE
@@ -176,14 +207,17 @@
 	END IF;
 #endif
 
+	-- TODO: check for an already existing trigger ?
+
 	EXECUTE ''CREATE TRIGGER check_auth BEFORE UPDATE OR DELETE ON '' 
-#if USE_VERSION >= 73
+#ifdef HAS_SCHEMAS
 		|| quote_ident(schema) || ''.'' || quote_ident($2)
 #else
 		|| quote_ident($2)
 #endif
 		||'' FOR EACH ROW EXECUTE PROCEDURE CheckAuthTrigger(''
 		|| quote_literal($3) || '')'';
+
 	RETURN 0;
 END;
 '
@@ -201,7 +235,141 @@
 	'@MODULE_FILENAME@', 'check_authorization'
 	LANGUAGE C;
 
+CREATEFUNCTION GetTransactionID()
+	RETURNS xid AS 
+	'@MODULE_FILENAME@', 'getTransactionID'
+	LANGUAGE C;
 
+
+--
+-- Enable Long transactions support
+--
+--  Creates the authorization_table if not already existing
+--
+CREATEFUNCTION EnableLongTransactions()
+	RETURNS TEXT
+	AS '
+DECLARE
+	query text;
+	exists bool;
+	rec RECORD;
+
+BEGIN
+
+	exists = ''f'';
+	FOR rec IN SELECT * FROM pg_class WHERE relname = ''authorization_table''
+	LOOP
+		exists = ''t'';
+	END LOOP;
+
+	IF NOT exists
+	THEN
+		query = ''CREATE TABLE authorization_table (
+			toid oid, -- table oid
+			rid text, -- row id
+			expires timestamp,
+			authid text
+		)'';
+		EXECUTE query;
+	END IF;
+
+	exists = ''f'';
+	FOR rec IN SELECT * FROM pg_class WHERE relname = ''authorized_tables''
+	LOOP
+		exists = ''t'';
+	END LOOP;
+
+	IF NOT exists THEN
+		query = ''CREATE VIEW authorized_tables AS '' ||
+			''SELECT '' ||
+#ifdef HAS_SCHEMAS
+			''n.nspname as schema, '' ||
+#endif
+			''c.relname as table, trim('' ||
+			quote_literal(''\\\\000'') ||
+			'' from t.tgargs) as id_column '' ||
+			''FROM pg_trigger t, pg_class c, pg_proc p '' ||
+#ifdef HAS_SCHEMAS
+			'', pg_namespace n '' ||
+#endif
+			''WHERE p.proname = '' || quote_literal(''checkauthtrigger'') ||
+#ifdef HAS_SCHEMAS
+			'' AND c.relnamespace = n.oid'' ||
+#endif
+			'' AND t.tgfoid = p.oid and t.tgrelid = c.oid'';
+		EXECUTE query;
+	END IF;
+
+	RETURN ''Long transactions support enabled'';
+END;
+'
+LANGUAGE 'plpgsql';
+
+--
+-- Check if Long transactions support is enabled
+--
+CREATEFUNCTION LongTransactionsEnabled()
+	RETURNS bool
+AS '
+DECLARE
+	rec RECORD;
+BEGIN
+	FOR rec IN SELECT oid FROM pg_class WHERE relname = ''authorized_tables''
+	LOOP
+		return ''t'';
+	END LOOP;
+	return ''f'';
+END;
+'
+LANGUAGE 'plpgsql';
+
+--
+-- Disable Long transactions support
+--
+--  (1) Drop any long_xact trigger 
+--  (2) Drop the authorization_table
+--  (3) KEEP the authorized_tables view
+--
+CREATEFUNCTION DisableLongTransactions()
+	RETURNS TEXT
+	AS '
+DECLARE
+	query text;
+	exists bool;
+	rec RECORD;
+
+BEGIN
+
+	--
+	-- Drop all triggers applied by CheckAuth()
+	--
+	FOR rec IN
+		SELECT c.relname, t.tgname, t.tgargs FROM pg_trigger t, pg_class c, pg_proc p
+		WHERE p.proname = ''checkauthtrigger'' and t.tgfoid = p.oid and t.tgrelid = c.oid
+	LOOP
+		EXECUTE ''DROP TRIGGER '' || quote_ident(rec.tgname) ||
+			'' ON '' || quote_ident(rec.relname);
+	END LOOP;
+
+	--
+	-- Drop the authorization_table table
+	--
+	FOR rec IN SELECT * FROM pg_class WHERE relname = ''authorization_table'' LOOP
+		DROP TABLE authorization_table;
+	END LOOP;
+
+	--
+	-- Drop the authorized_tables view
+	--
+	FOR rec IN SELECT * FROM pg_class WHERE relname = ''authorized_tables'' LOOP
+		DROP VIEW authorized_tables;
+	END LOOP;
+
+	RETURN ''Long transactions support disabled'';
+END;
+'
+LANGUAGE 'plpgsql';
+
 ---------------------------------------------------------------
 -- END
 ---------------------------------------------------------------

Copied: packages/postgis/trunk/extras/WFS_locks/test.sql (from rev 484, packages/postgis/upstream/extras/WFS_locks/test.sql)

Copied: packages/postgis/trunk/extras/ogc_test_suite/.cvsignore (from rev 484, packages/postgis/upstream/extras/ogc_test_suite/.cvsignore)

Modified: packages/postgis/trunk/extras/rpm/spec/postgis.spec
===================================================================
--- packages/postgis/trunk/extras/rpm/spec/postgis.spec	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/extras/rpm/spec/postgis.spec	2006-07-20 16:49:42 UTC (rev 485)
@@ -4,8 +4,8 @@
 
 Summary:        Geographic Information Systems Extensions to PostgreSQL
 Name:           postgis
-Version:        1.1.0
-Release:        2
+Version:        1.1.2
+Release:        1
 License:        GPL v2
 Group:          Applications/Databases
 Source0:        http://postgis.refractions.net/download/%{name}-%{version}.tar.gz
@@ -68,8 +68,10 @@
 rm -rf $RPM_BUILD_ROOT
 make install DESTDIR=$RPM_BUILD_ROOT PGXS=1 PGSQL_SRC=/usr/lib/pgsql/pgxs
 install lwgeom/%{name}.so $RPM_BUILD_ROOT%{_libdir}/pgsql
-install -d  $RPM_BUILD_ROOT/usr/share/pgsql/postgresql/contrib/
-install -m 755 *.sql $RPM_BUILD_ROOT/usr/share/pgsql/postgresql/contrib/
+#install -d  $RPM_BUILD_ROOT/usr/share/pgsql/postgresql/contrib/
+#install -m 755 *.sql $RPM_BUILD_ROOT/usr/share/pgsql/postgresql/contrib/
+install -d  $RPM_BUILD_ROOT/usr/share/pgsql/contrib/
+install -m 755 *.sql $RPM_BUILD_ROOT/usr/share/pgsql/contrib/
 
 %if %jdbc2
 # JDBC2
@@ -92,7 +94,7 @@
 %attr(755,root,root) %{_bindir}/*
 %attr(755,root,root) %{_libdir}/pgsql/*.so*
 #%attr(755,root,root) %{_mandir}/man1/*
-%attr(755,root,root) /usr/share/pgsql/postgresql/contrib/*
+%attr(755,root,root) /usr/share/pgsql/contrib/*
 
 %if %jdbc2
 %files jdbc2
@@ -112,6 +114,9 @@
 %endif
 
 %changelog
+* Thu May 11 2006 - Laurent WANDREBECK <lw at hygeos.com> 1.1.2-1
+- update to 1.1.2
+
 * Tue Dec 22 2005 - Devrim GUNDUZ <devrim at commandprompt.com> 1.1.0-2
 - Final fixes for 1.1.0
 

Copied: packages/postgis/trunk/extras/template_gis (from rev 484, packages/postgis/upstream/extras/template_gis)

Copied: packages/postgis/trunk/extras/wkb_reader/.cvsignore (from rev 484, packages/postgis/upstream/extras/wkb_reader/.cvsignore)

Copied: packages/postgis/trunk/jdbc2/.cvsignore (from rev 484, packages/postgis/upstream/jdbc2/.cvsignore)

Modified: packages/postgis/trunk/jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java
===================================================================
--- packages/postgis/trunk/jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java	2006-07-20 16:49:42 UTC (rev 485)
@@ -20,7 +20,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
  * http://www.gnu.org.
  * 
- * $Id: JtsGeometry.java,v 1.10 2006/02/06 20:04:33 mschaber Exp $
+ * $Id: JtsGeometry.java,v 1.11 2006/05/09 13:06:56 mschaber Exp $
  */
 
 package org.postgis.jts;
@@ -140,8 +140,14 @@
     }
 
     public boolean equals(Object obj) {
-        if (obj instanceof JtsGeometry)
-            return ((JtsGeometry) obj).getValue().equals(geom);
+        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;
     }
 }

Modified: packages/postgis/trunk/jdbc2/src/examples/TestParser.java
===================================================================
--- packages/postgis/trunk/jdbc2/src/examples/TestParser.java	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/jdbc2/src/examples/TestParser.java	2006-07-20 16:49:42 UTC (rev 485)
@@ -21,7 +21,7 @@
  * Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
  * http://www.gnu.org.
  * 
- * $Id: TestParser.java,v 1.13 2005/04/15 14:04:34 mschaber Exp $
+ * $Id: TestParser.java,v 1.16 2006/05/03 08:30:25 mschaber Exp $
  */
 
 package examples;
@@ -59,25 +59,40 @@
             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,
+            ALL, // broken format, see http://lists.jump-project.org/pipermail/jts-devel/2006-April/001572.html
             "MULTIPOINT(11 12, 20 20)"},
         {
-            ALL,
+            ALL,// broken format
             "MULTIPOINT(11 12 13, 20 20 20)"},
         {
-            ONLY10,
+            ONLY10,// broken format
             "MULTIPOINTM(11 12 13, 20 20 20)"},
         {
-            ONLY10,
+            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,
@@ -143,9 +158,12 @@
             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
+            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)))"},
@@ -158,9 +176,13 @@
             "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
+            // 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)"},
 
@@ -521,12 +543,11 @@
             dbuser = args[1];
             dbpass = args[2];
         } else {
-            System.err.println("Usage: java examples/TestParser dburls user pass [tablename]");
+            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.err.println("tablename is 'jdbc_test' by default.");
             System.exit(1);
             // Signal the compiler that code flow ends here.
             return;

Modified: packages/postgis/trunk/jdbc2/src/org/postgis/Geometry.java
===================================================================
--- packages/postgis/trunk/jdbc2/src/org/postgis/Geometry.java	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/jdbc2/src/org/postgis/Geometry.java	2006-07-20 16:49:42 UTC (rev 485)
@@ -21,7 +21,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
  * http://www.gnu.org.
  * 
- * $Id: Geometry.java,v 1.7 2005/07/28 12:23:16 mschaber Exp $
+ * $Id: Geometry.java,v 1.8 2006/05/09 13:06:55 mschaber Exp $
  */
 
 package org.postgis;
@@ -137,11 +137,12 @@
      * java.lang.Object equals implementation
      */
     public boolean equals(Object other) {
-        return (other instanceof Geometry) && equals((Geometry) other);
+        return (other != null) && (other instanceof Geometry) && equals((Geometry) other);
     }
 
     /**
-     * geometry specific equals implementation
+     * geometry specific equals implementation - only defined for non-null
+     * values
      */
     public boolean equals(Geometry other) {
         boolean firstline = (other != null) && (this.dimension == other.dimension)
@@ -201,7 +202,15 @@
         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() {

Modified: packages/postgis/trunk/jdbc2/src/org/postgis/Point.java
===================================================================
--- packages/postgis/trunk/jdbc2/src/org/postgis/Point.java	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/jdbc2/src/org/postgis/Point.java	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,5 +1,5 @@
 /*
- * Test.java
+ * Point.java
  * 
  * PostGIS extension for PostgreSQL JDBC driver - geometry model
  * 
@@ -21,7 +21,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
  * http://www.gnu.org.
  * 
- * $Id: Point.java,v 1.11 2005/11/16 13:04:30 mschaber Exp $
+ * $Id: Point.java,v 1.12 2006/05/10 10:47:35 mschaber Exp $
  */
 
 package org.postgis;

Copied: packages/postgis/trunk/loader/.cvsignore (from rev 484, packages/postgis/upstream/loader/.cvsignore)

Modified: packages/postgis/trunk/loader/pgsql2shp.c
===================================================================
--- packages/postgis/trunk/loader/pgsql2shp.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/loader/pgsql2shp.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: pgsql2shp.c,v 1.83 2006/02/03 20:53:36 strk Exp $
+ * $Id: pgsql2shp.c,v 1.85 2006/06/16 14:12:16 strk Exp $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
@@ -19,7 +19,7 @@
  **********************************************************************/
 
 static char rcsid[] =
-  "$Id: pgsql2shp.c,v 1.83 2006/02/03 20:53:36 strk Exp $";
+  "$Id: pgsql2shp.c,v 1.85 2006/06/16 14:12:16 strk Exp $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -58,6 +58,10 @@
 /* Define this to use HEX encoding instead of bytea encoding */
 #define HEXWKB 1
 
+/* Maximum DBF field width (according to ARCGIS) */
+#define MAX_DBF_FIELD_SIZE 255
+
+
 /*typedef unsigned long int uint32;*/
 typedef uint32_t uint32;
 typedef unsigned char byte;
@@ -149,9 +153,10 @@
 #define ZMFLAG(x) (((x)&((WKBZOFFSET)+(WKBMOFFSET)))>>30)
 
 
-static void exit_nicely(PGconn *conn){
+static void exit_nicely(PGconn *conn, int code)
+{
 	PQfinish(conn);
-	exit(1);
+	exit(code);
 }
 
 int
@@ -210,7 +215,7 @@
 	conn = PQconnectdb("");
 	if (PQstatus(conn) == CONNECTION_BAD) {
 		printf( "%s", PQerrorMessage(conn));
-		exit_nicely(conn);
+		exit_nicely(conn, 1);
 	}
 
 	/* Create temporary table for user query */
@@ -228,7 +233,7 @@
 
 	/* Initialize shapefile and database infos */
 	fprintf(stdout, "Initializing... "); fflush(stdout);
-	if ( ! initialize() ) exit_nicely(conn);
+	if ( ! initialize() ) exit_nicely(conn, 1);
 	fprintf(stdout, "Done (postgis major version: %d).\n",
 		pgis_major_version); 
 
@@ -248,7 +253,7 @@
 	res=PQexec(conn, "BEGIN");
 	if ( ! res || PQresultStatus(res) != PGRES_COMMAND_OK ) {
 		printf( "%s", PQerrorMessage(conn));
-		exit_nicely(conn);
+		exit_nicely(conn, 1);
 	}
 	PQclear(res);
 
@@ -271,7 +276,7 @@
 	free(query);
 	if ( ! res || PQresultStatus(res) != PGRES_COMMAND_OK ) {
 		printf( "MainScanQuery: %s", PQerrorMessage(conn));
-		exit_nicely(conn);
+		exit_nicely(conn, 1);
 	}
 	PQclear(res);
 
@@ -295,7 +300,7 @@
 		if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK ) {
 			printf( "RecordFetch: %s",
 				PQerrorMessage(conn));
-			exit_nicely(conn);
+			exit_nicely(conn, 1);
 		}
 
 		/* No more rows, break the loop */
@@ -307,7 +312,7 @@
 		for(i=0; i<PQntuples(res); i++)
 		{
 			/* Add record in all output files */
-			if ( ! addRecord(res, i, row) ) exit_nicely(conn);
+			if ( ! addRecord(res, i, row) ) exit_nicely(conn, 1);
 			row++; 
 		}
 
@@ -323,13 +328,13 @@
 
 	if (dbf) DBFClose(dbf);
 	if (shp) SHPClose(shp);
-	exit_nicely(conn);
 
 
 #ifdef DEBUG
 	fclose(debug);
 #endif	 /* DEBUG */
 
+	exit_nicely(conn, 0);
 	return 0;
 }
 
@@ -2091,7 +2096,7 @@
 	free(query);
 	if ( ! res3 || PQresultStatus(res3) != PGRES_TUPLES_OK ) {
 		printf( "TableOID: %s", PQerrorMessage(conn));
-		exit_nicely(conn);
+		exit_nicely(conn, 1);
 	}
 	if(PQntuples(res3) == 1 ){
 		ret = strdup(PQgetvalue(res3, 0, 0));
@@ -2772,12 +2777,22 @@
 				/* might 0 be a good size ? */
 			}
 		}
+
+		if ( size > MAX_DBF_FIELD_SIZE )
+		{
+			fprintf(stderr, "Warning: values of field '%s' "
+				"exceeding maximum dbf field width (%d) "
+				"will be truncated.\n",
+				fname, MAX_DBF_FIELD_SIZE);
+			size = MAX_DBF_FIELD_SIZE;
+		}
+
 /*printf( "FIELD_NAME: %s, SIZE: %d\n", field_name, size); */
-		
+
 		/* generic type (use string representation) */
 		if(DBFAddField(dbf, field_name, FTString, size, 0) == -1)
 		{
-			printf( "Error - String field could not "
+			fprintf(stderr, "Error - String field could not "
 					"be created.\n");
 			return 0;
 		}
@@ -3327,6 +3342,13 @@
 
 /**********************************************************************
  * $Log: pgsql2shp.c,v $
+ * Revision 1.85  2006/06/16 14:12:16  strk
+ *         - BUGFIX in pgsql2shp successful return code.
+ *         - BUGFIX in shp2pgsql handling of MultiLine WKT.
+ *
+ * Revision 1.84  2006/04/18 14:09:28  strk
+ * Limited text field size to 255 (bug #84)  [will eventually provide a switch to support wider fields ]
+ *
  * Revision 1.83  2006/02/03 20:53:36  strk
  * Swapped stdint.h (unavailable on Solaris9) with inttypes.h
  *

Modified: packages/postgis/trunk/loader/shp2pgsql.c
===================================================================
--- packages/postgis/trunk/loader/shp2pgsql.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/loader/shp2pgsql.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * $Id: shp2pgsql.c,v 1.106 2006/01/16 10:42:58 strk Exp $
+ * $Id: shp2pgsql.c,v 1.108 2006/06/16 14:12:17 strk Exp $
  *
  * 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.106 2006/01/16 10:42:58 strk Exp $";
+  "$Id: shp2pgsql.c,v 1.108 2006/06/16 14:12:17 strk Exp $";
 
 void *safe_malloc(size_t size)
 {
@@ -862,7 +862,7 @@
 
 		for ( vi=vs; vi<ve; vi++)
 		{
-			if ( vi ) printf(",");
+			if ( vi > vs ) printf(",");
 			printf("%.15g %.15g",
 				obj->padfX[vi],
 				obj->padfY[vi]);
@@ -1680,7 +1680,7 @@
 		fprintf(stderr, "utf8: malloc: %s\n", strerror (errno));
 		return NULL;
 	}
-	bzero (outputbuf, outbytesleft);
+	memset (outputbuf, 0, outbytesleft);
 	outputptr = outputbuf;
 
 	if (-1==iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft))
@@ -1698,6 +1698,13 @@
 
 /**********************************************************************
  * $Log: shp2pgsql.c,v $
+ * Revision 1.108  2006/06/16 14:12:17  strk
+ *         - BUGFIX in pgsql2shp successful return code.
+ *         - BUGFIX in shp2pgsql handling of MultiLine WKT.
+ *
+ * Revision 1.107  2006/04/18 09:16:26  strk
+ * Substituted bzero() use with memset()
+ *
  * Revision 1.106  2006/01/16 10:42:58  strk
  * Added support for Bool and Date DBF<=>PGIS mapping
  *

Copied: packages/postgis/trunk/lwgeom/.cvsignore (from rev 484, packages/postgis/upstream/lwgeom/.cvsignore)

Modified: packages/postgis/trunk/lwgeom/Makefile
===================================================================
--- packages/postgis/trunk/lwgeom/Makefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/Makefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -43,12 +43,12 @@
 		CSTAR_FLAGS += -I$(GEOS_DIR)/include 
 		GEOS_WRAPPER=
 		JTS_OBJ=lwgeom_geos_c.o
-		SHLIB_LINK += -L$(GEOS_DIR)/lib -lgeos_c
+		SHLIB_LINK += $(GEOS_LDFLAGS) -lgeos_c
 	else
 		CXXFLAGS += -I$(GEOS_DIR)/include 
 		GEOS_WRAPPER=lwgeom_geos_wrapper.o
 		JTS_OBJ=lwgeom_geos.o
-		SHLIB_LINK += -lstdc++ -L$(GEOS_DIR)/lib -lgeos
+		SHLIB_LINK += -lstdc++ $(GEOS_LDFLAGS) -lgeos
 		GEOS_RULES=detect_geos_version
 	endif
 endif
@@ -63,7 +63,7 @@
 
 ifeq ($(USE_PROJ),1)
 	override CFLAGS += -I$(PROJ_DIR)/include -DUSE_PROJ 
-	SHLIB_LINK += -L$(PROJ_DIR)/lib -lproj
+	SHLIB_LINK += -L$(PROJ_LIBDIR) -lproj
 endif
 
 override CFLAGS += $(PGBEINCLUDES) -DAUTOCACHE_BBOX=$(AUTOCACHE_BBOX) 
@@ -84,7 +84,7 @@
 
 SA_OBJS=measures.o box2d.o ptarray.o lwgeom_api.o lwgeom.o lwpoint.o lwline.o lwpoly.o lwmpoint.o lwmline.o lwmpoly.o lwcollection.o $(GEOS_WRAPPER) $(JTS_WRAPPER) wktunparse.o lwgparse.o wktparse.tab.o lex.yy.o vsprintf.o
 
-OBJS=$(SA_OBJS) liblwgeom.o lwgeom_pg.o lwgeom_debug.o lwgeom_spheroid.o lwgeom_ogc.o lwgeom_functions_analytic.o $(JTS_OBJ) lwgeom_inout.o lwgeom_estimate.o lwgeom_functions_basic.o lwgeom_gist.o lwgeom_btree.o lwgeom_transform.o stringBuffer.o lwgeom_box.o lwgeom_box3d.o lwgeom_box2dfloat4.o lwgeom_chip.o lwgeom_svg.o lwgeom_gml.o lwgeom_triggers.o lwgeom_dump.o lwgeom_functions_lrs.o
+OBJS=$(SA_OBJS) liblwgeom.o lwgeom_pg.o lwgeom_debug.o lwgeom_spheroid.o lwgeom_ogc.o lwgeom_functions_analytic.o $(JTS_OBJ) lwgeom_inout.o lwgeom_estimate.o lwgeom_functions_basic.o lwgeom_gist.o lwgeom_btree.o lwgeom_transform.o stringBuffer.o lwgeom_box.o lwgeom_box3d.o lwgeom_box2dfloat4.o lwgeom_chip.o lwgeom_svg.o lwgeom_gml.o lwgeom_triggers.o lwgeom_dump.o lwgeom_functions_lrs.o long_xact.o
 
 #OTHERS=y.output lex.yy.c wktparse.tab.c wktparse.tab.h lwpostgis.sql
 OTHERS=y.output postgis_geos_version.h
@@ -95,7 +95,7 @@
 include Makefile.shlib
 
 MODULE_FILENAME = $(LPATH)/$(shlib)
-REGRESS_MODULE_FILENAME = $(shell pwd)/$(shlib)
+REGRESS_MODULE_FILENAME = $(shell $(PWDREGRESS))/$(shlib)
 
 #---------------------------------------------------------------
 # Makefile targets
@@ -128,11 +128,11 @@
 ../lwpostgis_upgrade.sql: ../lwpostgis.sql ../utils/postgis_proc_upgrade.pl
 	$(PERL) ../utils/postgis_proc_upgrade.pl ../lwpostgis.sql > ../lwpostgis_upgrade.sql
 
-../lwpostgis.sql: lwpostgis.sql.in
+../lwpostgis.sql: lwpostgis.sql.in long_xact.sql
 	cpp -P -traditional-cpp -DUSE_VERSION=$(USE_VERSION) $< | sed -e 's:@MODULE_FILENAME@:$(MODULE_FILENAME):g;s:@POSTGIS_VERSION@:$(POSTGIS_VERSION):g;s:@POSTGIS_SCRIPTS_VERSION@:$(SCRIPTS_VERSION):g;s/@POSTGIS_BUILD_DATE@/$(POSTGIS_BUILD_DATE)/g' | grep -v '^#' > $@
 
-../regress/lwpostgis.sql: lwpostgis.sql.in
-	cpp -P -traditional-cpp -DUSE_VERSION=$(USE_VERSION) $< | sed -e 's:@MODULE_FILENAME@:$(REGRESS_MODULE_FILENAME):g;s:@POSTGIS_VERSION@:$(POSTGIS_VERSION):g;s:@POSTGIS_SCRIPTS_VERSION@:$(SCRIPTS_VERSION):g;s/@POSTGIS_BUILD_DATE@/$(POSTGIS_BUILD_DATE)/g' | grep -v '^#' > $@
+../regress/lwpostgis.sql: lwpostgis.sql.in long_xact.sql
+	cpp -P -traditional-cpp -DUSE_VERSION=$(USE_VERSION) $< | sed -e 's#@MODULE_FILENAME@#$(REGRESS_MODULE_FILENAME)#g;s#@POSTGIS_VERSION@#$(POSTGIS_VERSION)#g;s#@POSTGIS_SCRIPTS_VERSION@#$(SCRIPTS_VERSION)#g;s/@POSTGIS_BUILD_DATE@/$(POSTGIS_BUILD_DATE)/g' | grep -v '^#' > $@
 
 install: all install-lib-shared install-lwgeom-scripts
 

Modified: packages/postgis/trunk/lwgeom/lex.yy.c
===================================================================
--- packages/postgis/trunk/lwgeom/lex.yy.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lex.yy.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -20,7 +20,7 @@
 /* A lexical scanner generated by flex */
 
 /* Scanner skeleton version:
- * $Header: /home/cvs/postgis/postgis/lwgeom/lex.yy.c,v 1.4 2005/03/03 10:29:46 strk Exp $
+ * $Header: /home/cvs/postgis/postgis/lwgeom/lex.yy.c,v 1.7 2006/05/04 15:19:50 strk Exp $
  */
 
 #define FLEX_SCANNER
@@ -2327,7 +2327,8 @@
 
 #line 11 "wktparse.lex"
 #include "wktparse.tab.h"
-#include "unistd.h"
+#include <unistd.h>
+#include <stdlib.h> // need stdlib for atof() definition 
 
 void init_parser(const char *src);
 void close_parser(void);
@@ -2339,7 +2340,7 @@
    void close_parser() { lwg_parse_yy_delete_buffer(buf_state); }
    int lwg_parse_yywrap(void){ return 1; }
 
-#line 2343 "lex.yy.c"
+#line 2344 "lex.yy.c"
 
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
@@ -2486,10 +2487,10 @@
 	register char *yy_cp, *yy_bp;
 	register int yy_act;
 
-#line 26 "wktparse.lex"
+#line 27 "wktparse.lex"
 
 
-#line 2493 "lex.yy.c"
+#line 2494 "lex.yy.c"
 
 	if ( yy_init )
 		{
@@ -2562,145 +2563,145 @@
 
 case 1:
 YY_RULE_SETUP
-#line 28 "wktparse.lex"
+#line 29 "wktparse.lex"
 { lwg_parse_yylval.value=atof(lwg_parse_yytext); return VALUE; }
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 29 "wktparse.lex"
+#line 30 "wktparse.lex"
 { lwg_parse_yylval.value=atof(lwg_parse_yytext); return VALUE; }
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 31 "wktparse.lex"
+#line 32 "wktparse.lex"
 {  lwg_parse_yylval.wkb=lwg_parse_yytext; return WKB;}
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 32 "wktparse.lex"
+#line 33 "wktparse.lex"
 {  lwg_parse_yylval.wkb=lwg_parse_yytext; return WKB;}
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 34 "wktparse.lex"
+#line 35 "wktparse.lex"
 { return POINT; }
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 35 "wktparse.lex"
+#line 36 "wktparse.lex"
 { return POINTM; }
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 36 "wktparse.lex"
+#line 37 "wktparse.lex"
 { return LINESTRING; }
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 37 "wktparse.lex"
+#line 38 "wktparse.lex"
 { return LINESTRINGM; }
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 38 "wktparse.lex"
+#line 39 "wktparse.lex"
 { return POLYGON; }
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 39 "wktparse.lex"
+#line 40 "wktparse.lex"
 { return POLYGONM; }
 	YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 40 "wktparse.lex"
+#line 41 "wktparse.lex"
 { return MULTIPOINT; }
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 41 "wktparse.lex"
+#line 42 "wktparse.lex"
 { return MULTIPOINTM; }
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 42 "wktparse.lex"
+#line 43 "wktparse.lex"
 { return MULTILINESTRING; }
 	YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 43 "wktparse.lex"
+#line 44 "wktparse.lex"
 { return MULTILINESTRINGM; }
 	YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 44 "wktparse.lex"
+#line 45 "wktparse.lex"
 { return MULTIPOLYGON; }
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 45 "wktparse.lex"
+#line 46 "wktparse.lex"
 { return MULTIPOLYGONM; }
 	YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 46 "wktparse.lex"
+#line 47 "wktparse.lex"
 { return GEOMETRYCOLLECTION; }
 	YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 47 "wktparse.lex"
+#line 48 "wktparse.lex"
 { return GEOMETRYCOLLECTIONM; }
 	YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 48 "wktparse.lex"
+#line 49 "wktparse.lex"
 { BEGIN(vals_ok); return SRID; }
 	YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 49 "wktparse.lex"
+#line 50 "wktparse.lex"
 { return EMPTY; }
 	YY_BREAK
 case 21:
 YY_RULE_SETUP
-#line 51 "wktparse.lex"
+#line 52 "wktparse.lex"
 { BEGIN(vals_ok); return LPAREN; }
 	YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 52 "wktparse.lex"
+#line 53 "wktparse.lex"
 { return RPAREN; }
 	YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 53 "wktparse.lex"
+#line 54 "wktparse.lex"
 { return COMMA ; }
 	YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 54 "wktparse.lex"
+#line 55 "wktparse.lex"
 { return EQUALS ; }
 	YY_BREAK
 case 25:
 YY_RULE_SETUP
-#line 55 "wktparse.lex"
+#line 56 "wktparse.lex"
 { BEGIN(0); return SEMICOLON; }
 	YY_BREAK
 case 26:
 YY_RULE_SETUP
-#line 56 "wktparse.lex"
+#line 57 "wktparse.lex"
 /*eat whitespace*/
 	YY_BREAK
 case 27:
 YY_RULE_SETUP
-#line 57 "wktparse.lex"
+#line 58 "wktparse.lex"
 { return lwg_parse_yytext[0]; }
 	YY_BREAK
 case 28:
 YY_RULE_SETUP
-#line 59 "wktparse.lex"
+#line 60 "wktparse.lex"
 ECHO;
 	YY_BREAK
-#line 2704 "lex.yy.c"
+#line 2705 "lex.yy.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(vals_ok):
 	yyterminate();
@@ -3586,6 +3587,6 @@
 	return 0;
 	}
 #endif
-#line 59 "wktparse.lex"
+#line 60 "wktparse.lex"
 
 

Modified: packages/postgis/trunk/lwgeom/liblwgeom.c
===================================================================
--- packages/postgis/trunk/lwgeom/liblwgeom.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/liblwgeom.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -112,6 +112,11 @@
 const char *
 lwgeom_typename(int type)
 {
+	// something went wrong somewhere
+	if ( type < 0 || type > 7 ) {
+		// assert(0);
+		return "Invalid type";
+	}
 	return lwgeomTypeName[type];
 }
 

Modified: packages/postgis/trunk/lwgeom/liblwgeom.h
===================================================================
--- packages/postgis/trunk/lwgeom/liblwgeom.h	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/liblwgeom.h	2006-07-20 16:49:42 UTC (rev 485)
@@ -81,9 +81,13 @@
 	int datatype;	/* 1 = float32,
 			 * 5 = 24bit integer,
 			 * 6 = 16bit integer (short)
+			 * 7 = 16bit ???
+			 * 8 = 8bit ???
 			 * 101 = float32 (NDR),
 			 * 105 = 24bit integer (NDR),
-			 * 106=16bit int (NDR)
+			 * 106 = 16bit int (NDR)
+			 * 107 = 16bit ??? (NDR)
+			 * 108 = 8bit ??? (NDR) (this doesn't make sense)
 			 */
 	int height;
 	int width;
@@ -984,8 +988,14 @@
 	POINTARRAY *point);
 extern LWLINE *lwline_construct(int SRID, BOX2DFLOAT4 *bbox,
 	POINTARRAY *points);
+
+/*
+ * Construct a new LWPOLY.  arrays (points/points per ring) will NOT be copied
+ * use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
+ */
 extern LWPOLY *lwpoly_construct(int SRID, BOX2DFLOAT4 *bbox,
 	unsigned int nrings, POINTARRAY **points);
+
 extern LWCOLLECTION *lwcollection_construct(unsigned int type, int SRID,
 	BOX2DFLOAT4 *bbox, unsigned int ngeoms, LWGEOM **geoms);
 extern LWCOLLECTION *lwcollection_construct_empty(int SRID,

Copied: packages/postgis/trunk/lwgeom/long_xact.c (from rev 484, packages/postgis/upstream/lwgeom/long_xact.c)

Copied: packages/postgis/trunk/lwgeom/long_xact.sql (from rev 484, packages/postgis/upstream/lwgeom/long_xact.sql)

Modified: packages/postgis/trunk/lwgeom/lwcollection.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwcollection.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwcollection.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwcollection.c,v 1.32 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

Modified: packages/postgis/trunk/lwgeom/lwgeom.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwgeom.c,v 1.33 2006/05/30 08:47:00 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>

Modified: packages/postgis/trunk/lwgeom/lwgeom_chip.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_chip.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_chip.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -9,10 +9,15 @@
 #include "access/itup.h"
 #include "fmgr.h"
 #include "utils/elog.h"
+#include "funcapi.h"
 
 #include "lwgeom_pg.h"
 #include "liblwgeom.h"
 
+
+/* Define this to debug CHIP ops */
+/*#define DEBUG_CHIP 1*/
+
 /* Internal funcs */
 void swap_char(char *a,char *b);
 void flip_endian_double(char *d);
@@ -71,7 +76,7 @@
 	}
 /* if endian is wrong, flip it otherwise do nothing */
 	result->size = size;
-	if (result->size < sizeof(CHIP) )
+	if (result->size < sizeof(CHIP)-sizeof(void*) )
 	{
 		elog(ERROR,"CHIP_in parser - bad data (too small to be a CHIP)!");
 		PG_RETURN_NULL();	
@@ -118,9 +123,9 @@
 
 	if (result->compression ==0) /*only true for non-compressed data */
 	{
-		if (result->size != (sizeof(CHIP) + datum_size * result->width*result->height) )
+		if (result->size != (sizeof(CHIP) - sizeof(void*) + datum_size * result->width*result->height) )
 		{
-			elog(ERROR,"CHIP_in parser - bad data (actual size != computed size)!");
+			elog(ERROR,"CHIP_in parser - bad data (actual size [%d] != computed size [%d])!", result->size, (sizeof(CHIP)-sizeof(void*) + datum_size * result->width*result->height) );
 			PG_RETURN_NULL();
 		}
 	}
@@ -138,7 +143,9 @@
 	int size_result;
 	int t;
 
-/*printf("chip_out called\n"); */
+#if DEBUG_CHIP
+	lwnotice("CHIP_out: %dx%d chip, %d in size", chip->width, chip->height, chip->size);
+#endif
 
 	size_result = (chip->size ) *2 +1; /* +1 for null char */
 	result = palloc (size_result);
@@ -304,3 +311,1008 @@
 	swap_char (i+3,i);
 	swap_char (i+2,i+1);
 }
+
+/********************************************************************
+ *
+ * NEW chip code
+ * 
+ ********************************************************************/
+
+#define CHIP_BOUNDS_CHECKS 1
+
+
+/* Macros to find size (in geographic units) of a CHIP cell (or pixel) */
+#define CHIP_CELL_WIDTH(x) ( ((x)->bvol.xmax-(x)->bvol.xmin)/(x)->width )
+#define CHIP_CELL_HEIGHT(x) ( ((x)->bvol.ymax-(x)->bvol.ymin)/(x)->height )
+
+/* Return the size of values for pixel of the given datatype */
+size_t chip_pixel_value_size(int datatype);
+
+/********************************************************************
+ *
+ * IO primitives
+ * 
+ ********************************************************************/
+
+#define PIXELOP_OVERWRITE 1
+#define PIXELOP_ADD 2
+#define PIXELOP_MULTIPLY 3
+
+char *pixelop_name[] = {
+	"Unknown",
+	"Overwrite",
+	"Add",
+	"Multiply"
+};
+
+const char*
+pixelOpName(int op)
+{
+	if ( op < 0 || op > 3 )
+	{
+		return "Invalid";
+	}
+	return pixelop_name[op];
+}
+
+
+typedef struct RGB_T {
+	uchar red;
+	uchar green;
+	uchar blue;
+} RGB;
+
+typedef unsigned short int UINT16;
+typedef float FLOAT32;
+
+typedef struct PIXEL_T {
+	int type; /* 1=float32, 5=int24, 6=int16 */
+	uchar val[4];
+} PIXEL;
+
+const char*
+pixelHEX(PIXEL* p)
+{
+	static char buf[256];
+	size_t ps = chip_pixel_value_size(p->type);
+	int i,j;
+	static const char* hex = "0123456789ABCDEF";
+
+	for (i=0, j=0; i<ps; ++i)
+	{
+		uchar val = p->val[i];
+		int upper = (val & 0xF0) >> 4;
+		int lower = val & 0x0F;
+
+		buf[j++] = hex[ upper ];
+		buf[j++] = hex[ lower ];
+	}
+	buf[j]=0;
+
+	return buf;
+}
+
+UINT16
+pixel_readUINT16(PIXEL *p)
+{
+	UINT16 i=0;
+	memcpy(&i, &(p->val), 2);
+	//i = p->val[0] | (p->val[1] << 8);
+	return i;
+}
+
+void
+pixel_writeUINT16(PIXEL *p, UINT16 i)
+{
+	//memcpy(&(p->val), &i, 2);
+	p->val[0] = i&0xFF;
+	p->val[1] = i>>8;
+	p->val[2] = 0;
+	p->val[3] = 0;
+}
+
+/*
+ * Write text representation of a PIXEL value into provided
+ * buffer.
+ */
+void
+pixel_writeval(PIXEL *p, char *buf, size_t maxlen)
+{
+	FLOAT32 f32=0.0;
+	UINT16 i16=0;
+
+	switch (p->type)
+	{
+		case 1: /* float32 */
+			memcpy(&f32, p->val, 4);
+			sprintf(buf, "%g", f32);
+			break;
+		case 5: /* int24 (rgb) */
+			buf[0] = '#';
+			deparse_hex(p->val[0], &buf[1]);
+			deparse_hex(p->val[1], &buf[3]);
+			deparse_hex(p->val[2], &buf[5]);
+			buf[7]='\0';
+			break;
+		case 6: /* int16 */
+			i16=pixel_readUINT16(p);
+			snprintf(buf, maxlen, "%u", i16);
+			break;
+		default:
+			lwerror("Unsupported PIXEL value %d", p->type);
+	}
+}
+
+PIXEL
+pixel_readval(char *buf)
+{
+	FLOAT32 f32=0.0;
+	long int i16=0;
+	RGB rgb;
+	char *ptr;
+	PIXEL p;
+
+	/* RGB */
+	if ( buf[0] == '#' )
+	{
+		if ( strlen(buf) < 7 ) lwerror("RGB value too short");
+		p.type = 5; /* rgb */
+		ptr=buf+1;
+		rgb.red = parse_hex(ptr);
+		ptr+=2;
+		rgb.green = parse_hex(ptr);
+		ptr+=2;
+		rgb.blue = parse_hex(ptr);
+		memcpy(p.val, &rgb, 3);
+
+		return p;
+	}
+
+	/* float32 */
+	if ( strchr(buf, '.') )
+	{
+		f32 = strtod(buf, &ptr);
+		if ( ptr != buf+strlen(buf) )
+			lwerror("Malformed float value");
+		p.type = 1; /* float32 */
+		memcpy(p.val, &f32, 4);
+
+		return p;
+	}
+
+	/* int16 */
+	i16 = strtol(buf, &ptr, 0);
+	if ( ptr != buf+strlen(buf) ) lwerror("Malformed integer value");
+	if ( i16 > 65535 ) lwerror("Integer too high for an int16");
+	p.type = 6; /* int16 */
+	memcpy(p.val, &i16, 2);
+	p.val[2]=0;
+	p.val[3]=0;
+	return p;
+}
+
+void
+pixel_add_float32(PIXEL *where, PIXEL *what)
+{
+	FLOAT32 f1=0.0, f2=0.0;
+	memcpy(&f1, where->val, 4);
+	memcpy(&f2, what->val, 4);
+	f1 += f2;
+	memcpy(where->val, &f1, 4);
+}
+
+void
+pixel_add_int24(PIXEL *where, PIXEL *what)
+{
+	unsigned int red, green, blue;
+	RGB rgb1, rgb2;
+
+	memcpy(&rgb1, where->val, 3);
+	memcpy(&rgb2, what->val, 3);
+	red = rgb1.red + rgb2.red;
+	green = rgb1.green + rgb2.green;
+	blue = rgb1.blue + rgb2.blue;
+	if ( red > 255 )
+	{
+		lwnotice("Red channel saturated by add operation");
+		red = 255;
+	}
+	if ( green > 255 )
+	{
+		lwnotice("Green channel saturated by add operation");
+		green = 255;
+	}
+	if ( blue > 255 )
+	{
+		lwnotice("Blue channel saturated by add operation");
+		blue = 255;
+	}
+	rgb1.red = red;
+	rgb1.green = green;
+	rgb1.blue = blue;
+	memcpy(where->val, &rgb1, 3);
+}
+
+void
+pixel_add_int16(PIXEL *where, PIXEL *what)
+{
+	UINT16 i1, i2;
+	unsigned long int tmp;
+
+	i1 = pixel_readUINT16(where);
+	i2 = pixel_readUINT16(what);
+	tmp = (unsigned long)i1 + i2;
+	if ( tmp > 65535 )
+	{
+		lwnotice("UInt16 Pixel saturated by add operation (%u+%u=%u)",
+			i1, i2, tmp);
+		tmp = 65535;
+	}
+	i1 = tmp;
+	pixel_writeUINT16(where, i1);
+}
+
+void
+pixel_add(PIXEL *where, PIXEL *what)
+{
+	if ( where->type != what->type )
+		lwerror("Can't add pixels of different types");
+
+	switch (where->type)
+	{
+		case 1: /*float32*/
+			pixel_add_float32(where, what);
+			break;
+
+		case 5: /*int24*/
+			pixel_add_int24(where, what);
+			break;
+
+		case 6: /*int16*/
+			pixel_add_int16(where, what);
+			break;
+
+		default:
+			lwerror("pixel_add: unkown pixel type %d",
+				where->type);
+	}
+
+}
+
+/*
+ * Return size of pixel values in bytes
+ */
+size_t
+chip_pixel_value_size(int datatype)
+{
+	switch(datatype)
+	{
+		case 1:
+		case 101:
+			return 4;
+		case 5:
+		case 105:
+			return 3;
+		case 6:
+		case 7:
+		case 106:
+		case 107:
+			return 2;
+		case 8:
+		case 108:
+			return 1;
+		default:
+			lwerror("Unknown CHIP datatype: %d", datatype);
+			return 0;
+	}
+}
+
+/*
+ * Returns offset of pixel at X,Y
+ */
+#define CHIP_XY_OFF(c, x, y) ((x)+((y)*(c)->width))
+size_t
+chip_xy_off(CHIP *c, size_t x, size_t y)
+{
+#ifdef CHIP_BOUNDS_CHECKS
+	if ( x < 0 || x >= c->width || y < 0 || y >= c->height )
+	{
+		lwerror("Coordinates ouf of range");
+		return 0;
+	}
+#endif
+	return x+(y*c->width);
+}
+
+/*
+ * Set pixel value.
+ *
+ * CHIP is assumed to be:
+ *	- uncompressed
+ *	- in machine's byte order
+ */
+void
+chip_setPixel(CHIP *c, int x, int y, PIXEL *p)
+{
+	void *where;
+	size_t ps;
+	size_t off;
+
+#if DEBUG_CHIP
+	lwnotice("chip_setPixel([CHIP %p], %d, %d) called", c, x, y);
+#endif
+	if ( c->datatype != p->type ) lwerror("Pixel datatype mismatch");
+
+	ps = chip_pixel_value_size(c->datatype);
+	off = chip_xy_off(c, x, y)*ps;
+	if ( off > c->size + sizeof(CHIP) )
+	{
+		lwerror("Pixel offset out of CHIP size bounds");
+	}
+
+	where = ((char*)&(c->data))+off;
+
+#if DEBUG_CHIP
+	lwnotice("Writing %d bytes (%s) at offset %d (%p)",
+		ps, pixelHEX(p), off, where);
+#endif
+
+	memcpy(where, &(p->val), ps);
+}
+
+/*
+ * Get pixel value.
+ *
+ * CHIP is assumed to be:
+ *	- uncompressed
+ *	- in machine's byte order
+ */
+PIXEL
+chip_getPixel(CHIP *c, int x, int y)
+{
+	PIXEL p;
+	size_t ps = chip_pixel_value_size(c->datatype);
+	void *where = ((char*)&(c->data))+chip_xy_off(c, x, y)*ps;
+	p.type = c->datatype;
+	memset(p.val, '\0', 4);
+	memcpy(p.val, where, ps);
+
+	return p;
+}
+
+/********************************************************************
+ *
+ * Drawing primitives
+ * 
+ ********************************************************************/
+
+/*
+ * Coordinates are in CHIP offset, so callers must
+ * appropriately translate.
+ */
+void
+chip_draw_pixel(CHIP *chip, int x, int y, PIXEL *pixel, int op)
+{
+
+#if DEBUG_CHIP
+	lwnotice("chip_draw_pixel([CHIP %p], %d, %d, [PIXEL %p], %s) called",
+		(void*)chip, x, y, (void*)pixel, pixelOpName(op));
+#endif
+
+	if ( x < 0 || x >= chip->width || y < 0 || y >= chip->height )
+	{
+/* should this be a warning ? */
+lwnotice("chip_draw_pixel called with out-of-range coordinates (%d,%d)", x, y);
+return;
+	}
+
+	/*
+	 * Translate x and y values, which are in map units, to
+	 * CHIP units
+	 */
+
+	PIXEL p;
+
+	switch ( op )
+	{
+		case PIXELOP_OVERWRITE:
+			chip_setPixel(chip, x, y, pixel);
+			break;
+
+		case PIXELOP_ADD:
+			p = chip_getPixel(chip, x, y);
+			pixel_add(&p, pixel);
+			chip_setPixel(chip, x, y, &p);
+			break;
+
+		default:
+			lwerror("Unsupported PIXELOP: %d", op);
+	}
+
+}
+
+/* 
+ * Bresenham Line Algorithm
+ *  http://www.edepot.com/linebresenham.html
+ */
+void
+chip_draw_segment(CHIP *chip,
+	int x1, int y1, int x2, int y2,
+	PIXEL *pixel, int op)
+{
+	int x, y;
+	int dx, dy;
+	int incx, incy;
+	int balance;
+
+
+	if (x2 >= x1)
+	{
+		dx = x2 - x1;
+		incx = 1;
+	}
+	else
+	{
+		dx = x1 - x2;
+		incx = -1;
+	}
+
+	if (y2 >= y1)
+	{
+		dy = y2 - y1;
+		incy = 1;
+	}
+	else
+	{
+		dy = y1 - y2;
+		incy = -1;
+	}
+
+	x = x1;
+	y = y1;
+
+	if (dx >= dy)
+	{
+		dy <<= 1;
+		balance = dy - dx;
+		dx <<= 1;
+
+		while (x != x2)
+		{
+			chip_draw_pixel(chip, x, y, pixel, op);
+			if (balance >= 0)
+			{
+				y += incy;
+				balance -= dx;
+			}
+			balance += dy;
+			x += incx;
+		} chip_draw_pixel(chip, x, y, pixel, op);
+	}
+	else
+	{
+		dx <<= 1;
+		balance = dx - dy;
+		dy <<= 1;
+
+		while (y != y2)
+		{
+			chip_draw_pixel(chip, x, y, pixel, op);
+			if (balance >= 0)
+			{
+				x += incx;
+				balance -= dy;
+			}
+			balance += dx;
+			y += incy;
+		} chip_draw_pixel(chip, x, y, pixel, op);
+	}
+}
+
+void
+chip_fill(CHIP *chip, PIXEL *pixel, int op)
+{
+	int x, y;
+
+#if DEBUG_CHIP
+	lwnotice("chip_fill called");
+#endif
+
+	for (x=0; x<chip->width; x++)
+	{
+		for (y=0; y<chip->height; y++)
+		{
+			chip_draw_pixel(chip, x, y, pixel, op);
+		}
+	}
+}
+
+/********************************************************************
+ *
+ * CHIP constructors
+ * 
+ ********************************************************************/
+
+CHIP *
+pgchip_construct(BOX3D *bvol, int SRID, int width, int height,
+	int datatype, PIXEL *initvalue)
+{
+	size_t pixsize = chip_pixel_value_size(datatype);
+	size_t datasize = pixsize*width*height;
+	size_t size = sizeof(CHIP)-sizeof(void*)+datasize;
+	CHIP *chip = lwalloc(size);
+
+#if DEBUG_CHIP
+	lwnotice(" sizeof(CHIP):%d, pixelsize:%d, datasize:%d, total size:%d", sizeof(CHIP), pixsize, datasize, size);
+#endif
+
+	chip->size=size;
+	chip->endian_hint=1;
+	memcpy(&(chip->bvol), bvol, sizeof(BOX3D));
+	chip->SRID=SRID;
+	memset(chip->future, '\0', 4);
+	chip->factor=1.0;
+	chip->datatype=datatype;
+	chip->height=height;
+	chip->width=width;
+	chip->compression=0; // no compression
+	if ( ! initvalue ) {
+		memset(&(chip->data), '\0', datasize);
+	} else {
+		chip_fill(chip, initvalue, PIXELOP_OVERWRITE);
+	}
+	return chip;
+} 
+
+
+/********************************************************************
+ *
+ * Drawing functions
+ * 
+ ********************************************************************/
+
+
+/*
+ * Transform a POINT from geo coordinates to CHIP offsets.
+ * Can be optimized by caching CHIP info somewhere and using
+ * multiplications rather then divisions.
+ */
+static void
+transform_point(CHIP* chip, POINT2D* p)
+{
+	/* geo size of full grid/chip */
+	double geowidth = chip->bvol.xmax - chip->bvol.xmin;
+	double geoheight = chip->bvol.ymax - chip->bvol.ymin;
+
+	/* geo size of a cell/pixel */
+	double xscale = geowidth / chip->width; 
+	double yscale = geoheight / chip->height; 
+
+	double xoff = ( chip->bvol.xmin + xscale );
+	double yoff = ( chip->bvol.ymin + yscale );
+
+#if 0
+	double ox = p->x;
+	double oy = p->y;
+#endif
+
+	p->x = rint ( ( p->x - xoff ) / xscale );
+	p->y = rint ( ( p->y - yoff ) / yscale );
+
+#if 0
+	lwnotice("Old x: %g, new x: %g", ox, p->x);
+#endif
+
+}
+
+void
+chip_draw_ptarray(CHIP *chip, POINTARRAY *pa, PIXEL *pixel, int op)
+{
+	POINT2D A, B;
+	int i;
+	int x1, x2, y1, y2;
+
+	for (i=1; i<pa->npoints; i++)
+	{
+		getPoint2d_p(pa, i-1, &A);
+		getPoint2d_p(pa, i, &B);
+
+		transform_point(chip, &A);
+		transform_point(chip, &B);
+
+		x1 = A.x;
+		y1 = A.y;
+		x2 = B.x;
+		y2 = B.y;
+
+		chip_draw_segment(chip, x1, y1, x2, y2, pixel, op);
+	}
+}
+
+void
+chip_draw_lwpoint(CHIP *chip, LWPOINT *lwpoint, PIXEL* pixel, int op)
+{
+	POINTARRAY *pa;
+	POINT2D point;
+
+	pa = lwpoint->point;
+	getPoint2d_p(pa, 0, &point);
+
+	/* translate to CHIP plane */
+	transform_point(chip, &point);
+
+	chip_draw_pixel(chip, point.x, point.y, pixel, op);
+}
+
+void
+chip_draw_lwline(CHIP *chip, LWLINE *lwline, PIXEL* pixel, int op)
+{
+	POINTARRAY *pa;
+
+	pa = lwline->points;
+	chip_draw_ptarray(chip, pa, pixel, op);
+	return;
+}
+
+void
+chip_draw_lwgeom(CHIP *chip, LWGEOM *lwgeom, PIXEL *pixel, int op)
+{
+	int i;
+	LWCOLLECTION *coll;
+
+	/* Check wheter we should completely skip this geometry */
+	if ( lwgeom->bbox )
+	{
+		if ( chip->bvol.xmax < lwgeom->bbox->xmin ) return;
+		if ( chip->bvol.xmin > lwgeom->bbox->xmax ) return;
+		if ( chip->bvol.ymax < lwgeom->bbox->ymin ) return;
+		if ( chip->bvol.ymin > lwgeom->bbox->ymax ) return;
+	}
+
+	switch (TYPE_GETTYPE(lwgeom->type) )
+	{
+		case POINTTYPE:
+			chip_draw_lwpoint(chip, (LWPOINT*)lwgeom, pixel, op);
+			return;
+		case LINETYPE:
+			chip_draw_lwline(chip, (LWLINE*)lwgeom, pixel, op);
+			return;
+		case POLYGONTYPE:
+			lwerror("%s geometry unsupported by draw operation",
+				lwgeom_typename(TYPE_GETTYPE(lwgeom->type)));
+		case MULTIPOINTTYPE:
+		case MULTILINETYPE:
+		case MULTIPOLYGONTYPE:
+		case COLLECTIONTYPE:
+			coll = (LWCOLLECTION *)lwgeom;
+			for (i=0; i<coll->ngeoms; i++)
+			{
+				chip_draw_lwgeom(chip, coll->geoms[i],
+					pixel, op);
+			}
+			return;
+		default:
+			lwerror("Unknown geometry type: %d", lwgeom->type);
+	}
+}
+
+/********************************************************************
+ *
+ * PGsql interfaces
+ * 
+ ********************************************************************/
+
+typedef struct CHIPDUMPSTATE_T {
+	CHIP *chip;
+	int x;
+	int y;
+	char *values[3];
+	char fmt[8];
+} CHIPDUMPSTATE;
+
+/*
+ * Convert a TEXT to a C-String.
+ * Remember to lwfree the returned object.
+ */
+char *
+text_to_cstring(text *t)
+{
+	char *s;
+	size_t len;
+
+	len = VARSIZE(t)-VARHDRSZ;
+	s = lwalloc(len+1);
+	memcpy(s, VARDATA(t), len);
+	s[len] = '\0';
+
+	return s;
+}
+
+PG_FUNCTION_INFO_V1(CHIP_dump);
+Datum CHIP_dump(PG_FUNCTION_ARGS)
+{
+	CHIP *chip;
+	FuncCallContext *funcctx;
+	MemoryContext oldcontext, newcontext;
+	CHIPDUMPSTATE *state;
+	TupleDesc tupdesc;
+	AttInMetadata *attinmeta;
+	HeapTuple tuple;
+	TupleTableSlot *slot;
+	Datum result;
+
+	if (SRF_IS_FIRSTCALL())
+	{
+		funcctx = SRF_FIRSTCALL_INIT();
+		newcontext = funcctx->multi_call_memory_ctx;
+
+		oldcontext = MemoryContextSwitchTo(newcontext);
+
+		chip = (CHIP *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+
+		/* Create function state */
+		state = lwalloc(sizeof(CHIPDUMPSTATE));
+		state->chip = chip;
+		state->x=0;
+		state->y=0;
+		state->values[0] = lwalloc(256);
+		state->values[1] = lwalloc(256);
+		state->values[2] = lwalloc(256);
+
+		funcctx->user_fctx = state;
+
+		/*
+		 * Build a tuple description for an
+		 * geometry_dump tuple
+		 */
+		tupdesc = RelationNameGetTupleDesc("chip_dump");
+
+		/* allocate a slot for a tuple with this tupdesc */
+		slot = TupleDescGetSlot(tupdesc);
+
+		/* allocate a slot for a tuple with this tupdesc */
+		slot = TupleDescGetSlot(tupdesc);
+
+		/* assign slot to function context */
+		funcctx->slot = slot;
+
+		/*
+		 * generate attribute metadata needed later to produce
+		 * tuples from raw C strings
+		 */
+		attinmeta = TupleDescGetAttInMetadata(tupdesc);
+		funcctx->attinmeta = attinmeta;
+
+		MemoryContextSwitchTo(oldcontext);
+	}
+
+	/* stuff done on every call of the function */
+	funcctx = SRF_PERCALL_SETUP();
+	newcontext = funcctx->multi_call_memory_ctx;
+
+	/* get state */
+	state = funcctx->user_fctx;
+
+	/* Handled simple geometries */
+	while ( state->y < state->chip->height &&
+		state->x < state->chip->width )
+	{
+		char buf[256];
+
+		if ( ! state->chip ) lwerror("state->chip corrupted");
+		PIXEL p = chip_getPixel(state->chip, state->x, state->y);
+		pixel_writeval(&p, buf, 255);
+
+		sprintf(state->values[0], "%d", state->x);
+		sprintf(state->values[1], "%d", state->y);
+		sprintf(state->values[2], "%s", buf);
+
+		tuple = BuildTupleFromCStrings(funcctx->attinmeta,
+			state->values);
+		result = TupleGetDatum(funcctx->slot, tuple);
+		
+		if ( state->x < state->chip->width-1 )
+		{
+			state->x++;
+		}
+		else
+		{
+			state->x=0;
+			state->y++;
+		}
+
+		SRF_RETURN_NEXT(funcctx, result);
+
+	}
+
+	SRF_RETURN_DONE(funcctx);
+}
+
+PG_FUNCTION_INFO_V1(CHIP_construct);
+Datum CHIP_construct(PG_FUNCTION_ARGS)
+{
+	CHIP *chip;
+	BOX3D *box = (BOX3D *)PG_GETARG_POINTER(0);
+	int SRID = PG_GETARG_INT32(1);
+	int width = PG_GETARG_INT32(2);
+	int height = PG_GETARG_INT32(3);
+	text *pixel_text = PG_GETARG_TEXT_P(4);
+	char *pixel = text_to_cstring(pixel_text);
+	PIXEL pix = pixel_readval(pixel);
+
+#if DEBUG_CHIP
+	lwnotice("CHIP_construct called");
+#endif
+
+	if ( width <= 0 || height <= 0 )
+	{
+		lwerror("Invalid values for width or height");
+		PG_RETURN_NULL();
+	}
+
+	chip = pgchip_construct(box, SRID, width, height, pix.type, &pix);
+
+#if DEBUG_CHIP
+	lwnotice("Created %dx%d chip type", chip->width, chip->height);
+#endif
+
+	PG_RETURN_POINTER(chip);
+}
+
+PG_FUNCTION_INFO_V1(CHIP_getpixel);
+Datum CHIP_getpixel(PG_FUNCTION_ARGS)
+{
+	CHIP *chip = (CHIP *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+	int x = PG_GETARG_INT32(1);
+	int y = PG_GETARG_INT32(2);
+	char buf[256];
+	size_t len;
+	text *ret;
+	PIXEL p;
+
+	if ( x < 0 || x >= chip->width )
+	{
+		lwerror("X out of range %d..%d",
+			0, chip->width-1);
+		PG_RETURN_NULL();
+	}
+	if ( y < 0 || y >= chip->height )
+	{
+		lwerror("Y out of range %d..%d",
+			0, chip->height-1);
+		PG_RETURN_NULL();
+	}
+
+	p = chip_getPixel(chip, x, y);
+	pixel_writeval(&p, buf, 255);
+	len = strlen(buf);
+	ret = lwalloc(len+VARHDRSZ);
+	VARATT_SIZEP(ret) = len+VARHDRSZ;
+	memcpy(VARDATA(ret), buf, len);
+
+	PG_RETURN_POINTER(ret);
+}
+
+PG_FUNCTION_INFO_V1(CHIP_setpixel);
+Datum CHIP_setpixel(PG_FUNCTION_ARGS)
+{
+	CHIP *chip = (CHIP *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+	int x = PG_GETARG_INT32(1);
+	int y = PG_GETARG_INT32(2);
+	text *init_val_text = PG_GETARG_TEXT_P(3);
+	char *init_val;
+	PIXEL pixel;
+
+	/* Parse pixel */
+	init_val = text_to_cstring(init_val_text);
+	pixel = pixel_readval(init_val);
+
+	if ( chip->datatype != pixel.type )
+	{
+		lwerror("Pixel datatype %d mismatches chip datatype %d",
+			pixel.type, chip->datatype);
+	}
+
+	chip_setPixel(chip, x, y, &pixel);
+
+	PG_RETURN_POINTER(chip);
+
+}
+
+PG_FUNCTION_INFO_V1(CHIP_draw);
+Datum CHIP_draw(PG_FUNCTION_ARGS)
+{
+	CHIP *chip = (CHIP *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+	PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+	LWGEOM *lwgeom = pglwgeom_deserialize(geom);
+	text *pixel_text = PG_GETARG_TEXT_P(2);
+	char *pixel_str;
+	text *pixelop_text;
+	char *pixelop_str;
+	int pixelop = PIXELOP_OVERWRITE;
+	PIXEL pixel;
+
+	/* Check SRID match */
+	if ( chip->SRID != lwgeom->SRID )
+	{
+		lwerror("Operation on mixed SRID objects");
+	}
+
+	if ( PG_NARGS() > 3 )
+	{
+		pixelop_text = PG_GETARG_TEXT_P(3);
+		pixelop_str = text_to_cstring(pixelop_text);
+		if ( pixelop_str[0] == 'o' )
+		{
+			pixelop = PIXELOP_OVERWRITE;
+		}
+		else if ( pixelop_str[0] == 'a' )
+		{
+			pixelop = PIXELOP_ADD;
+		}
+		else
+		{
+			lwerror("Unsupported pixel operation %s", pixelop_str);
+		}
+	}
+
+	/* Parse pixel */
+	pixel_str = text_to_cstring(pixel_text);
+	pixel = pixel_readval(pixel_str);
+	lwfree(pixel_str);
+
+	if ( pixel.type != chip->datatype )
+	{
+		lwerror("Pixel/Chip datatype mismatch");
+	}
+
+	/* Perform drawing */
+	chip_draw_lwgeom(chip, lwgeom, &pixel, pixelop);
+
+	PG_RETURN_POINTER(chip);
+}
+
+PG_FUNCTION_INFO_V1(CHIP_fill);
+Datum CHIP_fill(PG_FUNCTION_ARGS)
+{
+	CHIP *chip = (CHIP *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+	text *pixel_text = PG_GETARG_TEXT_P(1);
+	char *pixel_str;
+	text *pixelop_text;
+	char *pixelop_str;
+	int pixelop = PIXELOP_OVERWRITE;
+	PIXEL pixel;
+
+	if ( PG_NARGS() > 2 )
+	{
+		pixelop_text = PG_GETARG_TEXT_P(2);
+		pixelop_str = text_to_cstring(pixelop_text);
+		if ( pixelop_str[0] == 'o' )
+		{
+			pixelop = PIXELOP_OVERWRITE;
+		}
+		else if ( pixelop_str[0] == 'a' )
+		{
+			pixelop = PIXELOP_ADD;
+		}
+		else
+		{
+			lwerror("Unsupported pixel operation %s", pixelop_str);
+		}
+	}
+
+	/* Parse pixel */
+	pixel_str = text_to_cstring(pixel_text);
+	pixel = pixel_readval(pixel_str);
+	lwfree(pixel_str);
+
+	if ( pixel.type != chip->datatype )
+	{
+		lwerror("Pixel/Chip datatype mismatch");
+	}
+
+	/* Perform fill */
+	chip_fill(chip, &pixel, pixelop);
+
+	PG_RETURN_POINTER(chip);
+}

Modified: packages/postgis/trunk/lwgeom/lwgeom_dump.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_dump.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_dump.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
+#include <assert.h>
 
 #include "postgres.h"
 #include "fmgr.h"
@@ -24,6 +25,7 @@
 /*#define PGIS_DEBUG 1 */
 
 Datum LWGEOM_dump(PG_FUNCTION_ARGS);
+Datum LWGEOM_dump_rings(PG_FUNCTION_ARGS);
 
 typedef struct GEOMDUMPNODE_T {
 	int idx;
@@ -189,5 +191,118 @@
 	SRF_RETURN_NEXT(funcctx, result);
 }
 
+struct POLYDUMPSTATE {
+	int ringnum;
+	LWPOLY *poly;
+};
 
+PG_FUNCTION_INFO_V1(LWGEOM_dump_rings);
+Datum LWGEOM_dump_rings(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *pglwgeom;
+	LWGEOM *lwgeom;
+	FuncCallContext *funcctx;
+	struct POLYDUMPSTATE *state;
+	TupleDesc tupdesc;
+	TupleTableSlot *slot;
+	HeapTuple tuple;
+	AttInMetadata *attinmeta;
+	MemoryContext oldcontext, newcontext;
+	Datum result;
+	char address[256];
+	char *values[2];
+
+	if (SRF_IS_FIRSTCALL())
+	{
+		funcctx = SRF_FIRSTCALL_INIT();
+		newcontext = funcctx->multi_call_memory_ctx;
+
+		oldcontext = MemoryContextSwitchTo(newcontext);
+
+		pglwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+		if ( TYPE_GETTYPE(pglwgeom->type) != POLYGONTYPE )
+		{
+			lwerror("Input is not a polygon");
+		}
+
+		lwgeom = lwgeom_deserialize(SERIALIZED_FORM(pglwgeom));
+
+		/* Create function state */
+		state = lwalloc(sizeof(struct POLYDUMPSTATE));
+		state->poly = lwgeom_as_lwpoly(lwgeom);
+		assert (state->poly);
+		state->ringnum=0;
+
+		funcctx->user_fctx = state;
+
+		/*
+		 * Build a tuple description for an
+		 * geometry_dump tuple
+		 */
+		tupdesc = RelationNameGetTupleDesc("geometry_dump");
+
+		/* allocate a slot for a tuple with this tupdesc */
+		slot = TupleDescGetSlot(tupdesc);
+
+		/* allocate a slot for a tuple with this tupdesc */
+		slot = TupleDescGetSlot(tupdesc);
+
+		/* assign slot to function context */
+		funcctx->slot = slot;
+
+		/*
+		 * generate attribute metadata needed later to produce
+		 * tuples from raw C strings
+		 */
+		attinmeta = TupleDescGetAttInMetadata(tupdesc);
+		funcctx->attinmeta = attinmeta;
+
+		MemoryContextSwitchTo(oldcontext);
+	}
+
+	/* stuff done on every call of the function */
+	funcctx = SRF_PERCALL_SETUP();
+	newcontext = funcctx->multi_call_memory_ctx;
+
+	/* get state */
+	state = funcctx->user_fctx;
+
+	/* Loop trough polygon rings */
+	while (state->ringnum < state->poly->nrings )
+	{
+		LWPOLY* poly = state->poly;
+
+		/* 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]);
+
+		/* Construct another polygon with shell only */
+		LWGEOM* ringgeom = (LWGEOM*)lwpoly_construct(
+			poly->SRID,
+			NULL, /* TODO: could use input bounding box here */
+			1, /* one ring */
+			&ring);
+
+		/* Write path as ``{ <ringnum> }'' */
+		sprintf(address, "{%d}", state->ringnum);
+
+		values[0] = address;
+		values[1] = lwgeom_to_hexwkb(ringgeom, -1);
+
+		MemoryContextSwitchTo(oldcontext);
+
+		tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
+		result = TupleGetDatum(funcctx->slot, tuple);
+		++state->ringnum;
+		SRF_RETURN_NEXT(funcctx, result);
+	}
+
+	SRF_RETURN_DONE(funcctx);
+
+}
+
+
 #endif /* USE_VERSION > 72 */

Modified: packages/postgis/trunk/lwgeom/lwgeom_estimate.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_estimate.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_estimate.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,9 +1,9 @@
 /**********************************************************************
- * $Id: lwgeom_estimate.c,v 1.38 2006/03/13 10:54:08 strk Exp $
+ * $Id: lwgeom_estimate.c,v 1.39 2006/05/30 08:38:58 strk Exp $
  *
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.refractions.net
- * Copyright 2001-2003 Refractions Research Inc.
+ * Copyright 2001-2006 Refractions Research Inc.
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU General Public Licence. See the COPYING file.
@@ -2630,6 +2630,9 @@
 
 /**********************************************************************
  * $Log: lwgeom_estimate.c,v $
+ * Revision 1.39  2006/05/30 08:38:58  strk
+ * Added some missing copyright headers.
+ *
  * Revision 1.38  2006/03/13 10:54:08  strk
  * Applied patch from Mark Cave Ayland embedding access control for
  * the estimated_extent functions.

Modified: packages/postgis/trunk/lwgeom/lwgeom_functions_basic.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_functions_basic.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_functions_basic.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwgeom_functions_basic.c,v 1.143 2006/06/26 00:41:24 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <math.h>
 #include <float.h>
 #include <string.h>
@@ -1748,7 +1760,7 @@
 	/* Make a DETOASTED copy of input geometry */
 	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(datum);
 #ifdef PGIS_DEBUG
-	elog(NOTICE, "geom_accum: detoasted geom: %x", geom);
+	elog(NOTICE, "geom_accum: detoasted geom: %p", (void*)geom);
 #endif
 
 	/*
@@ -1761,7 +1773,7 @@
 		nbytes = ARR_OVERHEAD_NONULLS(1)+INTALIGN(geom->size);
 #ifdef PGIS_DEBUG
 		elog(NOTICE, "geom_accum: adding %p (nelems=%d; nbytes=%d)",
-			geom, nelems, nbytes);
+			(void*)geom, nelems, nbytes);
 #endif
 		result = lwalloc(nbytes);
 		if ( ! result )
@@ -1790,7 +1802,7 @@
 		oldsize = array->size;
 		nbytes = oldsize + INTALIGN(geom->size);
 #ifdef PGIS_DEBUG
-		elog(NOTICE, "geom_accum: old array size: %d, adding %d bytes (nelems=%d; nbytes=%lu)", array->size, INTALIGN(geom->size), nelems, nbytes);
+		elog(NOTICE, "geom_accum: old array size: %d, adding %ld bytes (nelems=%d; nbytes=%u)", array->size, INTALIGN(geom->size), nelems, nbytes);
 #endif
 		result = (ArrayType *) lwrealloc(array, nbytes);
 		if ( ! result )
@@ -1803,7 +1815,7 @@
 #endif
 
 #ifdef PGIS_DEBUG
-		elog(NOTICE, " array start  @ %p", result);
+		elog(NOTICE, " array start  @ %p", (void*)result);
 		elog(NOTICE, " ARR_DATA_PTR @ %p (%d)",
 			ARR_DATA_PTR(result), (uchar *)ARR_DATA_PTR(result)-(uchar *)result);
 		elog(NOTICE, " next element @ %p", (uchar *)result+oldsize);
@@ -1812,7 +1824,7 @@
 		memcpy(ARR_DIMS(result), &nelems, sizeof(int));
 #ifdef PGIS_DEBUG
 		elog(NOTICE, " writing next element starting @ %p",
-			result+oldsize);
+			(void*)(result+oldsize));
 #endif
 		memcpy((uchar *)result+oldsize, geom, geom->size);
 	}
@@ -1867,7 +1879,7 @@
 	array = (ArrayType *) PG_DETOAST_DATUM(datum);
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE, " array is %d-bytes in size, %d w/out header",
+	elog(NOTICE, " array is %d-bytes in size, %ld w/out header",
 		array->size, array->size-ARR_OVERHEAD_NONULLS(ARR_NDIM(array)));
 #endif
 
@@ -2226,7 +2238,7 @@
 
 	outpoly = lwpoly_from_lwlines(shell, nholes, holes);
 #ifdef PGIS_DEBUG
-	lwnotice("%s", lwpoly_summary(outpoly));
+	lwnotice("%s", lwgeom_summary((LWGEOM*)outpoly, 0));
 #endif
 
 	result = pglwgeom_serialize((LWGEOM *)outpoly);
@@ -2381,7 +2393,7 @@
 
 
 /*
- *  Returns a modified [multi]polygon so that no ring segment is 
+ *  Returns a modified geometry so that no segment is 
  *  longer then the given distance (computed using 2d).
  *  Every input point is kept.
  *  Z and M values for added points (if needed) are set to 0.
@@ -2957,8 +2969,15 @@
 	double x,y,z;
 	POINT4D p4d;
 
+#ifdef PGIS_DEBUG
+	lwnotice("lwgeom_affine_ptarray start");
+#endif
+
 	if ( TYPE_HASZ(pa->dims) )
 	{
+#ifdef PGIS_DEBUG
+		lwnotice(" has z");
+#endif
 		for (i=0; i<pa->npoints; i++) {
 			getPoint4d_p(pa, i, &p4d);
 			x = p4d.x;
@@ -2968,10 +2987,16 @@
 			p4d.y = dfac * x + efac * y + ffac * z + yoff;
 			p4d.z = gfac * x + hfac * y + ifac * z + zoff;
 			setPoint4d(pa, i, &p4d);
+#ifdef PGIS_DEBUG
+		lwnotice(" POINT %g %g %g => %g %g %g", x, y, x, p4d.x, p4d.y, p4d.z);
+#endif
 		}
 	}
 	else
 	{
+#ifdef PGIS_DEBUG
+		lwnotice(" doesn't have z");
+#endif
 		for (i=0; i<pa->npoints; i++) {
 			getPoint4d_p(pa, i, &p4d);
   			x = p4d.x;
@@ -2979,8 +3004,16 @@
   			p4d.x = afac * x + bfac * y + xoff;
   			p4d.y = dfac * x + efac * y + yoff;
 			setPoint4d(pa, i, &p4d);
+#ifdef PGIS_DEBUG
+		lwnotice(" POINT %g %g %g => %g %g %g", x, y, x, p4d.x, p4d.y, p4d.z);
+#endif
 		}
 	}
+
+#ifdef PGIS_DEBUG
+	lwnotice("lwgeom_affine_ptarray end");
+#endif
+
 }
 
 void
@@ -3088,6 +3121,8 @@
 
 	/* COMPUTE_BBOX TAINTING */
 	tmp = pglwgeom_deserialize(geom);
+	lwgeom_dropBBOX(tmp);
+	tmp->bbox = lwgeom_compute_box2d(tmp);
 	ret = pglwgeom_serialize(tmp);
 
 	/* Release memory */

Modified: packages/postgis/trunk/lwgeom/lwgeom_geos_c.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_geos_c.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_geos_c.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -13,7 +13,7 @@
  * Define this to have have many notices printed
  * during postgis->geos and geos->postgis conversions
  */
-/*#define PGIS_DEBUG_CONVERTER 1 */
+/* #define PGIS_DEBUG_CONVERTER 1 */
 #ifdef PGIS_DEBUG_CONVERTER
 #define PGIS_DEBUG_POSTGIS2GEOS 1
 #define PGIS_DEBUG_GEOS2POSTGIS 1
@@ -404,8 +404,8 @@
 #endif
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"g1=%s",GEOSasText(g1));
-	elog(NOTICE,"g2=%s",GEOSasText(g2));
+	elog(NOTICE,"g1=%s", GEOSGeomToWKT(g1));
+	elog(NOTICE,"g2=%s", GEOSGeomToWKT(g2));
 #endif
 
 #ifdef PROFILE
@@ -417,7 +417,7 @@
 #endif
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"g3=%s",GEOSasText(g3));
+	elog(NOTICE,"g3=%s", GEOSGeomToWKT(g3));
 #endif
 
 	GEOSGeom_destroy(g1);
@@ -524,7 +524,7 @@
 	}
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3));
 #endif
 
 	GEOSSetSRID(g3, SRID);
@@ -606,7 +606,7 @@
 	}
 
 #ifdef PGIS_DEBUG
-  	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3));
 #endif
 
 	GEOSSetSRID(g3, SRID);
@@ -689,7 +689,7 @@
 
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3));
 #endif
 
 	GEOSSetSRID(g3, SRID);
@@ -785,7 +785,7 @@
 
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3));
 #endif
 
 	GEOSSetSRID(g3, pglwgeom_getSRID(geom1));
@@ -867,8 +867,8 @@
 
 #ifdef PGIS_DEBUG
 	elog(NOTICE," constructed geometrys - calling geos");
-	elog(NOTICE," g1 = %s", GEOSasText(g1));
-	elog(NOTICE," g2 = %s", GEOSasText(g2));
+	elog(NOTICE," g1 = %s", GEOSGeomToWKT(g1));
+	elog(NOTICE," g2 = %s", GEOSGeomToWKT(g2));
 /*elog(NOTICE,"g2 is valid = %i",GEOSisvalid(g2)); */
 /*elog(NOTICE,"g1 is valid = %i",GEOSisvalid(g1)); */
 #endif
@@ -898,7 +898,7 @@
 
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3) ) ;
 #endif
 
 	GEOSSetSRID(g3, SRID);
@@ -1001,7 +1001,7 @@
 	}
 
 #ifdef PGIS_DEBUG
-  	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+  	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3) ) ;
 #endif
 
 	GEOSSetSRID(g3, SRID);
@@ -1080,7 +1080,7 @@
 	}
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3) ) ;
 #endif
 
 	GEOSSetSRID(g3, pglwgeom_getSRID(geom1));
@@ -1933,8 +1933,8 @@
 		elog(NOTICE,"g1 or g2 are null");
 
 #ifdef PGIS_DEBUG
-	elog(NOTICE,GEOSasText(g1));
-	elog(NOTICE,GEOSasText(g2));
+	elog(NOTICE,GEOSGeomToWKT(g1));
+	elog(NOTICE,GEOSGeomToWKT(g2));
 
 	/*elog(NOTICE,"valid g1 = %i", GEOSisvalid(g1));*/
 	/*elog(NOTICE,"valid g2 = %i",GEOSisvalid(g2));*/
@@ -2298,6 +2298,9 @@
 	bool hasZ = GEOSHasZ(geom);
 	int SRID = GEOSGetSRID(geom);
 
+	/* GEOS's 0 is equivalent to our -1 as for SRID values */
+	if ( SRID == 0 ) SRID = -1;
+
 	if ( ! hasZ )
 	{
 		if ( want3d )
@@ -2361,11 +2364,15 @@
 	lwnotice("lwgeom_from_geometry: it's a Collection or Multi");
 #endif
 			ngeoms = GEOSGetNumGeometries(geom);
-			geoms = lwalloc(sizeof(LWGEOM *)*ngeoms);
-			for (i=0; i<ngeoms; i++)
+			geoms = NULL;
+			if ( ngeoms )
 			{
-				g = GEOSGetGeometryN(geom, i);
-				geoms[i] = GEOS2LWGEOM(g, want3d);
+				geoms = lwalloc(sizeof(LWGEOM *)*ngeoms);
+				for (i=0; i<ngeoms; i++)
+				{
+					g = GEOSGetGeometryN(geom, i);
+					geoms[i] = GEOS2LWGEOM(g, want3d);
+				}
 			}
 			return (LWGEOM *)lwcollection_construct(type,
 				SRID, NULL, ngeoms, geoms);
@@ -2766,7 +2773,7 @@
 
 
 #ifdef PGIS_DEBUG
-  	elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
+  	elog(NOTICE,"result: %s", GEOSGeomToWKT(g3) ) ;
 #endif
 
 	GEOSSetSRID(g3, pglwgeom_getSRID(geom1));

Modified: packages/postgis/trunk/lwgeom/lwgeom_inout.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_inout.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_inout.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -102,6 +102,55 @@
 }
 
 /*
+ * AsHEXEWKB(geom, string)
+ */
+PG_FUNCTION_INFO_V1(LWGEOM_asHEXEWKB);
+Datum LWGEOM_asHEXEWKB(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *lwgeom;
+	char *result;
+	text *text_result;
+	size_t size;
+	text *type;
+	unsigned int byteorder=-1;
+
+	init_pg_func();
+
+	lwgeom = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
+	if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
+	{
+		type = PG_GETARG_TEXT_P(1);
+		if (VARSIZE(type) < 7)  
+		{
+			elog(ERROR,"AsHEXEWKB(geometry, <type>) - type should be 'XDR' or 'NDR'.  type length is %i",VARSIZE(type) -VARHDRSZ);
+			PG_RETURN_NULL();
+		}
+
+		if  ( ! strncmp(VARDATA(type), "xdr", 3) ||
+			! strncmp(VARDATA(type), "XDR", 3) )
+		{
+			byteorder = XDR;
+		}
+		else
+		{
+			byteorder = NDR;
+		}
+	}
+
+	result = unparse_WKB(SERIALIZED_FORM(lwgeom),lwalloc,lwfree,
+			byteorder, &size, 1);
+
+	text_result = palloc(size+VARHDRSZ);
+	memcpy(VARDATA(text_result),result,size);
+	VARATT_SIZEP(text_result) = size+VARHDRSZ;
+	pfree(result);
+
+	PG_RETURN_POINTER(text_result);
+
+}
+
+/*
  * LWGEOM_to_text(lwgeom) --> text
  * output is 'SRID=#;<wkb in hex form>'
  * ie. 'SRID=-99;0101000000000000000000F03F0000000000000040'

Modified: packages/postgis/trunk/lwgeom/lwgeom_jts.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_jts.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_jts.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -39,8 +39,6 @@
 Datum LWGEOM_buildarea(PG_FUNCTION_ARGS);
 Datum linemerge(PG_FUNCTION_ARGS);
 
-
-
 /*
  * Define this to have have many notices printed
  * during postgis->geos and geos->postgis conversions
@@ -234,6 +232,31 @@
 		g2 = JTSUnion(g1,geos_result);
 		if ( g2 == NULL )
 		{
+//#define PGIS_SQL_FAILURES 1
+
+#ifdef PGIS_SQL_FAILURES
+			LWGEOM *failing1, *failing2;
+			char *hexwkb1, *hexwkb2;
+
+			failing1 = JTS2LWGEOM(g1, 0);
+			failing2 = JTS2LWGEOM(geos_result, 0);
+
+			failing1->SRID=-1;
+			failing2->SRID=-1;
+
+			hexwkb1 = lwgeom_to_hexwkb(failing1, getMachineEndian());
+			hexwkb2 = lwgeom_to_hexwkb(failing2, getMachineEndian());
+
+			lwnotice("\nINSERT INTO jts_failures(g1,g2,op) VALUES ('%s', '%s', 'union');",
+				hexwkb1, hexwkb2);
+
+			lwgeom_release(failing1);
+			lwgeom_release(failing2);
+
+			// let it leak (getting memory errors otherwise)
+			//free(hexwkb1);
+			//free(hexwkb2);
+#endif
 			finishJTS();
 			lwerror("JTS union() threw an error!");
 			PG_RETURN_NULL();

Modified: packages/postgis/trunk/lwgeom/lwgeom_pg.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwgeom_pg.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwgeom_pg.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,16 +1,26 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
-#include "postgres.h"
-#include "executor/spi.h"
+#include <postgres.h>
+#include <fmgr.h>
+#include <executor/spi.h>
 #include "liblwgeom.h"
 #include "lwgeom_pg.h"
 #include "wktparse.h"
 
+
 /* #undef PGIS_DEBUG */
 
 #define PARANOIA_LEVEL 1
 
+/*
+ * This is required for builds against pgsql 8.2
+ */
+/*#include "pgmagic.h"*/
+#ifdef PG_MODULE_MAGIC
+PG_MODULE_MAGIC;
+#endif
+
 void *
 pg_alloc(size_t size)
 {

Modified: packages/postgis/trunk/lwgeom/lwline.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwline.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwline.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwline.c,v 1.32 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 /* basic LWLINE functions */
 
 #include <stdio.h>
@@ -50,7 +62,7 @@
 
 	if ( lwgeom_getType(type) != LINETYPE)
 	{
-		lwerror("lwline_deserialize: attempt to deserialize a line when its not really a line");
+		lwerror("lwline_deserialize: attempt to deserialize a line which is really a %s", lwgeom_typename(type));
 		return NULL;
 	}
 

Modified: packages/postgis/trunk/lwgeom/lwmline.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwmline.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwmline.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwmline.c,v 1.14 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

Modified: packages/postgis/trunk/lwgeom/lwmpoint.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwmpoint.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwmpoint.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwmpoint.c,v 1.14 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

Modified: packages/postgis/trunk/lwgeom/lwmpoly.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwmpoly.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwmpoly.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwmpoly.c,v 1.15 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

Modified: packages/postgis/trunk/lwgeom/lwpoint.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwpoint.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwpoint.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwpoint.c,v 1.23 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -256,7 +268,11 @@
 
 	type = serialized_form[0];
 
-	if ( lwgeom_getType(type) != POINTTYPE) return NULL;
+	if ( lwgeom_getType(type) != POINTTYPE)
+	{
+		lwerror("lwpoint_deserialize: attempt to deserialize a point which is really a %s", lwgeom_typename(type));
+		return NULL;
+	}
 	result->type = type;
 
 	loc = serialized_form+1;

Modified: packages/postgis/trunk/lwgeom/lwpoly.c
===================================================================
--- packages/postgis/trunk/lwgeom/lwpoly.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwpoly.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: lwpoly.c,v 1.23 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 /* basic LWPOLY manipulation */
 
 #include <stdio.h>
@@ -84,8 +96,7 @@
 
 	if ( TYPE_GETTYPE(type) != POLYGONTYPE)
 	{
-		lwerror("lwpoly_deserialize called with arg of type %d",
-			lwgeom_getType(type));
+		lwerror("lwpoly_deserialize: attempt to deserialize a poly which is really a %s", lwgeom_typename(type));
 		return NULL;
 	}
 

Modified: packages/postgis/trunk/lwgeom/lwpostgis.sql.in
===================================================================
--- packages/postgis/trunk/lwgeom/lwpostgis.sql.in	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/lwpostgis.sql.in	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,6 +1,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- 
--- $Id: lwpostgis.sql.in,v 1.155 2006/03/13 10:54:08 strk Exp $
+-- $Id: lwpostgis.sql.in,v 1.159 2006/06/25 23:59:32 strk Exp $
 --
 -- PostGIS - Spatial Types for PostgreSQL
 -- http://postgis.refractions.net
@@ -42,6 +42,9 @@
 # define _SECURITY_DEFINER 
 #endif 
 
+#if USE_VERSION >= 73
+# define HAS_SCHEMAS 1
+#endif
 
 BEGIN;
 
@@ -226,7 +229,8 @@
 -- Availability: 1.1.0 
 CREATEFUNCTION transscale(geometry,float8,float8,float8,float8)
         RETURNS geometry
-        AS 'SELECT affine($1,  $4, 0, 0,  0, $5, 0,  0, 0, 1,  $2*$4, $3*$5, 0)'
+        AS 'SELECT affine($1,  $4, 0, 0,  0, $5, 0, 
+		0, 0, 1,  $2 * $4, $3 * $5, 0)'
         LANGUAGE 'SQL' _IMMUTABLE_STRICT;
 
 -- Availability: 1.1.0
@@ -1255,6 +1259,16 @@
 	AS '@MODULE_FILENAME@','WKBFromLWGEOM'
 	LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
 
+CREATEFUNCTION AsHEXEWKB(geometry)
+	RETURNS TEXT
+	AS '@MODULE_FILENAME@','LWGEOM_asHEXEWKB'
+	LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
+
+CREATEFUNCTION AsHEXEWKB(geometry, text)
+	RETURNS TEXT
+	AS '@MODULE_FILENAME@','LWGEOM_asHEXEWKB'
+	LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
+
 CREATEFUNCTION AsEWKB(geometry,text)
 	RETURNS bytea
 	AS '@MODULE_FILENAME@','WKBFromLWGEOM'
@@ -1388,11 +1402,16 @@
 
 CREATE TYPE geometry_dump AS (path integer[], geom geometry);
 
-CREATEFUNCTION dump(geometry)
+CREATEFUNCTION Dump(geometry)
 	RETURNS SETOF geometry_dump
 	AS '@MODULE_FILENAME@', 'LWGEOM_dump'
 	LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
 
+CREATEFUNCTION DumpRings(geometry)
+	RETURNS SETOF geometry_dump
+	AS '@MODULE_FILENAME@', 'LWGEOM_dump_rings'
+	LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
+
 #endif
 
 ------------------------------------------------------------------------
@@ -3670,6 +3689,7 @@
 '
 LANGUAGE 'plpgsql' _IMMUTABLE_STRICT; 
 
+#include "long_xact.sql"
 
 ---------------------------------------------------------------
 -- END

Modified: packages/postgis/trunk/lwgeom/measures.c
===================================================================
--- packages/postgis/trunk/lwgeom/measures.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/measures.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: measures.c,v 1.11 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <math.h>
 #include <string.h>
 
@@ -3,5 +15,5 @@
 #include "liblwgeom.h"
 
-/*#define PGIS_DEBUG*/
+/*#define PGIS_DEBUG 1*/
 
 /*
@@ -35,7 +47,7 @@
 
 #ifdef PGIS_DEBUG
 	lwnotice("pt_in_ring_2d called with point: %g %g", p->x, p->y);
-	printPA(ring);
+	//printPA(ring);
 #endif
 
 	/* loop through all edges of the polygon */
@@ -74,9 +86,15 @@
 
 double distance2d_pt_pt(POINT2D *p1, POINT2D *p2)
 {
-	return sqrt(
-		(p2->x-p1->x) * (p2->x-p1->x) + (p2->y-p1->y) * (p2->y-p1->y)
-		); 
+	double hside = p2->x - p1->x;
+	double vside = p2->y - p1->y;
+
+	return sqrt ( hside*hside + vside*vside );
+
+	// the above is more readable
+	//return sqrt(
+	//	(p2->x-p1->x) * (p2->x-p1->x) + (p2->y-p1->y) * (p2->y-p1->y)
+	//	); 
 }
 
 /*distance2d from p to line A->B */
@@ -459,7 +477,7 @@
 double distance2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2)
 {
 	POINT2D pt;
-	double mindist = 0;
+	double mindist = -1;
 	int i;
 
 #ifdef PGIS_DEBUG
@@ -492,14 +510,15 @@
 				poly2->rings[j]);
 			if ( d <= 0 ) return 0.0;
 
-			if (i) mindist = LW_MIN(mindist, d);
+			// mindist is -1 when not yet set
+			if (mindist > -1) mindist = LW_MIN(mindist, d);
 			else mindist = d;
-		}
-
 #ifdef PGIS_DEBUG
-		lwnotice("  ring%d dist: %f, mindist: %f", i, d, mindist);
+		lwnotice("  ring%i-%i dist: %f, mindist: %f", i, j, d, mindist);
 #endif
 
+		}
+
 	}
 
 	/* otherwise return closest approach of rings (no intersection) */
@@ -758,7 +777,7 @@
 
 #ifdef PGIS_DEBUG
 		lwnotice("dist %d-%d: %f - mindist: %f",
-				t1, t2, dist, mindist);
+				i, j, dist, mindist);
 #endif
 
 

Modified: packages/postgis/trunk/lwgeom/ptarray.c
===================================================================
--- packages/postgis/trunk/lwgeom/ptarray.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/ptarray.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,3 +1,15 @@
+/**********************************************************************
+ * $Id: ptarray.c,v 1.31 2006/05/30 08:38:58 strk Exp $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ * 
+ **********************************************************************/
+
 #include <stdio.h>
 #include <string.h>
 

Modified: packages/postgis/trunk/lwgeom/wktparse.lex
===================================================================
--- packages/postgis/trunk/lwgeom/wktparse.lex	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/wktparse.lex	2006-07-20 16:49:42 UTC (rev 485)
@@ -9,7 +9,8 @@
 %x vals_ok
 %{
 #include "wktparse.tab.h"
-#include "unistd.h"
+#include <unistd.h>
+#include <stdlib.h> // need stdlib for atof() definition 
 
 void init_parser(const char *src);
 void close_parser(void);

Modified: packages/postgis/trunk/lwgeom/wktparse.tab.c
===================================================================
--- packages/postgis/trunk/lwgeom/wktparse.tab.c	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/wktparse.tab.c	2006-07-20 16:49:42 UTC (rev 485)
@@ -256,16 +256,16 @@
 /* YYFINAL -- State number of the termination state. */
 #define YYFINAL  6
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   122
+#define YYLAST   104
 
 /* YYNTOKENS -- Number of terminals. */
 #define YYNTOKENS  26
 /* YYNNTS -- Number of nonterminals. */
-#define YYNNTS  57
+#define YYNNTS  66
 /* YYNRULES -- Number of rules. */
-#define YYNRULES  89
+#define YYNRULES  98
 /* YYNRULES -- Number of states. */
-#define YYNSTATES  130
+#define YYNSTATES  139
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 #define YYUNDEFTOK  2
@@ -315,55 +315,59 @@
 {
        0,     0,     3,     4,     9,    10,    13,    15,    17,    19,
       21,    23,    25,    27,    29,    33,    35,    38,    39,    43,
-      44,    47,    49,    53,    54,    58,    59,    63,    65,    66,
-      71,    73,    77,    79,    80,    83,    86,    87,    91,    92,
-      95,    97,    98,   103,   105,   109,   110,   114,   115,   119,
-     121,   122,   127,   129,   133,   136,   137,   141,   142,   145,
-     147,   148,   153,   155,   159,   160,   164,   165,   169,   171,
-     172,   177,   179,   183,   184,   188,   189,   193,   195,   196,
-     201,   203,   205,   209,   211,   213,   215,   218,   222,   227
+      45,    47,    48,    51,    52,    55,    59,    60,    64,    65,
+      69,    71,    72,    77,    79,    83,    85,    86,    89,    92,
+      93,    97,    99,   101,   102,   105,   106,   109,   110,   115,
+     117,   121,   122,   126,   127,   131,   133,   134,   139,   141,
+     145,   148,   149,   153,   155,   157,   158,   161,   162,   165,
+     166,   171,   173,   177,   178,   182,   183,   187,   189,   190,
+     195,   197,   201,   202,   206,   207,   211,   213,   214,   219,
+     221,   223,   227,   229,   231,   233,   236,   240,   245
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
 static const yysigned_char yyrhs[] =
 {
       27,     0,    -1,    -1,    31,    24,    28,    30,    -1,    -1,
-      29,    30,    -1,    32,    -1,    33,    -1,    46,    -1,    59,
-      -1,    38,    -1,    53,    -1,    66,    -1,    72,    -1,    17,
+      29,    30,    -1,    32,    -1,    33,    -1,    49,    -1,    65,
+      -1,    41,    -1,    59,    -1,    75,    -1,    81,    -1,    17,
       23,    19,    -1,    25,    -1,     3,    35,    -1,    -1,    10,
-      34,    35,    -1,    -1,    36,    37,    -1,    82,    -1,    20,
-      78,    21,    -1,    -1,     6,    39,    41,    -1,    -1,    13,
-      40,    41,    -1,    82,    -1,    -1,    42,    20,    43,    21,
-      -1,    44,    -1,    43,    22,    44,    -1,    35,    -1,    -1,
-      45,    78,    -1,     4,    48,    -1,    -1,    11,    47,    48,
-      -1,    -1,    49,    50,    -1,    82,    -1,    -1,    51,    20,
-      52,    21,    -1,    78,    -1,    52,    22,    78,    -1,    -1,
-       7,    54,    56,    -1,    -1,    14,    55,    56,    -1,    82,
-      -1,    -1,    57,    20,    58,    21,    -1,    48,    -1,    58,
-      22,    48,    -1,     5,    61,    -1,    -1,    12,    60,    61,
-      -1,    -1,    62,    63,    -1,    82,    -1,    -1,    64,    20,
-      65,    21,    -1,    50,    -1,    65,    22,    50,    -1,    -1,
-       8,    67,    69,    -1,    -1,    15,    68,    69,    -1,    82,
-      -1,    -1,    70,    20,    71,    21,    -1,    61,    -1,    71,
-      22,    61,    -1,    -1,     9,    73,    75,    -1,    -1,    16,
-      74,    75,    -1,    82,    -1,    -1,    76,    20,    77,    21,
-      -1,    82,    -1,    30,    -1,    77,    22,    30,    -1,    79,
-      -1,    80,    -1,    81,    -1,    19,    19,    -1,    19,    19,
-      19,    -1,    19,    19,    19,    19,    -1,    18,    -1
+      34,    35,    -1,    36,    -1,    38,    -1,    -1,    37,    91,
+      -1,    -1,    39,    40,    -1,    20,    87,    21,    -1,    -1,
+       6,    42,    44,    -1,    -1,    13,    43,    44,    -1,    91,
+      -1,    -1,    45,    20,    46,    21,    -1,    47,    -1,    46,
+      22,    47,    -1,    38,    -1,    -1,    48,    87,    -1,     4,
+      51,    -1,    -1,    11,    50,    51,    -1,    52,    -1,    54,
+      -1,    -1,    53,    91,    -1,    -1,    55,    56,    -1,    -1,
+      57,    20,    58,    21,    -1,    87,    -1,    58,    22,    87,
+      -1,    -1,     7,    60,    62,    -1,    -1,    14,    61,    62,
+      -1,    91,    -1,    -1,    63,    20,    64,    21,    -1,    54,
+      -1,    64,    22,    54,    -1,     5,    67,    -1,    -1,    12,
+      66,    67,    -1,    68,    -1,    70,    -1,    -1,    69,    91,
+      -1,    -1,    71,    72,    -1,    -1,    73,    20,    74,    21,
+      -1,    56,    -1,    74,    22,    56,    -1,    -1,     8,    76,
+      78,    -1,    -1,    15,    77,    78,    -1,    91,    -1,    -1,
+      79,    20,    80,    21,    -1,    70,    -1,    80,    22,    70,
+      -1,    -1,     9,    82,    84,    -1,    -1,    16,    83,    84,
+      -1,    91,    -1,    -1,    85,    20,    86,    21,    -1,    91,
+      -1,    30,    -1,    86,    22,    30,    -1,    88,    -1,    89,
+      -1,    90,    -1,    19,    19,    -1,    19,    19,    19,    -1,
+      19,    19,    19,    19,    -1,    18,    -1
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const unsigned char yyrline[] =
 {
-       0,    35,    35,    35,    36,    36,    38,    38,    38,    38,
-      38,    39,    39,    39,    41,    43,    48,    48,    48,    50,
-      50,    52,    52,    56,    56,    57,    57,    59,    59,    59,
-      61,    61,    63,    63,    63,    68,    68,    68,    70,    70,
-      72,    72,    72,    74,    74,    78,    78,    78,    78,    80,
-      80,    80,    82,    82,    87,    87,    87,    89,    89,    91,
-      91,    91,    93,    93,    97,    97,    97,    97,    99,    99,
-      99,   101,   101,   107,   107,   107,   107,   109,   109,   109,
-     111,   111,   111,   114,   114,   114,   116,   118,   120,   122
+       0,    36,    36,    36,    38,    38,    41,    43,    45,    47,
+      49,    51,    53,    55,    58,    61,    67,    69,    69,    72,
+      74,    77,    77,    80,    80,    84,    89,    89,    91,    91,
+      94,    96,    96,    99,   101,   104,   107,   107,   113,   115,
+     115,   118,   120,   123,   123,   126,   126,   129,   129,   132,
+     134,   139,   139,   142,   142,   146,   148,   148,   151,   153,
+     159,   161,   161,   164,   166,   169,   169,   172,   172,   175,
+     175,   178,   180,   185,   185,   187,   187,   191,   193,   193,
+     196,   198,   204,   204,   207,   207,   211,   213,   213,   217,
+     219,   221,   225,   227,   229,   232,   235,   238,   241
 };
 #endif
 
@@ -378,16 +382,17 @@
   "MULTIPOLYGONM", "GEOMETRYCOLLECTIONM", "SRID", "EMPTY", "VALUE", 
   "LPAREN", "RPAREN", "COMMA", "EQUALS", "SEMICOLON", "WKB", "$accept", 
   "geometry", "@1", "@2", "geometry_int", "srid", "geom_wkb", 
-  "geom_point", "@3", "point", "@4", "point_int", "geom_multipoint", "@5", 
-  "@6", "multipoint", "@7", "multipoint_int", "mpoint", "@8", 
-  "geom_linestring", "@9", "linestring", "@10", "linestring_1", "@11", 
-  "linestring_int", "geom_multilinestring", "@12", "@13", 
-  "multilinestring", "@14", "multilinestring_int", "geom_polygon", "@15", 
-  "polygon", "@16", "polygon_1", "@17", "polygon_int", 
-  "geom_multipolygon", "@18", "@19", "multipolygon", "@20", 
-  "multipolygon_int", "geom_geometrycollection", "@21", "@22", 
-  "geometrycollection", "@23", "geometrycollection_int", "a_point", 
-  "point_2d", "point_3d", "point_4d", "empty", 0
+  "geom_point", "@3", "point", "empty_point", "@4", "nonempty_point", 
+  "@5", "point_int", "geom_multipoint", "@6", "@7", "multipoint", "@8", 
+  "multipoint_int", "mpoint_element", "@9", "geom_linestring", "@10", 
+  "linestring", "empty_linestring", "@11", "nonempty_linestring", "@12", 
+  "linestring_1", "@13", "linestring_int", "geom_multilinestring", "@14", 
+  "@15", "multilinestring", "@16", "multilinestring_int", "geom_polygon", 
+  "@17", "polygon", "empty_polygon", "@18", "nonempty_polygon", "@19", 
+  "polygon_1", "@20", "polygon_int", "geom_multipolygon", "@21", "@22", 
+  "multipolygon", "@23", "multipolygon_int", "geom_geometrycollection", 
+  "@24", "@25", "geometrycollection", "@26", "geometrycollection_int", 
+  "a_point", "point_2d", "point_3d", "point_4d", "empty", 0
 };
 #endif
 
@@ -406,28 +411,30 @@
 static const unsigned char yyr1[] =
 {
        0,    26,    28,    27,    29,    27,    30,    30,    30,    30,
-      30,    30,    30,    30,    31,    32,    33,    34,    33,    36,
-      35,    37,    37,    39,    38,    40,    38,    41,    42,    41,
-      43,    43,    44,    45,    44,    46,    47,    46,    49,    48,
-      50,    51,    50,    52,    52,    54,    53,    55,    53,    56,
-      57,    56,    58,    58,    59,    60,    59,    62,    61,    63,
-      64,    63,    65,    65,    67,    66,    68,    66,    69,    70,
-      69,    71,    71,    73,    72,    74,    72,    75,    76,    75,
-      77,    77,    77,    78,    78,    78,    79,    80,    81,    82
+      30,    30,    30,    30,    31,    32,    33,    34,    33,    35,
+      35,    37,    36,    39,    38,    40,    42,    41,    43,    41,
+      44,    45,    44,    46,    46,    47,    48,    47,    49,    50,
+      49,    51,    51,    53,    52,    55,    54,    57,    56,    58,
+      58,    60,    59,    61,    59,    62,    63,    62,    64,    64,
+      65,    66,    65,    67,    67,    69,    68,    71,    70,    73,
+      72,    74,    74,    76,    75,    77,    75,    78,    79,    78,
+      80,    80,    82,    81,    83,    81,    84,    85,    84,    86,
+      86,    86,    87,    87,    87,    88,    89,    90,    91
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
 static const unsigned char yyr2[] =
 {
        0,     2,     0,     4,     0,     2,     1,     1,     1,     1,
-       1,     1,     1,     1,     3,     1,     2,     0,     3,     0,
-       2,     1,     3,     0,     3,     0,     3,     1,     0,     4,
-       1,     3,     1,     0,     2,     2,     0,     3,     0,     2,
-       1,     0,     4,     1,     3,     0,     3,     0,     3,     1,
-       0,     4,     1,     3,     2,     0,     3,     0,     2,     1,
-       0,     4,     1,     3,     0,     3,     0,     3,     1,     0,
+       1,     1,     1,     1,     3,     1,     2,     0,     3,     1,
+       1,     0,     2,     0,     2,     3,     0,     3,     0,     3,
+       1,     0,     4,     1,     3,     1,     0,     2,     2,     0,
+       3,     1,     1,     0,     2,     0,     2,     0,     4,     1,
+       3,     0,     3,     0,     3,     1,     0,     4,     1,     3,
+       2,     0,     3,     1,     1,     0,     2,     0,     2,     0,
        4,     1,     3,     0,     3,     0,     3,     1,     0,     4,
-       1,     1,     3,     1,     1,     1,     2,     3,     4,     1
+       1,     3,     0,     3,     0,     3,     1,     0,     4,     1,
+       1,     3,     1,     1,     1,     2,     3,     4,     1
 };
 
 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -435,100 +442,100 @@
    means the default is an error.  */
 static const unsigned char yydefact[] =
 {
-       4,     0,     0,     0,     0,     0,     1,    19,    38,    57,
-      23,    45,    64,    73,    17,    36,    55,    25,    47,    66,
-      75,    15,     5,     6,     7,    10,     8,    11,     9,    12,
-      13,     2,    14,    16,     0,    35,    41,    54,    60,    28,
-      50,    69,    78,    19,    38,    57,    28,    50,    69,    78,
-       0,    89,     0,    20,    21,    39,     0,    40,    58,     0,
-      59,    24,     0,    27,    46,     0,    49,    65,     0,    68,
-      74,     0,    77,    18,    37,    56,    26,    48,    67,    76,
-       3,     0,     0,    83,    84,    85,     0,    41,    19,    38,
-      57,     0,    86,    22,     0,    43,    62,     0,    32,     0,
-      30,     0,    52,     0,    71,     0,    81,     0,    80,    87,
-      42,     0,    61,    41,    29,    19,    34,    51,    38,    70,
-      57,    79,     0,    88,    44,    63,    31,    53,    72,    82
+       4,     0,     0,     0,     0,     0,     1,    21,    43,    65,
+      26,    51,    73,    82,    17,    39,    61,    28,    53,    75,
+      84,    15,     5,     6,     7,    10,     8,    11,     9,    12,
+      13,     2,    14,    16,    19,     0,    20,     0,    38,    41,
+       0,    42,    47,    60,    63,     0,    64,    69,    31,    56,
+      78,    87,    21,    43,    65,    31,    56,    78,    87,     0,
+      98,    22,     0,    24,    44,    46,     0,    66,    68,     0,
+      27,     0,    30,    52,     0,    55,    74,     0,    77,    83,
+       0,    86,    18,    40,    62,    29,    54,    76,    85,     3,
+       0,     0,    92,    93,    94,     0,    47,    23,    45,    67,
+       0,    95,    25,     0,    49,    71,     0,    35,     0,    33,
+       0,    58,     0,    80,     0,    90,     0,    89,    96,    48,
+       0,    70,    47,    32,    23,    37,    57,    45,    79,    67,
+      88,     0,    97,    50,    72,    34,    59,    81,    91
 };
 
 /* YYDEFGOTO[NTERM-NUM]. */
 static const yysigned_char yydefgoto[] =
 {
-      -1,     2,    50,     3,    22,     4,    23,    24,    43,    98,
-      34,    53,    25,    39,    46,    61,    62,    99,   100,   101,
-      26,    44,    35,    36,    55,    56,    94,    27,    40,    47,
-      64,    65,   103,    28,    45,    37,    38,    58,    59,    97,
-      29,    41,    48,    67,    68,   105,    30,    42,    49,    70,
-      71,   107,    82,    83,    84,    85,    57
+      -1,     2,    59,     3,    22,     4,    23,    24,    52,    33,
+      34,    35,    36,    37,    63,    25,    48,    55,    70,    71,
+     108,   109,   110,    26,    53,    38,    39,    40,    41,    42,
+      65,    66,   103,    27,    49,    56,    73,    74,   112,    28,
+      54,    43,    44,    45,    46,    47,    68,    69,   106,    29,
+      50,    57,    76,    77,   114,    30,    51,    58,    79,    80,
+     116,    91,    92,    93,    94,    72
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-#define YYPACT_NINF -83
+#define YYPACT_NINF -98
 static const yysigned_char yypact[] =
 {
-     -11,    -1,    20,    97,     6,    17,   -83,   -83,   -83,   -83,
-     -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,
-     -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,
-     -83,   -83,   -83,   -83,     1,   -83,    21,   -83,    21,    21,
-      21,    21,    21,   -83,   -83,   -83,    21,    21,    21,    21,
-      97,   -83,    19,   -83,   -83,   -83,    23,   -83,   -83,    24,
-     -83,   -83,    26,   -83,   -83,    28,   -83,   -83,    29,   -83,
-     -83,    30,   -83,   -83,   -83,   -83,   -83,   -83,   -83,   -83,
-     -83,    22,    31,   -83,   -83,   -83,    19,    21,    32,   -83,
-     -83,    74,    34,   -83,    -8,   -83,   -83,     2,   -83,     4,
-     -83,    19,   -83,     7,   -83,    11,   -83,    13,   -83,    35,
-     -83,    19,   -83,    21,   -83,    32,   -83,   -83,   -83,   -83,
-     -83,   -83,    97,   -83,   -83,   -83,   -83,   -83,   -83,   -83
+     -12,    13,    14,    70,     4,    18,   -98,    19,    20,    36,
+     -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,
+     -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,
+     -98,   -98,   -98,   -98,   -98,    40,   -98,    41,   -98,   -98,
+      40,   -98,   -98,   -98,   -98,    40,   -98,   -98,    40,    40,
+      40,    40,    19,    20,    36,    40,    40,    40,    40,    70,
+     -98,   -98,    43,   -98,   -98,   -98,    45,   -98,   -98,    47,
+     -98,    48,   -98,   -98,    49,   -98,   -98,    50,   -98,   -98,
+      51,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,
+      44,    17,   -98,   -98,   -98,    43,   -98,    68,   -98,   -98,
+      39,    69,   -98,   -13,   -98,   -98,    -9,   -98,    -3,   -98,
+      43,   -98,    -1,   -98,     5,   -98,     9,   -98,    71,   -98,
+      43,   -98,   -98,   -98,    68,   -98,   -98,   -98,   -98,   -98,
+     -98,    70,   -98,   -98,   -98,   -98,   -98,   -98,   -98
 };
 
 /* YYPGOTO[NTERM-NUM].  */
 static const yysigned_char yypgoto[] =
 {
-     -83,   -83,   -83,   -83,   -49,   -83,   -83,   -83,   -83,    -3,
-     -83,   -83,   -83,   -83,   -83,     9,   -83,   -83,   -59,   -83,
-     -83,   -83,   -42,   -83,   -82,   -83,   -83,   -83,   -83,   -83,
-      10,   -83,   -83,   -83,   -83,   -45,   -83,   -83,   -83,   -83,
-     -83,   -83,   -83,    14,   -83,   -83,   -83,   -83,   -83,    12,
-     -83,   -83,   -74,   -83,   -83,   -83,   -31
+     -98,   -98,   -98,   -98,   -59,   -98,   -98,   -98,   -98,     7,
+     -98,   -98,   -90,   -98,   -98,   -98,   -98,   -98,    34,   -98,
+     -98,   -64,   -98,   -98,   -98,    38,   -98,   -98,   -94,   -98,
+     -93,   -98,   -98,   -98,   -98,   -98,    37,   -98,   -98,   -98,
+     -98,    42,   -98,   -98,   -97,   -98,   -98,   -98,   -98,   -98,
+     -98,   -98,    35,   -98,   -98,   -98,   -98,   -98,    46,   -98,
+     -98,   -85,   -98,   -98,   -98,   -34
 };
 
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
    positive, shift that token.  If negative, reduce the rule which
    number is the opposite.  If zero, do what YYDEFACT says.
    If YYTABLE_NINF, syntax error.  */
-#define YYTABLE_NINF -34
+#define YYTABLE_NINF -68
 static const short yytable[] =
 {
-      75,    80,    74,    54,    33,    96,     1,    60,    63,    66,
-      69,    72,    95,   110,   111,    63,    66,    69,    72,    51,
-       6,    52,     5,   112,   113,   114,   115,   116,   117,   118,
-      31,   125,   119,   120,   121,   122,    32,   124,    81,    51,
-      73,    92,   106,    86,    87,   104,    88,   102,    89,    90,
-      91,   -33,    93,   109,   123,    76,   126,    77,     0,     0,
-     108,    79,    78,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,   129,     0,   128,   127,     7,     8,     9,
-      10,    11,    12,    13,    14,    15,    16,    17,    18,    19,
-      20,     0,    51,     0,     0,     0,     0,     0,     0,    21,
-       7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
-      17,    18,    19,    20,     0,     0,     0,     0,     0,     0,
-       0,     0,    21
+      89,    61,   113,   105,   111,     1,    64,   107,   119,   120,
+     104,    67,   121,   122,     6,    75,    78,    81,   123,   124,
+     126,   127,    75,    78,    81,   125,   128,   129,    31,   134,
+     130,   131,   137,   136,   107,   133,     5,    32,   102,   -23,
+     -45,   115,     7,     8,     9,    10,    11,    12,    13,    14,
+      15,    16,    17,    18,    19,    20,   -67,    60,    60,    82,
+     135,    62,    90,   101,    21,    95,   117,    96,    97,    98,
+      99,   100,   138,     7,     8,     9,    10,    11,    12,    13,
+      14,    15,    16,    17,    18,    19,    20,   -36,   118,    85,
+     132,    83,    87,    86,     0,    21,    84,     0,     0,     0,
+       0,     0,     0,     0,    88
 };
 
-static const yysigned_char yycheck[] =
+static const short yycheck[] =
 {
-      45,    50,    44,    34,     7,    87,    17,    38,    39,    40,
-      41,    42,    86,    21,    22,    46,    47,    48,    49,    18,
-       0,    20,    23,    21,    22,    21,    22,   101,    21,    22,
-      24,   113,    21,    22,    21,    22,    19,   111,    19,    18,
-      43,    19,    91,    20,    20,    90,    20,    89,    20,    20,
-      20,    19,    21,    19,    19,    46,   115,    47,    -1,    -1,
-      91,    49,    48,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   122,    -1,   120,   118,     3,     4,     5,
-       6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
-      16,    -1,    18,    -1,    -1,    -1,    -1,    -1,    -1,    25,
-       3,     4,     5,     6,     7,     8,     9,    10,    11,    12,
-      13,    14,    15,    16,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    25
+      59,    35,    99,    96,    98,    17,    40,    97,    21,    22,
+      95,    45,    21,    22,     0,    49,    50,    51,    21,    22,
+      21,    22,    56,    57,    58,   110,    21,    22,    24,   122,
+      21,    22,   129,   127,   124,   120,    23,    19,    21,    20,
+      20,   100,     3,     4,     5,     6,     7,     8,     9,    10,
+      11,    12,    13,    14,    15,    16,    20,    18,    18,    52,
+     124,    20,    19,    19,    25,    20,   100,    20,    20,    20,
+      20,    20,   131,     3,     4,     5,     6,     7,     8,     9,
+      10,    11,    12,    13,    14,    15,    16,    19,    19,    55,
+      19,    53,    57,    56,    -1,    25,    54,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    58
 };
 
 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
@@ -537,17 +544,18 @@
 {
        0,    17,    27,    29,    31,    23,     0,     3,     4,     5,
        6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
-      16,    25,    30,    32,    33,    38,    46,    53,    59,    66,
-      72,    24,    19,    35,    36,    48,    49,    61,    62,    39,
-      54,    67,    73,    34,    47,    60,    40,    55,    68,    74,
-      28,    18,    20,    37,    82,    50,    51,    82,    63,    64,
-      82,    41,    42,    82,    56,    57,    82,    69,    70,    82,
-      75,    76,    82,    35,    48,    61,    41,    56,    69,    75,
-      30,    19,    78,    79,    80,    81,    20,    20,    20,    20,
-      20,    20,    19,    21,    52,    78,    50,    65,    35,    43,
-      44,    45,    48,    58,    61,    71,    30,    77,    82,    19,
-      21,    22,    21,    22,    21,    22,    78,    21,    22,    21,
-      22,    21,    22,    19,    78,    50,    44,    48,    61,    30
+      16,    25,    30,    32,    33,    41,    49,    59,    65,    75,
+      81,    24,    19,    35,    36,    37,    38,    39,    51,    52,
+      53,    54,    55,    67,    68,    69,    70,    71,    42,    60,
+      76,    82,    34,    50,    66,    43,    61,    77,    83,    28,
+      18,    91,    20,    40,    91,    56,    57,    91,    72,    73,
+      44,    45,    91,    62,    63,    91,    78,    79,    91,    84,
+      85,    91,    35,    51,    67,    44,    62,    78,    84,    30,
+      19,    87,    88,    89,    90,    20,    20,    20,    20,    20,
+      20,    19,    21,    58,    87,    56,    74,    38,    46,    47,
+      48,    54,    64,    70,    80,    30,    86,    91,    19,    21,
+      22,    21,    22,    21,    22,    87,    21,    22,    21,    22,
+      21,    22,    19,    87,    56,    47,    54,    70,    30
 };
 
 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
@@ -1157,245 +1165,275 @@
   switch (yyn)
     {
         case 2:
-#line 35 "wktparse.y"
+#line 36 "wktparse.y"
     { alloc_lwgeom(srid); }
     break;
 
   case 4:
-#line 36 "wktparse.y"
+#line 38 "wktparse.y"
     { alloc_lwgeom(-1); }
     break;
 
   case 14:
-#line 41 "wktparse.y"
+#line 58 "wktparse.y"
     { set_srid(yyvsp[0].value); }
     break;
 
   case 15:
-#line 43 "wktparse.y"
-    {alloc_wkb(yyvsp[0].wkb) ; }
+#line 61 "wktparse.y"
+    { alloc_wkb(yyvsp[0].wkb); }
     break;
 
   case 17:
-#line 48 "wktparse.y"
+#line 69 "wktparse.y"
     { set_zm(0, 1); }
     break;
 
-  case 19:
-#line 50 "wktparse.y"
+  case 21:
+#line 77 "wktparse.y"
     { alloc_point(); }
     break;
 
-  case 20:
-#line 50 "wktparse.y"
-    { pop();}
+  case 22:
+#line 77 "wktparse.y"
+    { pop(); }
     break;
 
   case 23:
-#line 56 "wktparse.y"
-    { alloc_multipoint(); }
+#line 80 "wktparse.y"
+    { alloc_point(); }
     break;
 
   case 24:
-#line 56 "wktparse.y"
-    { pop();}
+#line 80 "wktparse.y"
+    { pop(); }
     break;
 
-  case 25:
-#line 57 "wktparse.y"
-    { set_zm(0, 1); alloc_multipoint(); }
+  case 26:
+#line 89 "wktparse.y"
+    { alloc_multipoint(); }
     break;
 
-  case 26:
-#line 57 "wktparse.y"
-    {pop();}
+  case 27:
+#line 89 "wktparse.y"
+    { pop(); }
     break;
 
   case 28:
-#line 59 "wktparse.y"
-    { alloc_counter(); }
+#line 91 "wktparse.y"
+    { set_zm(0, 1); alloc_multipoint(); }
     break;
 
   case 29:
-#line 59 "wktparse.y"
-    {pop();}
+#line 91 "wktparse.y"
+    {pop(); }
     break;
 
-  case 33:
-#line 63 "wktparse.y"
-    { alloc_point(); }
+  case 31:
+#line 96 "wktparse.y"
+    { alloc_counter(); }
     break;
 
-  case 34:
-#line 63 "wktparse.y"
-    { pop();}
+  case 32:
+#line 96 "wktparse.y"
+    { pop(); }
     break;
 
   case 36:
-#line 68 "wktparse.y"
-    { set_zm(0, 1); }
+#line 107 "wktparse.y"
+    { alloc_point(); }
     break;
 
-  case 38:
-#line 70 "wktparse.y"
-    { alloc_linestring(); }
+  case 37:
+#line 107 "wktparse.y"
+    { pop(); }
     break;
 
   case 39:
-#line 70 "wktparse.y"
-    {pop();}
+#line 115 "wktparse.y"
+    { set_zm(0, 1); }
     break;
 
-  case 41:
-#line 72 "wktparse.y"
-    { alloc_counter(); }
+  case 43:
+#line 123 "wktparse.y"
+    { alloc_linestring(); }
     break;
 
-  case 42:
-#line 72 "wktparse.y"
-    {popc(); }
+  case 44:
+#line 123 "wktparse.y"
+    { pop(); }
     break;
 
   case 45:
-#line 78 "wktparse.y"
-    { alloc_multilinestring(); }
+#line 126 "wktparse.y"
+    { alloc_linestring(); }
     break;
 
   case 46:
-#line 78 "wktparse.y"
-    { pop();}
+#line 126 "wktparse.y"
+    { pop(); }
     break;
 
   case 47:
-#line 78 "wktparse.y"
-    { set_zm(0, 1); alloc_multilinestring(); }
+#line 129 "wktparse.y"
+    { alloc_counter(); }
     break;
 
   case 48:
-#line 78 "wktparse.y"
-    { pop(); }
+#line 129 "wktparse.y"
+    { popc(); }
     break;
 
-  case 50:
-#line 80 "wktparse.y"
-    { alloc_counter(); }
-    break;
-
   case 51:
-#line 80 "wktparse.y"
-    { pop();}
+#line 139 "wktparse.y"
+    { alloc_multilinestring(); }
     break;
 
-  case 55:
-#line 87 "wktparse.y"
-    { set_zm(0, 1); }
+  case 52:
+#line 140 "wktparse.y"
+    { pop(); }
     break;
 
-  case 57:
-#line 89 "wktparse.y"
-    { alloc_polygon(); }
+  case 53:
+#line 142 "wktparse.y"
+    { set_zm(0, 1); alloc_multilinestring(); }
     break;
 
-  case 58:
-#line 89 "wktparse.y"
-    { pop();}
+  case 54:
+#line 143 "wktparse.y"
+    { pop(); }
     break;
 
-  case 60:
-#line 91 "wktparse.y"
+  case 56:
+#line 148 "wktparse.y"
     { alloc_counter(); }
     break;
 
-  case 61:
-#line 91 "wktparse.y"
+  case 57:
+#line 148 "wktparse.y"
     { pop();}
     break;
 
-  case 64:
-#line 97 "wktparse.y"
-    { alloc_multipolygon(); }
+  case 61:
+#line 161 "wktparse.y"
+    { set_zm(0, 1); }
     break;
 
   case 65:
-#line 97 "wktparse.y"
-    { pop();}
+#line 169 "wktparse.y"
+    { alloc_polygon(); }
     break;
 
   case 66:
-#line 97 "wktparse.y"
-    { set_zm(0, 1); alloc_multipolygon(); }
+#line 169 "wktparse.y"
+    { pop(); }
     break;
 
   case 67:
-#line 97 "wktparse.y"
-    { pop();}
+#line 172 "wktparse.y"
+    { alloc_polygon(); }
     break;
 
+  case 68:
+#line 172 "wktparse.y"
+    { pop(); }
+    break;
+
   case 69:
-#line 99 "wktparse.y"
+#line 175 "wktparse.y"
     { alloc_counter(); }
     break;
 
   case 70:
-#line 99 "wktparse.y"
+#line 175 "wktparse.y"
     { pop();}
     break;
 
   case 73:
-#line 107 "wktparse.y"
-    { alloc_geomertycollection(); }
+#line 185 "wktparse.y"
+    { alloc_multipolygon(); }
     break;
 
   case 74:
-#line 107 "wktparse.y"
-    { pop();}
+#line 185 "wktparse.y"
+    { pop(); }
     break;
 
   case 75:
-#line 107 "wktparse.y"
-    { set_zm(0, 1); alloc_geomertycollection(); }
+#line 187 "wktparse.y"
+    { set_zm(0, 1); alloc_multipolygon(); }
     break;
 
   case 76:
-#line 107 "wktparse.y"
+#line 188 "wktparse.y"
     { pop();}
     break;
 
   case 78:
-#line 109 "wktparse.y"
+#line 193 "wktparse.y"
     { alloc_counter(); }
     break;
 
   case 79:
-#line 109 "wktparse.y"
+#line 193 "wktparse.y"
+    { pop(); }
+    break;
+
+  case 82:
+#line 204 "wktparse.y"
+    { alloc_geomertycollection(); }
+    break;
+
+  case 83:
+#line 205 "wktparse.y"
+    { pop(); }
+    break;
+
+  case 84:
+#line 207 "wktparse.y"
+    { set_zm(0, 1); alloc_geomertycollection(); }
+    break;
+
+  case 85:
+#line 208 "wktparse.y"
     { pop();}
     break;
 
-  case 86:
-#line 116 "wktparse.y"
+  case 87:
+#line 213 "wktparse.y"
+    { alloc_counter(); }
+    break;
+
+  case 88:
+#line 213 "wktparse.y"
+    { pop(); }
+    break;
+
+  case 95:
+#line 232 "wktparse.y"
     {alloc_point_2d(yyvsp[-1].value,yyvsp[0].value); }
     break;
 
-  case 87:
-#line 118 "wktparse.y"
+  case 96:
+#line 235 "wktparse.y"
     {alloc_point_3d(yyvsp[-2].value,yyvsp[-1].value,yyvsp[0].value); }
     break;
 
-  case 88:
-#line 120 "wktparse.y"
+  case 97:
+#line 238 "wktparse.y"
     {alloc_point_4d(yyvsp[-3].value,yyvsp[-2].value,yyvsp[-1].value,yyvsp[0].value); }
     break;
 
-  case 89:
-#line 122 "wktparse.y"
-    {alloc_empty(); }
+  case 98:
+#line 241 "wktparse.y"
+    { alloc_empty(); }
     break;
 
 
     }
 
 /* Line 991 of yacc.c.  */
-#line 1398 "y.tab.c"
+#line 1436 "y.tab.c"
 
   yyvsp -= yylen;
   yyssp -= yylen;
@@ -1604,7 +1642,7 @@
 }
 
 
-#line 123 "wktparse.y"
+#line 35 "wktparse.y"
 
 
 

Modified: packages/postgis/trunk/lwgeom/wktparse.y
===================================================================
--- packages/postgis/trunk/lwgeom/wktparse.y	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/lwgeom/wktparse.y	2006-07-20 16:49:42 UTC (rev 485)
@@ -32,94 +32,213 @@
 
 %%
 
-geometry : srid  SEMICOLON  { alloc_lwgeom(srid); } geometry_int 
-	| { alloc_lwgeom(-1); } geometry_int	;
+geometry :
+	srid  SEMICOLON  { alloc_lwgeom(srid); } geometry_int 
+	|
+	{ alloc_lwgeom(-1); } geometry_int
 
-geometry_int : geom_wkb | geom_point | geom_linestring | geom_polygon | geom_multipoint 
-	| geom_multilinestring | geom_multipolygon| geom_geometrycollection;
+geometry_int :
+	geom_wkb
+	|
+	geom_point
+	|
+	geom_linestring
+	|
+	geom_polygon
+	|
+	geom_multipoint 
+	|
+	geom_multilinestring
+	|
+	geom_multipolygon
+	|
+	geom_geometrycollection
 
-srid : SRID EQUALS VALUE { set_srid($3); } ; 
+srid :
+	SRID EQUALS VALUE { set_srid($3); } 
 
-geom_wkb : WKB {alloc_wkb($1) ; } ;
+geom_wkb :
+	WKB { alloc_wkb($1); }
 
 
 /* POINT */
 
-geom_point : POINT point | POINTM { set_zm(0, 1); } point ;
+geom_point :
+	POINT point
+	|
+	POINTM { set_zm(0, 1); } point 
 
-point : { alloc_point(); } point_int { pop();} ;
+point :
+	empty_point
+	|
+	nonempty_point
 
-point_int : empty | LPAREN a_point RPAREN;
+empty_point :
+	{ alloc_point(); } empty { pop(); } 
 
+nonempty_point :
+	{ alloc_point(); } point_int { pop(); } 
+
+
+point_int :
+	LPAREN a_point RPAREN
+
 /* MULTIPOINT */
 
-geom_multipoint : MULTIPOINT { alloc_multipoint(); } multipoint  { pop();} | 
-	MULTIPOINTM { set_zm(0, 1); alloc_multipoint(); } multipoint {pop();};
+geom_multipoint :
+	MULTIPOINT { alloc_multipoint(); } multipoint  { pop(); }
+	| 
+	MULTIPOINTM { set_zm(0, 1); alloc_multipoint(); } multipoint {pop(); }
 
-multipoint : empty | { alloc_counter(); } LPAREN multipoint_int RPAREN {pop();} ;
+multipoint :
+	empty
+	|
+	{ alloc_counter(); } LPAREN multipoint_int RPAREN { pop(); } 
 
-multipoint_int : mpoint | multipoint_int COMMA mpoint;
+multipoint_int :
+	mpoint_element
+	|
+	multipoint_int COMMA mpoint_element
 
-mpoint : point  |  { alloc_point(); } a_point { pop();} ;
+mpoint_element :
+	nonempty_point
+	|
+	/* this is to allow MULTIPOINT(0 0, 1 1) */
+	{ alloc_point(); } a_point { pop(); }
 
 
 /* LINESTRING */
 
-geom_linestring : LINESTRING linestring | LINESTRINGM { set_zm(0, 1); } linestring ;
+geom_linestring :
+	LINESTRING linestring
+	|
+	LINESTRINGM { set_zm(0, 1); } linestring
 
-linestring : { alloc_linestring(); } linestring_1 {pop();} ;
+linestring :
+	empty_linestring
+	|
+	nonempty_linestring
 
-linestring_1 : empty | { alloc_counter(); } LPAREN linestring_int RPAREN {popc(); };
+empty_linestring :
+	{ alloc_linestring(); } empty { pop(); } 
 
-linestring_int : a_point | linestring_int COMMA a_point;
+nonempty_linestring :
+	{ alloc_linestring(); } linestring_1 { pop(); } 
 
+linestring_1 :
+	{ alloc_counter(); } LPAREN linestring_int RPAREN { popc(); }
+
+linestring_int :
+	a_point
+	|
+	linestring_int COMMA a_point;
+
 /* MULTILINESTRING */
 
-geom_multilinestring : MULTILINESTRING { alloc_multilinestring(); } multilinestring  { pop();} | MULTILINESTRINGM { set_zm(0, 1); alloc_multilinestring(); } multilinestring { pop(); } ;
+geom_multilinestring :
+	MULTILINESTRING { alloc_multilinestring(); }
+		multilinestring  { pop(); }
+	|
+	MULTILINESTRINGM { set_zm(0, 1); alloc_multilinestring(); }
+		multilinestring { pop(); } 
 
-multilinestring : empty | { alloc_counter(); } LPAREN multilinestring_int RPAREN{ pop();} ;
+multilinestring :
+	empty
+	|
+	{ alloc_counter(); } LPAREN multilinestring_int RPAREN{ pop();}
 
-multilinestring_int : linestring | multilinestring_int COMMA linestring;
+multilinestring_int :
+	nonempty_linestring
+	|
+	multilinestring_int COMMA nonempty_linestring
 
 
 /* POLYGON */
 
-geom_polygon : POLYGON polygon | POLYGONM { set_zm(0, 1); } polygon ;
+geom_polygon :
+	POLYGON polygon
+	|
+	POLYGONM { set_zm(0, 1); } polygon 
 
-polygon : { alloc_polygon(); } polygon_1  { pop();} ;
+polygon :
+	empty_polygon
+	|
+	nonempty_polygon
 
-polygon_1 : empty | { alloc_counter(); } LPAREN polygon_int RPAREN { pop();} ;
+empty_polygon :
+	{ alloc_polygon(); } empty  { pop(); } 
 
-polygon_int : linestring_1 | polygon_int COMMA linestring_1;
+nonempty_polygon :
+	{ alloc_polygon(); } polygon_1  { pop(); } 
+
+polygon_1 :
+	{ alloc_counter(); } LPAREN polygon_int RPAREN { pop();} 
+
+polygon_int :
+	linestring_1
+	|
+	polygon_int COMMA linestring_1
                                                                                                           
 /* MULTIPOLYGON */
 
-geom_multipolygon : MULTIPOLYGON { alloc_multipolygon(); } multipolygon   { pop();} | MULTIPOLYGONM { set_zm(0, 1); alloc_multipolygon(); } multipolygon  { pop();} ;
+geom_multipolygon :
+	MULTIPOLYGON { alloc_multipolygon(); } multipolygon { pop(); }
+	|
+	MULTIPOLYGONM { set_zm(0, 1); alloc_multipolygon(); }
+		multipolygon { pop();} 
 
-multipolygon : empty | { alloc_counter(); } LPAREN multipolygon_int RPAREN { pop();} ; 
+multipolygon :
+	empty
+	|
+	{ alloc_counter(); } LPAREN multipolygon_int RPAREN { pop(); }
 
-multipolygon_int : polygon | multipolygon_int COMMA polygon;
+multipolygon_int :
+	nonempty_polygon
+	|
+	multipolygon_int COMMA nonempty_polygon
 
 
-
 /* GEOMETRYCOLLECTION */
 
-geom_geometrycollection : GEOMETRYCOLLECTION { alloc_geomertycollection(); } geometrycollection { pop();} | GEOMETRYCOLLECTIONM { set_zm(0, 1); alloc_geomertycollection(); } geometrycollection { pop();} ;
+geom_geometrycollection :
+	GEOMETRYCOLLECTION { alloc_geomertycollection(); }
+		geometrycollection { pop(); }
+	|
+	GEOMETRYCOLLECTIONM { set_zm(0, 1); alloc_geomertycollection(); }
+		geometrycollection { pop();}
 
-geometrycollection : empty | { alloc_counter(); } LPAREN geometrycollection_int RPAREN { pop();} ;
+geometrycollection :
+	empty
+	|
+	{ alloc_counter(); } LPAREN geometrycollection_int RPAREN { pop(); }
 
-geometrycollection_int  : empty | geometry_int | geometrycollection_int  COMMA geometry_int;
+geometrycollection_int :
+	/* to support GEOMETRYCOLLECTION(EMPTY) for backward compatibility */
+	empty
+	|
+	geometry_int
+	|
+	geometrycollection_int COMMA geometry_int
 
 
-a_point : point_2d | point_3d | point_4d ;
+a_point :
+	point_2d
+	|
+	point_3d
+	|
+	point_4d 
 
-point_2d : VALUE VALUE {alloc_point_2d($1,$2); };
+point_2d :
+	VALUE VALUE {alloc_point_2d($1,$2); }
 
-point_3d : VALUE VALUE VALUE {alloc_point_3d($1,$2,$3); };
+point_3d :
+	VALUE VALUE VALUE {alloc_point_3d($1,$2,$3); }
 
-point_4d : VALUE VALUE VALUE VALUE {alloc_point_4d($1,$2,$3,$4); };
+point_4d :
+	VALUE VALUE VALUE VALUE {alloc_point_4d($1,$2,$3,$4); }
 
-empty : EMPTY  {alloc_empty(); };
+empty :
+	EMPTY { alloc_empty(); }
 %%
 
 

Copied: packages/postgis/trunk/make_dist.sh (from rev 484, packages/postgis/upstream/make_dist.sh)

Modified: packages/postgis/trunk/regress/Makefile
===================================================================
--- packages/postgis/trunk/regress/Makefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/regress/Makefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -2,7 +2,31 @@
 
 include ../Makefile.config
 
-TESTS=regress regress_index lwgeom_regress regress_lrs removepoint setpoint simplify snaptogrid affine
+TESTS = \
+	loader/Point \
+	loader/PointM \
+	loader/PointZ \
+	loader/MultiPoint \
+	loader/MultiPointM \
+	loader/MultiPointZ \
+	loader/Arc \
+	loader/ArcM \
+	loader/ArcZ \
+	loader/Polygon \
+	loader/PolygonM \
+	loader/PolygonZ \
+	regress \
+	regress_index \
+	lwgeom_regress \
+	regress_lrs \
+	removepoint \
+	setpoint \
+	simplify \
+	snaptogrid \
+	affine \
+	wkt \
+	measures \
+	long_xact
 
 ifeq ($(USE_GEOS),1)
 	TESTS += regress_ogc regress_bdpoly
@@ -14,8 +38,8 @@
 
 all: test 
 
-test: lwpostgis.sql ../lwgeom/liblwgeom.so
-	@./run_test $(TESTS)
+test check: lwpostgis.sql ../lwgeom/liblwgeom.so
+	@USE_VERSION="$(USE_VERSION)" ./run_test $(TESTS)
 
 lwpostgis.sql: ../lwgeom/lwpostgis.sql.in 
 	$(MAKE) -C ../lwgeom ../regress/lwpostgis.sql

Modified: packages/postgis/trunk/regress/affine.sql
===================================================================
--- packages/postgis/trunk/regress/affine.sql	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/regress/affine.sql	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,43 +1,51 @@
 -- Tests for affine transformations
 
 -- translate
-select 'translate', asewkt(translate('POINT(0 0)', 5, 12));
-select 'translate', asewkt(translate('POINT(0 0 0)', -3, -7, 3));
+select 'translate', asewkt(translate('POINT(0 0)'::geometry, 5, 12));
+select 'translate', asewkt(translate('POINT(0 0 0)'::geometry, -3, -7, 3));
 
 -- scale
-select 'scale', asewkt(scale('POINT(1 1)', 5, 5));
-select 'scale', asewkt(scale('POINT(1 1)', 3, 2));
-select 'scale', asewkt(scale('POINT(10 20 -5)', 4, 2, -8));
+select 'scale', asewkt(scale('POINT(1 1)'::geometry, 5, 5));
+select 'scale', asewkt(scale('POINT(1 1)'::geometry, 3, 2));
+select 'scale', asewkt(scale('POINT(10 20 -5)'::geometry, 4, 2, -8));
 
 -- rotateZ
-select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)', pi()), 0.1));
-select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)', pi()/2), 0.1));
-select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)', pi()+pi()/2), 0.1));
-select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)', 2*pi()), 0.1));
+select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)'::geometry, pi()), 0.1));
+select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)'::geometry, pi()/2), 0.1));
+select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)'::geometry, pi()+pi()/2), 0.1));
+select 'rotateZ', asewkt(SnapToGrid(rotateZ('POINT(1 1)'::geometry, 2*pi()), 0.1));
 
 -- rotateY
-select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)', pi()), 0.1));
-select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)', pi()/2), 0.1));
-select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)', pi()+pi()/2), 0.1));
-select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)', 2*pi()), 0.1));
+select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)'::geometry, pi()), 0.1));
+select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)'::geometry, pi()/2), 0.1));
+select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)'::geometry, pi()+pi()/2), 0.1));
+select 'rotateY', asewkt(SnapToGrid(rotateY('POINT(1 1 1)'::geometry, 2*pi()), 0.1));
 
 -- rotateX
-select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)', pi()), 0.1));
-select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)', pi()/2), 0.1));
-select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)', pi()+pi()/2), 0.1));
-select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)', 2*pi()), 0.1));
+select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)'::geometry, pi()), 0.1));
+select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)'::geometry, pi()/2), 0.1));
+select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)'::geometry, pi()+pi()/2), 0.1));
+select 'rotateX', asewkt(SnapToGrid(rotateX('POINT(1 1 1)'::geometry, 2*pi()), 0.1));
 
 -- transscale
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 1, 1, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(2 2)',1, 1, 1, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',-1, -1, -1, -1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',0, 1, 1, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 0, 1, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 1, 0, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 1, 1, 0), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',2, 1, 1, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 2, 1, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 1, 2, 1), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',1, 1, 1, 2), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)',2, 3, 5, 7), 0.1));
-select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1 1)',2, 3, 5, 7), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 1, 1, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(2 2)'::geometry,1, 1, 1, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,-1, -1, -1, -1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,0, 1, 1, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 0, 1, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 1, 0, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 1, 1, 0), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,2, 1, 1, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 2, 1, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 1, 2, 1), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,1, 1, 1, 2), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1)'::geometry,2, 3, 5, 7), 0.1));
+select 'transscale', asewkt(snapToGrid(transscale('POINT(1 1 1)'::geometry,2, 3, 5, 7), 0.1));
+
+-- postgis-users/2006-May/012119.html
+select 'transl_bbox', box2d(translate('LINESTRING(0 0, 1 1)'::geometry, 1, 0, 0));
+select 'scale_bbox', box2d(scale('LINESTRING(1 0, 2 1)'::geometry, 2, 0));
+select 'tscale_bbox', box2d(transscale('LINESTRING(1 0, 2 1)'::geometry, 2, 1, 1, 1));
+
+select 'rotZ_bbox', box2d(SnapToGrid(rotateZ('LINESTRING(0 0, 1 0)'::geometry, pi()), 0.1));
+select 'rotY_bbox', box2d(SnapToGrid(rotateY('LINESTRING(0 0, 1 0)'::geometry, pi()), 0.1));

Modified: packages/postgis/trunk/regress/affine_expected
===================================================================
--- packages/postgis/trunk/regress/affine_expected	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/regress/affine_expected	2006-07-20 16:49:42 UTC (rev 485)
@@ -28,3 +28,8 @@
 transscale|POINT(2 4)
 transscale|POINT(15 28)
 transscale|POINT(15 28 1)
+transl_bbox|BOX(1 0,2 1)
+scale_bbox|BOX(2 0,4 0)
+tscale_bbox|BOX(3 1,4 2)
+rotZ_bbox|BOX(-1 0,0 0)
+rotY_bbox|BOX(-1 0,0 0)

Copied: packages/postgis/trunk/regress/loader (from rev 484, packages/postgis/upstream/regress/loader)

Copied: packages/postgis/trunk/regress/long_xact.sql (from rev 484, packages/postgis/upstream/regress/long_xact.sql)

Copied: packages/postgis/trunk/regress/long_xact_expected (from rev 484, packages/postgis/upstream/regress/long_xact_expected)

Copied: packages/postgis/trunk/regress/measures.sql (from rev 484, packages/postgis/upstream/regress/measures.sql)

Copied: packages/postgis/trunk/regress/measures_expected (from rev 484, packages/postgis/upstream/regress/measures_expected)

Modified: packages/postgis/trunk/regress/regress.sql
===================================================================
--- packages/postgis/trunk/regress/regress.sql	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/regress/regress.sql	2006-07-20 16:49:42 UTC (rev 485)
@@ -179,19 +179,6 @@
 
 select '112',numgeometries('GEOMETRYCOLLECTION(POINT(1 1), LINESTRING( 1 1 , 2 2, 3 3),MULTIPOINT(1 1, 2 2))'::GEOMETRY) as value;
 
---- geo ops
-
-select '113', area2d('MULTIPOLYGON( ((0 0, 10 0, 10 10, 0 10, 0 0)),( (0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7 , 5 7, 5 5) ) ,( (0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7, 5 7, 5 5),(1 1,2 1, 2 2, 1 2, 1 1) ) )'::GEOMETRY) as value;
-
-select '114', perimeter2d('MULTIPOLYGON( ((0 0, 10 0, 10 10, 0 10, 0 0)),( (0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7 , 5 7, 5 5) ) ,( (0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7, 5 7, 5 5),(1 1,2 1, 2 2, 1 2, 1 1) ) )'::GEOMETRY) as value;
-
-select '115', perimeter3d('MULTIPOLYGON( ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0)),( (0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0),(5 5 0, 7 5 0, 7 7  0, 5 7 0, 5 5 0) ) ,( (0 0 1, 10 0 1, 10 10 1, 0 10 1, 0 0 1),(5 5 1, 7 5 1, 7 7 1, 5 7 1, 5 5 1),(1 1 1,2 1 1, 2 2 1, 1 2 1, 1 1 1) ) )'::GEOMETRY) as value;
-
-
-select '116', length2d('MULTILINESTRING((0 0, 1 1),(0 0, 1 1, 2 2) )'::GEOMETRY) as value;
-select '117', length3d('MULTILINESTRING((0 0, 1 1),(0 0, 1 1, 2 2) )'::GEOMETRY) as value;
-select '118', length3d('MULTILINESTRING((0 0 0, 1 1 1),(0 0 0, 1 1 1, 2 2 2) )'::GEOMETRY) as value;
-
 ---selection
 
 
@@ -227,11 +214,6 @@
 select '133d', M('POINTM(1 2 4)');
 select '133e', M('POINT(1 2 4)');
 
-select '134', distance('POINT(1 2)', 'POINT(1 2)');
-select '135', distance('POINT(5 0)', 'POINT(10 12)');
-
-select '136', distance('POINT(0 0)', translate('POINT(0 0)', 5, 12, 0));
-
 select '137', box3d('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)'::geometry);
 select '138', box3d('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT(0 0))'::geometry);
 

Modified: packages/postgis/trunk/regress/regress_expected
===================================================================
--- packages/postgis/trunk/regress/regress_expected	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/regress/regress_expected	2006-07-20 16:49:42 UTC (rev 485)
@@ -110,12 +110,6 @@
 110|6
 111|528
 112|3
-113|291
-114|140
-115|140
-116|4.24264068711929
-117|4.24264068711929
-118|5.19615242270663
 121|BOX3D(1.19894826 1.20265412 0,999.932129 999.692932 0)|BOX3D(1.40486765 1.3484304 0,999.857666 999.936401 0)
 122|f
 123|f
@@ -133,9 +127,6 @@
 133c|
 133d|4
 133e|
-134|0
-135|13
-136|13
 137|
 138|BOX3D(0 0 0,0 0 0)
 139|SRID=2;GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY,POINT(0 0))

Modified: packages/postgis/trunk/regress/run_test
===================================================================
--- packages/postgis/trunk/regress/run_test	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/regress/run_test	2006-07-20 16:49:42 UTC (rev 485)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 DB=postgis_reg
+SHP2PGSQL=../loader/shp2pgsql
+PGSQL2SHP=../loader/pgsql2shp
 
 ###################################################
 #
@@ -16,16 +18,333 @@
 #
 ###################################################
 
-PGOPTIONS="${PGOPTIONS} -c lc_messages=C"
-export PGOPTIONS
+if [ -n "$USE_VERSION" ]; then
+	if [ "$USE_VERSION" -gt 74 ]; then
+		PGOPTIONS="${PGOPTIONS} -c lc_messages=C"
+		export PGOPTIONS
+	fi
+fi
 
+PSQL="psql"
+
 if [ -z "$TMPDIR" ]; then
-	TMPDIR=/tmp
+	TMPDIR=/tmp/pgis_reg_$$
 fi
 
+mkdir -p ${TMPDIR}
+
 VERBOSE=0
 OPT_DROP=yes
 OPT_CREATE=yes
+
+if echo '\c' | grep c >/dev/null 2>&1; then
+	ECHO_N='echo -n'
+	ECHO_C=''
+else
+	ECHO_N='echo'
+	ECHO_C='\c'
+fi
+
+###################################################
+# 
+# Helper functions
+#
+###################################################
+
+# Print a single dot
+show_progress()
+{
+	${ECHO_N} ".${ECHO_C}"
+}
+
+#
+# fail <msg> <log>
+#
+fail ()
+{
+	_msg="$1"
+	_log="$2"
+
+	if [ -z "$_log" ]; then
+		echo " failed ($_msg)"
+	elif test "$VERBOSE" -eq "1"; then
+		echo " failed ($_msg: $_log)"
+		echo "-----------------------------------------------------------------------------"
+		cat $_log
+		echo "-----------------------------------------------------------------------------"
+	else
+		echo " failed ($_msg: $_log)"
+	fi
+
+	FAIL=`expr $FAIL + 1`
+}
+
+#
+#  run_simple_test 
+#
+#  Run an sql script and compare results with the given expected output
+#
+#  SQL input is ${TEST}.sql, expected output is {$TEST}_expected
+#
+run_simple_test ()
+{
+	_sql="$1"
+	_expected="$2"
+	if [ -n "$3" ]; then
+		_msg="$3: "
+	else
+		_msg=
+	fi
+
+	if [ ! -r "$_sql" ]; then
+		fail "can't read $_sql"
+		return 1
+	fi
+
+	if [ ! -r "$_expected" ]; then
+		fail "can't read $_expected"
+		return 1
+	fi
+
+	show_progress
+
+	OUTFILE="${TMPDIR}/test_${RUN}_out"
+	TMPFILE="${TMPDIR}/test_${RUN}_tmp"
+	DIFFILE="${TMPDIR}/test_${RUN}_diff"
+
+	# Use intermediate file to prevent MingW buffering problems
+	${PSQL} -tA < "${_sql}" ${DB} > ${TMPFILE} 2>&1
+	cat ${TMPFILE} \
+		| grep -v "^$" \
+		| grep -v "^INSERT" \
+		| grep -v "^UPDATE" \
+		| grep -v "^DROP" \
+		| grep -v "^CREATE" \
+		| grep -v "^SET" \
+		| sed 's/Infinity/inf/g;s/Inf/inf/g;s/1\.#INF/inf/g' \
+		| sed 's/[eE]\([+-]\)0\{1,\}\([0-9]\{1,\}\)/e\1\2/g' \
+		| sed 's/Self-intersection .*/Self-intersection/' \
+		| sed 's/^ROLLBACK/COMMIT/' \
+		> "${OUTFILE}"
+	rm ${TMPFILE}
+
+	if diff "${_expected}" "${OUTFILE}" > ${DIFFILE}; then
+		#SUCCESS=`expr $SUCCESS + 1`
+		rm "${OUTFILE}" "${DIFFILE}" # we don't need these anymore
+		return 0
+	else
+		fail "${_msg}diff expected obtained" "${DIFFILE}"
+		rm "${OUTFILE}" # diff is enough
+		return 1
+	fi
+}
+
+#
+#  run_loader_test 
+#
+#  Load a shapefile with different methods, create a 'select *' SQL
+#  test and run simple test with provided expected output. 
+#
+#  SHP input is ${TEST}.shp, expected output is {$TEST}_expected
+#
+run_loader_test ()
+{
+	_tblname=loadedshp
+
+	# ON_ERROR_STOP is used by psql to return non-0 on an error
+	_psql_opts="--variable ON_ERROR_STOP=true"
+
+	#echo "SELECT * from ${_tblname}" > ${TEST}.sql
+
+
+	#
+	# Run in HEXWKB insert mode
+	#
+
+	show_progress
+
+	${SHP2PGSQL} ${TEST}.shp $_tblname \
+		> ${TMPDIR}/loader \
+		2> ${TMPDIR}/loader.err
+
+	if [ $? -gt 0 ]; then
+		fail "running shp2pgsql" "${TMPDIR}/loader.err"
+		return 1
+
+	fi
+
+	show_progress
+
+	${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1
+	${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1
+	if [ $? -gt 0 ]; then
+		fail "sourcing shp2pgsql output" "${TMPDIR}/loader.err"
+		return 1
+	fi
+
+	if [ -f "${TEST}-wkb.sql" ]; then
+		if run_simple_test ${TEST}-wkb.sql ${TEST}-wkb.expected "wkb insert"; then
+			:
+		else
+			return 1
+		fi
+	fi
+
+
+	#
+	# Run in HEXWKB dump mode
+	#
+
+	show_progress
+
+	${SHP2PGSQL} -D ${TEST}.shp $_tblname \
+		> ${TMPDIR}/loader \
+		2> ${TMPDIR}/loader.err
+
+	if [ $? -gt 0 ]; then
+		fail "running shp2pgsql -D" "${TMPDIR}/loader.err"
+		return 1
+
+	fi
+
+	show_progress
+
+	${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1
+	${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1
+	if [ $? -gt 0 ]; then
+		fail "sourcing shp2pgsql -D output" "${TMPDIR}/loader.err"
+		return 1
+	fi
+
+	if [ -f "${TEST}-wkb.sql" ]; then
+		if run_simple_test ${TEST}-wkb.sql ${TEST}-wkb.expected "wkb dump"; then
+			:
+		else
+			return 1
+		fi
+	fi
+
+	###########################################################
+	#
+	# Dump and compare.
+	# Do this using WKB mode, as WKT is unable to reproduce
+	# M values
+	#
+
+	show_progress
+
+	${PGSQL2SHP} -f ${TMPDIR}/dumper ${DB} "${_tblname}" > "${TMPDIR}/dumper.err" 2>&1
+	if [ $? -gt 0 ]; then
+		fail "dumping loaded table" "${TMPDIR}/dumper.err"
+		return 1
+	fi
+
+	show_progress
+
+	if diff "${TMPDIR}"/dumper.shp "${TEST}".shp > /dev/null; then
+		:
+	else
+		ls -lL "${TMPDIR}"/dumper.shp "${TEST}".shp > "${TMPDIR}"/dumper.diff
+		fail "dumping loaded table" "${TMPDIR}/dumper.diff"
+		return 1
+	fi
+
+# I'm not sure it's safe to compare indexes
+#	if diff "${TMPDIR}"/dumper.shx "${TEST}".shx; then
+#		:
+#	else
+#		ls -lL "${TMPDIR}"/dumper.shx "${TEST}".shx > "${TMPDIR}"/dumper.diff
+#		fail "dumping loaded table" "${TMPDIR}/dumper.diff"
+#		return 1
+#	fi
+
+# Change in attribute sizes would make this fail
+#	if diff "${TMPDIR}"/dumper.dbf "${TEST}".dbf; then
+#		:
+#	else
+#		ls -lL "${TMPDIR}"/dumper.dbf "${TEST}".dbf > "${TMPDIR}"/dumper.diff
+#		fail "dumping loaded table" "${TMPDIR}/dumper.diff"
+#		return 1
+#	fi
+
+
+	#
+	# End of dump and compare.
+	#
+	################################################
+
+	show_progress
+
+	${SHP2PGSQL} -w ${TEST}.shp $_tblname \
+		> ${TMPDIR}/loader \
+		2> ${TMPDIR}/loader.err
+
+	if [ $? -gt 0 ]; then
+		fail "running shp2pgsql -w" "${TMPDIR}/loader.err"
+		return 1
+	fi
+
+	show_progress
+
+	${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1
+	${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1
+	if [ $? -gt 0 ]; then
+		fail "sourcing shp2pgsql -w output" "${TMPDIR}/loader.err"
+		return 1
+	fi
+
+	if [ -f "${TEST}-wkt.sql" ]; then
+		if run_simple_test ${TEST}-wkt.sql ${TEST}-wkt.expected "wkt insert"; then
+			:
+		else
+			return 1
+		fi
+	fi
+
+	#
+	# Run in WKT dump mode
+	#
+
+	show_progress
+
+	${SHP2PGSQL} -D -w ${TEST}.shp $_tblname \
+		> ${TMPDIR}/loader \
+		2> ${TMPDIR}/loader.err
+
+	if [ $? -gt 0 ]; then
+		fail "running shp2pgsql -D -w" "${TMPDIR}/loader.err"
+		return 1
+
+	fi
+
+	show_progress
+
+	${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1
+	${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1
+	if [ $? -gt 0 ]; then
+		fail "sourcing shp2pgsql -D -w output" "${TMPDIR}/loader.err"
+		return 1
+	fi
+
+	if [ -f "${TEST}-wkt.sql" ]; then
+		if run_simple_test ${TEST}-wkt.sql ${TEST}-wkt.expected "wkt dump"; then
+			:
+		else
+			return 1
+		fi
+	fi
+
+	#rm ${TEST}.sql
+
+	return 0;
+}
+
+###################################################
+# 
+# Parse command line opts
+#
+###################################################
+
 while [ -n "$1" ]; do
 
 	if test "$1" = "-v"; then
@@ -50,17 +369,22 @@
 	exit 1
 fi
 
+###################################################
+# 
+# Prepare the database
+#
+###################################################
 
-db_exists=`psql -l | grep -w ${DB}`
+db_exists=`${PSQL} -l | grep -w ${DB}`
 
 if test -z "$db_exists"; then
 
 	if test x"$OPT_CREATE" = "xyes"; then
 		echo "Creating spatial db ${DB} " 
 
-		createdb $DB > ${TMPDIR}/regress_log_$$
-		createlang plpgsql $DB >> ${TMPDIR}/regress_log_$$ 
-		psql -f lwpostgis.sql $DB >> ${TMPDIR}/regress_log_$$ 2>&1
+		createdb "${DB}" > ${TMPDIR}/regress_log
+		createlang plpgsql "${DB}" >> ${TMPDIR}/regress_log
+		${PSQL} -f lwpostgis.sql "${DB}" >> ${TMPDIR}/regress_log 2>&1
 	else
 
 		echo "Database ${DB} does not exist" >&2
@@ -78,13 +402,13 @@
 	fi
 fi
 
-libver=`psql -tAc "select postgis_lib_version()" $DB`
+libver=`${PSQL} -tAc "select postgis_lib_version()" "${DB}"`
 
 if [ -z "$libver" ]; then
 	echo
-	echo " Something went wrong (no postgis installed in $DB)." 
+	echo " Something went wrong (no postgis installed in ${DB})." 
 	if [ -z "$db_exists" ]; then
-		echo " Check ${TMPDIR}/regress_log_$$ for details."
+		echo " For details, check ${TMPDIR}/regress_log"
 	else
 		echo " Try dropping the database, it will be recreated" \
 			" on next run."
@@ -93,12 +417,20 @@
 	exit 1
 fi
 
-geosver=`psql -tAc "select postgis_geos_version()" $DB`
-jtsver=`psql -tAc "select postgis_jts_version()" $DB`
-projver=`psql -tAc "select postgis_proj_version()" $DB`
-libbuilddate=`psql -tAc "select postgis_lib_build_date()" $DB`
-pgsqlver=`psql -tAc "select version()" $DB`
+###################################################
+# 
+# Report runtime environment 
+#
+###################################################
 
+geosver=`${PSQL} -tAc "select postgis_geos_version()" "${DB}"`
+jtsver=`${PSQL} -tAc "select postgis_jts_version()" "${DB}"`
+projver=`${PSQL} -tAc "select postgis_proj_version()" "${DB}"`
+libbuilddate=`${PSQL} -tAc "select postgis_lib_build_date()" "${DB}"`
+pgsqlver=`${PSQL} -tAc "select version()" "${DB}"`
+
+echo "TMPDIR is ${TMPDIR}"
+
 echo
 echo " $pgsqlver"
 echo " Postgis $libver - $libbuilddate"
@@ -112,6 +444,12 @@
 	echo "   PROJ: $projver"
 fi
 
+###################################################
+# 
+# Run the tests
+#
+###################################################
+
 echo 
 echo "Running tests"
 echo
@@ -119,78 +457,47 @@
 RUN=0
 SKIP=0
 FAIL=0
-SUCCESS=0
+#SUCCESS=0
 while [ -n "$1" ]; do
 	TEST="$1"; shift;
 
 	# catch a common mistake (strip trailing .sql)
 	TEST=`echo "$TEST" | sed 's/\.sql$//'`
 
-	OUTFILE="${TMPDIR}/regress_${TEST}_out_$$"
-	TMPFILE="${TMPDIR}/regress_${TEST}_tmp_$$"
-	DIFFILE="${TMPDIR}/regress_${TEST}_diff_$$"
+	#printf %20s " ${TEST}"
+	#echo -ne " ${TEST}"
+	${ECHO_N} " ${TEST}${ECHO_C}"
 
-	printf %20s " ${TEST}: "
-	#echo -ne " ${TEST}:\t"
+	RUN=`expr $RUN + 1`
 
-	if [ ! -r "${TEST}.sql" ]; then
+	# Check .shp *before* .sql as loader test would
+	# create the .sql
+	if [ -r "${TEST}.shp" ]; then
+		if run_loader_test; then
+			echo " ok"
+		fi
+	elif [ -r "${TEST}.sql" ]; then
+		if run_simple_test ${TEST}.sql ${TEST}_expected; then
+			echo " ok"
+		fi
+	else
 		echo "Skipped (can't read ${TEST}.sql)"
 		SKIP=`expr $SKIP + 1`
 		continue
 	fi
 
-	if [ ! -r "${TEST}_expected" ]; then
-		echo " Skipped (can't read ${TEST}_expected)"
-		SKIP=`expr $SKIP + 1`
-		continue
-	fi
 
-	# Use intermediate file to prevent MingW buffering problems
-	psql -tA < "${TEST}.sql" $DB > ${TMPFILE} 2>&1
-	cat ${TMPFILE} \
-		| grep -v "^$" \
-		| grep -v "^INSERT" \
-		| grep -v "^UPDATE" \
-		| grep -v "^DROP" \
-		| grep -v "^CREATE" \
-		| grep -v "^SET" \
-		| sed 's/Infinity/inf/g;s/Inf/inf/g;s/1\.#INF/inf/g' \
-		| sed 's/[eE]\([+-]\)0\{1,\}\([0-9]\{1,\}\)/e\1\2/g' \
-		| sed 's/Self-intersection .*/Self-intersection/' \
-		> "${OUTFILE}"
-	rm ${TMPFILE}
-
-	if diff "${TEST}_expected" "${OUTFILE}" > ${DIFFILE}; then
-		SUCCESS=`expr $SUCCESS + 1`
-		echo "Ok."
-		rm "${OUTFILE}" "${DIFFILE}" # we don't need these anymore
-	else
-		FAIL=`expr $FAIL + 1`
-		if test "$VERBOSE" -eq "1"; then
-			echo "Failed (diff ${DIFFILE})"
-			echo "-----------------------------------------------------------------------------"
-			echo "expected:'<'     obtained:'>'"
-			echo "-----------------------------------------------------------------------------"
-			cat ${DIFFILE}
-			echo "-----------------------------------------------------------------------------"
-		else
-			echo "Failed (diff ${DIFFILE})"
-		fi
-		rm "${OUTFILE}" # diff is enough
-	fi
-	RUN=`expr $RUN + 1`
-
 done
 
 echo
 echo "Run tests: $RUN"
 #echo "Skipped: $SKIP"
-echo "Successful: $SUCCESS"
+#echo "Successful: $SUCCESS"
 echo "Failed: $FAIL"
 
 if test x"$OPT_DROP" = "xyes" -a x"$OPT_CREATE" = "xyes"; then
 	sleep 1
-	dropdb $DB > /dev/null
+	dropdb "${DB}" > /dev/null
 else
 	: echo "Drop database ${DB} manually"
 fi

Copied: packages/postgis/trunk/regress/wkt.sql (from rev 484, packages/postgis/upstream/regress/wkt.sql)

Copied: packages/postgis/trunk/regress/wkt_expected (from rev 484, packages/postgis/upstream/regress/wkt_expected)

Copied: packages/postgis/trunk/topology/.cvsignore (from rev 484, packages/postgis/upstream/topology/.cvsignore)

Copied: packages/postgis/trunk/topology/ER/.cvsignore (from rev 484, packages/postgis/upstream/topology/ER/.cvsignore)

Copied: packages/postgis/trunk/topology/test/.cvsignore (from rev 484, packages/postgis/upstream/topology/test/.cvsignore)

Modified: packages/postgis/trunk/topology/test/Makefile
===================================================================
--- packages/postgis/trunk/topology/test/Makefile	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/topology/test/Makefile	2006-07-20 16:49:42 UTC (rev 485)
@@ -67,13 +67,14 @@
 	@psql -tf geom_predicates.sql $(DATABASE)
 
 topo_predicates.sql: predicates.sql.in
-	cpp -P -traditional-cpp predicates.sql.in | sed -e 's:@COLUMN@:feature:g;s:@SCHEMA@:topology.:g' > topo_predicates.sql
+	@cpp -P -traditional-cpp predicates.sql.in | sed -e 's:@COLUMN@:feature:g;s:@SCHEMA@:topology.:g' > topo_predicates.sql
 
 geom_predicates.sql: predicates.sql.in
-	cpp -P -traditional-cpp predicates.sql.in | sed -e 's:@COLUMN@:the_geom:g;s:@SCHEMA@::g' > geom_predicates.sql
+	@cpp -P -traditional-cpp predicates.sql.in | sed -e 's:@COLUMN@:the_geom:g;s:@SCHEMA@::g' > geom_predicates.sql
 
 edit:
-	psql -f edit_topology.sql
+	psql -f edit_topology.sql $(DATABASE)
 
 clean distclean:
 	rm -f geom_predicates.sql topo_predicates.sql
+	-dropdb $(DATABASE)

Modified: packages/postgis/trunk/topology/test/load_topology.sql
===================================================================
--- packages/postgis/trunk/topology/test/load_topology.sql	2006-07-20 16:33:04 UTC (rev 484)
+++ packages/postgis/trunk/topology/test/load_topology.sql	2006-07-20 16:49:42 UTC (rev 485)
@@ -200,11 +200,11 @@
 CREATE SCHEMA features;
 
 CREATE TABLE features.land_parcels ( -- Land parcels (selected faces)
-  feature_name VARCHAR PRIMARY KEY);
+  feature_name VARCHAR PRIMARY KEY) with oids;
 CREATE TABLE features.city_streets ( -- City streets (selected edges)
-  feature_name VARCHAR PRIMARY KEY);
+  feature_name VARCHAR PRIMARY KEY) with oids;
 CREATE TABLE features.traffic_signs ( -- Traffic signs (selected nodes)
-  feature_name VARCHAR PRIMARY KEY);
+  feature_name VARCHAR PRIMARY KEY) with oids;
 
 
 




More information about the Pkg-grass-devel mailing list