1248{
1249 ArrayType *array;
1250 int nelems;
1251
1253 LWGEOM **lwgeoms, *outlwg;
1254 uint32 outtype;
1258
1259 ArrayIterator iterator;
1261 bool isnull;
1262
1263 POSTGIS_DEBUG(2, "LWGEOM_collect_garray called.");
1264
1265 if (PG_ARGISNULL(0))
1266 PG_RETURN_NULL();
1267
1268
1269 array = PG_GETARG_ARRAYTYPE_P(0);
1270 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1271
1272 POSTGIS_DEBUGF(3,
1273 " array is %d-bytes in size, %ld w/out header",
1274 ARR_SIZE(array),
1275 ARR_SIZE(array) - ARR_OVERHEAD_NONULLS(ARR_NDIM(array)));
1276
1277 POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: array has %d elements", nelems);
1278
1279
1280 if (nelems == 0)
1281 PG_RETURN_NULL();
1282
1283
1284
1285
1286
1287 lwgeoms = palloc(
sizeof(
LWGEOM *) * nelems);
1289 outtype = 0;
1290
1291 iterator = array_create_iterator(array, 0, NULL);
1292
1293 while (array_iterate(iterator, &value, &isnull))
1294 {
1296 uint8_t intype;
1297
1298
1299 if (isnull)
1300 continue;
1301
1304
1306
1307 POSTGIS_DEBUGF(3, "%s: geom %d deserialized", __func__, count);
1308
1309 if (!count)
1310 {
1311
1313
1314
1315 if (lwgeoms[count]->bbox)
1317 }
1318 else
1319 {
1320
1322
1323
1324 if (box)
1325 {
1326 if (lwgeoms[count]->bbox)
1328 else
1329 {
1330 pfree(box);
1331 box = NULL;
1332 }
1333 }
1334 }
1335
1338
1339
1340 if (!outtype)
1341 {
1343 }
1344
1345
1347 {
1349 }
1350
1352 }
1353 array_free_iterator(iterator);
1354
1355 POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: outtype = %d", outtype);
1356
1357
1358 if (!outtype)
1359 {
1360 PG_RETURN_NULL();
1361 }
1362 else
1363 {
1365
1366 result = geometry_serialize(outlwg);
1367
1368 PG_RETURN_POINTER(
result);
1369 }
1370}
char result[OUT_DOUBLE_BUFFER_SIZE]
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)