PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_convex_hull ( PG_FUNCTION_ARGS  )

Definition at line 1275 of file rt_pg.c.

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.

1276 {
1277  rt_pgraster *pgraster;
1278  rt_raster raster;
1279  LWGEOM *geom = NULL;
1280  GSERIALIZED* gser = NULL;
1281  size_t gser_size;
1282  int err = ES_NONE;
1283 
1284  bool minhull = FALSE;
1285 
1286  if (PG_ARGISNULL(0))
1287  PG_RETURN_NULL();
1288 
1289  /* # of args */
1290  if (PG_NARGS() > 1)
1291  minhull = TRUE;
1292 
1293  if (!minhull) {
1294  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
1295  raster = rt_raster_deserialize(pgraster, TRUE);
1296  }
1297  else {
1298  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1299  raster = rt_raster_deserialize(pgraster, FALSE);
1300  }
1301 
1302  if (!raster) {
1303  PG_FREE_IF_COPY(pgraster, 0);
1304  elog(ERROR, "RASTER_convex_hull: Could not deserialize raster");
1305  PG_RETURN_NULL();
1306  }
1307 
1308  if (!minhull)
1309  err = rt_raster_get_convex_hull(raster, &geom);
1310  else {
1311  int nband = -1;
1312 
1313  /* get arg 1 */
1314  if (!PG_ARGISNULL(1)) {
1315  nband = PG_GETARG_INT32(1);
1316  if (!rt_raster_has_band(raster, nband - 1)) {
1317  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
1318  rt_raster_destroy(raster);
1319  PG_FREE_IF_COPY(pgraster, 0);
1320  PG_RETURN_NULL();
1321  }
1322  nband = nband - 1;
1323  }
1324 
1325  err = rt_raster_get_perimeter(raster, nband, &geom);
1326  }
1327 
1328  rt_raster_destroy(raster);
1329  PG_FREE_IF_COPY(pgraster, 0);
1330 
1331  if (err != ES_NONE) {
1332  elog(ERROR, "RASTER_convex_hull: Could not get raster's convex hull");
1333  PG_RETURN_NULL();
1334  }
1335  else if (geom == NULL) {
1336  elog(NOTICE, "Raster's convex hull is NULL");
1337  PG_RETURN_NULL();
1338  }
1339 
1340  gser = gserialized_from_lwgeom(geom, 0, &gser_size);
1341  lwgeom_free(geom);
1342 
1343  SET_VARSIZE(gser, gser_size);
1344  PG_RETURN_POINTER(gser);
1345 }
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_api.c:8563
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_api.c:14683
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
tuple nband
Definition: pixval.py:52
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:908
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_api.c:6556
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function: