]> granicus.if.org Git - postgis/commitdiff
Added lwgeom_addBBOX() and lwcollection_construct_empty()
authorSandro Santilli <strk@keybit.net>
Mon, 11 Oct 2004 09:32:44 +0000 (09:32 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 11 Oct 2004 09:32:44 +0000 (09:32 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@975 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/liblwgeom.h
lwgeom/lwcollection.c
lwgeom/lwgeom.c

index 413561a2e4a56e687adef25c1c4754b666f293c0..17b6a99fdcfcf295582da6b9cf471acfa345af5c 100644 (file)
@@ -5,9 +5,6 @@
 
 #define INTEGRITY_CHECKS 1
 //#define DEBUG_ALLOCS 1
-
-//liblwgeom.h
-
 //#define DEBUG 1
 //#define DEBUG_CALLS 1
 
@@ -252,6 +249,8 @@ extern void lwgeom_changed(LWGEOM *lwgeom);
 // 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);
 
 //-------------------------------------------------------------
@@ -983,6 +982,8 @@ extern LWPOLY *lwpoly_construct(int SRID, BOX2DFLOAT4 *bbox,
        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);
index 268a2c54356cf3ade0ed7fab70af3881e9b67574..b0db74e05b4792d4a99fa0831bfcdb7a2c3f0755 100644 (file)
@@ -46,6 +46,22 @@ lwcollection_construct(unsigned int type, int SRID, BOX2DFLOAT4 *bbox,
        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)
index 387b36a4b9acc9ec4f97a06a53645b68238699c2..d5562a044ea7608e54827c8762c61371f0f76c7c 100644 (file)
@@ -317,6 +317,13 @@ lwgeom_add(const LWGEOM *to, uint32 where, const LWGEOM *what)
                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:
@@ -327,10 +334,24 @@ lwgeom_add(const LWGEOM *to, uint32 where, const LWGEOM *what)
                        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;
        }
 }
@@ -417,6 +438,18 @@ lwgeom_dropBBOX(LWGEOM *lwgeom)
        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)
 {