]> granicus.if.org Git - postgis/commitdiff
Changed collect() to return MULTI* if applicabe (all input is corresponding
authorSandro Santilli <strk@keybit.net>
Mon, 11 Oct 2004 10:31:29 +0000 (10:31 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 11 Oct 2004 10:31:29 +0000 (10:31 +0000)
SINGLE type).

git-svn-id: http://svn.osgeo.org/postgis/trunk@979 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_functions_basic.c

index 436123a788624ef66e4157125eb78c72e504ed18..210a1c4562c3d1c8767e6062db32aa3a5713a63f 100644 (file)
@@ -2357,6 +2357,7 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
        PG_LWGEOM *result=NULL;
        LWGEOM **lwgeoms, *outlwg;
        size_t size;
+       unsigned int outtype;
        int i;
 
 //elog(NOTICE, "LWGEOM_collect_garray called");
@@ -2389,20 +2390,39 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
 
        /*
         * Deserialize all geometries in array into the lwgeoms pointers
-        * array
+        * array. Check input types to form output type.
         */
        lwgeoms = palloc(sizeof(LWGEOM *)*nelems);
+       outtype = 0;
        for (i=0; i<nelems; i++)
        {
+               unsigned int intype = TYPE_GETTYPE(geoms[i]->type);
                lwgeoms[i] = lwgeom_deserialize(SERIALIZED_FORM(geoms[i]));
+
+               // Output type not initialized
+               if ( ! outtype ) {
+                       // Input is single, make multi
+                       if ( outtype < 4 ) outtype = intype+3;
+                       // Input is multi, make collection
+                       else outtype = COLLECTIONTYPE;
+               }
+
+               // Input type not compatible with output
+               // make output type a collection
+               else if ( outtype != COLLECTIONTYPE && intype != outtype-3 )
+               {
+                       outtype = COLLECTIONTYPE;
+               }
+
        }
 
        outlwg = (LWGEOM *)lwcollection_construct(
-               COLLECTIONTYPE,
+               outtype,
                lwgeom_getSRID(geoms[0]),
                NULL, nelems, lwgeoms);
 
        size = lwgeom_serialize_size(outlwg);
+       //lwnotice("lwgeom_serialize_size returned %d", size);
        result = palloc(size+4);
        result->size = (size+4);
        lwgeom_serialize_buf(outlwg, SERIALIZED_FORM(result), &size);