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

◆ lwt_GetFaceGeometry()

LWGEOM * lwt_GetFaceGeometry ( LWT_TOPOLOGY topo,
LWT_ELEMID  face 
)

Return the geometry of a face.

For ST_GetFaceGeometry

Parameters
topothe topology to operate on
faceidentifier of the face
Returns
a polygon geometry representing the face, ownership to caller, to be released with lwgeom_release, or NULL on error (liblwgeom error handler will be invoked with error message)

Definition at line 2958 of file lwgeom_topo.c.

2959{
2960 uint64_t numfaceedges;
2961 LWT_ISO_EDGE *edges;
2962 LWT_ISO_FACE *face;
2963 LWPOLY *out;
2964 LWGEOM *outg;
2965 uint64_t i, edgeid;
2966 int fields;
2967
2968 if (faceid == 0)
2969 {
2970 lwerror("SQL/MM Spatial exception - universal face has no geometry");
2971 return NULL;
2972 }
2973
2974 /* Construct the face geometry */
2975 numfaceedges = 1;
2976 fields = LWT_COL_EDGE_GEOM |
2980 ;
2981 edges = lwt_be_getEdgeByFace( topo, &faceid, &numfaceedges, fields, NULL );
2982 if (numfaceedges == UINT64_MAX)
2983 {
2985 return NULL;
2986 }
2987 LWDEBUGF(1, "lwt_GetFaceGeometry: lwt_be_getEdgeByFace returned %llu edges", numfaceedges);
2988
2989 if ( numfaceedges == 0 )
2990 {
2991 i = 1;
2992 face = lwt_be_getFaceById(topo, &faceid, &i, LWT_COL_FACE_FACE_ID);
2993 if (i == UINT64_MAX)
2994 {
2996 return NULL;
2997 }
2998 if ( i == 0 ) {
2999 lwerror("SQL/MM Spatial exception - non-existent face.");
3000 return NULL;
3001 }
3002 lwfree( face );
3003 if ( i > 1 ) {
3004 lwerror("Corrupted topology: multiple face records have face_id=%"
3005 LWTFMT_ELEMID, faceid);
3006 return NULL;
3007 }
3008 /* Face has no boundary edges, we'll return EMPTY, see
3009 * https://trac.osgeo.org/postgis/ticket/3221 */
3010 lwnotice("Corrupted topology: face %"
3011 LWTFMT_ELEMID " has no associated edges.", faceid);
3012 out = lwpoly_construct_empty(topo->srid, topo->hasZ, 0);
3013 return lwpoly_as_lwgeom(out);
3014 }
3015 edgeid = edges[0].edge_id;
3016
3017 outg = _lwt_FaceByEdges( topo, edges, numfaceedges );
3018 _lwt_release_edges(edges, numfaceedges);
3019
3020 if ( ! outg )
3021 {
3022 /* Face did have edges but no polygon could be constructed
3023 * with that material, sounds like a corrupted topology..
3024 *
3025 * We'll return EMPTY, see
3026 * https://trac.osgeo.org/postgis/ticket/3221 */
3027 lwnotice("Corrupted topology: face %"
3028 LWTFMT_ELEMID " could not be constructed only from edges "
3029 "knowing about it (like edge %" LWTFMT_ELEMID ").",
3030 faceid, edgeid);
3031 out = lwpoly_construct_empty(topo->srid, topo->hasZ, 0);
3032 return lwpoly_as_lwgeom(out);
3033 }
3034
3035 return outg;
3036}
void lwfree(void *mem)
Definition lwutil.c:248
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition lwgeom.c:357
#define LWT_COL_EDGE_FACE_RIGHT
#define LWT_COL_FACE_FACE_ID
Face fields.
#define LWT_COL_EDGE_FACE_LEFT
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_GEOM
#define PGTOPO_BE_ERROR()
#define LWTFMT_ELEMID
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static LWT_ISO_FACE * lwt_be_getFaceById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
static LWT_ISO_EDGE * lwt_be_getEdgeByFace(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box)
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
static LWGEOM * _lwt_FaceByEdges(LWT_TOPOLOGY *topo, LWT_ISO_EDGE *edges, int numfaceedges)
LWT_ELEMID edge_id

References _lwt_FaceByEdges(), _lwt_release_edges(), LWT_ISO_EDGE::edge_id, LWT_TOPOLOGY_T::hasZ, LWDEBUGF, lwerror(), lwfree(), lwnotice(), lwpoly_as_lwgeom(), lwpoly_construct_empty(), lwt_be_getEdgeByFace(), lwt_be_getFaceById(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_FACE_LEFT, LWT_COL_EDGE_FACE_RIGHT, LWT_COL_EDGE_GEOM, LWT_COL_FACE_FACE_ID, LWTFMT_ELEMID, PGTOPO_BE_ERROR, and LWT_TOPOLOGY_T::srid.

Referenced by _lwt_SnapEdgeToExistingNode(), and lwt_AddPolygon().

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