From: Sandro Santilli Date: Mon, 11 Oct 2004 10:31:29 +0000 (+0000) Subject: Changed collect() to return MULTI* if applicabe (all input is corresponding X-Git-Tag: pgis_1_0_0RC1~300 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13b10e6d9b63499239b45b8d994d975374123676;p=postgis Changed collect() to return MULTI* if applicabe (all input is corresponding SINGLE type). git-svn-id: http://svn.osgeo.org/postgis/trunk@979 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index 436123a78..210a1c456 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -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; itype); 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);