2004-09-29 10:50:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "liblwgeom.h"
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*#define PGIS_DEBUG_CALLS 1 */
|
2004-10-03 15:52:23 +00:00
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Convert this point into its serialize form
|
|
|
|
* result's first char will be the 8bit type. See serialized form doc
|
|
|
|
*/
|
2005-02-10 10:52:53 +00:00
|
|
|
uchar *
|
2004-09-29 10:50:30 +00:00
|
|
|
lwpoint_serialize(LWPOINT *point)
|
|
|
|
{
|
2004-09-30 15:42:28 +00:00
|
|
|
size_t size, retsize;
|
2005-02-10 10:52:53 +00:00
|
|
|
uchar *result;
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2004-09-30 15:42:28 +00:00
|
|
|
size = lwpoint_serialize_size(point);
|
2004-09-29 10:50:30 +00:00
|
|
|
result = lwalloc(size);
|
2004-09-30 15:42:28 +00:00
|
|
|
lwpoint_serialize_buf(point, result, &retsize);
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2004-09-30 15:42:28 +00:00
|
|
|
if ( retsize != size )
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
2004-09-30 15:42:28 +00:00
|
|
|
lwerror("lwpoint_serialize_size returned %d, ..serialize_buf returned %d", size, retsize);
|
2004-09-29 10:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Convert this point into its serialize form writing it into
|
|
|
|
* the given buffer, and returning number of bytes written into
|
|
|
|
* the given int pointer.
|
|
|
|
* result's first char will be the 8bit type. See serialized form doc
|
|
|
|
*/
|
2004-09-29 10:50:30 +00:00
|
|
|
void
|
2005-02-10 10:52:53 +00:00
|
|
|
lwpoint_serialize_buf(LWPOINT *point, uchar *buf, size_t *retsize)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
|
|
|
int size=1;
|
|
|
|
char hasSRID;
|
2005-02-10 10:52:53 +00:00
|
|
|
uchar *loc;
|
2005-11-11 17:45:46 +00:00
|
|
|
int ptsize = pointArray_ptsize(point->point);
|
|
|
|
|
|
|
|
if ( TYPE_GETZM(point->type) != TYPE_GETZM(point->point->dims) )
|
|
|
|
lwerror("Dimensions mismatch in lwpoint");
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG_CALLS
|
2004-10-03 15:52:23 +00:00
|
|
|
lwnotice("lwpoint_serialize_buf(%p, %p) called", point, buf);
|
2006-01-09 15:12:02 +00:00
|
|
|
/*printLWPOINT(point); */
|
2004-10-03 15:52:23 +00:00
|
|
|
#endif
|
|
|
|
|
2004-09-29 10:50:30 +00:00
|
|
|
hasSRID = (point->SRID != -1);
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
if (hasSRID) size +=4; /*4 byte SRID */
|
|
|
|
if (point->bbox) size += sizeof(BOX2DFLOAT4); /* bvol */
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2004-10-04 13:53:42 +00:00
|
|
|
size += sizeof(double)*TYPE_NDIMS(point->type);
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2005-02-10 10:52:53 +00:00
|
|
|
buf[0] = (uchar) lwgeom_makeType_full(
|
2004-10-05 16:28:34 +00:00
|
|
|
TYPE_HASZ(point->type), TYPE_HASM(point->type),
|
2004-10-08 13:20:55 +00:00
|
|
|
hasSRID, POINTTYPE, point->bbox?1:0);
|
2004-09-29 10:50:30 +00:00
|
|
|
loc = buf+1;
|
|
|
|
|
2004-10-08 13:20:55 +00:00
|
|
|
if (point->bbox)
|
2004-09-30 15:42:28 +00:00
|
|
|
{
|
2004-10-08 13:20:55 +00:00
|
|
|
memcpy(loc, point->bbox, sizeof(BOX2DFLOAT4));
|
2004-09-30 15:42:28 +00:00
|
|
|
loc += sizeof(BOX2DFLOAT4);
|
|
|
|
}
|
|
|
|
|
2004-09-29 10:50:30 +00:00
|
|
|
if (hasSRID)
|
|
|
|
{
|
|
|
|
memcpy(loc, &point->SRID, sizeof(int32));
|
|
|
|
loc += 4;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* copy in points */
|
2005-11-11 17:45:46 +00:00
|
|
|
memcpy(loc, getPoint_internal(point->point, 0), ptsize);
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
if (retsize) *retsize = size;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Find bounding box (standard one)
|
|
|
|
* zmin=zmax=NO_Z_VALUE if 2d
|
|
|
|
*/
|
2004-09-29 10:50:30 +00:00
|
|
|
BOX3D *
|
2005-03-18 12:36:27 +00:00
|
|
|
lwpoint_compute_box3d(LWPOINT *point)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2005-03-18 12:36:27 +00:00
|
|
|
lwnotice("lwpoint_compute_box3d called with point %p", point);
|
2004-09-29 10:50:30 +00:00
|
|
|
#endif
|
|
|
|
if (point == NULL)
|
|
|
|
{
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2005-03-18 12:36:27 +00:00
|
|
|
lwnotice("lwpoint_compute_box3d returning NULL");
|
2004-09-29 10:50:30 +00:00
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2005-03-18 12:36:27 +00:00
|
|
|
lwnotice("lwpoint_compute_box3d returning ptarray_compute_box3d return");
|
2004-09-29 10:50:30 +00:00
|
|
|
#endif
|
|
|
|
|
2005-03-18 12:36:27 +00:00
|
|
|
return ptarray_compute_box3d(point->point);
|
2004-09-29 10:50:30 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Convenience functions to hide the POINTARRAY
|
|
|
|
* TODO: obsolete this
|
|
|
|
*/
|
2004-10-05 16:28:34 +00:00
|
|
|
int
|
|
|
|
lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
2004-10-05 16:28:34 +00:00
|
|
|
return getPoint2d_p(point->point, 0, out);
|
2004-09-29 10:50:30 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* convenience functions to hide the POINTARRAY */
|
2004-10-05 16:28:34 +00:00
|
|
|
int
|
|
|
|
lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
2004-10-05 16:28:34 +00:00
|
|
|
return getPoint3dz_p(point->point,0,out);
|
|
|
|
}
|
|
|
|
int
|
|
|
|
lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
|
|
|
|
{
|
|
|
|
return getPoint3dm_p(point->point,0,out);
|
|
|
|
}
|
|
|
|
int
|
|
|
|
lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
|
|
|
|
{
|
|
|
|
return getPoint4d_p(point->point,0,out);
|
2004-09-29 10:50:30 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* find length of this deserialized point */
|
2004-09-29 15:25:21 +00:00
|
|
|
size_t
|
|
|
|
lwpoint_serialize_size(LWPOINT *point)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
2006-01-09 15:12:02 +00:00
|
|
|
size_t size = 1; /* type */
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG_CALLS
|
2004-10-03 15:52:23 +00:00
|
|
|
lwnotice("lwpoint_serialize_size called");
|
|
|
|
#endif
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
if ( point->SRID != -1 ) size += 4; /* SRID */
|
2004-12-31 11:30:38 +00:00
|
|
|
if ( point->bbox ) size += sizeof(BOX2DFLOAT4);
|
2004-09-30 15:42:28 +00:00
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
size += TYPE_NDIMS(point->type) * sizeof(double); /* point */
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG_CALLS
|
2004-10-03 15:52:23 +00:00
|
|
|
lwnotice("lwpoint_serialize_size returning %d", size);
|
|
|
|
#endif
|
|
|
|
|
2004-09-29 10:50:30 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Construct a new point. point will not be copied
|
|
|
|
* use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
|
|
|
|
*/
|
2004-09-29 10:50:30 +00:00
|
|
|
LWPOINT *
|
2004-10-08 13:20:55 +00:00
|
|
|
lwpoint_construct(int SRID, BOX2DFLOAT4 *bbox, POINTARRAY *point)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
|
|
|
LWPOINT *result ;
|
|
|
|
|
|
|
|
if (point == NULL)
|
2006-01-09 15:12:02 +00:00
|
|
|
return NULL; /* error */
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
result = lwalloc(sizeof(LWPOINT));
|
2004-10-08 13:20:55 +00:00
|
|
|
result->type = lwgeom_makeType_full(TYPE_HASZ(point->dims), TYPE_HASM(point->dims), (SRID!=-1), POINTTYPE, 0);
|
2004-09-29 10:50:30 +00:00
|
|
|
result->SRID = SRID;
|
|
|
|
result->point = point;
|
2004-10-08 13:20:55 +00:00
|
|
|
result->bbox = bbox;
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-10-13 14:26:36 +00:00
|
|
|
LWPOINT *
|
|
|
|
make_lwpoint2d(int SRID, double x, double y)
|
|
|
|
{
|
2005-02-10 17:41:55 +00:00
|
|
|
POINT2D p;
|
2004-10-13 14:26:36 +00:00
|
|
|
POINTARRAY *pa = ptarray_construct(0, 0, 1);
|
2005-02-10 17:41:55 +00:00
|
|
|
|
|
|
|
p.x = x;
|
|
|
|
p.y = y;
|
|
|
|
|
|
|
|
memcpy(getPoint_internal(pa, 0), &p, sizeof(POINT2D));
|
|
|
|
|
2004-10-13 14:26:36 +00:00
|
|
|
return lwpoint_construct(SRID, NULL, pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
LWPOINT *
|
|
|
|
make_lwpoint3dz(int SRID, double x, double y, double z)
|
|
|
|
{
|
2005-02-10 17:41:55 +00:00
|
|
|
POINT3DZ p;
|
2004-10-13 14:26:36 +00:00
|
|
|
POINTARRAY *pa = ptarray_construct(1, 0, 1);
|
2005-02-10 17:41:55 +00:00
|
|
|
|
|
|
|
p.x = x;
|
|
|
|
p.y = y;
|
|
|
|
p.z = z;
|
|
|
|
|
|
|
|
memcpy(getPoint_internal(pa, 0), &p, sizeof(POINT3DZ));
|
|
|
|
|
2004-10-13 14:26:36 +00:00
|
|
|
return lwpoint_construct(SRID, NULL, pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
LWPOINT *
|
|
|
|
make_lwpoint3dm(int SRID, double x, double y, double m)
|
|
|
|
{
|
|
|
|
POINTARRAY *pa = ptarray_construct(0, 1, 1);
|
2005-02-10 17:41:55 +00:00
|
|
|
POINT3DM p;
|
|
|
|
|
|
|
|
p.x = x;
|
|
|
|
p.y = y;
|
|
|
|
p.m = m;
|
|
|
|
|
|
|
|
memcpy(getPoint_internal(pa, 0), &p, sizeof(POINT3DM));
|
|
|
|
|
2004-10-13 14:26:36 +00:00
|
|
|
return lwpoint_construct(SRID, NULL, pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
LWPOINT *
|
|
|
|
make_lwpoint4d(int SRID, double x, double y, double z, double m)
|
|
|
|
{
|
|
|
|
POINTARRAY *pa = ptarray_construct(1, 1, 1);
|
2005-02-10 17:41:55 +00:00
|
|
|
POINT4D p;
|
|
|
|
|
|
|
|
p.x = x;
|
|
|
|
p.y = y;
|
|
|
|
p.z = z;
|
|
|
|
p.m = m;
|
|
|
|
|
|
|
|
memcpy(getPoint_internal(pa, 0), &p, sizeof(POINT4D));
|
|
|
|
|
2004-10-13 14:26:36 +00:00
|
|
|
return lwpoint_construct(SRID, NULL, pa);
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Given the LWPOINT serialized form (or a pointer into a muli* one)
|
|
|
|
* construct a proper LWPOINT.
|
|
|
|
* serialized_form should point to the 8bit type format (with type = 1)
|
|
|
|
* See serialized form doc
|
|
|
|
*/
|
2004-09-29 10:50:30 +00:00
|
|
|
LWPOINT *
|
2005-02-10 10:52:53 +00:00
|
|
|
lwpoint_deserialize(uchar *serialized_form)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
2005-02-10 10:52:53 +00:00
|
|
|
uchar type;
|
2004-09-29 10:50:30 +00:00
|
|
|
LWPOINT *result;
|
2005-02-10 10:52:53 +00:00
|
|
|
uchar *loc = NULL;
|
2004-09-29 10:50:30 +00:00
|
|
|
POINTARRAY *pa;
|
|
|
|
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG_CALLS
|
2004-09-29 10:50:30 +00:00
|
|
|
lwnotice("lwpoint_deserialize called");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
result = (LWPOINT*) lwalloc(sizeof(LWPOINT)) ;
|
|
|
|
|
2005-11-14 09:01:15 +00:00
|
|
|
type = serialized_form[0];
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
if ( lwgeom_getType(type) != POINTTYPE) return NULL;
|
2004-10-04 13:53:42 +00:00
|
|
|
result->type = type;
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
loc = serialized_form+1;
|
|
|
|
|
|
|
|
if (lwgeom_hasBBOX(type))
|
|
|
|
{
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2004-09-29 10:50:30 +00:00
|
|
|
lwnotice("lwpoint_deserialize: input has bbox");
|
|
|
|
#endif
|
2005-11-14 09:01:15 +00:00
|
|
|
result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
|
|
|
|
memcpy(result->bbox, loc, sizeof(BOX2DFLOAT4));
|
2004-09-29 10:50:30 +00:00
|
|
|
loc += sizeof(BOX2DFLOAT4);
|
|
|
|
}
|
2004-10-08 13:20:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
result->bbox = NULL;
|
|
|
|
}
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
if ( lwgeom_hasSRID(type))
|
|
|
|
{
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2004-09-29 10:50:30 +00:00
|
|
|
lwnotice("lwpoint_deserialize: input has SRID");
|
|
|
|
#endif
|
|
|
|
result->SRID = get_int32(loc);
|
2006-01-09 15:12:02 +00:00
|
|
|
loc += 4; /* type + SRID */
|
2004-09-29 10:50:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SRID = -1;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* we've read the type (1 byte) and SRID (4 bytes, if present) */
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2004-10-05 16:28:34 +00:00
|
|
|
pa = pointArray_construct(loc, TYPE_HASZ(type), TYPE_HASM(type), 1);
|
2004-09-29 10:50:30 +00:00
|
|
|
|
|
|
|
result->point = pa;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pfree_point (LWPOINT *pt)
|
|
|
|
{
|
|
|
|
pfree_POINTARRAY(pt->point);
|
|
|
|
lwfree(pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printLWPOINT(LWPOINT *point)
|
|
|
|
{
|
|
|
|
lwnotice("LWPOINT {");
|
2004-10-04 13:53:42 +00:00
|
|
|
lwnotice(" ndims = %i", (int)TYPE_NDIMS(point->type));
|
|
|
|
lwnotice(" BBOX = %i", TYPE_HASBBOX(point->type) ? 1 : 0 );
|
2004-09-29 10:50:30 +00:00
|
|
|
lwnotice(" SRID = %i", (int)point->SRID);
|
|
|
|
printPA(point->point);
|
|
|
|
lwnotice("}");
|
|
|
|
}
|
|
|
|
|
2004-09-30 15:42:28 +00:00
|
|
|
int
|
2005-03-18 12:36:27 +00:00
|
|
|
lwpoint_compute_box2d_p(LWPOINT *point, BOX2DFLOAT4 *box)
|
2004-09-30 15:42:28 +00:00
|
|
|
{
|
2005-03-18 12:36:27 +00:00
|
|
|
return ptarray_compute_box2d_p(point->point, box);
|
2004-09-30 15:42:28 +00:00
|
|
|
}
|
2004-10-01 14:49:34 +00:00
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* Clone LWPOINT object. POINTARRAY is not copied. */
|
2004-10-01 14:49:34 +00:00
|
|
|
LWPOINT *
|
|
|
|
lwpoint_clone(const LWPOINT *g)
|
|
|
|
{
|
|
|
|
LWPOINT *ret = lwalloc(sizeof(LWPOINT));
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG_CALLS
|
2004-10-03 15:52:23 +00:00
|
|
|
lwnotice("lwpoint_clone called");
|
|
|
|
#endif
|
2004-10-01 14:49:34 +00:00
|
|
|
memcpy(ret, g, sizeof(LWPOINT));
|
2005-11-14 09:01:15 +00:00
|
|
|
if ( g->bbox ) ret->bbox = box2d_clone(g->bbox);
|
2004-10-01 14:49:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* Add 'what' to this point at position 'where'.
|
|
|
|
* where=0 == prepend
|
|
|
|
* where=-1 == append
|
|
|
|
* Returns a MULTIPOINT or a GEOMETRYCOLLECTION
|
|
|
|
*/
|
2004-10-01 14:49:34 +00:00
|
|
|
LWGEOM *
|
|
|
|
lwpoint_add(const LWPOINT *to, uint32 where, const LWGEOM *what)
|
|
|
|
{
|
|
|
|
LWCOLLECTION *col;
|
|
|
|
LWGEOM **geoms;
|
|
|
|
int newtype;
|
|
|
|
|
|
|
|
if ( where != -1 && where != 0 )
|
|
|
|
{
|
|
|
|
lwerror("lwpoint_add only supports 0 or -1 as second argument, got %d", where);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* dimensions compatibility are checked by caller */
|
2004-10-01 14:49:34 +00:00
|
|
|
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* Construct geoms array */
|
2004-10-01 14:49:34 +00:00
|
|
|
geoms = lwalloc(sizeof(LWGEOM *)*2);
|
2006-01-09 15:12:02 +00:00
|
|
|
if ( where == -1 ) /* append */
|
2004-10-01 14:49:34 +00:00
|
|
|
{
|
|
|
|
geoms[0] = lwgeom_clone((LWGEOM *)to);
|
|
|
|
geoms[1] = lwgeom_clone(what);
|
|
|
|
}
|
2006-01-09 15:12:02 +00:00
|
|
|
else /* prepend */
|
2004-10-01 14:49:34 +00:00
|
|
|
{
|
|
|
|
geoms[0] = lwgeom_clone(what);
|
|
|
|
geoms[1] = lwgeom_clone((LWGEOM *)to);
|
|
|
|
}
|
2006-01-09 15:12:02 +00:00
|
|
|
/* reset SRID and wantbbox flag from component types */
|
2004-10-08 13:20:55 +00:00
|
|
|
lwgeom_dropSRID(geoms[0]);
|
|
|
|
lwgeom_dropBBOX(geoms[0]);
|
|
|
|
lwgeom_dropSRID(geoms[1]);
|
|
|
|
lwgeom_dropBBOX(geoms[1]);
|
2004-10-01 14:49:34 +00:00
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* Find appropriate geom type */
|
2004-10-04 13:53:42 +00:00
|
|
|
if ( TYPE_GETTYPE(what->type) == POINTTYPE ) newtype = MULTIPOINTTYPE;
|
2004-10-01 14:49:34 +00:00
|
|
|
else newtype = COLLECTIONTYPE;
|
|
|
|
|
2004-10-05 16:28:34 +00:00
|
|
|
col = lwcollection_construct(newtype,
|
2004-10-08 13:20:55 +00:00
|
|
|
to->SRID, NULL,
|
2004-10-04 13:53:42 +00:00
|
|
|
2, geoms);
|
2004-10-01 14:49:34 +00:00
|
|
|
|
|
|
|
return (LWGEOM *)col;
|
|
|
|
}
|
2004-10-05 17:15:42 +00:00
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* Find length of this serialized point */
|
2004-10-05 17:15:42 +00:00
|
|
|
size_t
|
2005-02-10 10:52:53 +00:00
|
|
|
lwgeom_size_point(const uchar *serialized_point)
|
2004-10-05 17:15:42 +00:00
|
|
|
{
|
|
|
|
uint32 result = 1;
|
2005-02-10 10:52:53 +00:00
|
|
|
uchar type;
|
|
|
|
const uchar *loc;
|
2004-10-05 17:15:42 +00:00
|
|
|
|
2005-02-10 10:52:53 +00:00
|
|
|
type = serialized_point[0];
|
2004-10-05 17:15:42 +00:00
|
|
|
|
|
|
|
if ( lwgeom_getType(type) != POINTTYPE) return 0;
|
|
|
|
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2004-10-05 17:15:42 +00:00
|
|
|
lwnotice("lwgeom_size_point called (%d)", result);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
loc = serialized_point+1;
|
|
|
|
|
|
|
|
if (lwgeom_hasBBOX(type))
|
|
|
|
{
|
|
|
|
loc += sizeof(BOX2DFLOAT4);
|
|
|
|
result +=sizeof(BOX2DFLOAT4);
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2004-10-05 17:15:42 +00:00
|
|
|
lwnotice("lwgeom_size_point: has bbox (%d)", result);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lwgeom_hasSRID(type))
|
|
|
|
{
|
2005-02-07 13:21:10 +00:00
|
|
|
#ifdef PGIS_DEBUG
|
2004-10-05 17:15:42 +00:00
|
|
|
lwnotice("lwgeom_size_point: has srid (%d)", result);
|
|
|
|
#endif
|
2006-01-09 15:12:02 +00:00
|
|
|
loc +=4; /* type + SRID */
|
2004-10-05 17:15:42 +00:00
|
|
|
result +=4;
|
|
|
|
}
|
|
|
|
|
|
|
|
result += lwgeom_ndims(type)*sizeof(double);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-01-09 15:12:02 +00:00
|
|
|
/* check coordinate equality */
|
2004-10-11 07:15:20 +00:00
|
|
|
char
|
|
|
|
lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
|
|
|
|
{
|
|
|
|
return ptarray_same(p1->point, p2->point);
|
|
|
|
}
|