]> granicus.if.org Git - postgis/commitdiff
API cleanup, more steps toward standalone library.
authorSandro Santilli <strk@keybit.net>
Thu, 7 Oct 2004 10:03:23 +0000 (10:03 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 7 Oct 2004 10:03:23 +0000 (10:03 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@951 b70326c6-7e19-0410-871a-916f4a2858ee

28 files changed:
lwgeom/Makefile
lwgeom/liblwgeom.c
lwgeom/liblwgeom.h
lwgeom/lwcollection.c
lwgeom/lwgeom.c
lwgeom/lwgeom.h
lwgeom/lwgeom_api.c
lwgeom/lwgeom_box2dfloat4.c
lwgeom/lwgeom_box3d.c
lwgeom/lwgeom_chip.c
lwgeom/lwgeom_functions_analytic.c
lwgeom/lwgeom_functions_basic.c
lwgeom/lwgeom_geos.c
lwgeom/lwgeom_geos_wrapper.cpp
lwgeom/lwgeom_gist.c
lwgeom/lwgeom_inout.c
lwgeom/lwgeom_ogc.c
lwgeom/lwgeom_pg.c
lwgeom/lwline.c
lwgeom/lwmline.c
lwgeom/lwmpoint.c
lwgeom/lwmpoly.c
lwgeom/lwpoint.c
lwgeom/lwpoly.c
lwgeom/ptarray.c [new file with mode: 0644]
lwgeom/test.c [new file with mode: 0644]
lwgeom/wktparse.h
lwgeom/wktunparse.c

index 42a5d48bf22509007a17a666c7016fabf507aea0..d177761070e90b4102f5c489c4708c333f8062fc 100644 (file)
@@ -66,7 +66,8 @@ ifeq ($(USE_STATS),1)
        override CFLAGS += -DUSE_STATS
 endif
  
-OBJS=lwgeom_pg.o lwgeom_debug.o liblwgeom.o lwgeom.o lwpoint.o lwline.o lwpoly.o lwmpoint.o lwmline.o lwmpoly.o lwcollection.o lwgeom_spheroid.o lwgeom_api.o lwgeom_ogc.o lwgeom_functions_analytic.o lwgeom_geos.o 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 lex.yy.o wktparse.tab.o lwgparse.o wktunparse.o lwgeom_svg.o lwgeom_gml.o $(GEOS_WRAPPER)
+SA_OBJS=ptarray.o lwgeom_api.o lwgeom.o lwpoint.o lwline.o lwpoly.o lwmpoint.o lwmline.o lwmpoly.o lwcollection.o $(GEOS_WRAPPER) wktunparse.o lwgparse.o wktparse.tab.o lex.yy.o
+OBJS=$(SA_OBJS) liblwgeom.o lwgeom_pg.o lwgeom_debug.o lwgeom_spheroid.o lwgeom_ogc.o lwgeom_functions_analytic.o lwgeom_geos.o 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 
 
 OTHERS=y.output lex.yy.c wktparse.tab.c wktparse.tab.h lwpostgis.sql
 
@@ -149,4 +150,20 @@ uninstall: uninstall-lib uninstall-lwgeom-scripts
 clean distclean maintainer-clean: clean-lib
        rm -f $(OBJS) 
        rm -f $(OTHERS)
+       rm -f liblwgeom_sa.o
+       rm -f liblwgeom_sa.so
+       rm -f test
 
+liblwgeom_sa.o: liblwgeom.c
+       $(CC) -DSTANDALONE -o $@ -c $<
+
+liblwgeom_sa.so: $(SA_OBJS) liblwgeom_sa.o 
+       $(CC) -shared -o $@ $^ 
+
+liblwgeom_sa.a: $(SA_OBJS) liblwgeom_sa.o 
+       $(AR) -rc $@ $^ 
+
+
+test: liblwgeom_sa.so liblwgeom_sa.a test.c
+       #$(CC) -o test -L. -llwgeom_sa $(SHLIB_LINK) test.c
+       $(CC) -Wall -g -o test test.c liblwgeom_sa.a 
index d84e75548d9369b90b69e0c208daac0498d513c2..948042ef23970e30df07d06e388a02fbb54e32ce 100644 (file)
@@ -2,25 +2,30 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
-#include "lwgeom_pg.h"
-#include "liblwgeom.h"
-
 #define CONTEXT_PG 0
 #define CONTEXT_SA 1
 
+#ifdef STANDALONE
+#define DEFAULT_CONTEXT CONTEXT_SA
+#else
 #define DEFAULT_CONTEXT CONTEXT_PG
+#endif
 
 /* Global variables */
 #if DEFAULT_CONTEXT == CONTEXT_SA
-lwallocator lwalloc = default_allocator;
-lwreallocator lwrealloc = default_reallocator;
-lwfreeor lwfree = default_freeor;
+#include "liblwgeom.h"
+lwallocator lwalloc_var = default_allocator;
+lwreallocator lwrealloc_var = default_reallocator;
+lwfreeor lwfree_var = default_freeor;
 lwreporter lwerror = default_errorreporter;
 lwreporter lwnotice = default_noticereporter;
 #else
-lwallocator lwalloc = pg_alloc;
-lwreallocator lwrealloc = pg_realloc;
-lwfreeor lwfree = pg_free;
+#include "lwgeom_pg.h"
+#include "liblwgeom.h"
+
+lwallocator lwalloc_var = pg_alloc;
+lwreallocator lwrealloc_var = pg_realloc;
+lwfreeor lwfree_var = pg_free;
 lwreporter lwerror = pg_error;
 lwreporter lwnotice = pg_notice;
 #endif
@@ -98,6 +103,7 @@ default_errorreporter(const char *fmt, ...)
        fprintf(stderr, "%s\n", msg);
        va_end(ap);
        free(msg);
+       exit(1);
 }
 
 const char *
@@ -105,3 +111,21 @@ lwgeom_typename(int type)
 {
        return lwgeomTypeName[type];
 }
+
+void *
+lwalloc(size_t size)
+{
+       return lwalloc_var(size);
+}
+
+void *
+lwrealloc(void *mem, size_t size)
+{
+       return lwrealloc_var(mem, size);
+}
+
+void
+lwfree(void *mem)
+{
+       return lwfree_var(mem);
+}
index 3b4b9c73ecce0ae8566e7d75196e09b206bfd803..9b81dc455128b79775bb7e513c9ba498b078ea82 100644 (file)
@@ -25,9 +25,9 @@ void default_errorreporter(const char *fmt, ...);
 void default_noticereporter(const char *fmt, ...);
 
 /* globals */
-extern lwreallocator lwrealloc;
-extern lwallocator lwalloc;
-extern lwfreeor lwfree;
+extern lwreallocator lwrealloc_var;
+extern lwallocator lwalloc_var;
+extern lwfreeor lwfree_var;
 extern lwreporter lwerror;
 extern lwreporter lwnotice;
 
@@ -402,7 +402,7 @@ extern size_t lwgeom_size_poly(const char *serialized_line);
 
 // construct a new point.  point will NOT be copied
 // use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
-extern LWPOINT  *lwpoint_construct(char hasZ, char hasM, int SRID, char wantbbox, POINTARRAY *point);
+extern LWPOINT  *lwpoint_construct(int SRID, char wantbbox, POINTARRAY *point);
 
 // given the LWPOINT serialized form (or a pointer into a muli* one)
 // construct a proper LWPOINT.
@@ -434,7 +434,7 @@ extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out);
 
 // construct a new LWLINE.  points will *NOT* be copied
 // use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
-extern LWLINE *lwline_construct(char hasz, char hasm, int SRID, char wantbbox, POINTARRAY *points);
+extern LWLINE *lwline_construct(int SRID, char wantbbox, POINTARRAY *points);
 
 // given the LWGEOM serialized form (or a pointer into a muli* one)
 // construct a proper LWLINE.
@@ -460,7 +460,7 @@ extern BOX3D *lwline_findbbox(LWLINE *line);
 
 // 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(char hasz, char hasm, int SRID, char wantbbox, int nrings, POINTARRAY **points);
+extern LWPOLY *lwpoly_construct(int SRID, char wantbbox, unsigned int nrings, POINTARRAY **points);
 
 // given the LWPOLY serialized form (or a pointer into a muli* one)
 // construct a proper LWPOLY.
@@ -730,7 +730,6 @@ extern void printLWLINE(LWLINE *line);
 extern void printLWPOLY(LWPOLY *poly);
 extern void printBYTES(unsigned char *a, int n);
 extern void printMULTI(char *serialized);
-extern void deparse_hex(unsigned char str, unsigned char *result);
 extern void printType(unsigned char str);
 
 
@@ -947,9 +946,26 @@ extern LWLINE *lwline_clone(const LWLINE *lwgeom);
 extern LWPOLY *lwpoly_clone(const LWPOLY *lwgeom);
 extern LWCOLLECTION *lwcollection_clone(const LWCOLLECTION *lwgeom);
 
-extern LWCOLLECTION *lwcollection_construct(int type, char hasz, char hasm, uint32 SRID, char hasbbox, int ngeoms, LWGEOM **geoms);
+extern LWCOLLECTION *lwcollection_construct(unsigned int type, int SRID, char hasbbox, unsigned int ngeoms, LWGEOM **geoms);
 
 // Return a char string with ASCII versionf of type flags
 extern const char *lwgeom_typeflags(unsigned char type);
 
+// Construct an empty pointarray
+extern POINTARRAY *ptarray_construct(char hasz, char hasm, unsigned int npoints);
+extern POINTARRAY *ptarray_construct2d(uint32 npoints, POINT2D const* const* pts);
+
+extern int32 lwgeom_nrings_recursive(char *serialized);
+extern void dump_lwexploded(LWGEOM_EXPLODED *exploded);
+extern void ptarray_reverse(POINTARRAY *pa);
+
+extern unsigned char   parse_hex(char *str);
+extern void deparse_hex(unsigned char str, unsigned char *result);
+extern char *parse_lwgeom_wkt(char *wkt_input);
+extern char * lwgeom_to_wkt(LWGEOM *lwgeom);
+
+extern void *lwalloc(size_t size);
+extern void *lwrealloc(void *mem, size_t size);
+extern void lwfree(void *mem);
+
 #endif // !defined _LIBLWGEOM_H 
index cab581ea9bab4ba7fec3213c3663a5add1b5e576..5887a0781f90c6b2950d2706b063bb37c64714c8 100644 (file)
@@ -5,6 +5,46 @@
 
 //#define DEBUG_CALLS 1
 
+#define CHECK_LWGEOM_ZM 1
+
+LWCOLLECTION *
+lwcollection_construct(unsigned int type, int SRID, char hasbbox,
+       unsigned int ngeoms, LWGEOM **geoms)
+{
+       LWCOLLECTION *ret;
+       int hasz, hasm;
+#ifdef CHECK_LWGEOM_ZM
+       char zm;
+       unsigned int i;
+#endif
+
+       hasz = 0;
+       hasm = 0;
+       if ( ngeoms > 0 )
+       {
+               hasz = TYPE_HASZ(geoms[0]->type);
+               hasm = TYPE_HASM(geoms[0]->type);
+       }
+
+#ifdef CHECK_LWGEOM_ZM
+       zm = TYPE_GETZM(geoms[0]->type);
+       for (i=1; i<ngeoms; i++)
+       {
+               if ( zm != TYPE_GETZM(geoms[i]->type) )
+                       lwerror("lwcollection_construct: mixed dimension geometries");
+       }
+#endif
+
+       ret = lwalloc(sizeof(LWCOLLECTION));
+       ret->type = lwgeom_makeType_full(hasz, hasm, (SRID!=-1),
+               type, hasbbox);
+       ret->SRID = SRID;
+       ret->ngeoms = ngeoms;
+       ret->geoms = geoms;
+       return ret;
+}
+
+
 LWCOLLECTION *
 lwcollection_deserialize(char *srl)
 {
@@ -149,20 +189,6 @@ lwcollection_compute_bbox_p(LWCOLLECTION *col, BOX2DFLOAT4 *box)
        return 1;
 }
 
-LWCOLLECTION *
-lwcollection_construct(int type, char hasz, char hasm, uint32 SRID, char hasbbox,
-       int ngeoms, LWGEOM **geoms)
-{
-       LWCOLLECTION *ret;
-       ret = lwalloc(sizeof(LWCOLLECTION));
-       ret->type = lwgeom_makeType_full(hasz, hasm, (SRID!=-1),
-               type, hasbbox);
-       ret->SRID = SRID;
-       ret->ngeoms = ngeoms;
-       ret->geoms = geoms;
-       return ret;
-}
-
 // Clone LWCOLLECTION object. POINTARRAY are not copied.
 LWCOLLECTION *
 lwcollection_clone(const LWCOLLECTION *g)
@@ -211,7 +237,6 @@ lwcollection_add(const LWCOLLECTION *to, uint32 where, const LWGEOM *what)
        }
 
        col = lwcollection_construct(COLLECTIONTYPE,
-               TYPE_HASZ(to->type), TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                to->ngeoms+1, geoms);
index c84ff48a0df6c767868a4b8cd6c38b395af0bc76..01226413ca581dde433ea70433dec752898910c5 100644 (file)
@@ -1,8 +1,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include "wktparse.h"
 
-#include "lwgeom_pg.h"
+//#include "lwgeom_pg.h"
 #include "liblwgeom.h"
 
 //#define DEBUG_CALLS 1
@@ -326,3 +327,18 @@ lwgeom_add(const LWGEOM *to, uint32 where, const LWGEOM *what)
        }
 }
 
+/*
+ * Return an alloced string
+ */
+char *
+lwgeom_to_wkt(LWGEOM *lwgeom)
+{
+       char *serialized = lwgeom_serialize(lwgeom);
+       if ( ! serialized ) {
+               lwerror("Error serializing geom %p", lwgeom);
+       }
+       char *ret = unparse_WKT(serialized, lwalloc, lwfree);
+       lwfree(serialized);
+       return ret;
+}
+
index 025a8612a0a53fdad347bf404104b4c0c492a3fd..55f6fd2a59189c9d6bbbc83969ee9d4837c4ea04 100644 (file)
@@ -1,10 +1,40 @@
-typedef struct LWGEOM_T LWGEOM;
+/*****************************************************************
+ * MEMORY MANAGEMENT
+ ****************************************************************/
+void *lwalloc(size_t size);
+void *lwrealloc(void *mem, size_t size);
+void lwfree(void *mem);
 
-// Serialization / deserialization
-extern LWGEOM *lwgeom_deserialize(char *serializedform);
-extern char *lwgeom_serialize(LWGEOM *lwgeom);
-extern char *lwgeom_serialize_size(LWGEOM *lwgeom);
-extern void lwgeom_serialize_buf(LWGEOM *lwgeom, char *buf);
+/*****************************************************************
+ * POINT
+ ****************************************************************/
 
-extern void lwgeom_reverse(LWGEOM *lwgeom);
-extern void lwgeom_forceRHR(LWGEOM *lwgeom);
+typedef struct { double x; double y; } POINT2D;
+typedef struct { double x; double y; double m; } POINT3DM;
+typedef struct { double x; double y; double z; } POINT3DZ;
+typedef struct { double x; double y; double z; double m; } POINT4D;
+
+/*****************************************************************
+ * POINTARRAY
+ ****************************************************************/
+
+typedef struct POINTARRAY_T *POINTARRAY;
+
+// Constructs a POINTARRAY copying given 2d points
+POINTARRAY ptarray_construct2d(unsigned int npoints, POINT2D ** pts);
+
+/*****************************************************************
+ * LWGEOM
+ ****************************************************************/
+
+typedef struct LWGEOM_T *LWGEOM;
+
+// Conversions
+extern char *lwgeom_to_wkt(LWGEOM lwgeom);
+
+// Construction
+extern LWGEOM lwpoint_construct(int SRID, char wantbbox, POINTARRAY pa);
+
+// Spatial functions
+extern void lwgeom_reverse(LWGEOM lwgeom);
+extern void lwgeom_forceRHR(LWGEOM lwgeom);
index 4c1ebe18f61c31af15c303533e83087317c0f556..a5940d879d115d0f9a7da8a182a23c81db924a93 100644 (file)
@@ -23,6 +23,7 @@ extern  BOX3D *lw_geom_getBB_simple(char *serialized_form);
 #ifdef DEBUG_EXPLODED
 void checkexplodedsize(char *srl, LWGEOM_EXPLODED *exploded, int alloced, char wantbbox);
 #endif
+extern char *parse_lwg(const char* geometry, lwallocator allocfunc, lwreporter errfunc);
 
 //*********************************************************************
 // BOX routines
@@ -2644,3 +2645,259 @@ lwgeom_typeflags(unsigned char type)
        //lwnotice("Flags: %s - returning %p", flags, flags);
        return flags;
 }
+
+//given a string with at least 2 chars in it, convert them to
+// a byte value.  No error checking done!
+unsigned char
+parse_hex(char *str)
+{
+       //do this a little brute force to make it faster
+
+       unsigned char           result_high = 0;
+       unsigned char           result_low = 0;
+
+       switch (str[0])
+       {
+               case '0' :
+                       result_high = 0;
+                       break;
+               case '1' :
+                       result_high = 1;
+                       break;
+               case '2' :
+                       result_high = 2;
+                       break;
+               case '3' :
+                       result_high = 3;
+                       break;
+               case '4' :
+                       result_high = 4;
+                       break;
+               case '5' :
+                       result_high = 5;
+                       break;
+               case '6' :
+                       result_high = 6;
+                       break;
+               case '7' :
+                       result_high = 7;
+                       break;
+               case '8' :
+                       result_high = 8;
+                       break;
+               case '9' :
+                       result_high = 9;
+                       break;
+               case 'A' :
+                       result_high = 10;
+                       break;
+               case 'B' :
+                       result_high = 11;
+                       break;
+               case 'C' :
+                       result_high = 12;
+                       break;
+               case 'D' :
+                       result_high = 13;
+                       break;
+               case 'E' :
+                       result_high = 14;
+                       break;
+               case 'F' :
+                       result_high = 15;
+                       break;
+       }
+       switch (str[1])
+       {
+               case '0' :
+                       result_low = 0;
+                       break;
+               case '1' :
+                       result_low = 1;
+                       break;
+               case '2' :
+                       result_low = 2;
+                       break;
+               case '3' :
+                       result_low = 3;
+                       break;
+               case '4' :
+                       result_low = 4;
+                       break;
+               case '5' :
+                       result_low = 5;
+                       break;
+               case '6' :
+                       result_low = 6;
+                       break;
+               case '7' :
+                       result_low = 7;
+                       break;
+               case '8' :
+                       result_low = 8;
+                       break;
+               case '9' :
+                       result_low = 9;
+                       break;
+               case 'A' :
+                       result_low = 10;
+                       break;
+               case 'B' :
+                       result_low = 11;
+                       break;
+               case 'C' :
+                       result_low = 12;
+                       break;
+               case 'D' :
+                       result_low = 13;
+                       break;
+               case 'E' :
+                       result_low = 14;
+                       break;
+               case 'F' :
+                       result_low = 15;
+                       break;
+       }
+       return (unsigned char) ((result_high<<4) + result_low);
+}
+
+
+//given one byte, populate result with two byte representing
+// the hex number
+// ie deparse_hex( 255, mystr)
+//             -> mystr[0] = 'F' and mystr[1] = 'F'
+// no error checking done
+void
+deparse_hex(unsigned char str, unsigned char *result)
+{
+       int     input_high;
+       int  input_low;
+
+       input_high = (str>>4);
+       input_low = (str & 0x0F);
+
+       switch (input_high)
+       {
+               case 0:
+                       result[0] = '0';
+                       break;
+               case 1:
+                       result[0] = '1';
+                       break;
+               case 2:
+                       result[0] = '2';
+                       break;
+               case 3:
+                       result[0] = '3';
+                       break;
+               case 4:
+                       result[0] = '4';
+                       break;
+               case 5:
+                       result[0] = '5';
+                       break;
+               case 6:
+                       result[0] = '6';
+                       break;
+               case 7:
+                       result[0] = '7';
+                       break;
+               case 8:
+                       result[0] = '8';
+                       break;
+               case 9:
+                       result[0] = '9';
+                       break;
+               case 10:
+                       result[0] = 'A';
+                       break;
+               case 11:
+                       result[0] = 'B';
+                       break;
+               case 12:
+                       result[0] = 'C';
+                       break;
+               case 13:
+                       result[0] = 'D';
+                       break;
+               case 14:
+                       result[0] = 'E';
+                       break;
+               case 15:
+                       result[0] = 'F';
+                       break;
+       }
+
+       switch (input_low)
+       {
+               case 0:
+                       result[1] = '0';
+                       break;
+               case 1:
+                       result[1] = '1';
+                       break;
+               case 2:
+                       result[1] = '2';
+                       break;
+               case 3:
+                       result[1] = '3';
+                       break;
+               case 4:
+                       result[1] = '4';
+                       break;
+               case 5:
+                       result[1] = '5';
+                       break;
+               case 6:
+                       result[1] = '6';
+                       break;
+               case 7:
+                       result[1] = '7';
+                       break;
+               case 8:
+                       result[1] = '8';
+                       break;
+               case 9:
+                       result[1] = '9';
+                       break;
+               case 10:
+                       result[1] = 'A';
+                       break;
+               case 11:
+                       result[1] = 'B';
+                       break;
+               case 12:
+                       result[1] = 'C';
+                       break;
+               case 13:
+                       result[1] = 'D';
+                       break;
+               case 14:
+                       result[1] = 'E';
+                       break;
+               case 15:
+                       result[1] = 'F';
+                       break;
+       }
+}
+
+char *
+parse_lwgeom_wkt(char *wkt_input)
+{
+       char *serialized_form = parse_lwg((const char *)wkt_input,
+               lwalloc, lwerror);
+
+
+#ifdef DEBUG
+       lwnotice("parse_lwgeom_wkt with %s",wkt_input);
+#endif
+
+       if (serialized_form == NULL)
+       {
+               lwerror("parse_WKT:: couldnt parse!");
+               return NULL;
+       }
+
+       return serialized_form;
+
+}
index 347cb2e921581c7c93698c02d421d105aba5d98e..e673cb02a7007e9af7b91dabf935dd66c27863d2 100644 (file)
@@ -434,7 +434,7 @@ Datum BOX2DFLOAT4_to_LWGEOM(PG_FUNCTION_ARGS)
        pa[0]->npoints = 5;
 
        // Construct polygon
-       poly = lwpoly_construct(0, 0, -1, wantbbox, 1, pa);
+       poly = lwpoly_construct(-1, wantbbox, 1, pa);
 
        // Serialize polygon
        ser = lwpoly_serialize(poly);
index 1f735c60032d23bb2c3bd93fb701d387ec8234b9..6b83276fee48a26d561201ca827a3d079a5a861e 100644 (file)
@@ -180,7 +180,7 @@ Datum BOX3D_to_LWGEOM(PG_FUNCTION_ARGS)
        pa[0]->npoints = 5;
 
        // Construct polygon
-       poly = lwpoly_construct(0, 0, -1, wantbbox, 1, pa);
+       poly = lwpoly_construct(-1, wantbbox, 1, pa);
 
        // Serialize polygon
        ser = lwpoly_serialize(poly);
index 82c1475553d67c6dae022f698b2481be3f95d212..c1e2c3a2da53fc0b512c44bc30831290964f652d 100644 (file)
@@ -180,7 +180,7 @@ Datum CHIP_to_LWGEOM(PG_FUNCTION_ARGS)
        pa[0]->npoints = 5;
 
        // Construct polygon
-       poly = lwpoly_construct(0, 0, chip->SRID, wantbbox, 1, pa);
+       poly = lwpoly_construct(chip->SRID, wantbbox, 1, pa);
 
        // Serialize polygon
        ser = lwpoly_serialize(poly);
index af7ceb052daec7d5c693894219a9041d115073d1..e859b032326fecc00053f2644b16065c4ee1795d 100644 (file)
@@ -175,11 +175,7 @@ simplify2d_lwline(LWLINE *iline, double dist)
 
        ipts = iline->points;
        opts = DP_simplify2d(ipts, dist);
-       oline = lwline_construct(
-               TYPE_HASZ(ipts->dims),
-               TYPE_HASM(ipts->dims),
-               iline->SRID,
-               TYPE_HASBBOX(iline->type), opts);
+       oline = lwline_construct(iline->SRID, TYPE_HASBBOX(iline->type), opts);
 
        return oline;
 }
@@ -388,10 +384,7 @@ Datum LWGEOM_line_interpolate_point(PG_FUNCTION_ARGS)
                        TYPE_HASZ(line->type),
                        TYPE_HASM(line->type),
                        1);
-               point = lwpoint_construct(
-                       TYPE_HASZ(line->type),
-                       TYPE_HASM(line->type),
-                       line->SRID, 0, opa);
+               point = lwpoint_construct(line->SRID, 0, opa);
                srl = lwpoint_serialize(point);
                pfree_point(point);
                PG_RETURN_POINTER(PG_LWGEOM_construct(srl, line->SRID, 0));
@@ -424,10 +417,7 @@ Datum LWGEOM_line_interpolate_point(PG_FUNCTION_ARGS)
                                TYPE_HASZ(line->type),
                                TYPE_HASM(line->type),
                                1);
-                       point = lwpoint_construct(
-                               TYPE_HASZ(line->type),
-                               TYPE_HASM(line->type),
-                               line->SRID, 0, opa);
+                       point = lwpoint_construct(line->SRID, 0, opa);
                        srl = lwpoint_serialize(point);
                        pfree_point(point);
                        PG_RETURN_POINTER(PG_LWGEOM_construct(srl, line->SRID, 0));
@@ -442,10 +432,7 @@ Datum LWGEOM_line_interpolate_point(PG_FUNCTION_ARGS)
                TYPE_HASZ(line->type),
                TYPE_HASM(line->type),
                1);
-       point = lwpoint_construct(
-               TYPE_HASZ(line->type),
-               TYPE_HASM(line->type),
-               line->SRID, 0, opa);
+       point = lwpoint_construct(line->SRID, 0, opa);
        srl = lwpoint_serialize(point);
        pfree_point(point);
        PG_RETURN_POINTER(PG_LWGEOM_construct(srl, line->SRID, 0));
index 0678752df6bcd1d2c439fb6ec05b0a8c2334810f..4fe05a7e888feee7fbf1fad9b35add0f740f13af 100644 (file)
@@ -51,11 +51,6 @@ Datum LWGEOM_forceRHR_poly(PG_FUNCTION_ARGS);
 Datum LWGEOM_noop(PG_FUNCTION_ARGS);
 Datum LWGEOM_zmflag(PG_FUNCTION_ARGS);
 
-// internal
-int32 lwgeom_nrings_recursive(char *serialized);
-void dump_lwexploded(LWGEOM_EXPLODED *exploded);
-void ptarray_reverse(POINTARRAY *pa);
-
 
 /*------------------------------------------------------------------*/
 
@@ -759,61 +754,6 @@ lwgeom_pt_inside_circle(POINT2D *p, double cx, double cy, double rad)
 
 }
 
-void
-ptarray_reverse(POINTARRAY *pa)
-{
-       POINT4D pbuf;
-       uint32 i;
-       int ptsize = pointArray_ptsize(pa);
-       int last = pa->npoints-1;
-       int mid = last/2;
-
-       for (i=0; i<=mid; i++)
-       {
-               char *from, *to;
-               from = getPoint(pa, i);
-               to = getPoint(pa, (last-i));
-               memcpy((char *)&pbuf, to, ptsize);
-               memcpy(to, from, ptsize);
-               memcpy(from, (char *)&pbuf, ptsize);
-       }
-
-}
-
-void
-lwline_reverse(LWLINE *line)
-{
-       ptarray_reverse(line->points);
-}
-
-void
-lwpoly_reverse(LWPOLY *poly)
-{
-       int i;
-
-       for (i=0; i<poly->nrings; i++)
-               ptarray_reverse(poly->rings[i]);
-}
-
-void
-lwpoly_forceRHR(LWPOLY *poly)
-{
-       int i;
-
-       if ( ptarray_isccw(poly->rings[0]) )
-       {
-               ptarray_reverse(poly->rings[0]);
-       }
-
-       for (i=1; i<poly->nrings; i++)
-       {
-               if ( ! ptarray_isccw(poly->rings[i]) )
-               {
-                       ptarray_reverse(poly->rings[i]);
-               }
-       }
-}
-
 /*------------------------------------------------------------------*/
 
 //find the size of geometry
@@ -2681,8 +2621,8 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS)
        TYPE_SETZM(pa[0]->dims, 0, 0);
        pa[0]->npoints = 5;
 
-       // Construct polygon
-       poly = lwpoly_construct(0, 0, SRID, lwgeom_hasBBOX(geom->type), 1, pa);
+       // Construct polygon 
+       poly = lwpoly_construct(SRID, lwgeom_hasBBOX(geom->type), 1, pa);
 
        // Serialize polygon
        ser = lwpoly_serialize(poly);
@@ -2748,10 +2688,8 @@ Datum LWGEOM_envelope(PG_FUNCTION_ARGS)
        TYPE_SETZM(pa[0]->dims, 0, 0);
        pa[0]->npoints = 5;
 
-       // Construct polygon 2d
-       poly = lwpoly_construct(
-               0, 0,
-               SRID, lwgeom_hasBBOX(geom->type), 1, pa);
+       // Construct polygon 
+       poly = lwpoly_construct(SRID, lwgeom_hasBBOX(geom->type), 1, pa);
 
        // Serialize polygon
        ser = lwpoly_serialize(poly);
@@ -2825,7 +2763,7 @@ Datum centroid(PG_FUNCTION_ARGS)
        pa = pointArray_construct((char *)&cent, 1, 0, 1);
 
        // Construct LWPOINT
-       point = lwpoint_construct(1, 0, SRID, wantbbox, pa);
+       point = lwpoint_construct(SRID, wantbbox, pa);
 
        // Serialize LWPOINT 
        srl = lwpoint_serialize(point);
index b96701475971d9c48f971a31315d9d52090456ac..b6fdc925a87ddc8f9b4a8585b02ff50f3e30c49c 100644 (file)
@@ -1900,10 +1900,7 @@ lwpoint_from_geometry(Geometry *g, char want3d)
        GEOSdeleteChar( (char*) pts);
 
        // Construct LWPOINT
-       point = lwpoint_construct(
-               TYPE_HASZ(pa->dims),
-               TYPE_HASM(pa->dims),
-               -1, 0, pa);
+       point = lwpoint_construct(-1, 0, pa);
 
        return point;
 }
@@ -1943,10 +1940,7 @@ lwline_from_geometry(Geometry *g, char want3d)
        GEOSdeleteChar( (char*) pts);
 
        // Construct LWPOINT
-       line = lwline_construct(
-               TYPE_HASZ(pa->dims),
-               TYPE_HASM(pa->dims),
-               -1, 0, pa);
+       line = lwline_construct(-1, 0, pa);
 
        return line;
 }
@@ -2012,10 +2006,7 @@ lwpoly_from_geometry(Geometry *g, char want3d)
        }
 
        // Construct LWPOLY
-       poly = lwpoly_construct(
-               TYPE_HASZ(pa->dims),
-               TYPE_HASM(pa->dims),
-               -1, 0, nrings+1, rings);
+       poly = lwpoly_construct(-1, 0, nrings+1, rings);
 
        return poly;
 }
@@ -2053,10 +2044,7 @@ lwcollection_from_geometry(Geometry *geom, char want3d)
 #endif
        }
 
-       ret = lwcollection_construct(type,
-               want3d, 0, 
-               SRID,
-               wantbbox, ngeoms, geoms);
+       ret = lwcollection_construct(type, SRID, wantbbox, ngeoms, geoms);
        return ret;
 }
 
@@ -2223,7 +2211,7 @@ Datum GEOSnoop(PG_FUNCTION_ARGS)
 
        geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 #ifdef DEBUG_CONVERTER
-       elog(NOTICE, "GEOSnoop: IN: %s", unparse_WKT((char *)geom, malloc, free));
+       elog(NOTICE, "GEOSnoop: IN: %s", unparse_WKT(SERIALIZED_FORM(geom), malloc, free));
 #endif
 
        geosgeom = POSTGIS2GEOS(geom);
@@ -2239,7 +2227,7 @@ Datum GEOSnoop(PG_FUNCTION_ARGS)
        GEOSdeleteGeometry(geosgeom);
 
 #ifdef DEBUG_CONVERTER
-       elog(NOTICE, "GEOSnoop: OUT: %s", unparse_WKT((char *)result, malloc, free));
+       elog(NOTICE, "GEOSnoop: OUT: %s", unparse_WKT(SERIALIZED_FORM(result), malloc, free));
 #endif
 
        PG_RETURN_POINTER(result);
index df284bb9a64e7d3e8e4f4b797a10a2a00fe05795..a6ca4ae58726ae5eee352de26a53d6a5ee643a62 100644 (file)
@@ -148,7 +148,7 @@ extern "C" Geometry *GEOSpointonSurface(Geometry *g1);
 
 extern "C" Geometry *GEOSGetCentroid(Geometry *g1);
 
-extern "C" void NOTICE_MESSAGE(char *msg);
+extern "C" void lwnotice(char *msg);
 
 
 
@@ -203,7 +203,7 @@ Geometry *PostGIS2GEOS_box3d(BOX3D *box, int SRID)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete cl;
                return NULL;
        }
@@ -223,12 +223,12 @@ Geometry *PostGIS2GEOS_point(const LWPOINT *lwpoint)
 #ifdef DEBUG_POSTGIS2GEOS
        char buf[256];
        sprintf(buf, "PostGIS2GEOS_point got lwpoint[%p]", lwpoint);
-       NOTICE_MESSAGE(buf);
+       lwnotice(buf);
 #endif
 
        if ( lwpoint == NULL )
        {
-               NOTICE_MESSAGE("PostGIS2GEOS_point got a NULL lwpoint");
+               lwnotice("PostGIS2GEOS_point got a NULL lwpoint");
                return NULL;
        }
 
@@ -253,7 +253,7 @@ Geometry *PostGIS2GEOS_point(const LWPOINT *lwpoint)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -277,7 +277,7 @@ PostGIS2GEOS_linestring(const LWLINE *lwline)
 #ifdef DEBUG_POSTGIS2GEOS
        char buf[256];
        sprintf(buf, "PostGIS2GEOS_line got lwline[%p]", lwline);
-       NOTICE_MESSAGE(buf);
+       lwnotice(buf);
 #endif
 
        try{
@@ -338,7 +338,7 @@ PostGIS2GEOS_linestring(const LWLINE *lwline)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -358,7 +358,7 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly)
 #ifdef DEBUG_POSTGIS2GEOS
        char buf[256];
        sprintf(buf, "PostGIS2GEOS_poly got lwpoly[%p]", lwpoly);
-       NOTICE_MESSAGE(buf);
+       lwnotice(buf);
 #endif
 
        try
@@ -491,7 +491,7 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -528,7 +528,7 @@ Geometry *PostGIS2GEOS_multipoint(LWPOINT **geoms, uint32 ngeoms, int SRID, bool
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -565,7 +565,7 @@ Geometry *PostGIS2GEOS_multilinestring(LWLINE **geoms, uint32 ngeoms, int SRID,
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -602,7 +602,7 @@ Geometry *PostGIS2GEOS_multipolygon(LWPOLY **polygons, uint32 npolys, int SRID,
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -619,7 +619,7 @@ Geometry *PostGIS2GEOS_collection(int type, Geometry **geoms, int ngeoms, int SR
        char buf[256];
        sprintf(buf, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
                        type, ngeoms);
-       NOTICE_MESSAGE(buf);
+       lwnotice(buf);
 #endif
 
        try
@@ -648,7 +648,7 @@ Geometry *PostGIS2GEOS_collection(int type, Geometry **geoms, int ngeoms, int SR
                                g = geomFactory->createMultiPolygon(subGeos);
                                break;
                        default:
-                               NOTICE_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
+                               lwnotice("Unsupported type request for PostGIS2GEOS_collection");
                                g = NULL;
                                
                }
@@ -662,7 +662,7 @@ Geometry *PostGIS2GEOS_collection(int type, Geometry **geoms, int ngeoms, int SR
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -688,7 +688,7 @@ char GEOSrelateDisjoint(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -707,7 +707,7 @@ char GEOSrelateTouches(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -727,7 +727,7 @@ char GEOSrelateIntersects(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -747,7 +747,7 @@ char GEOSrelateCrosses(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -767,7 +767,7 @@ char GEOSrelateWithin(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -791,7 +791,7 @@ char GEOSrelateContains(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -811,7 +811,7 @@ char GEOSrelateOverlaps(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -837,7 +837,7 @@ char GEOSrelatePattern(Geometry *g1, Geometry*g2,char *pat)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -868,7 +868,7 @@ char *GEOSrelate(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -895,7 +895,7 @@ char GEOSisvalid(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -921,7 +921,7 @@ char GEOSequals(Geometry *g1, Geometry*g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -948,7 +948,7 @@ char *GEOSasText(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -967,7 +967,7 @@ char GEOSisEmpty(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -986,7 +986,7 @@ char GEOSisSimple(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -1005,7 +1005,7 @@ char GEOSisRing(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 2;
        }
@@ -1033,7 +1033,7 @@ char *GEOSGeometryType(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1072,7 +1072,7 @@ int GEOSGeometryTypeId(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return -1;
        }
@@ -1099,7 +1099,7 @@ Geometry *GEOSIntersection(Geometry *g1,Geometry *g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1119,7 +1119,7 @@ Geometry *GEOSBuffer(Geometry *g1,double width)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1139,7 +1139,7 @@ Geometry *GEOSConvexHull(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1159,7 +1159,7 @@ Geometry *GEOSDifference(Geometry *g1,Geometry *g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1179,7 +1179,7 @@ Geometry *GEOSBoundary(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1199,7 +1199,7 @@ Geometry *GEOSSymDifference(Geometry *g1,Geometry *g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1219,7 +1219,7 @@ Geometry *GEOSUnion(Geometry *g1,Geometry *g2)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1239,7 +1239,7 @@ Geometry *GEOSpointonSurface(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1267,7 +1267,7 @@ void GEOSdeleteGeometry(Geometry *a)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                //return NULL;
        }
@@ -1285,7 +1285,7 @@ void GEOSdeleteChar(char *a)
        }
        catch (GEOSException *ge) // ???
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                //return NULL;
        }
@@ -1317,7 +1317,7 @@ POINT3D  *GEOSGetCoordinate(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1360,7 +1360,7 @@ POINT3D  *GEOSGetCoordinates(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1421,7 +1421,7 @@ POINT3D  *GEOSGetCoordinates_Polygon(Polygon *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1443,7 +1443,7 @@ int      GEOSGetNumCoordinate(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 0;
        }
@@ -1462,7 +1462,7 @@ int      GEOSGetNumInteriorRings(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 0;
        }
@@ -1483,7 +1483,7 @@ int      GEOSGetNumGeometries(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 0;
        }
@@ -1504,7 +1504,7 @@ const Geometry *GEOSGetGeometryN(Geometry *g1, int n)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1525,7 +1525,7 @@ const Geometry *GEOSGetExteriorRing(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 0;
        }
@@ -1545,7 +1545,7 @@ const Geometry *GEOSGetInteriorRingN(Geometry *g1,int n)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1563,7 +1563,7 @@ Geometry *GEOSGetCentroid(Geometry *g)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return NULL;
        }
@@ -1582,7 +1582,7 @@ int      GEOSGetSRID(Geometry *g1)
        }
        catch (GEOSException *ge)
        {
-               NOTICE_MESSAGE((char *)ge->toString().c_str());
+               lwnotice((char *)ge->toString().c_str());
                delete ge;
                return 0;
        }
index 41c567ed4c6ada065e33eab084e6da95cb61b1e8..52eb7ae9b266845cf8b3ecfce5ae4ee787947fb9 100644 (file)
@@ -288,7 +288,7 @@ Datum gist_lwgeom_compress(PG_FUNCTION_ARGS)
                        in = (char*)PG_DETOAST_DATUM(entry->key);
 
 #ifdef DEBUG_GIST4
-               elog(NOTICE,"GIST: gist_lwgeom_compress detoasted entry->key: %s", unparse_WKT(in, malloc, free));
+               elog(NOTICE,"GIST: gist_lwgeom_compress detoasted entry->key: %s", unparse_WKT(SERIALIZED_FORM(in), malloc, free));
 #endif
 
                        if (in == NULL)
index 4f918a451d8c6a8e7c585736f0a7337f530e4c29..05ab4c441ebba687169df9820ea1910b78475c95 100644 (file)
 void elog_ERROR(const char* string);
 
 
-extern unsigned char   parse_hex(char *str);
-extern void deparse_hex(unsigned char str, unsigned char *result);
-extern char *parse_lwgeom_wkt(char *wkt_input);
-
 // needed for OGC conformance
 Datum LWGEOMFromWKB(PG_FUNCTION_ARGS);
 Datum WKBFromLWGEOM(PG_FUNCTION_ARGS);
@@ -115,13 +111,13 @@ Datum LWGEOM_in(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_out);
 Datum LWGEOM_out(PG_FUNCTION_ARGS)
 {
-       char *lwgeom;
+       PG_LWGEOM *lwgeom;
        char *result;
 
        init_pg_func();
 
-       lwgeom = (char *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       result = unparse_WKB(lwgeom,lwalloc,lwfree);
+       lwgeom = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       result = unparse_WKB(SERIALIZED_FORM(lwgeom),lwalloc,lwfree);
 
        PG_RETURN_CSTRING(result);
 }
@@ -143,7 +139,7 @@ Datum LWGEOMFromWKB(PG_FUNCTION_ARGS)
        int    SRID = -1;
        char    sridText[100];
        char    *loc;
-       char    *lwgeom;
+       PG_LWGEOM *lwgeom;
        int t;
 
        wkb_input = (WellKnownBinary *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
@@ -181,12 +177,12 @@ Datum LWGEOMFromWKB(PG_FUNCTION_ARGS)
        elog(NOTICE,"LWGEOMFromWKB :: '%s'", wkb_srid_hexized);
 #endif
 
-       lwgeom =  parse_lwgeom_wkt(wkb_srid_hexized);
+       lwgeom = (PG_LWGEOM *)parse_lwgeom_wkt(wkb_srid_hexized);
 
        pfree(wkb_srid_hexized);
 
 #ifdef DEBUG
-       elog(NOTICE, "LWGEOMFromWKB returning %s", unparse_WKB(lwgeom, pg_alloc, pg_free));
+       elog(NOTICE, "LWGEOMFromWKB returning %s", unparse_WKB(SERIALIZED_FORM(lwgeom), pg_alloc, pg_free));
 #endif
 
        PG_RETURN_POINTER(lwgeom);
@@ -197,7 +193,7 @@ Datum LWGEOMFromWKB(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(WKBFromLWGEOM);
 Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
 {
-       char *lwgeom_input; // SRID=#;<hexized wkb>
+       PG_LWGEOM *lwgeom_input; // SRID=#;<hexized wkb>
        char *hexized_wkb_srid;
        char *hexized_wkb; // hexized_wkb_srid w/o srid
        char *result; //wkb
@@ -208,8 +204,8 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
 
        init_pg_func();
 
-       lwgeom_input = (char *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       hexized_wkb_srid = unparse_WKB(lwgeom_input, lwalloc, lwfree);
+       lwgeom_input = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       hexized_wkb_srid = unparse_WKB(SERIALIZED_FORM(lwgeom_input), lwalloc, lwfree);
 
 //elog(NOTICE, "in WKBFromLWGEOM with WKB = '%s'", hexized_wkb_srid);
 
@@ -243,242 +239,6 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
 
 
 
-
-
-
-
-//given one byte, populate result with two byte representing
-// the hex number
-// ie deparse_hex( 255, mystr)
-//             -> mystr[0] = 'F' and mystr[1] = 'F'
-// no error checking done
-void deparse_hex(unsigned char str, unsigned char *result)
-{
-       int     input_high;
-       int  input_low;
-
-       input_high = (str>>4);
-       input_low = (str & 0x0F);
-
-       switch (input_high)
-       {
-               case 0:
-                       result[0] = '0';
-                       break;
-               case 1:
-                       result[0] = '1';
-                       break;
-               case 2:
-                       result[0] = '2';
-                       break;
-               case 3:
-                       result[0] = '3';
-                       break;
-               case 4:
-                       result[0] = '4';
-                       break;
-               case 5:
-                       result[0] = '5';
-                       break;
-               case 6:
-                       result[0] = '6';
-                       break;
-               case 7:
-                       result[0] = '7';
-                       break;
-               case 8:
-                       result[0] = '8';
-                       break;
-               case 9:
-                       result[0] = '9';
-                       break;
-               case 10:
-                       result[0] = 'A';
-                       break;
-               case 11:
-                       result[0] = 'B';
-                       break;
-               case 12:
-                       result[0] = 'C';
-                       break;
-               case 13:
-                       result[0] = 'D';
-                       break;
-               case 14:
-                       result[0] = 'E';
-                       break;
-               case 15:
-                       result[0] = 'F';
-                       break;
-       }
-
-       switch (input_low)
-       {
-               case 0:
-                       result[1] = '0';
-                       break;
-               case 1:
-                       result[1] = '1';
-                       break;
-               case 2:
-                       result[1] = '2';
-                       break;
-               case 3:
-                       result[1] = '3';
-                       break;
-               case 4:
-                       result[1] = '4';
-                       break;
-               case 5:
-                       result[1] = '5';
-                       break;
-               case 6:
-                       result[1] = '6';
-                       break;
-               case 7:
-                       result[1] = '7';
-                       break;
-               case 8:
-                       result[1] = '8';
-                       break;
-               case 9:
-                       result[1] = '9';
-                       break;
-               case 10:
-                       result[1] = 'A';
-                       break;
-               case 11:
-                       result[1] = 'B';
-                       break;
-               case 12:
-                       result[1] = 'C';
-                       break;
-               case 13:
-                       result[1] = 'D';
-                       break;
-               case 14:
-                       result[1] = 'E';
-                       break;
-               case 15:
-                       result[1] = 'F';
-                       break;
-       }
-}
-
-//given a string with at least 2 chars in it, convert them to
-// a byte value.  No error checking done!
-unsigned char  parse_hex(char *str)
-{
-       //do this a little brute force to make it faster
-
-       unsigned char           result_high = 0;
-       unsigned char           result_low = 0;
-
-       switch (str[0])
-       {
-               case '0' :
-                       result_high = 0;
-                       break;
-               case '1' :
-                       result_high = 1;
-                       break;
-               case '2' :
-                       result_high = 2;
-                       break;
-               case '3' :
-                       result_high = 3;
-                       break;
-               case '4' :
-                       result_high = 4;
-                       break;
-               case '5' :
-                       result_high = 5;
-                       break;
-               case '6' :
-                       result_high = 6;
-                       break;
-               case '7' :
-                       result_high = 7;
-                       break;
-               case '8' :
-                       result_high = 8;
-                       break;
-               case '9' :
-                       result_high = 9;
-                       break;
-               case 'A' :
-                       result_high = 10;
-                       break;
-               case 'B' :
-                       result_high = 11;
-                       break;
-               case 'C' :
-                       result_high = 12;
-                       break;
-               case 'D' :
-                       result_high = 13;
-                       break;
-               case 'E' :
-                       result_high = 14;
-                       break;
-               case 'F' :
-                       result_high = 15;
-                       break;
-       }
-       switch (str[1])
-       {
-               case '0' :
-                       result_low = 0;
-                       break;
-               case '1' :
-                       result_low = 1;
-                       break;
-               case '2' :
-                       result_low = 2;
-                       break;
-               case '3' :
-                       result_low = 3;
-                       break;
-               case '4' :
-                       result_low = 4;
-                       break;
-               case '5' :
-                       result_low = 5;
-                       break;
-               case '6' :
-                       result_low = 6;
-                       break;
-               case '7' :
-                       result_low = 7;
-                       break;
-               case '8' :
-                       result_low = 8;
-                       break;
-               case '9' :
-                       result_low = 9;
-                       break;
-               case 'A' :
-                       result_low = 10;
-                       break;
-               case 'B' :
-                       result_low = 11;
-                       break;
-               case 'C' :
-                       result_low = 12;
-                       break;
-               case 'D' :
-                       result_low = 13;
-                       break;
-               case 'E' :
-                       result_low = 14;
-                       break;
-               case 'F' :
-                       result_low = 15;
-                       break;
-       }
-       return (unsigned char) ((result_high<<4) + result_low);
-}
-
 // puts a bbox inside the geometry
 PG_FUNCTION_INFO_V1(LWGEOM_addBBOX);
 Datum LWGEOM_addBBOX(PG_FUNCTION_ARGS)
@@ -580,22 +340,6 @@ Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS)
 }
 
 
-char *parse_lwgeom_wkt(char *wkt_input)
-{
-       char *serialized_form = parse_lwg((const char *)wkt_input,(allocator)pg_alloc, (report_error)elog_ERROR);
-
-
-#ifdef DEBUG
-       elog(NOTICE,"parse_lwgeom_wkt with %s",wkt_input);
-#endif
-
-       if (serialized_form == NULL)
-               elog(ERROR,"parse_WKT:: couldnt parse!");
-
-       return serialized_form;
-
-}
-
 #if USE_VERSION > 73
 /*
  * This function must advance the StringInfo.cursor pointer
@@ -609,7 +353,7 @@ Datum LWGEOM_recv(PG_FUNCTION_ARGS)
 {
        StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
         bytea *wkb;
-       char *result;
+       PG_LWGEOM *result;
 
 #ifdef DEBUG
        elog(NOTICE, "LWGEOM_recv start");
@@ -625,7 +369,7 @@ Datum LWGEOM_recv(PG_FUNCTION_ARGS)
 #endif
 
        /* Call slow LWGEOMFromWKB function... */
-       result = DatumGetPointer(DirectFunctionCall1(LWGEOMFromWKB,
+       result = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall1(LWGEOMFromWKB,
                PointerGetDatum(wkb)));
 
 #ifdef DEBUG
@@ -633,7 +377,7 @@ Datum LWGEOM_recv(PG_FUNCTION_ARGS)
 #endif
 
 #ifdef DEBUG
-       elog(NOTICE, "LWGEOMFromWKB returned %s", unparse_WKB(result,pg_alloc,pg_free));
+       elog(NOTICE, "LWGEOMFromWKB returned %s", unparse_WKB(SERIALIZED_FORM(result),pg_alloc,pg_free));
 #endif
 
 
index 0980c781bc341c2ccee8197f25363b23638cfcec..dc110b1e326d6f4b4335328008b0cd4ff8123329 100644 (file)
@@ -333,11 +333,7 @@ Datum LWGEOM_exteriorring_polygon(PG_FUNCTION_ARGS)
        extring = poly->rings[0];
 
        // This is a LWLINE constructed by exterior ring POINTARRAY
-       line = lwline_construct(
-               TYPE_HASZ(poly->type),
-               TYPE_HASM(poly->type),
-               poly->SRID,
-               lwgeom_hasBBOX(geom->type), extring);
+       line = lwline_construct(poly->SRID, lwgeom_hasBBOX(geom->type), extring);
 
        // Now we serialized it (copying data)
        serializedline = lwline_serialize(line);
@@ -420,11 +416,7 @@ Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS)
        ring = poly->rings[wanted_index+1];
 
        // This is a LWLINE constructed by exterior ring POINTARRAY
-       line = lwline_construct(
-               TYPE_HASZ(poly->type),
-               TYPE_HASM(poly->type),
-               poly->SRID,
-               lwgeom_hasBBOX(geom->type), ring);
+       line = lwline_construct(poly->SRID, lwgeom_hasBBOX(geom->type), ring);
 
        // Now we serialized it (copying data)
        serializedline = lwline_serialize(line);
@@ -483,8 +475,7 @@ Datum LWGEOM_pointn_linestring(PG_FUNCTION_ARGS)
                TYPE_HASZ(line->type), TYPE_HASM(line->type), 1);
 
        // Construct an LWPOINT
-       point = lwpoint_construct(TYPE_HASZ(line->type), TYPE_HASM(line->type),
-               lwgeom_getSRID(geom), lwgeom_hasBBOX(geom->type), pts);
+       point = lwpoint_construct(lwgeom_getSRID(geom), lwgeom_hasBBOX(geom->type), pts);
 
        // Serialized the point
        serializedpoint = lwpoint_serialize(point);
@@ -626,11 +617,7 @@ Datum LWGEOM_startpoint_linestring(PG_FUNCTION_ARGS)
                TYPE_HASM(line->type), 1);
 
        // Construct an LWPOINT
-       point = lwpoint_construct(
-               TYPE_HASZ(line->type),
-               TYPE_HASM(line->type),
-               lwgeom_getSRID(geom),
-               lwgeom_hasBBOX(geom->type), pts);
+       point = lwpoint_construct(lwgeom_getSRID(geom), lwgeom_hasBBOX(geom->type), pts);
 
        // Serialized the point
        serializedpoint = lwpoint_serialize(point);
@@ -681,11 +668,7 @@ Datum LWGEOM_endpoint_linestring(PG_FUNCTION_ARGS)
                TYPE_HASM(line->type), 1);
 
        // Construct an LWPOINT
-       point = lwpoint_construct(
-               TYPE_HASZ(line->type),
-               TYPE_HASM(line->type),
-               lwgeom_getSRID(geom),
-               lwgeom_hasBBOX(geom->type), pts);
+       point = lwpoint_construct(lwgeom_getSRID(geom), lwgeom_hasBBOX(geom->type), pts);
 
        // Serialized the point
        serializedpoint = lwpoint_serialize(point);
@@ -731,7 +714,7 @@ Datum LWGEOM_from_text(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_asText);
 Datum LWGEOM_asText(PG_FUNCTION_ARGS)
 {
-       char *lwgeom;
+       PG_LWGEOM *lwgeom;
        char *result_cstring;
        int len;
         char *result,*loc_wkt;
@@ -739,8 +722,8 @@ Datum LWGEOM_asText(PG_FUNCTION_ARGS)
 
        init_pg_func();
 
-       lwgeom = (char *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       result_cstring =  unparse_WKT(lwgeom,lwalloc,lwfree);
+       lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       result_cstring =  unparse_WKT(SERIALIZED_FORM(lwgeom),lwalloc,lwfree);
 
        semicolonLoc = strchr(result_cstring,';');
 
index 6e17453159d8274203694cdd1159e9c691b0e21c..bc06e288608ed5a955285424a535b2910f5b1e1c 100644 (file)
@@ -93,9 +93,10 @@ pg_notice(const char *fmt, ...)
 void
 init_pg_func()
 {
-       lwalloc = pg_alloc;
-       lwrealloc = pg_realloc;
-       lwfree = pg_free;
+       lwalloc_var = pg_alloc;
+       lwrealloc_var = pg_realloc;
+       lwfree_var = pg_free;
        lwerror = pg_error;
        lwnotice = pg_notice;
 }
+
index 29722aca00325791fd6758fea0fb22c5b83c019c..d10175ffcc48f355e927de5009418bf1871393e7 100644 (file)
 // construct a new LWLINE.  points will *NOT* be copied
 // use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
 LWLINE *
-lwline_construct(char hasz, char hasm, int SRID, char wantbbox, POINTARRAY *points)
+lwline_construct(int SRID, char wantbbox, POINTARRAY *points)
 {
        LWLINE *result;
-       result = (LWLINE*) lwalloc( sizeof(LWLINE));
+       result = (LWLINE*) lwalloc(sizeof(LWLINE));
 
-       result->type = lwgeom_makeType_full(hasz, hasm, (SRID!=-1), LINETYPE,
+       result->type = lwgeom_makeType_full(
+               TYPE_HASZ(points->dims),
+               TYPE_HASM(points->dims),
+               (SRID!=-1), LINETYPE,
                wantbbox);
        result->SRID = SRID;
        result->points = points;
@@ -337,11 +340,15 @@ lwline_add(const LWLINE *to, uint32 where, const LWGEOM *what)
        else newtype = COLLECTIONTYPE;
 
        col = lwcollection_construct(newtype,
-               TYPE_HASZ(to->type),
-               TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                2, geoms);
        
        return (LWGEOM *)col;
 }
+
+void
+lwline_reverse(LWLINE *line)
+{
+       ptarray_reverse(line->points);
+}
index c995949e84ed57c8503a959e7aa4760a8ec27a7f..fe5c0d06259bc914e73cc19d71c512c93b3ae00c 100644 (file)
@@ -80,8 +80,6 @@ lwmline_add(const LWMLINE *to, uint32 where, const LWGEOM *what)
        else newtype = COLLECTIONTYPE;
 
        col = lwcollection_construct(newtype,
-               TYPE_HASZ(to->type),
-               TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                to->ngeoms+1, geoms);
index cc19d443ba0f567e6bb37d3f6f7f6498fbf7fed3..5ac12bb2defb75a1a87e733f0ce27fe3ee71138f 100644 (file)
@@ -80,7 +80,6 @@ lwmpoint_add(const LWMPOINT *to, uint32 where, const LWGEOM *what)
        else newtype = COLLECTIONTYPE;
 
        col = lwcollection_construct(newtype,
-               TYPE_HASZ(to->type), TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                to->ngeoms+1, geoms);
index 0b6e8a84c9ad882d6cf6a09bf3b20d02fa31e006..5364c67f7a2d20a5e87de3f1a8db41d92b731015 100644 (file)
@@ -86,8 +86,6 @@ lwmpoly_add(const LWMPOLY *to, uint32 where, const LWGEOM *what)
        else newtype = COLLECTIONTYPE;
 
        col = lwcollection_construct(newtype,
-               TYPE_HASZ(to->type),
-               TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                to->ngeoms+1, geoms);
index 15e1f4f23ad2c3d3e0fcf5411e48f321b33e7421..67405b113495bcf481449f2fa5623efd57aaea69 100644 (file)
@@ -154,7 +154,7 @@ lwpoint_serialize_size(LWPOINT *point)
 // construct a new point.  point will not be copied
 // use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
 LWPOINT *
-lwpoint_construct(char hasZ, char hasM, int SRID, char wantbbox, POINTARRAY *point)
+lwpoint_construct(int SRID, char wantbbox, POINTARRAY *point)
 {
        LWPOINT *result ;
 
@@ -162,7 +162,7 @@ lwpoint_construct(char hasZ, char hasM, int SRID, char wantbbox, POINTARRAY *poi
                return NULL; // error
 
        result = lwalloc(sizeof(LWPOINT));
-       result->type = lwgeom_makeType_full(hasZ, hasM, (SRID!=-1),
+       result->type = lwgeom_makeType_full(TYPE_HASZ(point->dims), TYPE_HASM(point->dims), (SRID!=-1),
                POINTTYPE, wantbbox);
        result->SRID = SRID;
        result->point = point;
@@ -303,8 +303,6 @@ lwpoint_add(const LWPOINT *to, uint32 where, const LWGEOM *what)
        else newtype = COLLECTIONTYPE;
 
        col = lwcollection_construct(newtype,
-               TYPE_HASZ(to->type),
-               TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                2, geoms);
index 917f4f9632fe018b9b259cb6f8935dce2e06d16c..192b560db3c3a3c84d94d3eadfbbb48228f01a92 100644 (file)
@@ -7,12 +7,33 @@
 
 //#define DEBUG_CALLS 1
 
+#define CHECK_POLY_RINGS_ZM 1
+
 // 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)
 LWPOLY *
-lwpoly_construct(char hasz, char hasm, int SRID, char wantbbox, int nrings, POINTARRAY **points)
+lwpoly_construct(int SRID, char wantbbox, unsigned int nrings, POINTARRAY **points)
 {
        LWPOLY *result;
+       int hasz, hasm;
+#ifdef CHECK_POLY_RINGS_ZM
+       char zm;
+       unsigned int i;
+#endif
+
+       if ( nrings < 1 ) lwerror("lwpoly_construct: need at least 1 ring");
+
+       hasz = TYPE_HASZ(points[0]->dims);
+       hasm = TYPE_HASM(points[0]->dims);
+
+#ifdef CHECK_POLY_RINGS_ZM
+       zm = TYPE_GETZM(points[0]->dims);
+       for (i=1; i<nrings; i++)
+       {
+               if ( zm != TYPE_GETZM(points[i]->dims) )
+                       lwerror("lwpoly_construct: mixed dimensioned rings");
+       }
+#endif
 
        result = (LWPOLY*) lwalloc(sizeof(LWPOLY));
        result->type = lwgeom_makeType_full(hasz, hasm, (SRID!=-1), POLYGONTYPE,
@@ -449,11 +470,38 @@ lwpoly_add(const LWPOLY *to, uint32 where, const LWGEOM *what)
        else newtype = COLLECTIONTYPE;
 
        col = lwcollection_construct(newtype,
-               TYPE_HASZ(to->type),
-               TYPE_HASM(to->type),
                to->SRID,
                ( TYPE_HASBBOX(what->type) || TYPE_HASBBOX(to->type) ),
                2, geoms);
        
        return (LWGEOM *)col;
 }
+
+void
+lwpoly_forceRHR(LWPOLY *poly)
+{
+       int i;
+
+       if ( ptarray_isccw(poly->rings[0]) )
+       {
+               ptarray_reverse(poly->rings[0]);
+       }
+
+       for (i=1; i<poly->nrings; i++)
+       {
+               if ( ! ptarray_isccw(poly->rings[i]) )
+               {
+                       ptarray_reverse(poly->rings[i]);
+               }
+       }
+}
+
+
+void
+lwpoly_reverse(LWPOLY *poly)
+{
+       int i;
+
+       for (i=0; i<poly->nrings; i++)
+               ptarray_reverse(poly->rings[i]);
+}
diff --git a/lwgeom/ptarray.c b/lwgeom/ptarray.c
new file mode 100644 (file)
index 0000000..2d9eb5a
--- /dev/null
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "liblwgeom.h"
+
+POINTARRAY *
+ptarray_construct(char hasz, char hasm, unsigned int npoints)
+{
+       unsigned char dims = 0;
+       size_t size; 
+       char *ptlist;
+       POINTARRAY *pa;
+       
+       TYPE_SETZM(dims, hasz?1:0, hasm?1:0);
+       size = TYPE_NDIMS(dims)*npoints;
+       ptlist = (char *)lwalloc(size);
+       pa = lwalloc(sizeof(POINTARRAY));
+       pa->dims = dims;
+       pa->serialized_pointlist = ptlist;
+       pa->npoints = npoints;
+
+       return pa;
+
+}
+
+POINTARRAY *
+ptarray_construct2d(uint32 npoints, POINT2D const* const* pts)
+{
+       POINTARRAY *pa = ptarray_construct(0, 0, npoints);
+       uint32 i;
+
+       for (i=0; i<npoints; i++)
+       {
+               POINT2D *pap = (POINT2D *)getPoint(pa, i);
+               pap->x = pts[i]->x;
+               pap->y = pts[i]->y;
+       }
+       
+       return pa;
+}
+
+void
+ptarray_reverse(POINTARRAY *pa)
+{
+       POINT4D pbuf;
+       uint32 i;
+       int ptsize = pointArray_ptsize(pa);
+       int last = pa->npoints-1;
+       int mid = last/2;
+
+       for (i=0; i<=mid; i++)
+       {
+               char *from, *to;
+               from = getPoint(pa, i);
+               to = getPoint(pa, (last-i));
+               memcpy((char *)&pbuf, to, ptsize);
+               memcpy(to, from, ptsize);
+               memcpy(from, (char *)&pbuf, ptsize);
+       }
+
+}
diff --git a/lwgeom/test.c b/lwgeom/test.c
new file mode 100644 (file)
index 0000000..2cf580c
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include "lwgeom.h"
+
+int main()
+{
+       POINT2D *pts2d[10];
+       POINT3DM *pts3dm[10];
+       POINT3DZ *pts3dz[10];
+       POINT4D *pts4d[10];
+       unsigned int npoints;
+       POINTARRAY pa;
+       LWGEOM point, line, poly;
+
+       // Construct a point2d
+       pts2d[0] = lwalloc(sizeof(POINT2D));
+       pts2d[0]->x = 10;
+       pts2d[0]->y = 20;
+
+       // Construct a pointarray2d
+       pa = ptarray_construct2d(1, pts2d);
+
+       // Construct a point LWGEOM
+       point = lwpoint_construct(-1, 0, pa);
+
+       // Print WKT
+       printf("WKT: %s\n", lwgeom_to_wkt(point));
+
+       return 1;
+}
index e2535c1ed94bae51f9a8c370e1017254c0397dca..a0fb5136f4cd0886e8913595825966e145666b20 100644 (file)
@@ -67,7 +67,7 @@ void alloc_wkb(const char* parser);
 
 byte* parse_lwg(const char* wkt,allocator allocfunc,report_error errfunc);
 byte* parse_lwgi(const char* wkt,allocator allocfunc,report_error errfunc);
-char* unparse_WKT(byte* lw_geom,allocator alloc,freeor free);
-char* unparse_WKB(byte* lw_geom,allocator alloc,freeor free);
+char* unparse_WKT(byte* serialized, allocator alloc,freeor free);
+char* unparse_WKB(byte* serialized, allocator alloc,freeor free);
 
 
index c1602f03e075a308f9742122ff1ab8adfb65c76b..92bc6acbebc25c871a78336f1e49f844b937ab87 100644 (file)
@@ -348,10 +348,10 @@ output_wkt(byte* geom, int supress)
 }
 
 char *
-unparse_WKT(byte* lw_geom, allocator alloc, freeor free)
+unparse_WKT(byte* serialized, allocator alloc, freeor free)
 {
 
-       if (lw_geom==NULL)
+       if (serialized==NULL)
                return NULL;
 
        local_malloc=alloc;
@@ -360,7 +360,7 @@ unparse_WKT(byte* lw_geom, allocator alloc, freeor free)
        out_start = out_pos = alloc(len);
        lwgi=0;
 
-       output_wkt(lw_geom+4, 0);
+       output_wkt(serialized, 0);
 
        return out_start;
 }
@@ -501,14 +501,14 @@ output_wkb(byte* geom)
 }
 
 char *
-unparse_WKB(byte* lw_geom,allocator alloc,freeor free)
+unparse_WKB(byte* serialized, allocator alloc, freeor free)
 {
 
 #ifdef DEBUG
-       lwnotice("unparse_WKB(%p,...) called", lw_geom);
+       lwnotice("unparse_WKB(%p,...) called", serialized);
 #endif
 
-       if (lw_geom==NULL)
+       if (serialized==NULL)
                return NULL;
 
        local_malloc=alloc;
@@ -517,7 +517,7 @@ unparse_WKB(byte* lw_geom,allocator alloc,freeor free)
        out_start = out_pos = alloc(len);
        lwgi=0;
 
-       output_wkb(lw_geom+4);
+       output_wkb(serialized);
        ensure(1);
        *out_pos=0;