54{
60 int32_t srid;
61 bool use_spheroid = true;
63
64
65 g = PG_GETARG_GSERIALIZED_P(0);
67
68 if (g == NULL)
69 {
70 PG_RETURN_NULL();
71 }
72
74
75
77 {
80 g_out = geography_serialize(lwgeom_out);
81 PG_RETURN_POINTER(g_out);
82 }
83
84
85 spheroid_init_from_srid(srid, &
s);
86
87
88 use_spheroid = PG_GETARG_BOOL(1);
89 if ( ! use_spheroid )
91
93 {
94
96 {
97
98 PG_RETURN_POINTER(g);
99 break;
100 }
101
103 {
105
106
107 uint32_t size = mpoints->
ngeoms;
109
110 uint32_t i;
111 for (i = 0; i < size; i++) {
115 }
116
118 pfree(points);
119 break;
120 }
121
123 {
125
126
129
132 break;
133 }
134
136 {
139 break;
140 }
141
143 {
145
146
149
152 break;
153 }
154
156 {
159 break;
160 }
161 default:
162 elog(ERROR, "ST_Centroid(geography) unhandled geography type");
163 PG_RETURN_NULL();
164 }
165
166 PG_FREE_IF_COPY(g, 0);
167
169 g_out = geography_serialize(lwgeom_out);
170
171 PG_RETURN_POINTER(g_out);
172}
LWPOINT * geography_centroid_from_mpoly(const LWMPOLY *mpoly, bool use_spheroid, SPHEROID *s)
Split polygons into triangles and use centroid of the triangle with the triangle area as weight to ca...
LWPOINT * geography_centroid_from_mline(const LWMLINE *mline, SPHEROID *s)
Split lines into segments and calculate with middle of segment as weighted point.
LWPOINT * geography_centroid_from_wpoints(const int32_t srid, const POINT3DM *points, const uint32_t size)
Convert lat-lon-points to x-y-z-coordinates, calculate a weighted average point and return lat-lon-co...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
LWMPOLY * lwmpoly_construct_empty(int32_t srid, char hasz, char hasm)
LWMLINE * lwmline_construct_empty(int32_t srid, char hasz, char hasm)
void lwmpoly_free(LWMPOLY *mpoly)
double lwpoint_get_x(const LWPOINT *point)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
void lwmline_free(LWMLINE *mline)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
double lwpoint_get_y(const LWPOINT *point)
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.