659{
662 int num_bands = 0;
664 int err;
667
668
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
682 if (num_bands < 1) {
683 elog(NOTICE, "Raster provided has no bands");
685 PG_FREE_IF_COPY(pgraster, 0);
686 PG_RETURN_NULL();
687 }
688
689
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");
695 PG_FREE_IF_COPY(pgraster, 0);
696 PG_RETURN_NULL();
697 }
698
699
702 PG_FREE_IF_COPY(pgraster, 0);
703
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
715
716 PG_RETURN_POINTER(rtn);
717}
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): ...
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)