PostGIS 3.6.2dev-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 2841 of file lwgeom_topo.c.

2842{
2843 uint64_t numfaceedges;
2844 LWT_ISO_EDGE *edges;
2845 LWT_ISO_FACE *face;
2846 LWPOLY *out;
2847 LWGEOM *outg;
2848 uint64_t i, edgeid;
2849 int fields;
2850
2851 if (faceid == 0)
2852 {
2853 lwerror("SQL/MM Spatial exception - universal face has no geometry");
2854 return NULL;
2855 }
2856
2857 /* Construct the face geometry */
2858 numfaceedges = 1;
2859 fields = LWT_COL_EDGE_GEOM |
2863 ;
2864 edges = lwt_be_getEdgeByFace( topo, &faceid, &numfaceedges, fields, NULL );
2865 if (numfaceedges == UINT64_MAX)
2866 {
2868 return NULL;
2869 }
2870 LWDEBUGF(1, "lwt_GetFaceGeometry: lwt_be_getEdgeByFace returned %llu edges", numfaceedges);
2871
2872 if ( numfaceedges == 0 )
2873 {
2874 i = 1;
2875 face = lwt_be_getFaceById(topo, &faceid, &i, LWT_COL_FACE_FACE_ID);
2876 if (i == UINT64_MAX)
2877 {
2879 return NULL;
2880 }
2881 if ( i == 0 ) {
2882 lwerror("SQL/MM Spatial exception - non-existent face.");
2883 return NULL;
2884 }
2885 lwfree( face );
2886 if ( i > 1 ) {
2887 lwerror("Corrupted topology: multiple face records have face_id=%"
2888 LWTFMT_ELEMID, faceid);
2889 return NULL;
2890 }
2891 /* Face has no boundary edges, we'll return EMPTY, see
2892 * https://trac.osgeo.org/postgis/ticket/3221 */
2893 lwnotice("Corrupted topology: face %"
2894 LWTFMT_ELEMID " has no associated edges.", faceid);
2895 out = lwpoly_construct_empty(topo->srid, topo->hasZ, 0);
2896 return lwpoly_as_lwgeom(out);
2897 }
2898 edgeid = edges[0].edge_id;
2899
2900 outg = _lwt_FaceByEdges( topo, edges, numfaceedges );
2901 _lwt_release_edges(edges, numfaceedges);
2902
2903 if ( ! outg )
2904 {
2905 /* Face did have edges but no polygon could be constructed
2906 * with that material, sounds like a corrupted topology..
2907 *
2908 * We'll return EMPTY, see
2909 * https://trac.osgeo.org/postgis/ticket/3221 */
2910 lwnotice("Corrupted topology: face %"
2911 LWTFMT_ELEMID " could not be constructed only from edges "
2912 "knowing about it (like edge %" LWTFMT_ELEMID ").",
2913 faceid, edgeid);
2914 out = lwpoly_construct_empty(topo->srid, topo->hasZ, 0);
2915 return lwpoly_as_lwgeom(out);
2916 }
2917
2918 return outg;
2919}
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:329
#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: