981{
984 int num_bands = 0;
986 int err;
989
990
991 if (PG_ARGISNULL(0))
992 PG_RETURN_NULL();
993 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
994
996 if (!raster) {
997 PG_FREE_IF_COPY(pgraster, 0);
998 elog(ERROR, "RASTER_getPolygon: Could not deserialize raster");
999 PG_RETURN_NULL();
1000 }
1001
1002
1004 if (num_bands < 1) {
1005 elog(NOTICE, "Raster provided has no bands");
1007 PG_FREE_IF_COPY(pgraster, 0);
1008 PG_RETURN_NULL();
1009 }
1010
1011
1012 if (!PG_ARGISNULL(1))
1013 nband = PG_GETARG_INT32(1);
1014 if (nband < 1 || nband > num_bands) {
1015 elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
1017 PG_FREE_IF_COPY(pgraster, 0);
1018 PG_RETURN_NULL();
1019 }
1020
1021
1024 PG_FREE_IF_COPY(pgraster, 0);
1025
1027 elog(ERROR, "RASTER_getPolygon: Could not get raster band's surface");
1028 PG_RETURN_NULL();
1029 }
1030 else if (surface == NULL) {
1031 elog(NOTICE, "Raster is empty or all pixels of band are NODATA. Returning NULL");
1032 PG_RETURN_NULL();
1033 }
1034
1037
1038 PG_RETURN_POINTER(rtn);
1039}
void lwmpoly_free(LWMPOLY *mpoly)
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...