PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ RASTER_getPolygon()

Datum RASTER_getPolygon ( PG_FUNCTION_ARGS  )

Definition at line 661 of file rtpg_geometry.c.

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

Referenced by RASTER_getPixelPolygons().

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");
687  rt_raster_destroy(raster);
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");
697  rt_raster_destroy(raster);
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);
704  rt_raster_destroy(raster);
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 }
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
nband
Definition: pixval.py:52
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
#define FALSE
Definition: dbfopen.c:168
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Struct definitions.
Definition: librtcore.h:2250
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:285
Here is the call graph for this function:
Here is the caller graph for this function: