#define INTEGRITY_CHECKS 1
//#define DEBUG_ALLOCS 1
-
-//liblwgeom.h
-
//#define DEBUG 1
//#define DEBUG_CALLS 1
// with the HASBBOX flag and has a bbox, it
// will be released.
extern void lwgeom_dropBBOX(LWGEOM *lwgeom);
+// Compute a bbox if not already computed
+extern void lwgeom_addBBOX(LWGEOM *lwgeom);
extern void lwgeom_dropSRID(LWGEOM *lwgeom);
//-------------------------------------------------------------
unsigned int nrings, POINTARRAY **points);
extern LWCOLLECTION *lwcollection_construct(unsigned int type, int SRID,
BOX2DFLOAT4 *bbox, unsigned int ngeoms, LWGEOM **geoms);
+extern LWCOLLECTION *lwcollection_construct_empty(int SRID,
+ char hasZ, char hasM);
// Return a char string with ASCII versionf of type flags
extern const char *lwgeom_typeflags(unsigned char type);
return ret;
}
+LWCOLLECTION *
+lwcollection_construct_empty(int SRID, char hasZ, char hasM);
+{
+ LWCOLLECTION *ret;
+
+ ret = lwalloc(sizeof(LWCOLLECTION));
+ ret->type = lwgeom_makeType_full(hasz, hasm, (SRID!=-1),
+ COLLECTIONTYPE, 0);
+ ret->SRID = SRID;
+ ret->ngeoms = 0;
+ ret->geoms = NULL;
+ ret->bbox = bbox;
+
+ return ret;
+}
+
LWCOLLECTION *
lwcollection_deserialize(char *srl)
return NULL;
}
+#ifdef DEBUG_CALLS
+ lwnotice("lwgeom_add(%s, %d, %s) called",
+ lwgeom_typename(TYPE_GETTYPE(to->type)),
+ where,
+ lwgeom_typename(TYPE_GETTYPE(what->type)));
+#endif
+
switch(TYPE_GETTYPE(to->type))
{
case POINTTYPE:
return (LWGEOM *)lwpoly_add((const LWPOLY *)to, where, what);
case MULTIPOINTTYPE:
+ return (LWGEOM *)lwmpoint_add((const LWMPOINT *)to,
+ where, what);
+
case MULTILINETYPE:
+ return (LWGEOM *)lwmline_add((const LWMLINE *)to,
+ where, what);
+
case MULTIPOLYGONTYPE:
- return (LWGEOM *)lwcollection_add((const LWCOLLECTION *)to, where, what);
+ return (LWGEOM *)lwmpoly_add((const LWMPOLY *)to,
+ where, what);
+
+ case COLLECTIONTYPE:
+ return (LWGEOM *)lwcollection_add(
+ (const LWCOLLECTION *)to, where, what);
+
default:
+ lwerror("lwgeom_add: unknown geometry type: %d",
+ TYPE_GETTYPE(to->type));
return NULL;
}
}
lwgeom->bbox = NULL;
}
+/*
+ * Ensure there's a box in the LWGEOM.
+ * If the box is already there just return,
+ * else compute it.
+ */
+void
+lwgeom_addBBOX(LWGEOM *lwgeom)
+{
+ if ( lwgeom->bbox ) return;
+ lwgeom->bbox = lwgeom_compute_bbox(lwgeom);
+}
+
void
lwgeom_dropSRID(LWGEOM *lwgeom)
{