From: Paul Ramsey Date: Thu, 27 Oct 2011 21:03:00 +0000 (+0000) Subject: Remove serialized_form functions: X-Git-Tag: 2.0.0alpha1~834 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=912a2ca7db746800c955f65a2c50e7fbd411e0ed;p=postgis Remove serialized_form functions: lwpoint_serialize_size lwpoint_serialize lwpoint_serialize_buf lwline_serialize_size lwline_serialize lwline_serialize_buf lwpoly_serialize_size lwpoly_serialize lwpoly_serialize_buf lwtriangle_serialize_size lwtriangle_serialize lwtriangle_serialize_buf lwcircstring_serialize_size lwcircstring_serialize lwcircstring_serialize_buf lwcollection_serialize_size lwcollection_serialize_buf lwgeom_constructempty lwgeom_constructempty_buf lwgeom_empty_length lwgeom_serialize_size lwgeom_serialize lwgeom_serialized_construct lwgeom_getsrid git-svn-id: http://svn.osgeo.org/postgis/trunk@8023 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index c6cb38065..3b432a1f7 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -850,21 +850,6 @@ extern uint8_t lwgeom_makeType_full(char hasZ, char hasM, char has_srid, int typ * 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) @@ -883,19 +868,6 @@ extern int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out); * 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) */ @@ -910,19 +882,6 @@ extern int lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where); * 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) */ @@ -952,19 +911,6 @@ extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom); * 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) */ @@ -974,19 +920,6 @@ extern BOX3D *lwtriangle_compute_box3d(LWTRIANGLE *triangle); * 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) */ @@ -998,11 +931,6 @@ extern BOX3D *lwcircstring_compute_box3d(const LWCIRCSTRING *curve); * 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. */ @@ -1030,28 +958,6 @@ LWCOLLECTION* lwcollection_extract(LWCOLLECTION *col, int type); * 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 diff --git a/liblwgeom/lwcircstring.c b/liblwgeom/lwcircstring.c index 902534ad3..ea120288a 100644 --- a/liblwgeom/lwcircstring.c +++ b/liblwgeom/lwcircstring.c @@ -83,131 +83,6 @@ lwcircstring_release(LWCIRCSTRING *lwcirc) 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) { diff --git a/liblwgeom/lwcollection.c b/liblwgeom/lwcollection.c index ff923ef90..c5b6d1b3c 100644 --- a/liblwgeom/lwcollection.c +++ b/liblwgeom/lwcollection.c @@ -93,106 +93,12 @@ lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm) 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; ingeoms; 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; ingeoms; 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. diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 3d8e3e1a2..f3adc37c0 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -19,117 +19,6 @@ #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) diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index f3e13cddf..e90eef022 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -797,178 +797,6 @@ lw_get_int32_t(const uint8_t *loc) } -/* - * 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 -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) { diff --git a/liblwgeom/lwline.c b/liblwgeom/lwline.c index aabedc4c1..8d15c0f78 100644 --- a/liblwgeom/lwline.c +++ b/liblwgeom/lwline.c @@ -61,105 +61,6 @@ lwline_construct_empty(int srid, char hasz, char hasm) -/* - * 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) @@ -177,24 +78,6 @@ lwline_compute_box3d(LWLINE *line) } -/* 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) { diff --git a/liblwgeom/lwpoint.c b/liblwgeom/lwpoint.c index 1713b6227..e5b3c2d40 100644 --- a/liblwgeom/lwpoint.c +++ b/liblwgeom/lwpoint.c @@ -17,119 +17,6 @@ #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 diff --git a/liblwgeom/lwpoly.c b/liblwgeom/lwpoly.c index 378a861bb..ce603e990 100644 --- a/liblwgeom/lwpoly.c +++ b/liblwgeom/lwpoly.c @@ -75,111 +75,6 @@ lwpoly_construct_empty(int srid, char hasz, char hasm) 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; tnrings; 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) @@ -193,33 +88,6 @@ 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; inrings; 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; diff --git a/liblwgeom/lwtriangle.c b/liblwgeom/lwtriangle.c index 95cd5daef..df9006919 100644 --- a/liblwgeom/lwtriangle.c +++ b/liblwgeom/lwtriangle.c @@ -53,110 +53,6 @@ lwtriangle_construct_empty(int srid, char hasz, char hasm) 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) @@ -169,27 +65,6 @@ 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) diff --git a/postgis/BBOXCACHE_BEHAVIOURS b/postgis/BBOXCACHE_BEHAVIOURS deleted file mode 100644 index f84ca9c0c..000000000 --- a/postgis/BBOXCACHE_BEHAVIOURS +++ /dev/null @@ -1,136 +0,0 @@ -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* -