1221{
1222 ArrayType *array;
1223 int nelems;
1224
1226 LWGEOM **lwgeoms, *outlwg;
1227 uint32 outtype;
1231
1232 ArrayIterator iterator;
1234 bool isnull;
1235
1236 POSTGIS_DEBUG(2, "LWGEOM_collect_garray called.");
1237
1238 if (PG_ARGISNULL(0))
1239 PG_RETURN_NULL();
1240
1241
1242 array = PG_GETARG_ARRAYTYPE_P(0);
1243 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1244
1245 POSTGIS_DEBUGF(3,
1246 " array is %d-bytes in size, %ld w/out header",
1247 ARR_SIZE(array),
1248 ARR_SIZE(array) - ARR_OVERHEAD_NONULLS(ARR_NDIM(array)));
1249
1250 POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: array has %d elements", nelems);
1251
1252
1253 if (nelems == 0)
1254 PG_RETURN_NULL();
1255
1256
1257
1258
1259
1260 lwgeoms = palloc(
sizeof(
LWGEOM *) * nelems);
1262 outtype = 0;
1263
1264 iterator = array_create_iterator(array, 0, NULL);
1265
1266 while (array_iterate(iterator, &value, &isnull))
1267 {
1269 uint8_t intype;
1270
1271
1272 if (isnull)
1273 continue;
1274
1277
1279
1280 POSTGIS_DEBUGF(3, "%s: geom %d deserialized", __func__, count);
1281
1282 if (!count)
1283 {
1284
1286
1287
1288 if (lwgeoms[count]->bbox)
1290 }
1291 else
1292 {
1293
1295
1296
1297 if (box)
1298 {
1299 if (lwgeoms[count]->bbox)
1301 else
1302 {
1303 pfree(box);
1304 box = NULL;
1305 }
1306 }
1307 }
1308
1311
1312
1313 if (!outtype)
1314 {
1316 }
1317
1318
1320 {
1322 }
1323
1325 }
1326 array_free_iterator(iterator);
1327
1328 POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: outtype = %d", outtype);
1329
1330
1331 if (!outtype)
1332 {
1333 PG_RETURN_NULL();
1334 }
1335 else
1336 {
1338
1340
1341 PG_RETURN_POINTER(result);
1342 }
1343}
int gbox_merge(const GBOX *new_box, GBOX *merge_box)
Update the merged GBOX to be large enough to include itself and the new box.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
uint32_t lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
#define SRID_UNKNOWN
Unknown SRID value.
void lwgeom_drop_srid(LWGEOM *lwgeom)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)