Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of the specified type.
WARNING: the output will contain references to geometries in the input, so the result must be carefully released, not freed.
388{
389 uint32_t i = 0;
392 int geomlistsize = 16;
393 int geomlistlen = 0;
394 uint8_t outtype;
395
396 if (!col) return NULL;
397
398 switch (type)
399 {
402 break;
405 break;
408 break;
409 default:
411 "Only POLYGON, LINESTRING and POINT are supported by "
412 "lwcollection_extract. %s requested.",
414 return NULL;
415 }
416
418
419
420 for (i = 0; i < col->
ngeoms; i++)
421 {
423
425
426 if (subtype == type)
427 {
428
429
430 if (geomlistlen == geomlistsize)
431 {
432 geomlistsize *= 2;
434 geomlist,
sizeof(
LWGEOM*) * geomlistsize);
435 }
437 geomlistlen++;
438 }
439
441 {
442 uint32_t j = 0;
445 for (j = 0; j < tmpcol->
ngeoms; j++)
446 {
447
448
449 if (geomlistlen == geomlistsize)
450 {
451 geomlistsize *= 2;
454 geomlistsize);
455 }
456 geomlist[geomlistlen] = tmpcol->
geoms[j];
457 geomlistlen++;
458 }
462 }
463 }
464
465 if (geomlistlen > 0)
466 {
469 outtype, col->
srid, NULL, geomlistlen, geomlist);
472 }
473 else
474 {
480 }
481
482 return outcol;
483}
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
void * lwrealloc(void *mem, size_t size)
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
void * lwalloc(size_t size)
#define FLAGS_GET_M(flags)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)