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

◆ lwgeom_extract_geometry_n()

static LWGEOM * lwgeom_extract_geometry_n ( LWGEOM lwgeom,
int32  idx,
bool  patches_as_geometries 
)
static

Definition at line 320 of file lwgeom_ogc.c.

321{
322 LWCOLLECTION *coll = NULL;
323 LWGEOM *subgeom = NULL;
324
325 /* Empty returns NULL */
326 if (lwgeom_is_empty(lwgeom))
327 return NULL;
328
329 /* Unitary geometries */
330 if (lwgeom_is_unitary(lwgeom))
331 {
332 /* If it's a TIN or PolyhedralSurface and we want to access patches */
333 if (lwgeom_has_patches(lwgeom) && patches_as_geometries)
334 {
335 coll = lwgeom_as_lwcollection(lwgeom);
336 if (!coll)
337 {
338 /* Single patch case */
339 if (idx == 1)
340 return lwgeom;
341 else
342 return NULL;
343 }
344 }
345 else
346 {
347 /* Standard unitary geometry handling */
348 if (idx == 1)
349 return lwgeom;
350 else
351 return NULL;
352 }
353 }
354 else
355 {
356 coll = lwgeom_as_lwcollection(lwgeom);
357 }
358
359 if (!coll)
360 return NULL;
361
362 /* Handle out-of-range index value */
363 idx -= 1;
364 if (idx < 0 || idx >= (int32) coll->ngeoms)
365 return NULL;
366
367 subgeom = coll->geoms[idx];
368 return subgeom;
369}
int lwgeom_is_unitary(const LWGEOM *geom)
Determine whether a Geometry is a bag of sub-geometries.
Definition lwgeom.c:1168
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:261
int lwgeom_has_patches(const LWGEOM *geom)
Definition lwgeom.c:1154
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
unsigned int int32
Definition shpopen.c:54
uint32_t ngeoms
Definition liblwgeom.h:580
LWGEOM ** geoms
Definition liblwgeom.h:575

References LWCOLLECTION::geoms, lwgeom_as_lwcollection(), lwgeom_has_patches(), lwgeom_is_empty(), lwgeom_is_unitary(), and LWCOLLECTION::ngeoms.

Referenced by LWGEOM_geometryn_collection(), and LWGEOM_patchn().

Here is the call graph for this function:
Here is the caller graph for this function: