4019 uint32_t bandnum = 0, numbands = 0;
4020 ArrayType *arraysrc, *arraydst;
4021 bool hasnodata =
false;
4022 double nodataval = 0.0;
4023 text *pixeltype = NULL;
4024 uint32_t szsrc, szdst;
4025 ArrayIterator itersrc, iterdst;
4027 bool nullsrc, nulldst;
4032 if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3) || PG_ARGISNULL(4))
4036 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4037 arraysrc = PG_GETARG_ARRAYTYPE_P(1);
4038 arraydst = PG_GETARG_ARRAYTYPE_P(2);
4039 bandnum = PG_GETARG_INT32(3);
4040 pixeltype = PG_GETARG_TEXT_P(4);
4041 if (!PG_ARGISNULL(5)) {
4043 nodataval = PG_GETARG_FLOAT8(5);
4047 szsrc = ArrayGetNItems(ARR_NDIM(arraysrc), ARR_DIMS(arraysrc));
4048 szdst = ArrayGetNItems(ARR_NDIM(arraydst), ARR_DIMS(arraydst));
4050 elog(ERROR,
"array lengths must be the same");
4055 PG_FREE_IF_COPY(pgraster, 0);
4056 elog(ERROR,
"%s: Could not deserialize raster", __func__);
4062 elog(ERROR,
"Raster has no bands");
4063 if (bandnum < 1 || bandnum > numbands)
4064 elog(ERROR,
"Invalid band index %d, input raster has %d bands. Band indexes are one-based.",
4070 elog(ERROR,
"Could not find raster band of index %d", bandnum);
4077 elog(ERROR,
"Unknown output pixel type '%s'", text_to_cstring(pixeltype));
4081 elog(ERROR,
"Unsupported pixtype");
4085 reclassmap->
count = 0;
4086 reclassmap->
srctype = pixtypsrc;
4087 reclassmap->
dsttype = pixtypdst;
4094 itersrc = array_create_iterator(arraysrc, 0, NULL);
4095 iterdst = array_create_iterator(arraydst, 0, NULL);
4096 while(array_iterate(itersrc, &dsrc, &nullsrc) &&
4097 array_iterate(iterdst, &ddst, &nulldst))
4099 double valsrc = nullsrc ? nodataval : (double)DatumGetFloat8(dsrc);
4100 double valdst = nulldst ? nodataval : (double)DatumGetFloat8(ddst);
4101 Assert(szdst > reclassmap->
count);
4104 reclassmap->
count++;
4106 array_free_iterator(itersrc);
4107 array_free_iterator(iterdst);
4112 pfree(reclassmap->
pairs);
4115 elog(ERROR,
"Band reclassification failed");
4121 PG_FREE_IF_COPY(pgraster, 0);
4122 elog(ERROR,
"Could not replace raster band of index %d with reclassified band", bandnum);
4127 PG_FREE_IF_COPY(pgraster, 0);
4131 SET_VARSIZE(pgrtn, pgrtn->
size);
4132 PG_RETURN_POINTER(pgrtn);
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index)
Replace band at provided index with new band.
void rt_band_destroy(rt_band band)
Destroy a raster band.
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_band rt_band_reclass_exact(rt_band srcband, rt_reclassmap map, uint32_t hasnodata, double nodataval)
Returns new band with values reclassified.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
struct rt_classpair_t * pairs