PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_patchn()

Datum LWGEOM_patchn ( PG_FUNCTION_ARGS  )

Definition at line 407 of file lwgeom_ogc.c.

408 {
409  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
410  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
411  GSERIALIZED *result = NULL;
412  int32 idx = PG_GETARG_INT32(1);
413  LWGEOM *subgeom = NULL;
414 
415  if (!lwgeom_has_patches(lwgeom))
416  {
417  lwgeom_free(lwgeom);
418  PG_FREE_IF_COPY(geom, 0);
419  elog(ERROR, "ST_PatchN only supports TIN and PolyhedralSurface geometries");
420  }
421 
422  /* Access patches individually */
423  subgeom = lwgeom_extract_geometry_n(lwgeom, idx, true);
424 
425  if (!subgeom)
426  PG_RETURN_NULL();
427 
428  /* If returning the original geometry */
429  if (subgeom == lwgeom)
430  PG_RETURN_POINTER(geom);
431 
432  subgeom->srid = lwgeom->srid;
433  /* COMPUTE_BBOX==TAINTING */
434  if (lwgeom->bbox) lwgeom_add_bbox(subgeom);
435 
436  result = geometry_serialize(subgeom);
437  lwgeom_free(lwgeom);
438  PG_FREE_IF_COPY(geom, 0);
439  PG_RETURN_POINTER(result);
440 }
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.
Definition: gserialized.c:268
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
int lwgeom_has_patches(const LWGEOM *geom)
Definition: lwgeom.c:1126
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:695
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: