* bounding box finder and (TODO) serialized form size finder.
*--------------------------------------------------------*/
-/*
- * Find size this point would get when serialized (no BBOX)
- */
-extern size_t lwpoint_serialize_size(LWPOINT *point);
-
-/*
- * convert this point into its serialize form
- * result's first char will be the 8bit type.
- * See serialized form doc
- */
-extern uint8_t *lwpoint_serialize(LWPOINT *point);
-
-/* same as above, writes to buf */
-extern void lwpoint_serialize_buf(LWPOINT *point, uint8_t *buf, size_t *size);
-
/*
* find bounding box (standard one)
* zmin=zmax=0 if 2d (might change to NaN)
* LWLINE functions
******************************************************************/
-/* find the size this line would get when serialized */
-extern size_t lwline_serialize_size(LWLINE *line);
-
-/*
- * convert this line into its serialize form
- * result's first char will be the 8bit type. See serialized form doc
- * copies data.
- */
-extern uint8_t *lwline_serialize(LWLINE *line);
-
-/* same as above, writes to buf */
-extern void lwline_serialize_buf(LWLINE *line, uint8_t *buf, size_t *size);
-
/*
* find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
*/
* LWPOLY functions
******************************************************************/
-/* find the size this polygon would get when serialized */
-extern size_t lwpoly_serialize_size(LWPOLY *poly);
-
-/*
- * create the serialized form of the polygon
- * result's first char will be the 8bit type. See serialized form doc
- * points copied
- */
-extern uint8_t *lwpoly_serialize(LWPOLY *poly);
-
-/* same as above, writes to buf */
-extern void lwpoly_serialize_buf(LWPOLY *poly, uint8_t *buf, size_t *size);
-
/*
* find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
*/
* LWTRIANGLE functions
******************************************************************/
-/* find the size this triangle would get when serialized */
-extern size_t lwtriangle_serialize_size(LWTRIANGLE *triangle);
-
-/*
- * convert this triangle into its serialize form
- * result's first char will be the 8bit type. See serialized form doc
- * copies data.
- */
-extern uint8_t *lwtriangle_serialize(LWTRIANGLE *triangle);
-
-/* same as above, writes to buf */
-extern void lwtriangle_serialize_buf(LWTRIANGLE *triangle, uint8_t *buf, size_t *size);
-
/*
* find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
*/
* LWCIRCSTRING functions
******************************************************************/
-/* find the size this curve would get when serialized */
-extern size_t lwcircstring_serialize_size(LWCIRCSTRING *curve);
-
-/*
- * convert this circularstring into its serialize form
- * result's first char will be the 8bit type. See serialized form doc
- * copies data.
- */
-extern uint8_t *lwcircstring_serialize(LWCIRCSTRING *curve);
-
-/* same as above, writes to buf */
-extern void lwcircstring_serialize_buf(LWCIRCSTRING *curve, uint8_t *buf, size_t *size);
-
/*
* find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
*/
* LWGEOM functions
******************************************************************/
-extern size_t lwgeom_serialize_size(LWGEOM *geom);
-extern size_t lwcollection_serialize_size(LWCOLLECTION *coll);
-extern void lwgeom_serialize_buf(LWGEOM *geom, uint8_t *buf, size_t *size);
-extern uint8_t *lwgeom_serialize(LWGEOM *geom);
-extern void lwcollection_serialize_buf(LWCOLLECTION *mcoll, uint8_t *buf, size_t *size);
extern int lwcollection_ngeoms(const LWCOLLECTION *col);
/* Given a generic geometry/collection, return the "simplest" form. */
* SERIALIZED FORM functions
******************************************************************/
-
-/*
- * set finalType to COLLECTIONTYPE or 0 (0 means choose a best type)
- * (ie. give it 2 points and ask it to be a multipoint)
- * use SRID=SRID_UNKNOWN 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 uint8_t *lwgeom_serialized_construct(int srid, int finalType, char hasz, char hasm, int nsubgeometries, uint8_t **serialized_subs);
-
-
-/* construct the empty geometry (GEOMETRYCOLLECTION EMPTY) */
-extern uint8_t *lwgeom_constructempty(int srid, char hasz, char hasm);
-extern void lwgeom_constructempty_buf(int srid, char hasz, char hasm, uint8_t *buf, size_t *size);
-size_t lwgeom_empty_length(int srid);
-
-/*
- * get the SRID from the LWGEOM
- * none present => -1
- */
-extern int lwgeom_getsrid(uint8_t *serialized);
-
/**
* Set the SRID on an LWGEOM
* For collections, only the parent gets an SRID, all
lwgeom_release(lwcircstring_as_lwgeom(lwcirc));
}
-
-
-/*
- * convert this circularstring into its serialized form
- * result's first char will be the 8bit type. See serialized form doc
- */
-uint8_t *
-lwcircstring_serialize(LWCIRCSTRING *curve)
-{
- size_t size, retsize;
- uint8_t * result;
-
- if (curve == NULL)
- {
- lwerror("lwcircstring_serialize:: given null curve");
- return NULL;
- }
-
- size = lwcircstring_serialize_size(curve);
- result = lwalloc(size);
- lwcircstring_serialize_buf(curve, result, &retsize);
- if (retsize != size)
- lwerror("lwcircstring_serialize_size returned %d, ..serialize_buf returned %d", size, retsize);
- return result;
-}
-
-/*
- * convert this circularstring into its serialized 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
- */
-void lwcircstring_serialize_buf(LWCIRCSTRING *curve, uint8_t *buf, size_t *retsize)
-{
- char has_srid;
- uint8_t *loc;
- int ptsize;
- size_t size;
-
- LWDEBUGF(2, "lwcircstring_serialize_buf(%p, %p, %p) called",
- curve, buf, retsize);
-
- if (curve == NULL)
- {
- lwerror("lwcircstring_serialize:: given null curve");
- return;
- }
-
- if (FLAGS_GET_ZM(curve->flags) != FLAGS_GET_ZM(curve->points->flags))
- {
- lwerror("Dimensions mismatch in lwcircstring");
- return;
- }
-
- ptsize = ptarray_point_size(curve->points);
-
- has_srid = (curve->srid != SRID_UNKNOWN);
-
- buf[0] = (uint8_t)lwgeom_makeType_full(
- FLAGS_GET_Z(curve->flags), FLAGS_GET_M(curve->flags),
- has_srid, CIRCSTRINGTYPE, curve->bbox ? 1 : 0);
- loc = buf+1;
-
- LWDEBUGF(3, "lwcircstring_serialize_buf added type (%d)", curve->type);
-
- if (curve->bbox)
- {
- BOX2DFLOAT4 *box2df;
-
- box2df = box2df_from_gbox(curve->bbox);
- memcpy(loc, box2df, sizeof(BOX2DFLOAT4));
- lwfree(box2df);
- loc += sizeof(BOX2DFLOAT4);
-
- LWDEBUG(3, "lwcircstring_serialize_buf added BBOX");
- }
-
- if (has_srid)
- {
- memcpy(loc, &curve->srid, sizeof(int32_t));
- loc += sizeof(int32_t);
-
- LWDEBUG(3, "lwcircstring_serialize_buf added SRID");
- }
-
- memcpy(loc, &curve->points->npoints, sizeof(uint32_t));
- loc += sizeof(uint32_t);
-
- LWDEBUGF(3, "lwcircstring_serialize_buf added npoints (%d)",
- curve->points->npoints);
-
- /* copy in points */
- size = curve->points->npoints * ptsize;
- memcpy(loc, getPoint_internal(curve->points, 0), size);
- loc += size;
-
- LWDEBUGF(3, "lwcircstring_serialize_buf copied serialized_pointlist (%d bytes)",
- ptsize * curve->points->npoints);
-
- if (retsize) *retsize = loc-buf;
-
- LWDEBUGF(3, "lwcircstring_serialize_buf returning (loc: %p, size: %d)",
- loc, loc-buf);
-}
-
-/* find length of this deserialized circularstring */
-size_t
-lwcircstring_serialize_size(LWCIRCSTRING *curve)
-{
- size_t size = 1; /* type */
-
- LWDEBUG(2, "lwcircstring_serialize_size called");
-
- if (curve->srid != SRID_UNKNOWN) size += 4; /* SRID */
- if (curve->bbox) size += sizeof(BOX2DFLOAT4);
-
- size += 4; /* npoints */
- size += ptarray_point_size(curve->points) * curve->points->npoints;
-
- LWDEBUGF(3, "lwcircstring_serialize_size returning %d", size);
-
- return size;
-}
-
-
BOX3D *
lwcircle_compute_box3d(POINT4D *p1, POINT4D *p2, POINT4D *p3)
{
return ret;
}
-
-
-
LWGEOM *
lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
{
return (LWGEOM *)col->geoms[gnum];
}
-/**
- * @brief find serialized size of this collection
- * @param col #LWCOLLECTION to find serialized size of
- */
-size_t
-lwcollection_serialize_size(LWCOLLECTION *col)
-{
- size_t size = 5; /* type + nsubgeoms */
- int i;
-
- if ( col->srid != SRID_UNKNOWN ) size += 4; /* srid */
- if ( col->bbox ) size += sizeof(BOX2DFLOAT4);
-
- LWDEBUGF(2, "lwcollection_serialize_size[%p]: start size: %d", col, size);
-
-
- for (i=0; i<col->ngeoms; i++)
- {
- size += lwgeom_serialize_size(col->geoms[i]);
-
- LWDEBUGF(3, "lwcollection_serialize_size[%p]: with geom%d: %d", col, i, size);
- }
-
- LWDEBUGF(3, "lwcollection_serialize_size[%p]: returning %d", col, size);
-
- return size;
-}
-
-/** @brief convert an #LWCOLLECTION into its serialized form writing it into
- * the given buffer, and returning number of bytes written into
- * the given int pointer.
- */
-void
-lwcollection_serialize_buf(LWCOLLECTION *coll, uint8_t *buf, size_t *retsize)
-{
- size_t size=1; /* type */
- size_t subsize=0;
- char has_srid;
- uint8_t *loc;
- int i;
-
- LWDEBUGF(2, "lwcollection_serialize_buf called (%s with %d elems)",
- lwtype_name(coll->type), coll->ngeoms);
-
- has_srid = (coll->srid != SRID_UNKNOWN);
-
- buf[0] = lwgeom_makeType_full(FLAGS_GET_Z(coll->flags),
- FLAGS_GET_M(coll->flags),
- has_srid,
- coll->type,
- coll->bbox ? 1 : 0 );
- loc = buf+1;
-
- /* Add BBOX if requested */
- if ( coll->bbox )
- {
- BOX2DFLOAT4 *box2df;
-
- box2df = box2df_from_gbox(coll->bbox);
- memcpy(loc, box2df, sizeof(BOX2DFLOAT4));
- lwfree(box2df);
- size += sizeof(BOX2DFLOAT4);
- loc += sizeof(BOX2DFLOAT4);
- }
-
- /* Add SRID if requested */
- if (has_srid)
- {
- memcpy(loc, &coll->srid, 4);
- size += 4;
- loc += 4;
- }
-
- /* Write number of subgeoms */
- memcpy(loc, &coll->ngeoms, 4);
- size += 4;
- loc += 4;
-
- /* Serialize subgeoms */
- for (i=0; i<coll->ngeoms; i++)
- {
- lwgeom_serialize_buf(coll->geoms[i], loc, &subsize);
- size += subsize;
- loc += subsize;
- }
-
- if (retsize) *retsize = size;
-
- LWDEBUG(3, "lwcollection_serialize_buf returning");
-}
-
/**
* @brief Clone #LWCOLLECTION object. #POINTARRAY are not copied.
* Bbox is cloned if present in input.
#include "libtgeom.h"
-size_t
-lwgeom_serialize_size(LWGEOM *lwgeom)
-{
-
-// if( lwgeom->type != COLLECTIONTYPE && lwgeom_is_empty(lwgeom) )
-// {
-// LWGEOM *tmp = (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
-// lwgeom = tmp;
-// }
-
- switch (lwgeom->type)
- {
- case POINTTYPE:
- return lwpoint_serialize_size((LWPOINT *)lwgeom);
- case LINETYPE:
- return lwline_serialize_size((LWLINE *)lwgeom);
- case POLYGONTYPE:
- return lwpoly_serialize_size((LWPOLY *)lwgeom);
- case TRIANGLETYPE:
- return lwtriangle_serialize_size((LWTRIANGLE *)lwgeom);
- case CIRCSTRINGTYPE:
- return lwcircstring_serialize_size((LWCIRCSTRING *)lwgeom);
- case CURVEPOLYTYPE:
- case COMPOUNDTYPE:
- case MULTIPOINTTYPE:
- case MULTILINETYPE:
- case MULTICURVETYPE:
- case MULTIPOLYGONTYPE:
- case MULTISURFACETYPE:
- case POLYHEDRALSURFACETYPE:
- case TINTYPE:
- case COLLECTIONTYPE:
- return lwcollection_serialize_size((LWCOLLECTION *)lwgeom);
- default:
- lwerror("lwgeom_serialize_size: Unknown geometry type: %s",
- lwtype_name(lwgeom->type));
-
- return 0;
- }
-}
-
-void
-lwgeom_serialize_buf(LWGEOM *lwgeom, uint8_t *buf, size_t *retsize)
-{
- LWDEBUGF(2, "lwgeom_serialize_buf called with a %s",
- lwtype_name(lwgeom->type));
-
-// if( lwgeom->type != COLLECTIONTYPE && lwgeom_is_empty(lwgeom) )
-// {
-// LWGEOM *tmp = (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
-// lwgeom = tmp;
-// }
-
- switch (lwgeom->type)
- {
- case POINTTYPE:
- lwpoint_serialize_buf((LWPOINT *)lwgeom, buf, retsize);
- break;
- case LINETYPE:
- lwline_serialize_buf((LWLINE *)lwgeom, buf, retsize);
- break;
- case POLYGONTYPE:
- lwpoly_serialize_buf((LWPOLY *)lwgeom, buf, retsize);
- break;
- case TRIANGLETYPE:
- lwtriangle_serialize_buf((LWTRIANGLE *)lwgeom, buf, retsize);
- break;
- case CIRCSTRINGTYPE:
- lwcircstring_serialize_buf((LWCIRCSTRING *)lwgeom, buf, retsize);
- break;
- case CURVEPOLYTYPE:
- case COMPOUNDTYPE:
- case MULTIPOINTTYPE:
- case MULTILINETYPE:
- case MULTICURVETYPE:
- case MULTIPOLYGONTYPE:
- case MULTISURFACETYPE:
- case POLYHEDRALSURFACETYPE:
- case TINTYPE:
- case COLLECTIONTYPE:
- lwcollection_serialize_buf((LWCOLLECTION *)lwgeom, buf,
- retsize);
- break;
- default:
- lwerror("lwgeom_serialize_buf: Unknown geometry type: %s",
- lwtype_name(lwgeom->type));
- return;
- }
- return;
-}
-
-uint8_t *
-lwgeom_serialize(LWGEOM *lwgeom)
-{
- size_t size = lwgeom_serialize_size(lwgeom);
- size_t retsize;
- uint8_t *serialized = lwalloc(size);
-
- lwgeom_serialize_buf(lwgeom, serialized, &retsize);
-
-#if POSTGIS_DEBUG_LEVEL > 0
- if ( retsize != size )
- {
- lwerror("lwgeom_serialize: computed size %d, returned size %d",
- size, retsize);
- }
-#endif
-
- return serialized;
-}
-
/** Force Right-hand-rule on LWGEOM polygons **/
void
lwgeom_force_clockwise(LWGEOM *lwgeom)
}
-/*
- * Set finalType to COLLECTIONTYPE or 0 (0 means choose a best type)
- * (ie. give it 2 points and ask it to be a multipoint)
- * use SRID=SRID_UNKNOWN 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...
- */
-uint8_t *
-lwgeom_serialized_construct(int srid, int finalType, char hasz, char hasm,
- int nsubgeometries, uint8_t **serialized_subs)
-{
- uint32_t *lengths;
- int t;
- int total_length = 0;
- char type = (char)-1;
- char this_type = -1;
- uint8_t *result;
- uint8_t *loc;
-
- if (nsubgeometries == 0)
- return lwgeom_constructempty(srid, hasz, hasm);
-
- lengths = lwalloc(sizeof(int32_t) * nsubgeometries);
-
- for (t=0; t<nsubgeometries; t++)
- {
-// lengths[t] = lwgeom_size_subgeom(serialized_subs[t],-1);
- lengths[t] = 0;
- total_length += lengths[t];
- this_type = lwgeom_getType((uint8_t) (serialized_subs[t][0]));
- if (type == (char)-1)
- {
- type = this_type;
- }
- else if (type == COLLECTIONTYPE)
- {
- /* still a collection type... */
- }
- else
- {
- if ( (this_type == MULTIPOINTTYPE) || (this_type == MULTILINETYPE) || (this_type == MULTIPOLYGONTYPE) || (this_type == COLLECTIONTYPE) )
- {
- type = COLLECTIONTYPE;
- }
- else
- {
- if ( (this_type == POINTTYPE) && (type==POINTTYPE) )
- type=MULTIPOINTTYPE;
- else if ( (this_type == LINETYPE) && (type==LINETYPE) )
- type=MULTILINETYPE;
- else if ( (this_type == POLYGONTYPE) && (type==POLYGONTYPE) )
- type=MULTIPOLYGONTYPE;
- else if ( (this_type == POLYGONTYPE) && (type==MULTIPOLYGONTYPE) )
- ; /* nop */
- else if ( (this_type == LINETYPE) && (type==MULTILINETYPE) )
- ; /* nop */
- else if ( (this_type == POINTTYPE) && (type==MULTIPOINTTYPE) )
- ; /* nop */
- else
- type = COLLECTIONTYPE;
- }
- }
- }
-
- if (type == POINTTYPE)
- type = MULTIPOINTTYPE;
- if (type == LINETYPE)
- type = MULTILINETYPE;
- if (type == POINTTYPE)
- type = MULTIPOINTTYPE;
-
- if (finalType == COLLECTIONTYPE)
- type = COLLECTIONTYPE;
-
- /* now we have a multi* or GEOMETRYCOLLECTION, let's serialize it */
-
- if (srid != SRID_UNKNOWN)
- total_length +=4; /* space for SRID */
-
- total_length +=1 ; /* main type; */
- total_length +=4 ; /* nsubgeometries */
-
- result = lwalloc(total_length);
- result[0] = (uint8_t) lwgeom_makeType(hasz, hasm, srid != SRID_UNKNOWN, type);
- if (srid != SRID_UNKNOWN)
- {
- memcpy(&result[1],&srid,4);
- loc = result+5;
- }
- else
- loc = result+1;
-
- memcpy(loc,&nsubgeometries,4);
- loc +=4;
-
- for (t=0; t<nsubgeometries; t++)
- {
- memcpy(loc, serialized_subs[t], lengths[t] );
- loc += lengths[t] ;
- }
-
- lwfree(lengths);
- return result;
-}
-
-
-/*
- * Construct the empty geometry (GEOMETRYCOLLECTION EMPTY).
- *
- * Returns serialized form
- */
-uint8_t *
-lwgeom_constructempty(int srid, char hasz, char hasm)
-{
- int size = 0;
- uint8_t *result;
- int ngeoms = 0;
- uint8_t *loc;
-
- if (srid != SRID_UNKNOWN)
- size +=4;
-
- size += 5;
-
- result = lwalloc(size);
-
- result[0] = lwgeom_makeType(hasz, hasm, srid != SRID_UNKNOWN, COLLECTIONTYPE);
- if (srid != SRID_UNKNOWN)
- {
- memcpy(&result[1],&srid,4);
- loc = result+5;
- }
- else
- loc = result+1;
-
- memcpy(loc,&ngeoms,4);
- return result;
-}
-
-size_t
-lwgeom_empty_length(int srid)
-{
- int size = 5;
- if ( srid != 1 ) size += 4;
- return size;
-}
-
-/**
- * Construct the empty geometry (GEOMETRYCOLLECTION EMPTY)
- * writing it into the provided buffer.
- */
-void
-lwgeom_constructempty_buf(int srid, char hasz, char hasm,
- uint8_t *buf, size_t *retsize)
-{
- int ngeoms = 0;
-
- buf[0] =(uint8_t) lwgeom_makeType( hasz, hasm, srid != SRID_UNKNOWN, COLLECTIONTYPE);
- if (srid != SRID_UNKNOWN)
- {
- memcpy(&buf[1],&srid,4);
- buf += 5;
- }
- else
- buf += 1;
-
- memcpy(buf, &ngeoms, 4);
-
- if (retsize) *retsize = lwgeom_empty_length(srid);
-}
-
-
/************************************************
* debugging routines
************************************************/
}
-
-/**
- * Get the srid from the LWGEOM.
- * None present => -1
- */
-int
-lwgeom_getsrid(uint8_t *serialized)
-{
- uint8_t type = serialized[0];
- uint8_t *loc = serialized+1;
-
- if ( ! lwgeom_hasSRID(type)) return -1;
-
- if (lwgeom_hasBBOX(type))
- {
- loc += sizeof(BOX2DFLOAT4);
- }
-
- return lw_get_int32_t(loc);
-}
-
char
ptarray_isccw(const POINTARRAY *pa)
{
-/*
- * convert this line into its serialize form
- * result's first char will be the 8bit type. See serialized form doc
- */
-uint8_t *
-lwline_serialize(LWLINE *line)
-{
- size_t size, retsize;
- uint8_t * result;
-
- if (line == NULL) lwerror("lwline_serialize:: given null line");
-
- size = lwline_serialize_size(line);
- result = lwalloc(size);
- lwline_serialize_buf(line, result, &retsize);
-
- if ( retsize != size )
- {
- lwerror("lwline_serialize_size returned %d, ..serialize_buf returned %d", size, retsize);
- }
-
- return result;
-}
-
-/*
- * convert this line 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
- */
-void
-lwline_serialize_buf(LWLINE *line, uint8_t *buf, size_t *retsize)
-{
- char has_srid;
- uint8_t *loc;
- int ptsize;
- size_t size;
-
- LWDEBUGF(2, "lwline_serialize_buf(%p, %p, %p) called",
- line, buf, retsize);
-
- if (line == NULL)
- lwerror("lwline_serialize:: given null line");
-
- if ( FLAGS_GET_ZM(line->flags) != FLAGS_GET_ZM(line->points->flags) )
- lwerror("Dimensions mismatch in lwline");
-
- ptsize = ptarray_point_size(line->points);
-
- has_srid = (line->srid != SRID_UNKNOWN);
-
- buf[0] = (uint8_t) lwgeom_makeType_full(
- FLAGS_GET_Z(line->flags), FLAGS_GET_M(line->flags),
- has_srid, LINETYPE, line->bbox ? 1 : 0);
- loc = buf+1;
-
- LWDEBUGF(3, "lwline_serialize_buf added type (%d)", line->type);
-
- if (line->bbox)
- {
- BOX2DFLOAT4 *box2df;
-
- box2df = box2df_from_gbox(line->bbox);
- memcpy(loc, box2df, sizeof(BOX2DFLOAT4));
- lwfree(box2df);
- loc += sizeof(BOX2DFLOAT4);
-
- LWDEBUG(3, "lwline_serialize_buf added BBOX");
- }
-
- if (has_srid)
- {
- memcpy(loc, &line->srid, sizeof(int32_t));
- loc += sizeof(int32_t);
-
- LWDEBUG(3, "lwline_serialize_buf added SRID");
- }
-
- memcpy(loc, &line->points->npoints, sizeof(uint32_t));
- loc += sizeof(uint32_t);
-
- LWDEBUGF(3, "lwline_serialize_buf added npoints (%d)",
- line->points->npoints);
-
- /*copy in points */
- size = line->points->npoints*ptsize;
- memcpy(loc, getPoint_internal(line->points, 0), size);
- loc += size;
-
- LWDEBUGF(3, "lwline_serialize_buf copied serialized_pointlist (%d bytes)",
- ptsize * line->points->npoints);
-
- if (retsize) *retsize = loc-buf;
-
- /*printBYTES((uint8_t *)result, loc-buf); */
-
- LWDEBUGF(3, "lwline_serialize_buf returning (loc: %p, size: %d)",
- loc, loc-buf);
-}
/*
* Find bounding box (standard one)
}
-/* find length of this deserialized line */
-size_t
-lwline_serialize_size(LWLINE *line)
-{
- size_t size = 1; /* type */
-
- LWDEBUG(2, "lwline_serialize_size called");
-
- if ( line->srid != SRID_UNKNOWN ) size += 4; /* SRID */
- if ( line->bbox ) size += sizeof(BOX2DFLOAT4);
-
- size += 4; /* npoints */
- size += ptarray_point_size(line->points)*line->points->npoints;
-
- LWDEBUGF(3, "lwline_serialize_size returning %d", size);
-
- return size;
-}
void lwline_free (LWLINE *line)
{
#include "lwgeom_log.h"
-/*
- * Convert this point into its serialize form
- * result's first char will be the 8bit type. See serialized form doc
- */
-uint8_t *
-lwpoint_serialize(LWPOINT *point)
-{
- size_t size, retsize;
- uint8_t *result;
-
- size = lwpoint_serialize_size(point);
- result = lwalloc(size);
- lwpoint_serialize_buf(point, result, &retsize);
-
- if ( retsize != size )
- {
- lwerror("lwpoint_serialize_size returned %d, ..serialize_buf returned %d", size, retsize);
- }
-
- return result;
-}
-
-/*
- * 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
- */
-void
-lwpoint_serialize_buf(LWPOINT *point, uint8_t *buf, size_t *retsize)
-{
- int size=1;
- char has_srid;
- uint8_t *loc;
- int ptsize = ptarray_point_size(point->point);
-
- if ( FLAGS_GET_ZM(point->flags) != FLAGS_GET_ZM(point->point->flags) )
- lwerror("Dimensions mismatch in lwpoint");
-
- LWDEBUGF(2, "lwpoint_serialize_buf(%p, %p) called", point, buf);
- /*printLWPOINT(point); */
-
- if ( lwgeom_is_empty((LWGEOM*)point) )
- {
- LWCOLLECTION *mp = lwcollection_construct_empty(MULTIPOINTTYPE, point->srid, FLAGS_GET_Z(point->flags), FLAGS_GET_M(point->flags));
- LWDEBUG(4,"serializing 'POINT EMPTY' to 'MULTIPOINT EMPTY");
- lwcollection_serialize_buf(mp, buf, retsize);
- lwcollection_free(mp);
- return;
- }
-
- has_srid = (point->srid != SRID_UNKNOWN);
-
- if (has_srid) size +=4; /*4 byte SRID */
- if (point->bbox) size += sizeof(BOX2DFLOAT4); /* bvol */
-
- size += sizeof(double)*FLAGS_NDIMS(point->flags);
-
- buf[0] = (uint8_t) lwgeom_makeType_full(
- FLAGS_GET_Z(point->flags), FLAGS_GET_M(point->flags),
- has_srid, POINTTYPE, point->bbox?1:0);
- loc = buf+1;
-
- if (point->bbox)
- {
- BOX2DFLOAT4 *box2df;
-
- box2df = box2df_from_gbox(point->bbox);
- memcpy(loc, box2df, sizeof(BOX2DFLOAT4));
- lwfree(box2df);
- loc += sizeof(BOX2DFLOAT4);
- }
-
- if (has_srid)
- {
- memcpy(loc, &point->srid, sizeof(int32_t));
- loc += 4;
- }
-
- /* copy in points */
- memcpy(loc, getPoint_internal(point->point, 0), ptsize);
-
- if (retsize) *retsize = size;
-}
-
-/* find length of this deserialized point */
-size_t
-lwpoint_serialize_size(LWPOINT *point)
-{
- size_t size = 1; /* type */
-
- LWDEBUG(2, "lwpoint_serialize_size called");
-
- if ( lwgeom_is_empty((LWGEOM*)point) )
- {
- LWCOLLECTION *mp = lwcollection_construct_empty(MULTIPOINTTYPE, point->srid, FLAGS_GET_Z(point->flags), FLAGS_GET_M(point->flags));
- size_t s = lwcollection_serialize_size(mp);
- LWDEBUGF(4,"serializing 'POINT EMPTY' to 'MULTIPOINT EMPTY', size=%d", s);
- lwcollection_free(mp);
- return s;
- }
-
-
- if ( point->srid != SRID_UNKNOWN ) size += 4; /* SRID */
- if ( point->bbox ) size += sizeof(BOX2DFLOAT4);
-
- size += FLAGS_NDIMS(point->flags) * sizeof(double); /* point */
-
- LWDEBUGF(3, "lwpoint_serialize_size returning %d", size);
-
- return size;
-}
-
/*
* Find bounding box (standard one)
* zmin=zmax=NO_Z_VALUE if 2d
return result;
}
-
-/*
- * create the serialized form of the polygon
- * result's first char will be the 8bit type. See serialized form doc
- * points copied
- */
-uint8_t *
-lwpoly_serialize(LWPOLY *poly)
-{
- size_t size, retsize;
- uint8_t *result;
-
- size = lwpoly_serialize_size(poly);
- result = lwalloc(size);
- lwpoly_serialize_buf(poly, result, &retsize);
-
- if ( retsize != size )
- {
- lwerror("lwpoly_serialize_size returned %d, ..serialize_buf returned %d", size, retsize);
- }
-
- return result;
-}
-
-/*
- * create the serialized form of the polygon 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
- * points copied
- */
-void
-lwpoly_serialize_buf(LWPOLY *poly, uint8_t *buf, size_t *retsize)
-{
- size_t size=1; /* type byte */
- char has_srid;
- int t;
- uint8_t *loc;
- int ptsize;
-
- LWDEBUG(2, "lwpoly_serialize_buf called");
-
- ptsize = sizeof(double)*FLAGS_NDIMS(poly->flags);
-
- has_srid = (poly->srid != SRID_UNKNOWN);
-
- size += 4; /* nrings */
- size += 4*poly->nrings; /* npoints/ring */
-
- buf[0] = (uint8_t) lwgeom_makeType_full(
- FLAGS_GET_Z(poly->flags), FLAGS_GET_M(poly->flags),
- has_srid, POLYGONTYPE, poly->bbox ? 1 : 0);
- loc = buf+1;
-
- if (poly->bbox)
- {
- BOX2DFLOAT4 *box2df;
-
- box2df = box2df_from_gbox(poly->bbox);
- memcpy(loc, box2df, sizeof(BOX2DFLOAT4));
- lwfree(box2df);
- size += sizeof(BOX2DFLOAT4); /* bvol */
- loc += sizeof(BOX2DFLOAT4);
- }
-
- if (has_srid)
- {
- memcpy(loc, &poly->srid, sizeof(int32_t));
- loc += 4;
- size +=4; /* 4 byte SRID */
- }
-
- memcpy(loc, &poly->nrings, sizeof(int32_t)); /* nrings */
- loc+=4;
-
- for (t=0; t<poly->nrings; t++)
- {
- POINTARRAY *pa = poly->rings[t];
- size_t pasize;
- uint32_t npoints;
-
- LWDEBUGF(4, "FLAGS_GET_ZM(poly->type) == %d", FLAGS_GET_ZM(poly->flags));
- LWDEBUGF(4, "FLAGS_GET_ZM(pa->flags) == %d", FLAGS_GET_ZM(pa->flags));
-
- if ( FLAGS_GET_ZM(poly->flags) != FLAGS_GET_ZM(pa->flags) )
- lwerror("Dimensions mismatch in lwpoly");
-
- npoints = pa->npoints;
-
- memcpy(loc, &npoints, sizeof(uint32_t)); /* npoints this ring */
- loc+=4;
-
- pasize = npoints*ptsize;
- size += pasize;
-
- /* copy points */
- memcpy(loc, getPoint_internal(pa, 0), pasize);
- loc += pasize;
-
- }
-
- if (retsize) *retsize = size;
-}
-
-
/* find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN) */
BOX3D *
lwpoly_compute_box3d(LWPOLY *poly)
return result;
}
-
-/* find length of this deserialized polygon */
-size_t
-lwpoly_serialize_size(LWPOLY *poly)
-{
- size_t size = 1; /* type */
- uint32_t i;
-
- if ( poly->srid != SRID_UNKNOWN ) size += 4; /* SRID */
- if ( poly->bbox ) size += sizeof(BOX2DFLOAT4);
-
- LWDEBUGF(2, "lwpoly_serialize_size called with poly[%p] (%d rings)",
- poly, poly->nrings);
-
- size += 4; /* nrings */
-
- for (i=0; i<poly->nrings; i++)
- {
- size += 4; /* npoints */
- size += poly->rings[i]->npoints*FLAGS_NDIMS(poly->flags)*sizeof(double);
- }
-
- LWDEBUGF(3, "lwpoly_serialize_size returning %d", size);
-
- return size;
-}
-
void lwpoly_free(LWPOLY *poly)
{
int t;
return result;
}
-
-/*
- * create the serialized form of the triangle
- * result's first char will be the 8bit type. See serialized form doc
- * points copied
- */
-uint8_t *
-lwtriangle_serialize(LWTRIANGLE *triangle)
-{
- size_t size, retsize;
- uint8_t *result;
-
- size = lwtriangle_serialize_size(triangle);
- result = lwalloc(size);
- lwtriangle_serialize_buf(triangle, result, &retsize);
-
- if ( retsize != size )
- {
- lwerror("lwtriangle_serialize_size returned %d, ..serialize_buf returned %d", size, retsize);
- }
-
- return result;
-}
-
-/*
- * create the serialized form of the triangle 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
- * points copied
- */
-void
-lwtriangle_serialize_buf(LWTRIANGLE *triangle, uint8_t *buf, size_t *retsize)
-{
- char has_srid;
- uint8_t *loc;
- int ptsize;
- size_t size;
-
- LWDEBUGF(2, "lwtriangle_serialize_buf(%p, %p, %p) called",
- triangle, buf, retsize);
-
- if (triangle == NULL)
- lwerror("lwtriangle_serialize:: given null triangle");
-
- if ( FLAGS_GET_ZM(triangle->flags) != FLAGS_GET_ZM(triangle->points->flags) )
- lwerror("Dimensions mismatch in lwtriangle");
-
- ptsize = ptarray_point_size(triangle->points);
-
- has_srid = (triangle->srid != SRID_UNKNOWN);
-
- buf[0] = (uint8_t) lwgeom_makeType_full(
- FLAGS_GET_Z(triangle->flags), FLAGS_GET_M(triangle->flags),
- has_srid, TRIANGLETYPE, triangle->bbox ? 1 : 0);
- loc = buf+1;
-
- LWDEBUGF(3, "lwtriangle_serialize_buf added type (%d)", triangle->type);
-
- if (triangle->bbox)
- {
- BOX2DFLOAT4 *box2df;
-
- box2df = box2df_from_gbox(triangle->bbox);
- memcpy(loc, box2df, sizeof(BOX2DFLOAT4));
- loc += sizeof(BOX2DFLOAT4);
- lwfree(box2df);
-
- LWDEBUG(3, "lwtriangle_serialize_buf added BBOX");
- }
-
- if (has_srid)
- {
- memcpy(loc, &triangle->srid, sizeof(int32_t));
- loc += sizeof(int32_t);
-
- LWDEBUG(3, "lwtriangle_serialize_buf added SRID");
- }
-
- memcpy(loc, &triangle->points->npoints, sizeof(uint32_t));
- loc += sizeof(uint32_t);
-
- LWDEBUGF(3, "lwtriangle_serialize_buf added npoints (%d)",
- triangle->points->npoints);
-
- /*copy in points */
- if ( triangle->points->npoints > 0 )
- {
- size = triangle->points->npoints*ptsize;
- memcpy(loc, getPoint_internal(triangle->points, 0), size);
- loc += size;
- }
- LWDEBUGF(3, "lwtriangle_serialize_buf copied serialized_pointlist (%d bytes)",
- ptsize * triangle->points->npoints);
-
- if (retsize) *retsize = loc-buf;
-
- /*printBYTES((uint8_t *)result, loc-buf); */
-
- LWDEBUGF(3, "lwtriangle_serialize_buf returning (loc: %p, size: %d)",
- loc, loc-buf);
-}
-
-
/* find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN) */
BOX3D *
lwtriangle_compute_box3d(LWTRIANGLE *triangle)
return result;
}
-
-
-/* find length of this deserialized triangle */
-size_t
-lwtriangle_serialize_size(LWTRIANGLE *triangle)
-{
- size_t size = 1; /* type */
-
- LWDEBUG(2, "lwtriangle_serialize_size called");
-
- if ( triangle->srid != SRID_UNKNOWN ) size += 4; /* SRID */
- if ( triangle->bbox ) size += sizeof(BOX2DFLOAT4);
-
- size += 4; /* npoints */
- size += ptarray_point_size(triangle->points)*triangle->points->npoints;
-
- LWDEBUGF(3, "lwtriangle_serialize_size returning %d", size);
-
- return size;
-}
-
void lwtriangle_free(LWTRIANGLE *triangle)
{
if (triangle->bbox)
+++ /dev/null
-Possible strategies:
-
- 1) compute bbox if geometry is complex.
-
- 2) compute bbox if it's a simple operation (some combination
- of input bboxes - iff all available)
-
- 3) compute bbox if any input geoms have one
-
- 4) never compute bbox
-
- 5) always compute bbox
-
-We can express the strategies with these labels:
-
-COMPUTE_BBOX:
- 1) FOR_COMPLEX_GEOMS,
- 2) WHEN_SIMPLE,
- 3) TAINTING,
- 4) ALWAYS,
- 5) NEVER
-
-Following is a list of geometry-returning functions with the bbox cache
-strategy they use. Note that current condition matching
-FOR_COMPLEX_GEOMS is that geometrytype(geom) != POINTTYPE.
-
-These marks show output creation methods (to find single entry
-points where some BBOX caching strategies could be enforced).
-
- *SRL* Directly works on the serialized geometries,
- uses PG_LWGEOM_construct() for final output
-
- **SRL** Directly works on the serialized geometries,
- uses internal strategies to construct output.
-
- *EXP* Uses LWGEOM_EXPLODED, and lwexploded_serialize()
-
- *LWG* Uses LWGEOM, pglwgeom_serialize()
-
-
-AUTOCACHE_BBOX is currently used by all functions using *LWG*
-(pglwgeom_serialize entry point) and *SRL* (PG_LWGEOM_construct
-entry point). Other functions explicitly listed in the AUTOCACHE_BBOX
-section also use it.
-
-
-[ explicit control ]
- addBBOX(geometry)
- dropBBOX(geometry)
-
-[ AUTOCACHE_BBOX==1 ? FOR_COMPLEX_GEOMS : NEVER ]
- geometry_in(cstring) **SRL**
- geometry_recv(internal) **SRL**
- geometry(text) **SRL**
- geometry(bytea) **SRL**
- GeometryFromText(geometry, SRID) *SRL*
- GeomFromWKB(bytea, SRID) **SRL**
- GeomFromEWKB(bytea) **SRL**
- GeomFromEWKT(text) **SRL**
-
- -- GEOS
- polygonize_garray (geometry[]) *LWG*
- intersection(geometry,geometry) *LWG*
- buffer(geometry,float8,[integer]) *LWG*
- difference(geometry,geometry) *LWG*
- boundary(geometry) *LWG*
- symdifference(geometry,geometry) *LWG*
- symmetricdifference(geometry,geometry) *LWG*
- GeomUnion(geometry,geometry) *LWG*
- unite_garray (geometry[]) *LWG*
- GEOSnoop(geometry) *LWG*
- Centroid(geometry) *LWG*
- PointOnSurface(geometry) *LWG*
-
-[ TAINING ]
- GeometryN(geometry,integer) *LWG*
- InteriorRingN(geometry,integer) *LWG*
- simplify(geometry, float8) *LWG*
- transform(geometry,integer) *SRL*
- snaptogrid(*) *LWG*
-
-[ WHEN_SIMPLE (use input bbox if present) ]
- noop(geometry) *LWG*
- ExteriorRing(geometry) *LWG*
- SetSRID(geometry,int4) *SRL*
-
- # WARNING! these don't change bbox cache status if input is already 2d
- force_2d(geometry) *SRL*
- force_3dz(geometry) *SRL*
- force_3d(geometry) *SRL*
- force_3dm(geometry) *SRL*
- force_4d(geometry) *SRL*
-
- force_collection(geometry) *LWG*
- multi(geometry) *LWG*
-
- envelope(geometry) *SRL*
-
- ### computes union of
- ### input bbox (if all available)
- collect(geometry, geometry) *LWG*
- collect_garray (geometry[]) *LWG*
-
- ## transform eventually present box in input
- apply_grid(geometry, float8, float8, float8, float8); *LWG*
- translate(geometry,float8,float8,[float8]) *SRL*
- scale(geometry,float8,float8,[float8]) *SRL*
-
- ## These use LWGEOM as a mean to access and modify SERIALIZED form
- reverse(geometry) *LWG*
- ForceRHR(geometry) *LWG*
-
- segmentize(geometry, float8) *LWG*
-
- convexhull(geometry) *LWG*
-
-[ NEVER ]
- PointN(geometry,integer) *SRL*
- StartPoint(geometry) *SRL*
- EndPoint(geometry) *SRL*
-
- makePoint(float8, float8, [float8], [float8]) *LWG*
- makePointM(float8, float8, float8) *LWG*
- makeline_garray (geometry[]) *LWG*
- LineFromMultiPoint(geometry) *LWG*
- MakeLine(geometry, geometry) *LWG*
- AddPoint(geometry, geometry, [integer]) *LWG*
- geometry(box2d) *SRL*
- geometry(box3d) *SRL*
- geometry(chip) *SRL*
- line_interpolate_point(geometry, float8) *SRL*
- Centroid(geometry) [the version w/out GEOS] *SRL*
-
-[ ALWAYS ]
- expand(geometry,float8) *LWG*
-