PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_convex_hull()

Datum RASTER_convex_hull ( PG_FUNCTION_ARGS  )

Definition at line 119 of file rtpg_geometry.c.

120 {
121  rt_pgraster *pgraster;
123  LWGEOM *geom = NULL;
124  GSERIALIZED* gser = NULL;
125  size_t gser_size;
126  int err = ES_NONE;
127 
128  bool minhull = FALSE;
129 
130  if (PG_ARGISNULL(0))
131  PG_RETURN_NULL();
132 
133  /* # of args */
134  if (PG_NARGS() > 1)
135  minhull = TRUE;
136 
137  if (!minhull) {
138  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
139  raster = rt_raster_deserialize(pgraster, TRUE);
140  }
141  else {
142  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
143  raster = rt_raster_deserialize(pgraster, FALSE);
144  }
145 
146  if (!raster) {
147  PG_FREE_IF_COPY(pgraster, 0);
148  elog(ERROR, "RASTER_convex_hull: Could not deserialize raster");
149  PG_RETURN_NULL();
150  }
151 
152  if (!minhull)
153  err = rt_raster_get_convex_hull(raster, &geom);
154  else {
155  int nband = -1;
156 
157  /* get arg 1 */
158  if (!PG_ARGISNULL(1)) {
159  nband = PG_GETARG_INT32(1);
160  if (!rt_raster_has_band(raster, nband - 1)) {
161  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
163  PG_FREE_IF_COPY(pgraster, 0);
164  PG_RETURN_NULL();
165  }
166  nband = nband - 1;
167  }
168 
169  err = rt_raster_get_perimeter(raster, nband, &geom);
170  }
171 
173  PG_FREE_IF_COPY(pgraster, 0);
174 
175  if (err != ES_NONE) {
176  elog(ERROR, "RASTER_convex_hull: Could not get raster's convex hull");
177  PG_RETURN_NULL();
178  }
179  else if (geom == NULL) {
180  elog(NOTICE, "Raster's convex hull is NULL");
181  PG_RETURN_NULL();
182  }
183 
184  gser = gserialized_from_lwgeom(geom, &gser_size);
185  lwgeom_free(geom);
186 
187  SET_VARSIZE(gser, gser_size);
188  PG_RETURN_POINTER(gser);
189 }
#define TRUE
Definition: dbfopen.c:169
#define FALSE
Definition: dbfopen.c:168
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_raster.c:1347
@ ES_NONE
Definition: librtcore.h:180
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_geometry.c:803
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_geometry.c:182
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
nband
Definition: pixval.py:52
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
Struct definitions.
Definition: librtcore.h:2250

References ES_NONE, FALSE, gserialized_from_lwgeom(), lwgeom_free(), pixval::nband, rtrowdump::raster, rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_convex_hull(), rt_raster_get_perimeter(), rt_raster_has_band(), and TRUE.

Here is the call graph for this function: