From 4c8fa68722b63c05e4a45cec73cbf308499489f5 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 22 Sep 2004 16:09:54 +0000 Subject: [PATCH] Moved size computation functions in module static scope. Renamed public one to lwgeom_size(char *). git-svn-id: http://svn.osgeo.org/postgis/trunk@879 b70326c6-7e19-0410-871a-916f4a2858ee --- lwgeom/lwgeom.h | 21 +++----- lwgeom/lwgeom_api.c | 93 +++++++++++++++++---------------- lwgeom/lwgeom_functions_basic.c | 6 +-- 3 files changed, 58 insertions(+), 62 deletions(-) diff --git a/lwgeom/lwgeom.h b/lwgeom/lwgeom.h index 98fda247f..4cc3e3486 100644 --- a/lwgeom/lwgeom.h +++ b/lwgeom/lwgeom.h @@ -238,6 +238,14 @@ extern int lwgeom_getType(unsigned char type); // returns the tttt value extern unsigned char lwgeom_makeType(int ndims, char hasSRID, int type); extern unsigned char lwgeom_makeType_full(int ndims, char hasSRID, int type, bool hasBBOX); +/* + * This function computes the size in bytes + * of the serialized geometries. + */ +extern int lwgeom_size(char *serialized_form); +extern int lwgeom_size(char *serialized_form); +extern int lwgeom_size_subgeom(char *serialized_form, int geom_number); + /* * Construct a full LWGEOM type (including size header) * from a serialized form. @@ -254,7 +262,6 @@ extern LWGEOM *LWGEOM_construct(char *serialized, int SRID, int wantbbox); // bounding box finder. - //-------------------------------------------------------- typedef struct @@ -493,18 +500,6 @@ extern char *lwgeom_constructempty(int SRID,int ndims); extern void lwgeom_constructempty_buf(int SRID, int ndims, char *buf, int *size); int lwgeom_empty_length(int SRID); -// helper function (not for general use) -// find the size a geometry (or a sub-geometry) -// 1st geometry has geom_number = 0 -// use geom_number = -1 to find the actual type of the serialized form. -// ie lwgeom_gettype( <'MULTIPOINT(0 0, 1 1)'>, -1) -// --> size of the multipoint -// ie lwgeom_gettype( <'MULTIPOINT(0 0, 1 1)'>, 0) -// --> size of the point -extern int lwgeom_seralizedformlength_simple(char *serialized_form); -extern int lwgeom_seralizedformlength(char *serialized_form, int geom_number); -extern int lwgeom_seralizedformlength_inspected(LWGEOM_INSPECTED *inspected, int geom_number); - // get the SRID from the LWGEOM // none present => -1 extern int lwgeom_getSRID(LWGEOM *lwgeom); diff --git a/lwgeom/lwgeom_api.c b/lwgeom/lwgeom_api.c index ed4c09499..56452d473 100644 --- a/lwgeom/lwgeom_api.c +++ b/lwgeom/lwgeom_api.c @@ -30,9 +30,11 @@ extern BOX3D *lw_geom_getBB_simple(char *serialized_form); #ifdef DEBUG_EXPLODED void checkexplodedsize(char *srl, LWGEOM_EXPLODED *exploded, int alloced, char wantbbox); #endif -static uint32 lwline_findlength(char *serialized_line); -static uint32 lwpoint_findlength(char *serialized_point); -static uint32 lwpoly_findlength(char *serialized_line); +static uint32 lwgeom_size_line(char *serialized_line); +static uint32 lwgeom_size_point(char *serialized_point); +static uint32 lwgeom_size_poly(char *serialized_line); +static int lwgeom_size_inspected(LWGEOM_INSPECTED *inspected, int geom_number); + //********************************************************************* @@ -1116,7 +1118,7 @@ BOX3D *lwline_findbbox(LWLINE *line) } //find length of this serialized line -uint32 lwline_findlength(char *serialized_line) +uint32 lwgeom_size_line(char *serialized_line) { int type = (unsigned char) serialized_line[0]; uint32 result =1; //type @@ -1124,7 +1126,7 @@ uint32 lwline_findlength(char *serialized_line) uint32 npoints; if ( lwgeom_getType(type) != LINETYPE) - elog(ERROR,"lwline_findlength::attempt to find the length of a non-line"); + elog(ERROR,"lwgeom_size_line::attempt to find the length of a non-line"); loc = serialized_line+1; @@ -1158,7 +1160,7 @@ uint32 lwline_findlength(char *serialized_line) { return result+ npoints * 32; } - elog(ERROR,"lwline_findlength :: invalid ndims"); + elog(ERROR,"lwgeom_size_line :: invalid ndims"); return 0; //never get here } @@ -1356,7 +1358,7 @@ POINT3D lwpoint_getPoint3d(LWPOINT *point) //find length of this serialized point -uint32 lwpoint_findlength(char *serialized_point) +uint32 lwgeom_size_point(char *serialized_point) { uint result = 1; unsigned char type; @@ -1367,7 +1369,7 @@ uint32 lwpoint_findlength(char *serialized_point) if ( lwgeom_getType(type) != POINTTYPE) return 0; #ifdef DEBUG -elog(NOTICE, "lwpoint_findlength called (%d)", result); +elog(NOTICE, "lwgeom_size_point called (%d)", result); #endif loc = serialized_point+1; @@ -1377,14 +1379,14 @@ elog(NOTICE, "lwpoint_findlength called (%d)", result); loc += sizeof(BOX2DFLOAT4); result +=sizeof(BOX2DFLOAT4); #ifdef DEBUG -elog(NOTICE, "lwpoint_findlength: has bbox (%d)", result); +elog(NOTICE, "lwgeom_size_point: has bbox (%d)", result); #endif } if ( lwgeom_hasSRID(type)) { #ifdef DEBUG -elog(NOTICE, "lwpoint_findlength: has srid (%d)", result); +elog(NOTICE, "lwgeom_size_point: has srid (%d)", result); #endif loc +=4; // type + SRID result +=4; @@ -1393,26 +1395,26 @@ elog(NOTICE, "lwpoint_findlength: has srid (%d)", result); if (lwgeom_ndims(type) == 3) { #ifdef DEBUG -elog(NOTICE, "lwpoint_findlength: returning (%d)", result+24); +elog(NOTICE, "lwgeom_size_point: returning (%d)", result+24); #endif return result + 24; } else if (lwgeom_ndims(type) == 2) { #ifdef DEBUG -elog(NOTICE, "lwpoint_findlength: returning (%d)", result+16); +elog(NOTICE, "lwgeom_size_point: returning (%d)", result+16); #endif return result + 16; } else if (lwgeom_ndims(type) == 4) { #ifdef DEBUG -elog(NOTICE, "lwpoint_findlength: returning (%d)", result+32); +elog(NOTICE, "lwgeom_size_point: returning (%d)", result+32); #endif return result + 32; } - elog(ERROR,"lwpoint_findlength :: invalid ndims = %i", + elog(ERROR,"lwgeom_size_point :: invalid ndims = %i", lwgeom_ndims(type)); return 0; //never get here } @@ -1701,7 +1703,7 @@ BOX3D *lwpoly_findbbox(LWPOLY *poly) } //find length of this serialized polygon -uint32 lwpoly_findlength(char *serialized_poly) +uint32 lwgeom_size_poly(char *serialized_poly) { uint32 result = 1; // char type uint32 nrings; @@ -1727,7 +1729,7 @@ uint32 lwpoly_findlength(char *serialized_poly) if (lwgeom_hasBBOX(type)) { #ifdef DEBUG - elog(NOTICE, "lwpoly_findlength: has bbox"); + elog(NOTICE, "lwgeom_size_poly: has bbox"); #endif loc += sizeof(BOX2DFLOAT4); result +=sizeof(BOX2DFLOAT4); @@ -1737,7 +1739,7 @@ uint32 lwpoly_findlength(char *serialized_poly) if ( lwgeom_hasSRID(type)) { #ifdef DEBUG - elog(NOTICE, "lwpoly_findlength: has srid"); + elog(NOTICE, "lwgeom_size_poly: has srid"); #endif loc +=4; // type + SRID result += 4; @@ -1850,7 +1852,7 @@ LWGEOM_INSPECTED *lwgeom_inspect(char *serialized_form) #endif for (t=1;tngeometries; t++) { - int sub_length = lwgeom_seralizedformlength(sub_geoms[t-1], -1);//-1 = entire object + int sub_length = lwgeom_size_subgeom(sub_geoms[t-1], -1);//-1 = entire object sub_geoms[t] = sub_geoms[t-1] + sub_length; #ifdef DEBUG elog(NOTICE, "subgeom[%d] @ %p (sub_length: %d)", @@ -2119,7 +2121,7 @@ extern char *lwgeom_construct(int SRID,int finalType,int ndims, int nsubgeometri for (t=0;t size of the point // take a geometry, and find its length -int lwgeom_seralizedformlength_simple(char *serialized_form) +int lwgeom_size(char *serialized_form) { unsigned char type = lwgeom_getType((unsigned char) serialized_form[0]); int t; @@ -2276,34 +2278,34 @@ int lwgeom_seralizedformlength_simple(char *serialized_form) int result = 1; //"type" #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple called"); + elog(NOTICE, "lwgeom_size called"); #endif if (type == POINTTYPE) { #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple: is a point"); + elog(NOTICE, "lwgeom_size: is a point"); #endif - return lwpoint_findlength(serialized_form); + return lwgeom_size_point(serialized_form); } else if (type == LINETYPE) { #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple: is a line"); + elog(NOTICE, "lwgeom_size: is a line"); #endif - return lwline_findlength(serialized_form); + return lwgeom_size_line(serialized_form); } else if (type == POLYGONTYPE) { #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple: is a polygon"); + elog(NOTICE, "lwgeom_size: is a polygon"); #endif - return lwpoly_findlength(serialized_form); + return lwgeom_size_poly(serialized_form); } if ( type == 0 ) { - elog(ERROR, "lwgeom_seralizedformlength_simple called with unknown-typed serialized geometry"); + elog(ERROR, "lwgeom_size called with unknown-typed serialized geometry"); return 0; } @@ -2311,7 +2313,7 @@ int lwgeom_seralizedformlength_simple(char *serialized_form) //NOTE: for a geometry collection of GC of GC of GC we will be recursing... #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple called on a geoemtry with type %d", type); + elog(NOTICE, "lwgeom_size called on a geoemtry with type %d", type); #endif loc = serialized_form+1; @@ -2319,7 +2321,7 @@ int lwgeom_seralizedformlength_simple(char *serialized_form) if (lwgeom_hasBBOX((unsigned char) serialized_form[0])) { #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple: has bbox"); + elog(NOTICE, "lwgeom_size: has bbox"); #endif loc += sizeof(BOX2DFLOAT4); @@ -2329,7 +2331,7 @@ int lwgeom_seralizedformlength_simple(char *serialized_form) if (lwgeom_hasSRID( (unsigned char) serialized_form[0]) ) { #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple: has srid"); + elog(NOTICE, "lwgeom_size: has srid"); #endif result +=4; loc +=4; @@ -2341,12 +2343,12 @@ int lwgeom_seralizedformlength_simple(char *serialized_form) result += 4; // numgeoms #ifdef DEBUG - elog(NOTICE, "lwgeom_seralizedformlength_simple called on a geoemtry with %d elems (result so far: %d)", ngeoms, result); + elog(NOTICE, "lwgeom_size called on a geoemtry with %d elems (result so far: %d)", ngeoms, result); #endif for (t=0;tsub_geoms[geom_number], -1); + return lwgeom_size(inspected->sub_geoms[geom_number]); } @@ -2467,7 +2469,7 @@ elog(NOTICE, "lw_geom_getBB_simple: bbox found"); for (t=0;tnpoints; i++) { - size += lwpoint_findlength(exploded->points[i]); + size += lwgeom_size_point(exploded->points[i]); if ( lwgeom_hasBBOX(exploded->points[i][0]) ) size -= sizeof(BOX2DFLOAT4); if ( lwgeom_hasSRID(exploded->points[i][0]) ) @@ -3394,7 +3395,7 @@ lwexploded_findlength(LWGEOM_EXPLODED *exploded, int wantbbox) ntypes++; for (i=0; inlines; i++) { - size += lwline_findlength(exploded->lines[i]); + size += lwgeom_size_line(exploded->lines[i]); if ( lwgeom_hasBBOX(exploded->lines[i][0]) ) size -= sizeof(BOX2DFLOAT4); if ( lwgeom_hasSRID(exploded->lines[i][0]) ) @@ -3412,7 +3413,7 @@ lwexploded_findlength(LWGEOM_EXPLODED *exploded, int wantbbox) ntypes++; for (i=0; inpolys; i++) { - size += lwpoly_findlength(exploded->polys[i]); + size += lwgeom_size_poly(exploded->polys[i]); if ( lwgeom_hasBBOX(exploded->polys[i][0]) ) size -= sizeof(BOX2DFLOAT4); if ( lwgeom_hasSRID(exploded->polys[i][0]) ) diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index bd11d8fa6..702175417 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -760,7 +760,7 @@ Datum LWGEOM_mem_size(PG_FUNCTION_ARGS) { LWGEOM *geom = (LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); int32 size = geom->size; - int32 computed_size = lwgeom_seralizedformlength_simple(SERIALIZED_FORM(geom)); + int32 computed_size = lwgeom_size(SERIALIZED_FORM(geom)); computed_size += 4; // varlena size if ( size != computed_size ) { @@ -2176,7 +2176,7 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS) // And create LWGEOM type (could provide a _buf version of // the serializer instead) - size = lwgeom_seralizedformlength_simple(serialized_result); + size = lwgeom_size(serialized_result); result = LWGEOM_construct(serialized_result, lwgeom_getsrid(serialized_result), wantbbox); pfree(serialized_result); @@ -2411,7 +2411,7 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS) // Create LWGEOM type (could provide a _buf version of // the serializer instead) - size = lwgeom_seralizedformlength_simple(serialized_result); + size = lwgeom_size(serialized_result); result = LWGEOM_construct(serialized_result, lwgeom_getsrid(serialized_result), wantbbox); pfree(serialized_result); -- 2.50.1