PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwgeom_centroid()

LWGEOM* lwgeom_centroid ( const LWGEOM geom)

Definition at line 801 of file liblwgeom/lwgeom_geos.c.

References LWGEOM::flags, FLAGS_GET_Z, geos_clean(), geos_clean_and_fail(), get_result_srid(), input_lwgeom_to_geos(), lwgeom_geos_error(), lwgeom_has_m(), lwgeom_is_empty(), lwnotice(), lwpoint_as_lwgeom(), lwpoint_construct_empty(), output_geos_as_lwgeom(), and SRID_INVALID.

Referenced by lwgeom_cluster_2d_kmeans().

802 {
803  LWGEOM* result;
804  int32_t srid = get_result_srid(geom, NULL, __func__);
805  uint8_t is3d = FLAGS_GET_Z(geom->flags);
806  GEOSGeometry *g1, *g3;
808  if (srid == SRID_INVALID) return NULL;
810  if (lwgeom_is_empty(geom))
811  {
812  LWPOINT* lwp = lwpoint_construct_empty(srid, is3d, lwgeom_has_m(geom));
813  return lwpoint_as_lwgeom(lwp);
814  }
816  initGEOS(lwnotice, lwgeom_geos_error);
818  if (!input_lwgeom_to_geos(&g1, geom, __func__)) return NULL;
820  g3 = GEOSGetCentroid(g1);
822  if (!g3) return geos_clean_and_fail(g1, NULL, NULL, __func__);
824  if (!output_geos_as_lwgeom(&g3, &result, srid, is3d, __func__))
825  return geos_clean_and_fail(g1, NULL, g3, __func__);
827  geos_clean(g1, NULL, g3);
829  return result;
830 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:399
static LWGEOM * geos_clean_and_fail(GEOSGeometry *g1, GEOSGeometry *g2, GEOSGeometry *g3, const char *funcname)
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
static uint8_t output_geos_as_lwgeom(GEOSGeometry **g, LWGEOM **geom, const int32_t srid, const uint8_t is3d, const char *funcname)
void lwgeom_geos_error(const char *fmt,...)
static void geos_clean(GEOSGeometry *g1, GEOSGeometry *g2, GEOSGeometry *g3)
Definition: liblwgeom.h:191
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
static uint8_t input_lwgeom_to_geos(GEOSGeometry **g, const LWGEOM *geom, const char *funcname)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
static int32_t get_result_srid(const LWGEOM *geom1, const LWGEOM *geom2, const char *funcname)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1393
unsigned char uint8_t
Definition: uthash.h:79
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
Here is the call graph for this function:
Here is the caller graph for this function: