extern uint8_t lwgeom_makeType(char hasZ, char hasM, char has_srid, int type);
extern uint8_t lwgeom_makeType_full(char hasZ, char hasM, char has_srid, int type, char hasBBOX);
-/*
- * Compute bbox of serialized geom
- */
-extern BOX3D *compute_serialized_box3d(uint8_t *serialized_form);
-extern int compute_serialized_box3d_p(uint8_t *serialized_form, BOX3D *box);
-
-
/*
* This function computes the size in bytes
* of the serialized geometries.
}
-int
-compute_serialized_box3d_p(uint8_t *srl, BOX3D *out)
-{
- BOX3D *box = compute_serialized_box3d(srl);
- if ( ! box ) return 0;
- out->xmin = box->xmin;
- out->ymin = box->ymin;
- out->zmin = box->zmin;
- out->xmax = box->xmax;
- out->ymax = box->ymax;
- out->zmax = box->zmax;
- lwfree(box);
-
- return 1;
-}
-
-
-/**
- * Don't forget to lwfree() result !
- */
-BOX3D *
-compute_serialized_box3d(uint8_t *srl)
-{
- int type = lwgeom_getType(srl[0]);
- int t;
- uint8_t *loc = srl;
- uint32_t nelems;
- BOX3D *result;
- BOX3D b1;
- int sub_size;
- char nboxes=0;
-
- LWDEBUGF(2, "compute_serialized_box3d called on type %d", type);
-
- loc += 1; /* Move past the 'type' byte. */
-
- if (lwgeom_hasBBOX(srl[0]))
- {
- loc += sizeof(BOX2DFLOAT4); /* Move past the bbox */
- }
-
- if (lwgeom_hasSRID(srl[0]) )
- {
- loc +=4; /* Move past the SRID */
- }
-
- if (type == POINTTYPE)
- {
- LWPOINT *pt = lwpoint_deserialize(srl);
-
- LWDEBUG(3, "compute_serialized_box3d: lwpoint deserialized");
-
- result = lwpoint_compute_box3d(pt);
-
- LWDEBUG(3, "compute_serialized_box3d: bbox found");
-
- lwpoint_free(pt);
- return result;
- }
-
- /*
- ** For items that have elements (everything except points),
- ** nelems == 0 => EMPTY geometry
- */
- nelems = lw_get_uint32_t(loc);
- if ( nelems == 0 ) return NULL;
-
- if (type == LINETYPE)
- {
- LWLINE *line = lwline_deserialize(srl);
- result = lwline_compute_box3d(line);
- lwline_free(line);
- return result;
-
- }
- else if (type == CIRCSTRINGTYPE)
- {
- LWCIRCSTRING *curve = lwcircstring_deserialize(srl);
- result = lwcircstring_compute_box3d(curve);
- lwcircstring_free(curve);
- return result;
- }
- else if (type == POLYGONTYPE)
- {
- LWPOLY *poly = lwpoly_deserialize(srl);
- result = lwpoly_compute_box3d(poly);
- lwpoly_free(poly);
- return result;
- }
- else if (type == TRIANGLETYPE)
- {
- LWTRIANGLE *triangle = lwtriangle_deserialize(srl);
- result = lwtriangle_compute_box3d(triangle);
- lwtriangle_free(triangle);
- return result;
- }
-
- if ( ! ( type == MULTIPOINTTYPE || type == MULTILINETYPE ||
- type == MULTIPOLYGONTYPE || type == COLLECTIONTYPE ||
- type == COMPOUNDTYPE || type == CURVEPOLYTYPE ||
- type == MULTICURVETYPE || type == MULTISURFACETYPE ||
- type == POLYHEDRALSURFACETYPE || type == TINTYPE ))
- {
- lwnotice("compute_serialized_box3d called on unknown type %d", type);
- return NULL;
- }
-
- loc += 4;
-
- /* each sub-type */
- result = NULL;
- for (t=0; t<nelems; t++)
- {
- if ( compute_serialized_box3d_p(loc, &b1) )
- {
- LWDEBUG(3, "Geom %d have box:");
-#if POSTGIS_DEBUG_LEVEL >= 3
- printBOX3D(&b1);
-#endif
-
- if (result)
- {
- nboxes += box3d_union_p(result, &b1, result);
- }
- else
- {
- result = lwalloc(sizeof(BOX3D));
- memcpy(result, &b1, sizeof(BOX3D));
- }
- }
-
- sub_size = serialized_lwgeom_size(loc);
- loc += sub_size;
- }
-
- return result;
-}
/****************************************************************
* memory management