PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_getPolygon()

Datum RASTER_getPolygon ( PG_FUNCTION_ARGS  )

Definition at line 658 of file rtpg_geometry.c.

659{
660 rt_pgraster *pgraster = NULL;
661 rt_raster raster = NULL;
662 int num_bands = 0;
663 int nband = 1;
664 int err;
665 LWMPOLY *surface = NULL;
666 GSERIALIZED *rtn = NULL;
667
668 /* raster */
669 if (PG_ARGISNULL(0))
670 PG_RETURN_NULL();
671 pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
672
674 if (!raster) {
675 PG_FREE_IF_COPY(pgraster, 0);
676 elog(ERROR, "RASTER_getPolygon: Could not deserialize raster");
677 PG_RETURN_NULL();
678 }
679
680 /* num_bands */
681 num_bands = rt_raster_get_num_bands(raster);
682 if (num_bands < 1) {
683 elog(NOTICE, "Raster provided has no bands");
684 rt_raster_destroy(raster);
685 PG_FREE_IF_COPY(pgraster, 0);
686 PG_RETURN_NULL();
687 }
688
689 /* band index is 1-based */
690 if (!PG_ARGISNULL(1))
691 nband = PG_GETARG_INT32(1);
692 if (nband < 1 || nband > num_bands) {
693 elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
694 rt_raster_destroy(raster);
695 PG_FREE_IF_COPY(pgraster, 0);
696 PG_RETURN_NULL();
697 }
698
699 /* get band surface */
700 err = rt_raster_surface(raster, nband - 1, &surface);
701 rt_raster_destroy(raster);
702 PG_FREE_IF_COPY(pgraster, 0);
703
704 if (err != ES_NONE) {
705 elog(ERROR, "RASTER_getPolygon: Could not get raster band's surface");
706 PG_RETURN_NULL();
707 }
708 else if (surface == NULL) {
709 elog(NOTICE, "Raster is empty or all pixels of band are NODATA. Returning NULL");
710 PG_RETURN_NULL();
711 }
712
714 lwmpoly_free(surface);
715
716 PG_RETURN_POINTER(rtn);
717}
#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:276
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).
@ 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.
nband
Definition pixval.py:53
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:2251

References ES_NONE, FALSE, geometry_serialize(), lwmpoly_as_lwgeom(), lwmpoly_free(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), and rt_raster_surface().

Here is the call graph for this function: