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

Definition at line 4565 of file rt_pg.c.

References ES_NONE, FALSE, geometry_serialize(), lwmpoly_as_lwgeom(), lwmpoly_free(), pixval::nband, rtrowdump::raster, rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), and rt_raster_surface().

4566 {
4567  rt_pgraster *pgraster = NULL;
4568  rt_raster raster = NULL;
4569  int num_bands = 0;
4570  int nband = 1;
4571  int err;
4572  LWMPOLY *surface = NULL;
4573  GSERIALIZED *rtn = NULL;
4574 
4575  /* raster */
4576  if (PG_ARGISNULL(0))
4577  PG_RETURN_NULL();
4578  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4579 
4580  raster = rt_raster_deserialize(pgraster, FALSE);
4581  if (!raster) {
4582  PG_FREE_IF_COPY(pgraster, 0);
4583  elog(ERROR, "RASTER_getPolygon: Could not deserialize raster");
4584  PG_RETURN_NULL();
4585  }
4586 
4587  /* num_bands */
4588  num_bands = rt_raster_get_num_bands(raster);
4589  if (num_bands < 1) {
4590  elog(NOTICE, "Raster provided has no bands");
4591  rt_raster_destroy(raster);
4592  PG_FREE_IF_COPY(pgraster, 0);
4593  PG_RETURN_NULL();
4594  }
4595 
4596  /* band index is 1-based */
4597  if (!PG_ARGISNULL(1))
4598  nband = PG_GETARG_INT32(1);
4599  if (nband < 1 || nband > num_bands) {
4600  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
4601  rt_raster_destroy(raster);
4602  PG_FREE_IF_COPY(pgraster, 0);
4603  PG_RETURN_NULL();
4604  }
4605 
4606  /* get band surface */
4607  err = rt_raster_surface(raster, nband - 1, &surface);
4608  rt_raster_destroy(raster);
4609  PG_FREE_IF_COPY(pgraster, 0);
4610 
4611  if (err != ES_NONE) {
4612  elog(ERROR, "RASTER_getPolygon: Could not get raster band's surface");
4613  PG_RETURN_NULL();
4614  }
4615  else if (surface == NULL) {
4616  elog(NOTICE, "Raster is empty or all pixels of band are NODATA. Returning NULL");
4617  PG_RETURN_NULL();
4618  }
4619 
4620  rtn = geometry_serialize(lwmpoly_as_lwgeom(surface));
4621  lwmpoly_free(surface);
4622 
4623  PG_RETURN_POINTER(rtn);
4624 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:40
tuple nband
Definition: pixval.py:52
#define FALSE
Definition: dbfopen.c:169
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_api.c:13242
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
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:204

Here is the call graph for this function: