static uint32 lwgeom_size_poly(char *serialized_line);
static int lwgeom_size_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
-
-
//*********************************************************************
// BOX routines
return ret;
}
-//find length of this serialized line
-uint32 lwgeom_size_line(char *serialized_line)
+// find length of this serialized line
+uint32
+lwgeom_size_line(char *serialized_line)
{
int type = (unsigned char) serialized_line[0];
uint32 result =1; //type
return 0; //never get here
}
+// find length of this deserialized line
+uint32
+lwline_size(LWLINE *line)
+{
+ uint32 size = 1; //type
+
+ if ( line->SRID != -1 ) size += 4; // SRID
+ size += sizeof(double)*line->ndims*line->points->npoints; // points
+
+ return size;
+}
+
//********************************************************************
// support for the LWPOINT sub-type
// construct a new point. point will not be copied
// use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
-LWPOINT *lwpoint_construct(int ndims, int SRID, POINTARRAY *point)
+LWPOINT *
+lwpoint_construct(int ndims, int SRID, POINTARRAY *point)
{
LWPOINT *result ;
// construct a proper LWPOINT.
// serialized_form should point to the 8bit type format (with type = 1)
// See serialized form doc
-LWPOINT *lwpoint_deserialize(char *serialized_form)
+LWPOINT *
+lwpoint_deserialize(char *serialized_form)
{
unsigned char type;
LWPOINT *result;
// convert this point into its serialize form
// result's first char will be the 8bit type. See serialized form doc
-char *lwpoint_serialize(LWPOINT *point)
+char *
+lwpoint_serialize(LWPOINT *point)
{
int size=1;
char hasSRID;
// 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, char *buf, int *retsize)
+void
+lwpoint_serialize_buf(LWPOINT *point, char *buf, int *retsize)
{
int size=1;
char hasSRID;
}
// find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
-BOX3D *lwpoint_findbbox(LWPOINT *point)
+BOX3D *
+lwpoint_findbbox(LWPOINT *point)
{
#ifdef DEBUG
elog(NOTICE, "lwpoint_findbbox called with point %p", point);
}
// convenience functions to hide the POINTARRAY
-POINT2D lwpoint_getPoint2d(LWPOINT *point)
+// TODO: obsolete this
+POINT2D
+lwpoint_getPoint2d(LWPOINT *point)
{
POINT2D result;
}
// convenience functions to hide the POINTARRAY
-POINT3D lwpoint_getPoint3d(LWPOINT *point)
+POINT3D
+lwpoint_getPoint3d(LWPOINT *point)
{
POINT3D result;
//find length of this serialized point
-uint32 lwgeom_size_point(char *serialized_point)
+uint32
+lwgeom_size_point(char *serialized_point)
{
uint result = 1;
unsigned char type;
return 0; //never get here
}
+// find length of this deserialized point
+uint32
+lwpoint_size(LWPOINT *point)
+{
+ uint32 size = 1; // type
+
+ if ( point->SRID != -1 ) size += 4; // SRID
+ size += point->ndims * sizeof(double); // point
+
+ return size;
+}
+
//********************************************************************
// basic polygon manipulation
// construct a new LWPOLY. arrays (points/points per ring) will NOT be copied
// use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
-LWPOLY *lwpoly_construct(int ndims, int SRID, int nrings,POINTARRAY **points)
+LWPOLY *
+lwpoly_construct(int ndims, int SRID, int nrings,POINTARRAY **points)
{
LWPOLY *result;
// construct a proper LWPOLY.
// serialized_form should point to the 8bit type format (with type = 3)
// See serialized form doc
-LWPOLY *lwpoly_deserialize(char *serialized_form)
+LWPOLY *
+lwpoly_deserialize(char *serialized_form)
{
LWPOLY *result;
// create the serialized form of the polygon
// result's first char will be the 8bit type. See serialized form doc
// points copied
-char *lwpoly_serialize(LWPOLY *poly)
+char *
+lwpoly_serialize(LWPOLY *poly)
{
int size=1; // type byte
char hasSRID;
// 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, char *buf, int *retsize)
+void
+lwpoly_serialize_buf(LWPOLY *poly, char *buf, int *retsize)
{
int size=1; // type byte
char hasSRID;
// find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
-BOX3D *lwpoly_findbbox(LWPOLY *poly)
+BOX3D *
+lwpoly_findbbox(LWPOLY *poly)
{
// int t;
}
//find length of this serialized polygon
-uint32 lwgeom_size_poly(char *serialized_poly)
+uint32
+lwgeom_size_poly(char *serialized_poly)
{
uint32 result = 1; // char type
uint32 nrings;
return result;
}
+// find length of this deserialized polygon
+uint32
+lwpoly_size(LWPOLY *poly)
+{
+ uint32 size = 1; // type
+ uint32 i;
-//*************************************************************************
-// multi-geometry support
+ if ( poly->SRID != -1 ) size += 4; // SRID
+
+ size += 4; // nrings
+ for (i=0; i<poly->nrings; i++)
+ {
+ size += 4; // npoints
+ size += poly->rings[i]->npoints*poly->ndims*sizeof(double);
+ }
+ return size;
+}
+
+//*************************************************************************
+// multi-geometry support
// note - for a simple type (ie. point), this will have sub_geom[0] = serialized_form.
// for multi-geomtries sub_geom[0] will be a few bytes into the serialized form
// This function just computes the length of each sub-object and pre-caches this info.
-int lwgeom_size_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
+int
+lwgeom_size_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
return lwgeom_size(inspected->sub_geoms[geom_number]);
}
// Now serialized collected LWGEOM_EXPLODED
serialized_result = lwexploded_serialize(expcoll, wantbbox);
- //serialized_result = lwexploded_serialize(exp1, wantbbox);
if ( ! serialized_result )
{
elog(ERROR, "Could not serialize exploded geoms");
// And create LWGEOM type (could provide a _buf version of
// the serializer instead)
- size = lwgeom_size(serialized_result);
+ //size = lwgeom_size(serialized_result);
result = LWGEOM_construct(serialized_result,
lwgeom_getsrid(serialized_result), wantbbox);
pfree(serialized_result);
// Create LWGEOM type (could provide a _buf version of
// the serializer instead)
- size = lwgeom_size(serialized_result);
+ //size = lwgeom_size(serialized_result);
result = LWGEOM_construct(serialized_result,
lwgeom_getsrid(serialized_result), wantbbox);
pfree(serialized_result);
- PG_RETURN_POINTER( result );
+ PG_RETURN_POINTER(result);
}
// makes a polygon of the expanded features bvol - 1st point = LL 3rd=UR