PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_patchn()

Datum LWGEOM_patchn ( PG_FUNCTION_ARGS  )

Definition at line 401 of file lwgeom_ogc.c.

402{
403 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
404 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
405 GSERIALIZED *result = NULL;
406 int32 idx = PG_GETARG_INT32(1);
407 LWGEOM *subgeom = NULL;
408
409 if (!lwgeom_has_patches(lwgeom))
410 {
411 lwgeom_free(lwgeom);
412 PG_FREE_IF_COPY(geom, 0);
413 elog(ERROR, "ST_PatchN only supports TIN and PolyhedralSurface geometries");
414 }
415
416 /* Access patches individually */
417 subgeom = lwgeom_extract_geometry_n(lwgeom, idx, true);
418
419 if (!subgeom)
420 PG_RETURN_NULL();
421
422 /* If returning the original geometry */
423 if (subgeom == lwgeom)
424 PG_RETURN_POINTER(geom);
425
426 subgeom->srid = lwgeom->srid;
427 /* COMPUTE_BBOX==TAINTING */
428 if (lwgeom->bbox) lwgeom_add_bbox(subgeom);
429
430 result = geometry_serialize(subgeom);
431 lwgeom_free(lwgeom);
432 PG_FREE_IF_COPY(geom, 0);
433 PG_RETURN_POINTER(result);
434}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
int lwgeom_has_patches(const LWGEOM *geom)
Definition lwgeom.c:1154
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:723
static LWGEOM * lwgeom_extract_geometry_n(LWGEOM *lwgeom, int32 idx, bool patches_as_geometries)
Definition lwgeom_ogc.c:320
unsigned int int32
Definition shpopen.c:54
GBOX * bbox
Definition liblwgeom.h:458
int32_t srid
Definition liblwgeom.h:460

References LWGEOM::bbox, lwgeom_add_bbox(), lwgeom_extract_geometry_n(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_has_patches(), result, and LWGEOM::srid.

Here is the call graph for this function: