PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_getPolygon()

Datum RASTER_getPolygon ( PG_FUNCTION_ARGS  )

Definition at line 661 of file rtpg_geometry.c.

662 {
663  rt_pgraster *pgraster = NULL;
664  rt_raster raster = NULL;
665  int num_bands = 0;
666  int nband = 1;
667  int err;
668  LWMPOLY *surface = NULL;
669  GSERIALIZED *rtn = NULL;
670 
671  /* raster */
672  if (PG_ARGISNULL(0))
673  PG_RETURN_NULL();
674  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
675 
676  raster = rt_raster_deserialize(pgraster, FALSE);
677  if (!raster) {
678  PG_FREE_IF_COPY(pgraster, 0);
679  elog(ERROR, "RASTER_getPolygon: Could not deserialize raster");
680  PG_RETURN_NULL();
681  }
682 
683  /* num_bands */
684  num_bands = rt_raster_get_num_bands(raster);
685  if (num_bands < 1) {
686  elog(NOTICE, "Raster provided has no bands");
688  PG_FREE_IF_COPY(pgraster, 0);
689  PG_RETURN_NULL();
690  }
691 
692  /* band index is 1-based */
693  if (!PG_ARGISNULL(1))
694  nband = PG_GETARG_INT32(1);
695  if (nband < 1 || nband > num_bands) {
696  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
698  PG_FREE_IF_COPY(pgraster, 0);
699  PG_RETURN_NULL();
700  }
701 
702  /* get band surface */
703  err = rt_raster_surface(raster, nband - 1, &surface);
705  PG_FREE_IF_COPY(pgraster, 0);
706 
707  if (err != ES_NONE) {
708  elog(ERROR, "RASTER_getPolygon: Could not get raster band's surface");
709  PG_RETURN_NULL();
710  }
711  else if (surface == NULL) {
712  elog(NOTICE, "Raster is empty or all pixels of band are NODATA. Returning NULL");
713  PG_RETURN_NULL();
714  }
715 
716  rtn = geometry_serialize(lwmpoly_as_lwgeom(surface));
717  lwmpoly_free(surface);
718 
719  PG_RETURN_POINTER(rtn);
720 }
#define FALSE
Definition: dbfopen.c:168
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:285
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
@ ES_NONE
Definition: librtcore.h:180
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
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
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Struct definitions.
Definition: librtcore.h:2250

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().

Here is the call graph for this function: