Added support for 4d coordinates
authorDavid Blasby <dblasby@gmail.com>
Fri, 2 Apr 2004 19:03:06 +0000 (19:03 +0000)
committerDavid Blasby <dblasby@gmail.com>
Fri, 2 Apr 2004 19:03:06 +0000 (19:03 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@498 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom.h
lwgeom/lwgeom_api.c
lwgeom/lwgeom_inout.c

index f22d6226c3be582c2197637660d16fc5c1c799a9..86db6a0428a808c7f5e2853ab84feb2df8d00cd1 100644 (file)
@@ -8,10 +8,6 @@
 
 
 
-#define TWODIMS 0
-#define THREEDIMS 1
-#define FOURDIMS 2
-
 typedef struct
 {
        float xmin;
@@ -28,6 +24,7 @@ typedef struct
 } BOX3D;
 
 
+
 // POINT3D already defined in postgis.h
 // ALL LWGEOM structures will use POINT3D as an abstract point.
 // This means a 2d geometry will be stored as (x,y) in its serialized
@@ -65,10 +62,24 @@ typedef struct
 typedef struct
 {
     char  *serialized_pointlist; // probably missaligned. 2d or 3d.  points to a double
-    char  is3d; // true if these are 3d points
+    char  ndims; // 2=2d, 3=3d, 4=4d, 5=undef
     uint32 npoints;
 }  POINTARRAY;
 
+// copies a point from the point array into the parameter point
+// will set point's z=0 (or NaN) if pa is 2d
+// will set point's m=0 (or NaN( if pa is 3d or 2d
+// NOTE: point is a real POINT3D *not* a pointer
+extern POINT4D getPoint4d(POINTARRAY *pa, int n);
+
+// copies a point from the point array into the parameter point
+// will set point's z=0 (or NaN) if pa is 2d
+// will set point's m=0 (or NaN( if pa is 3d or 2d
+// NOTE: this will modify the point4d pointed to by 'point'.
+extern void getPoint4d_p(POINTARRAY *pa, int n, char *point);
+
+
+
 // copies a point from the point array into the parameter point
 // will set point's z=0 (or NaN) if pa is 2d
 // NOTE: point is a real POINT3D *not* a pointer
@@ -93,9 +104,9 @@ extern void getPoint2d_p(POINTARRAY *pa, int n, char *point);
 
 // constructs a POINTARRAY.
 // NOTE: points is *not* copied, so be careful about modification (can be aligned/missaligned)
-// NOTE: is3d is descriptive - it describes what type of data 'points'
+// NOTE: ndims is descriptive - it describes what type of data 'points'
 //       points to.  No data conversion is done.
-extern POINTARRAY *pointArray_construct(char *points, char is3d, uint32 npoints);
+extern POINTARRAY *pointArray_construct(char *points, int ndims, uint32 npoints);
 
 //calculate the bounding box of a set of points
 // returns a 3d box
@@ -148,9 +159,9 @@ WHERE
 
 
 extern bool lwgeom_hasSRID(char type); // true iff S bit is set
-extern bool lwgeom_is3d(char type);    // true iff D bit is set
+extern int  lwgeom_ndims(char type);    // true iff D bit is set
 extern int  lwgeom_getType(char type); // returns the tttt value
-extern char lwgeom_makeType(char is3d, char hasSRID, int type);
+extern char lwgeom_makeType(int ndims, char hasSRID, int type);
 
 
 // all the base types (point/line/polygon) will have a
@@ -163,14 +174,14 @@ extern char lwgeom_makeType(char is3d, char hasSRID, int type);
 
 typedef struct
 {
-       char          is3d;   // true means points represent 3d points
+       char  ndims; // 2=2d, 3=3d, 4=4d, 5=undef
        int  SRID;   // spatial ref sys -1=none
        POINTARRAY    *points; // array of POINT3D
 } LWLINE; //"light-weight line"
 
 // construct a new LWLINE.  points will be copied
 // use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
-extern LWLINE *lwline_construct(char is3d, int SRID, POINTARRAY *points);
+extern LWLINE *lwline_construct(int ndims, int SRID, POINTARRAY *points);
 
 // given the LWGEOM serialized form (or a pointer into a muli* one)
 // construct a proper LWLINE.
@@ -194,14 +205,14 @@ extern uint32 lwline_findlength(char *serialized_line);
 
 typedef struct
 {
-       char     is3d;   // true means points represent 3d points
+       char     ndims; // 2=2d, 3=3d, 4=4d, 5=undef
        int      SRID;   // spatial ref sys
        POINTARRAY  *point;  // hide 2d/3d (this will be an array of 1 point)
 }  LWPOINT; // "light-weight point"
 
 // 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 is3d, int SRID, POINTARRAY *point);
+extern LWPOINT  *lwpoint_construct(int ndims, int SRID, POINTARRAY *point);
 
 // given the LWPOINT serialized form (or a pointer into a muli* one)
 // construct a proper LWPOINT.
@@ -230,14 +241,14 @@ extern uint32 lwpoint_findlength(char *serialized_line);
 typedef struct
 {
        int32 SRID;
-       char is3d;
+       char ndims;
        int  nrings;
        POINTARRAY **rings; // list of rings (list of points)
 } LWPOLY; // "light-weight polygon"
 
 // construct a new LWLINE.  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 is3d, int SRID, int nrings,POINTARRAY **points);
+extern LWPOLY *lwpoly_construct(int ndims, int SRID, int nrings,POINTARRAY **points);
 
 
 // given the LWPOLY serialized form (or a pointer into a muli* one)
@@ -353,11 +364,11 @@ extern int lwgeom_getnumgeometries_inspected(LWGEOM_INSPECTED *inspected);
 //  use SRID=-1 for unknown SRID  (will have 8bit type's S = 0)
 // all subgeometries must have the same SRID
 // if you want to construct an inspected, call this then inspect the result...
-extern char *lwgeom_construct(int SRID,int finalType,char is3d, int nsubgeometries, char **serialized_subs);
+extern char *lwgeom_construct(int SRID,int finalType,int ndims, int nsubgeometries, char **serialized_subs);
 
 
 // construct the empty geometry (GEOMETRYCOLLECTION(EMPTY))
-extern char *lwgeom_constructempty(int SRID,char is3d);
+extern char *lwgeom_constructempty(int SRID,int ndims);
 
 // helper function (not for general use)
 // find the size a geometry (or a sub-geometry)
index d04cbb5ef8f7b99489fd83127d01f66c5e917b9b..02f2b0c47bfc870c912378836fa10d9c9111a62b 100644 (file)
@@ -18,8 +18,8 @@
 #include "lwgeom.h"
 
 
-extern float nextDown_f(double d);
-extern float nextUp_f(double d);
+extern float  nextDown_f(double d);
+extern float  nextUp_f(double d);
 extern double nextDown_d(float d);
 extern double nextUp_d(float d);
 
@@ -210,6 +210,73 @@ BOX3D *combine_boxes(BOX3D *b1, BOX3D *b2)
 // POINTARRAY support functions
 
 
+// copies a point from the point array into the parameter point
+// will set point's z=0 (or NaN) if pa is 2d
+// will set point's m=0 (or NaN( if pa is 3d or 2d
+// NOTE: point is a real POINT3D *not* a pointer
+POINT4D getPoint4d(POINTARRAY *pa, int n)
+{
+                POINT4D result;
+                int size;
+
+                if ( (n<0) || (n>=pa->npoints))
+                {
+                        return result; //error
+                }
+
+                size = pointArray_ptsize(pa);
+
+                       // this does x,y
+                memcpy(&result.x, &pa->serialized_pointlist[size*n],sizeof(double)*2 );
+                if (pa->ndims >2)
+                       memcpy(&result.z, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
+                else
+                       result.z = NO_Z_VALUE;
+                if (pa->ndims >3)
+                       memcpy(&result.m, &pa->serialized_pointlist[size*n + sizeof(double)*3],sizeof(double) );
+                else
+                       result.m = NO_Z_VALUE;
+
+                return result;
+}
+
+// copies a point from the point array into the parameter point
+// will set point's z=0 (or NaN) if pa is 2d
+// will set point's m=0 (or NaN( if pa is 3d or 2d
+// NOTE: this will modify the point4d pointed to by 'point'.
+void getPoint4d_p(POINTARRAY *pa, int n, char *point)
+{
+               int size;
+
+                if ( (n<0) || (n>=pa->npoints))
+                {
+                        return ; //error
+                }
+
+               size = pointArray_ptsize(pa);
+
+                       // this does x,y
+                memcpy(point, &pa->serialized_pointlist[size*n],sizeof(double)*2 );
+                if (pa->ndims >2)
+                       memcpy(point+16, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
+                else
+                {
+                        double bad=NO_Z_VALUE;
+                        memcpy(point+16, &bad,sizeof(double) );
+                        //point->z = NO_Z_VALUE;
+                }
+
+                if (pa->ndims >3)
+                       memcpy(point+24, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
+                else
+                {
+                        double bad=NO_Z_VALUE;
+                        memcpy(point+24, &bad,sizeof(double) );
+                       //point->z = NO_Z_VALUE;
+                }
+}
+
+
 
 // copies a point from the point array into the parameter point
 // will set point's z=0 (or NaN) if pa is 2d
@@ -228,7 +295,7 @@ BOX3D *combine_boxes(BOX3D *b1, BOX3D *b2)
 
                // this does x,y
         memcpy(&result.x, &pa->serialized_pointlist[size*n],sizeof(double)*2 );
-        if (pa->is3d)
+        if (pa->ndims >2)
                memcpy(&result.z, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
         else
                result.z = NO_Z_VALUE;
@@ -253,12 +320,12 @@ void getPoint3d_p(POINTARRAY *pa, int n, char *point)
 
                // this does x,y
         memcpy(point, &pa->serialized_pointlist[size*n],sizeof(double)*2 );
-        if (pa->is3d)
+        if (pa->ndims >2)
                memcpy(point+16, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
         else
         {
                 double bad=NO_Z_VALUE;
-               memcpy(point+24, &bad,sizeof(double) );
+               memcpy(point+16, &bad,sizeof(double) );
                //point->z = NO_Z_VALUE;
         }
  }
@@ -307,17 +374,17 @@ void getPoint2d_p(POINTARRAY *pa, int n, char *point)
 
 // constructs a POINTARRAY.
 // NOTE: points is *not* copied, so be careful about modification (can be aligned/missaligned)
-// NOTE: is3d is descriptive - it describes what type of data 'points'
+// NOTE: ndims is descriptive - it describes what type of data 'points'
 //       points to.  No data conversion is done.
-POINTARRAY *pointArray_construct(char *points, char is3d, uint32 npoints)
+POINTARRAY *pointArray_construct(char *points, int ndims, uint32 npoints)
 {
        POINTARRAY  *pa;
        pa = (POINTARRAY*)palloc(sizeof(pa));
 
-       if (is3d>2)
-               elog(ERROR,"pointArray_construct:: called with dims = %i", (int) is3d);
+       if (ndims>2)
+               elog(ERROR,"pointArray_construct:: called with dims = %i", (int) ndims);
 
-       pa->is3d = is3d;
+       pa->ndims = ndims;
        pa->npoints = npoints;
        pa->serialized_pointlist = points;
 
@@ -370,10 +437,14 @@ BOX3D *pointArray_bbox(POINTARRAY *pa)
 // 16 for 2d, 24 for 3d, 32 for 4d
 int pointArray_ptsize(POINTARRAY *pa)
 {
-       if (pa->is3d)
+       if (pa->ndims == 3)
                return 24;
-       else
+       else if (pa->ndims == 2)
                return 16;
+       else if (pa->ndims == 4)
+               return 32;
+       elog(ERROR,"pointArray_ptsize:: ndims isnt 2,3, or 4");
+       return 0; // never get here
 }
 
 
@@ -386,9 +457,9 @@ bool lwgeom_hasSRID(char type)
        return (type & 0x40);
 }
 
-bool lwgeom_is3d(char type)
+int lwgeom_ndims(char type)
 {
-       return ( (type & 0x30) >>4);
+       return  ( (type & 0x30) >>4) +2;
 }
 
 int  lwgeom_getType(char type)
@@ -396,14 +467,16 @@ int  lwgeom_getType(char type)
        return (type & 0x0F);
 }
 
-char lwgeom_makeType(char is3d, char hasSRID, int type)
+char lwgeom_makeType(int ndims, char hasSRID, int type)
 {
        char result = type;
 
-       if (is3d)
+       if (ndims == 3)
                result = result | 0x10;
-       if (hasSRID)
+       if (ndims == 4)
                result = result | 0x20;
+       if (hasSRID)
+               result = result | 0x40;
 
        return result;
 }
@@ -437,12 +510,12 @@ int32 get_int32(char *loc)
 
 // construct a new LWLINE.  points will be copied
 // use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
-LWLINE *lwline_construct(char is3d, int SRID,  POINTARRAY *points)
+LWLINE *lwline_construct(int ndims, int SRID,  POINTARRAY *points)
 {
        LWLINE *result;
        result = (LWLINE*) palloc( sizeof(LWLINE));
 
-       result->is3d =is3d;
+       result->ndims =ndims;
        result->SRID = SRID;
        result->points = points;
 
@@ -487,10 +560,10 @@ LWLINE *lwline_deserialize(char *serialized_form)
 
        npoints = get_uint32(loc);
        loc +=4;
-       pa = pointArray_construct( loc, lwgeom_is3d(type), npoints);
+       pa = pointArray_construct( loc, lwgeom_ndims(type), npoints);
 
        result->points = pa;
-       result->is3d = lwgeom_is3d(type);
+       result->ndims = lwgeom_ndims(type);
 
        return result;
 }
@@ -513,21 +586,25 @@ if (line == NULL)
        if (hasSRID)
                size +=4;  //4 byte SRID
 
-       if (line->is3d)
+       if (line->ndims == 3)
        {
                size += 24 * line->points->npoints; //x,y,z
        }
-       else
+       else if (line->ndims == 2)
        {
                size += 16 * line->points->npoints; //x,y
        }
+       else if (line->ndims == 4)
+       {
+                       size += 32 * line->points->npoints; //x,y
+       }
 
 
        size+=4; // npoints
 
        result = palloc(size);
 
-       result[0] = lwgeom_makeType(line->is3d,hasSRID, LINETYPE);
+       result[0] = lwgeom_makeType(line->ndims,hasSRID, LINETYPE);
        loc = result+1;
 
        if (hasSRID)
@@ -542,7 +619,7 @@ if (line == NULL)
 
 elog(NOTICE," line serialize - size = %i", size);
 
-       if (line->is3d)
+       if (line->ndims == 3)
        {
                for (t=0; t< line->points->npoints;t++)
                {
@@ -550,7 +627,7 @@ elog(NOTICE," line serialize - size = %i", size);
                        loc += 24; // size of a 3d point
                }
        }
-       else
+       else if (line->ndims == 2)
        {
                for (t=0; t< line->points->npoints;t++)
                {
@@ -558,6 +635,14 @@ elog(NOTICE," line serialize - size = %i", size);
                        loc += 16; // size of a 2d point
                }
        }
+       else if (line->ndims == 4)
+       {
+               for (t=0; t< line->points->npoints;t++)
+               {
+                       getPoint4d_p(line->points, t, loc);
+                       loc += 32; // size of a 2d point
+               }
+       }
        //printBYTES((unsigned char *)result, size);
        return result;
 }
@@ -597,14 +682,20 @@ uint32 lwline_findlength(char *serialized_line)
                npoints = get_uint32(loc);
                result += 4; //npoints
 
-               if (lwgeom_is3d(type) )
+               if (lwgeom_ndims(type) ==3)
                {
                        return result + npoints * 24;
                }
-               else
+               else if (lwgeom_ndims(type) ==2)
                {
                        return result+ npoints * 16;
                }
+               else if (lwgeom_ndims(type) ==4)
+               {
+                       return result+ npoints * 32;
+               }
+               elog(NOTICE,"lwline_findlength :: invalid ndims");
+               return 0; //never get here
 }
 
 //********************************************************************
@@ -612,7 +703,7 @@ uint32 lwline_findlength(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)
-LWPOINT  *lwpoint_construct(char is3d, int SRID, POINTARRAY *point)
+LWPOINT  *lwpoint_construct(int ndims, int SRID, POINTARRAY *point)
 {
        LWPOINT *result ;
 
@@ -620,7 +711,7 @@ LWPOINT  *lwpoint_construct(char is3d, int SRID, POINTARRAY *point)
                return NULL; // error
 
        result = palloc(sizeof(LWPOINT));
-       result->is3d = is3d;
+       result->ndims = ndims;
        result->SRID = SRID;
 
        result->point = point;
@@ -660,10 +751,10 @@ LWPOINT *lwpoint_deserialize(char *serialized_form)
 
                // we've read the type (1 byte) and SRID (4 bytes, if present)
 
-               pa = pointArray_construct( loc, lwgeom_is3d(type), 1);
+               pa = pointArray_construct( loc, lwgeom_ndims(type), 1);
 
                result->point = pa;
-               result->is3d = lwgeom_is3d(type);
+               result->ndims = lwgeom_ndims(type);
 
        return result;
 
@@ -683,18 +774,22 @@ char  *lwpoint_serialize(LWPOINT *point)
                if (hasSRID)
                        size +=4;  //4 byte SRID
 
-               if (point->is3d)
+               if (point->ndims == 3)
                {
                        size += 24; //x,y,z
                }
-               else
+               else if (point->ndims == 2)
                {
                        size += 16 ; //x,y,z
                }
+               else if (point->ndims == 4)
+               {
+                       size += 32 ; //x,y,z,m
+               }
 
                result = palloc(size);
 
-               result[0] = lwgeom_makeType(point->is3d,hasSRID, POINTTYPE);
+               result[0] = lwgeom_makeType(point->ndims,hasSRID, POINTTYPE);
                loc = result+1;
 
                if (hasSRID)
@@ -705,15 +800,20 @@ char  *lwpoint_serialize(LWPOINT *point)
 
                //copy in points
 
-               if (point->is3d)
+               if (point->ndims == 3)
                {
                                getPoint3d_p(point->point, 0, loc);
                }
-               else
+               else if (point->ndims == 2)
                {
 
                                getPoint2d_p(point->point, 0, loc);
                }
+               else if (point->ndims == 4)
+               {
+
+                       getPoint4d_p(point->point, 0, loc);
+               }
        return result;
 }
 
@@ -772,14 +872,20 @@ uint32 lwpoint_findlength(char *serialized_point)
                        loc = serialized_point +1;
                }
 
-               if (lwgeom_is3d(type))
+               if (lwgeom_ndims(type) == 3)
                {
                        return result + 24;
                }
-               else
+               else if (lwgeom_ndims(type) == 3)
                {
                        return result + 16;
                }
+               else if (lwgeom_ndims(type) == 4)
+               {
+                       return result + 32;
+               }
+           elog(NOTICE,"lwpoint_findlength :: invalid ndims");
+               return 0; //never get here
 }
 
 
@@ -788,12 +894,12 @@ uint32 lwpoint_findlength(char *serialized_point)
 
 // construct a new LWLINE.  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 is3d, int SRID, int nrings,POINTARRAY **points)
+LWPOLY *lwpoly_construct(int ndims, int SRID, int nrings,POINTARRAY **points)
 {
        LWPOLY *result;
 
        result = (LWPOLY*) palloc(sizeof(LWPOLY));
-       result->is3d = is3d;
+       result->ndims = ndims;
        result->SRID = SRID;
        result->nrings = nrings;
        result->rings = points;
@@ -811,7 +917,7 @@ LWPOLY *lwpoly_deserialize(char *serialized_form)
 
        LWPOLY *result;
        uint32 nrings;
-       bool   is3d;
+       int ndims;
        uint32 npoints;
        char type;
        char  *loc;
@@ -824,7 +930,7 @@ LWPOLY *lwpoly_deserialize(char *serialized_form)
 
 
        type = serialized_form[0];
-       is3d = lwgeom_is3d(type);
+       ndims = lwgeom_ndims(type);
        loc = serialized_form;
 
        if ( lwgeom_getType(type) != POLYGONTYPE)
@@ -852,13 +958,15 @@ LWPOLY *lwpoly_deserialize(char *serialized_form)
                npoints = get_uint32(loc);
                loc +=4;
 
-               result->rings[t] = pointArray_construct(loc, is3d, npoints);
-               if (is3d)
+               result->rings[t] = pointArray_construct(loc, ndims, npoints);
+               if (ndims == 3)
                        loc += 24*npoints;
-               else
+               else if (ndims == 2)
                        loc += 16*npoints;
+               else if (ndims == 4)
+                       loc += 32*npoints;
        }
-       result->is3d = is3d;
+       result->ndims = ndims;
 
        return result;
 }
@@ -889,14 +997,16 @@ char *lwpoly_serialize(LWPOLY *poly)
                {
                        total_points  += poly->rings[t]->npoints;
                }
-               if (poly->is3d)
+               if (poly->ndims == 3)
                        size += 24*total_points;
-               else
+               else if (poly->ndims == 2)
                        size += 16*total_points;
+               else if (poly->ndims == 4)
+                       size += 32*total_points;
 
                result = palloc(size);
 
-               result[0] = lwgeom_makeType(poly->is3d,hasSRID, POLYGONTYPE);
+               result[0] = lwgeom_makeType(poly->ndims,hasSRID, POLYGONTYPE);
                loc = result+1;
 
                if (hasSRID)
@@ -916,7 +1026,7 @@ char *lwpoly_serialize(LWPOLY *poly)
                        npoints = poly->rings[t]->npoints;
                        memcpy(loc, &npoints, sizeof(int32)); //npoints this ring
                        loc+=4;
-                       if (poly->is3d)
+                       if (poly->ndims == 3)
                        {
                                for (u=0;u<npoints;u++)
                                {
@@ -924,7 +1034,7 @@ char *lwpoly_serialize(LWPOLY *poly)
                                        loc+= 24;
                                }
                        }
-                       else
+                       else if (poly->ndims == 2)
                        {
                                for (u=0;u<npoints;u++)
                                {
@@ -932,6 +1042,14 @@ char *lwpoly_serialize(LWPOLY *poly)
                                        loc+= 16;
                                }
                        }
+                       else if (poly->ndims == 4)
+                       {
+                               for (u=0;u<npoints;u++)
+                               {
+                                       getPoint4d_p(pa, u, loc);
+                                       loc+= 32;
+                               }
+                       }
                }
 
                return result;
@@ -966,7 +1084,7 @@ uint32 lwpoly_findlength(char *serialized_poly)
 {
                uint32 result = 1; // char type
                uint32 nrings;
-               bool   is3d;
+               int   ndims;
                int t;
                char type;
                uint32 npoints;
@@ -977,7 +1095,7 @@ uint32 lwpoly_findlength(char *serialized_poly)
 
 
                type = serialized_poly[0];
-               is3d = lwgeom_is3d(type);
+               ndims = lwgeom_ndims(type);
 
                if ( lwgeom_getType(type) != POLYGONTYPE)
                        return -9999;
@@ -1004,12 +1122,17 @@ uint32 lwpoly_findlength(char *serialized_poly)
                        loc +=4;
                        result +=4;
 
-                       if (is3d)
+                       if (ndims == 3)
                        {
                                loc += 24*npoints;
                                result += 24*npoints;
                        }
-                       else
+                       else if (ndims == 2)
+                       {
+                               loc += 16*npoints;
+                               result += 16*npoints;
+                       }
+                       else if (ndims == 4)
                        {
                                loc += 16*npoints;
                                result += 16*npoints;
@@ -1313,7 +1436,7 @@ int lwgeom_getnumgeometries_inspected(LWGEOM_INSPECTED *inspected)
 //  use SRID=-1 for unknown SRID  (will have 8bit type's S = 0)
 // all subgeometries must have the same SRID
 // if you want to construct an inspected, call this then inspect the result...
-extern char *lwgeom_construct(int SRID,int finalType,char is3d, int nsubgeometries, char **serialized_subs)
+extern char *lwgeom_construct(int SRID,int finalType,int ndims, int nsubgeometries, char **serialized_subs)
 {
        uint32 *lengths;
        int t;
@@ -1324,7 +1447,7 @@ extern char *lwgeom_construct(int SRID,int finalType,char is3d, int nsubgeometri
        char *loc;
 
        if (nsubgeometries == 0)
-               return lwgeom_constructempty(SRID,is3d);
+               return lwgeom_constructempty(SRID,ndims);
 
        lengths = palloc(sizeof(int32) * nsubgeometries);
 
@@ -1386,7 +1509,7 @@ extern char *lwgeom_construct(int SRID,int finalType,char is3d, int nsubgeometri
        total_length +=4 ;   // nsubgeometries
 
        result = palloc(total_length);
-       result[0] = lwgeom_makeType( is3d, SRID != -1,  type);
+       result[0] = lwgeom_makeType( ndims, SRID != -1,  type);
        if (SRID != -1)
        {
                memcpy(&result[1],&SRID,4);
@@ -1411,7 +1534,7 @@ extern char *lwgeom_construct(int SRID,int finalType,char is3d, int nsubgeometri
 
 // construct the empty geometry (GEOMETRYCOLLECTION(EMPTY))
 //returns serialized form
-char *lwgeom_constructempty(int SRID,char is3d)
+char *lwgeom_constructempty(int SRID,int ndims)
 {
        int size = 0;
        char *result;
@@ -1425,7 +1548,7 @@ char *lwgeom_constructempty(int SRID,char is3d)
 
        result = palloc(size);
 
-       result[0] = lwgeom_makeType( is3d, SRID != -1,  COLLECTIONTYPE);
+       result[0] = lwgeom_makeType( ndims, SRID != -1,  COLLECTIONTYPE);
        if (SRID != -1)
        {
                memcpy(&result[1],&SRID,4);
@@ -1675,7 +1798,7 @@ void pfree_POINTARRAY(POINTARRAY *pa)
 void printLWLINE(LWLINE *line)
 {
        elog(NOTICE,"LWLINE {");
-       elog(NOTICE,"    is3d = %i", (int)line->is3d);
+       elog(NOTICE,"    ndims = %i", (int)line->ndims);
        elog(NOTICE,"    SRID = %i", (int)line->SRID);
        printPA(line->points);
        elog(NOTICE,"}");
@@ -1687,23 +1810,29 @@ void printPA(POINTARRAY *pa)
        int t;
        POINT2D pt2;
        POINT3D pt3;
+       POINT4D pt4;
 
        elog(NOTICE,"      POINTARRAY{");
-       elog(NOTICE,"                 is3d =%i,   ptsize=%i", (int) pa->is3d,pointArray_ptsize(pa));
+       elog(NOTICE,"                 ndims =%i,   ptsize=%i", (int) pa->ndims,pointArray_ptsize(pa));
        elog(NOTICE,"                 npoints = %i", pa->npoints);
 
        for (t =0; t<pa->npoints;t++)
        {
-               if (pa->is3d == TWODIMS)
+               if (pa->ndims == 2)
                {
                        pt2 = getPoint2d(pa,t);
                        elog(NOTICE,"                    %i : %lf,%lf",t,pt2.x,pt2.y);
                }
-               if (pa->is3d == THREEDIMS)
+               if (pa->ndims == 3)
                {
                        pt3 = getPoint3d(pa,t);
                        elog(NOTICE,"                    %i : %lf,%lf,%lf",t,pt3.x,pt3.y,pt3.z);
                }
+               if (pa->ndims == 4)
+               {
+                       pt4 = getPoint4d(pa,t);
+                       elog(NOTICE,"                    %i : %lf,%lf,%lf,%lf",t,pt3.x,pt4.y,pt4.z,pt4.m);
+               }
        }
 
        elog(NOTICE,"      }");
@@ -1730,7 +1859,7 @@ void printLWPOLY(LWPOLY *poly)
 {
        int t;
        elog(NOTICE,"LWPOLY {");
-       elog(NOTICE,"    is3d = %i", (int)poly->is3d);
+       elog(NOTICE,"    ndims = %i", (int)poly->ndims);
        elog(NOTICE,"    SRID = %i", (int)poly->SRID);
        elog(NOTICE,"    nrings = %i", (int)poly->nrings);
        for (t=0;t<poly->nrings;t++)
index a19d5a4facdc520ea0790b9c8bf0505ec9d9fe8b..a90e5de1270260ea655b87bcb00e703d0684c3d0 100644 (file)
@@ -385,11 +385,11 @@ LWPOLY *wkb_poly_to_lwpoly(char *wkb,int SRID)
                        //point size
 
                ptsize =16;
-               if (dims == FOURDIMS)
+               if (dims == 4)
                {
                        ptsize = 32;
                }
-               if (dims == THREEDIMS)
+               if (dims == 3)
                {
                        ptsize = 24;
         }
@@ -433,7 +433,7 @@ char *lwgeom_to_wkb(char *serialized_form,int *wkblength,char desiredWKBEndian)
        char   *multigeom = NULL;
 
 #ifdef DEBUG
-        elog(NOTICE,"lwgeom_to_wkb: entry with  simpletype=%i, dims=%i",(int) simple_type,(int)  lwgeom_is3d( serialized_form[0]) );
+        elog(NOTICE,"lwgeom_to_wkb: entry with  simpletype=%i, dims=%i",(int) simple_type,  lwgeom_ndims( serialized_form[0]) );
 #endif
 
 
@@ -476,7 +476,7 @@ char *lwpoint_to_wkb(LWPOINT *pt, char desiredWKBEndian, int *wkbsize)
        bool need_flip =  requiresflip( desiredWKBEndian );
 
 #ifdef DEBUG
-        elog(NOTICE,"lwpoint_to_wkb:  pa dims = %i", (int)pt->point->is3d );
+        elog(NOTICE,"lwpoint_to_wkb:  pa dims = %i", (int)pt->point->ndims );
 #endif
 
 
@@ -486,10 +486,10 @@ char *lwpoint_to_wkb(LWPOINT *pt, char desiredWKBEndian, int *wkbsize)
 
        result[0] = desiredWKBEndian; //endian flag
 
-       wkbtype = constructWKBType(POINTTYPE, pt->point->is3d);
+       wkbtype = constructWKBType(POINTTYPE, pt->point->ndims);
 
 #ifdef DEBUG
-        elog(NOTICE,"lwpoint_to_wkb: entry with wkbtype=%i, pa dims = %i",wkbtype, (int)pt->point->is3d );
+        elog(NOTICE,"lwpoint_to_wkb: entry with wkbtype=%i, pa dims = %i",wkbtype, (int)pt->point->ndims );
 #endif
 
 
@@ -500,7 +500,7 @@ char *lwpoint_to_wkb(LWPOINT *pt, char desiredWKBEndian, int *wkbsize)
 
        memcpy(result+5, pt->point->serialized_pointlist, pointArray_ptsize(pt->point) );
        if (need_flip)
-               flipPoints(result+5, 1, pt->point->is3d);
+               flipPoints(result+5, 1, pt->point->ndims);
 
        return result;
 }
@@ -518,7 +518,7 @@ char *lwline_to_wkb(LWLINE *line, char desiredWKBEndian, int *wkbsize)
 
                result[0] = desiredWKBEndian; //endian flag
 
-               wkbtype = constructWKBType(LINETYPE, line->points->is3d);
+               wkbtype = constructWKBType(LINETYPE, line->points->ndims);
                memcpy(result+1, &wkbtype, 4);
                if (need_flip)
                        flip_endian_int32(result+1);
@@ -529,7 +529,7 @@ char *lwline_to_wkb(LWLINE *line, char desiredWKBEndian, int *wkbsize)
 
                memcpy(result+9, line->points->serialized_pointlist, ptsize * line->points->npoints);
                if (need_flip)
-                       flipPoints(result+9, line->points->npoints, line->points->is3d);
+                       flipPoints(result+9, line->points->npoints, line->points->ndims);
                return result;
 }
 
@@ -555,7 +555,7 @@ char *lwpoly_to_wkb(LWPOLY *poly, char desiredWKBEndian, int *wkbsize)
 
                result[0] = desiredWKBEndian; //endian flag
 
-               wkbtype = constructWKBType(POLYGONTYPE, poly->is3d);
+               wkbtype = constructWKBType(POLYGONTYPE, poly->ndims);
                memcpy(result+1, &wkbtype, 4);  // type
                if (need_flip)
                        flip_endian_int32(result+1);
@@ -574,7 +574,7 @@ char *lwpoly_to_wkb(LWPOLY *poly, char desiredWKBEndian, int *wkbsize)
                                flip_endian_int32(loc);
                        memcpy(loc+4, poly->rings[t]->serialized_pointlist, ptsize * npoints);
                        if (need_flip)
-                               flipPoints(loc+4, npoints, poly->is3d);
+                               flipPoints(loc+4, npoints, poly->ndims);
                        loc += 4+ ptsize * npoints;
                }
                return result;
@@ -620,10 +620,10 @@ void              flip_endian_int32(char          *i)
 char wkb_dims(uint32 type)
 {
        if (type & 0x80000000)
-               return THREEDIMS;
+               return 3;
        if (type & 0x40000000)
-               return FOURDIMS;
-       return TWODIMS;
+               return 4;
+       return 2;
 }
 
 
@@ -638,11 +638,11 @@ void flipPoints(char *pts, int npoints, char dims)
        char *loc = pts;
        int size =16;
 
-       if (dims == FOURDIMS)
+       if (dims == 4)
        {
                size = 32;
        }
-       if (dims == THREEDIMS)
+       if (dims == 3)
        {
                size = 24;
        }
@@ -651,11 +651,11 @@ void flipPoints(char *pts, int npoints, char dims)
        {
                flip_endian_double(loc);
                flip_endian_double(loc+8);
-               if ( (dims == THREEDIMS)  || (dims == FOURDIMS) )
+               if ( (dims == 3)  || (dims == 4) )
                {
                        flip_endian_double(loc+16);
                }
-               if (dims == FOURDIMS)
+               if (dims == 4)
                {
                        flip_endian_double(loc+24);
                }
@@ -665,9 +665,9 @@ void flipPoints(char *pts, int npoints, char dims)
 
 uint32 constructWKBType(int simple_type, char dims)
 {
-       if (dims == TWODIMS)
+       if (dims == 2)
                return simple_type;
-       if (dims == THREEDIMS)
+       if (dims == 3)
                return simple_type | 0x80000000;
 
        return simple_type | 0x40000000;