PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ 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 2817 of file lwgeom_topo.c.

2818 {
2819  uint64_t numfaceedges;
2820  LWT_ISO_EDGE *edges;
2821  LWT_ISO_FACE *face;
2822  LWPOLY *out;
2823  LWGEOM *outg;
2824  uint64_t i, edgeid;
2825  int fields;
2826 
2827  if (faceid == 0)
2828  {
2829  lwerror("SQL/MM Spatial exception - universal face has no geometry");
2830  return NULL;
2831  }
2832 
2833  /* Construct the face geometry */
2834  numfaceedges = 1;
2835  fields = LWT_COL_EDGE_GEOM |
2839  ;
2840  edges = lwt_be_getEdgeByFace( topo, &faceid, &numfaceedges, fields, NULL );
2841  if (numfaceedges == UINT64_MAX)
2842  {
2843  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
2844  return NULL;
2845  }
2846  LWDEBUGF(1, "lwt_GetFaceGeometry: lwt_be_getEdgeByFace returned %d edges", numfaceedges);
2847 
2848  if ( numfaceedges == 0 )
2849  {
2850  i = 1;
2851  face = lwt_be_getFaceById(topo, &faceid, &i, LWT_COL_FACE_FACE_ID);
2852  if (i == UINT64_MAX)
2853  {
2854  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
2855  return NULL;
2856  }
2857  if ( i == 0 ) {
2858  lwerror("SQL/MM Spatial exception - non-existent face.");
2859  return NULL;
2860  }
2861  lwfree( face );
2862  if ( i > 1 ) {
2863  lwerror("Corrupted topology: multiple face records have face_id=%"
2864  LWTFMT_ELEMID, faceid);
2865  return NULL;
2866  }
2867  /* Face has no boundary edges, we'll return EMPTY, see
2868  * https://trac.osgeo.org/postgis/ticket/3221 */
2869  lwnotice("Corrupted topology: face %"
2870  LWTFMT_ELEMID " has no associated edges.", faceid);
2871  out = lwpoly_construct_empty(topo->srid, topo->hasZ, 0);
2872  return lwpoly_as_lwgeom(out);
2873  }
2874  edgeid = edges[0].edge_id;
2875 
2876  outg = _lwt_FaceByEdges( topo, edges, numfaceedges );
2877  _lwt_release_edges(edges, numfaceedges);
2878 
2879  if ( ! outg )
2880  {
2881  /* Face did have edges but no polygon could be constructed
2882  * with that material, sounds like a corrupted topology..
2883  *
2884  * We'll return EMPTY, see
2885  * https://trac.osgeo.org/postgis/ticket/3221 */
2886  lwnotice("Corrupted topology: face %"
2887  LWTFMT_ELEMID " could not be constructed only from edges "
2888  "knowing about it (like edge %" LWTFMT_ELEMID ").",
2889  faceid, edgeid);
2890  out = lwpoly_construct_empty(topo->srid, topo->hasZ, 0);
2891  return lwpoly_as_lwgeom(out);
2892  }
2893 
2894  return outg;
2895 }
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:329
void lwfree(void *mem)
Definition: lwutil.c:242
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoly.c:161
#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 LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:125
static LWT_ISO_EDGE * lwt_be_getEdgeByFace(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box)
Definition: lwgeom_topo.c:244
static LWGEOM * _lwt_FaceByEdges(LWT_TOPOLOGY *topo, LWT_ISO_EDGE *edges, int numfaceedges)
Definition: lwgeom_topo.c:2770
static LWT_ISO_FACE * lwt_be_getFaceById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:232
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:43
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:471
LWT_ELEMID edge_id
const LWT_BE_IFACE * be_iface

References _lwt_FaceByEdges(), _lwt_release_edges(), LWT_TOPOLOGY_T::be_iface, 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_be_lastErrorMessage(), 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, and LWT_TOPOLOGY_T::srid.

Referenced by lwt_AddPolygon().

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