3527 HeapTupleHeader tup;
3532 text *exprtext = NULL;
3537 char *pixeltype = NULL;
3538 text *pixeltypetext = NULL;
3540 double nodataval = 0;
3541 bool hasnodata =
FALSE;
3543 char **comma_set = NULL;
3545 char **colon_set = NULL;
3547 char **dash_set = NULL;
3553 if (PG_ARGISNULL(0))
3555 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
3560 PG_FREE_IF_COPY(pgraster, 0);
3561 elog(ERROR,
"RASTER_reclass: Could not deserialize raster");
3565 POSTGIS_RT_DEBUGF(3,
"RASTER_reclass: %d possible bands to be reclassified", numBands);
3569 array = PG_GETARG_ARRAYTYPE_P(1);
3570 etype = ARR_ELEMTYPE(array);
3571 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
3573 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
3577 elog(NOTICE,
"Invalid argument for reclassargset. Returning original raster");
3581 PG_FREE_IF_COPY(pgraster, 0);
3585 SET_VARSIZE(pgrtn, pgrtn->
size);
3586 PG_RETURN_POINTER(pgrtn);
3594 for (i = 0; i < n; i++) {
3595 if (nulls[i])
continue;
3598 tup = (HeapTupleHeader) DatumGetPointer(e[i]);
3600 elog(NOTICE,
"Invalid argument for reclassargset. Returning original raster");
3604 PG_FREE_IF_COPY(pgraster, 0);
3608 SET_VARSIZE(pgrtn, pgrtn->
size);
3609 PG_RETURN_POINTER(pgrtn);
3613 tupv = GetAttributeByName(tup,
"nband", &isnull);
3615 elog(NOTICE,
"Invalid argument for reclassargset. Missing value of nband for reclassarg of index %d . Returning original raster", i);
3619 PG_FREE_IF_COPY(pgraster, 0);
3623 SET_VARSIZE(pgrtn, pgrtn->
size);
3624 PG_RETURN_POINTER(pgrtn);
3626 nband = DatumGetInt32(tupv);
3630 if (nband < 1 || nband > numBands) {
3631 elog(NOTICE,
"Invalid argument for reclassargset. Invalid band index (must use 1-based) for reclassarg of index %d . Returning original raster", i);
3635 PG_FREE_IF_COPY(pgraster, 0);
3639 SET_VARSIZE(pgrtn, pgrtn->
size);
3640 PG_RETURN_POINTER(pgrtn);
3644 tupv = GetAttributeByName(tup,
"reclassexpr", &isnull);
3646 elog(NOTICE,
"Invalid argument for reclassargset. Missing value of reclassexpr for reclassarg of index %d . Returning original raster", i);
3650 PG_FREE_IF_COPY(pgraster, 0);
3654 SET_VARSIZE(pgrtn, pgrtn->
size);
3655 PG_RETURN_POINTER(pgrtn);
3657 exprtext = (text *) DatumGetPointer(tupv);
3658 if (NULL == exprtext) {
3659 elog(NOTICE,
"Invalid argument for reclassargset. Missing value of reclassexpr for reclassarg of index %d . Returning original raster", i);
3663 PG_FREE_IF_COPY(pgraster, 0);
3667 SET_VARSIZE(pgrtn, pgrtn->
size);
3668 PG_RETURN_POINTER(pgrtn);
3679 elog(NOTICE,
"Invalid argument for reclassargset. Invalid expression of reclassexpr for reclassarg of index %d . Returning original raster", i);
3683 PG_FREE_IF_COPY(pgraster, 0);
3687 SET_VARSIZE(pgrtn, pgrtn->
size);
3688 PG_RETURN_POINTER(pgrtn);
3695 for (a = 0, j = 0; a < comma_n; a++) {
3701 elog(NOTICE,
"Invalid argument for reclassargset. Invalid expression of reclassexpr for reclassarg of index %d . Returning original raster", i);
3702 for (k = 0; k < j; k++) pfree(exprset[k]);
3707 PG_FREE_IF_COPY(pgraster, 0);
3711 SET_VARSIZE(pgrtn, pgrtn->
size);
3712 PG_RETURN_POINTER(pgrtn);
3718 for (b = 0; b < colon_n; b++) {
3723 if (dash_n < 1 || dash_n > 3) {
3724 elog(NOTICE,
"Invalid argument for reclassargset. Invalid expression of reclassexpr for reclassarg of index %d . Returning original raster", i);
3725 for (k = 0; k < j; k++) pfree(exprset[k]);
3730 PG_FREE_IF_COPY(pgraster, 0);
3734 SET_VARSIZE(pgrtn, pgrtn->
size);
3735 PG_RETURN_POINTER(pgrtn);
3738 for (c = 0; c < dash_n; c++) {
3742 strlen(dash_set[c]) == 1 && (
3743 strchr(dash_set[c],
'(') != NULL ||
3744 strchr(dash_set[c],
'[') != NULL ||
3745 strchr(dash_set[c],
')') != NULL ||
3746 strchr(dash_set[c],
']') != NULL
3750 junk = palloc(
sizeof(
char) * (strlen(dash_set[c + 1]) + 2));
3752 for (k = 0; k <= j; k++) pfree(exprset[k]);
3755 PG_FREE_IF_COPY(pgraster, 0);
3757 elog(ERROR,
"RASTER_reclass: Could not allocate memory");
3761 sprintf(junk,
"%s%s", dash_set[c], dash_set[c + 1]);
3763 dash_set[c] = repalloc(dash_set[c],
sizeof(
char) * (strlen(junk) + 1));
3764 strcpy(dash_set[c], junk);
3768 for (dash_it = 1; dash_it < dash_n; dash_it++) {
3769 dash_set[dash_it - 1] = repalloc(dash_set[dash_it - 1], (strlen(dash_set[dash_it]) + 1) *
sizeof(
char));
3770 strcpy(dash_set[dash_it - 1], dash_set[dash_it]);
3774 pfree(dash_set[dash_n]);
3775 dash_set = repalloc(dash_set,
sizeof(
char *) * dash_n);
3779 if (c < 1 && dash_n > 2) {
3780 elog(NOTICE,
"Invalid argument for reclassargset. Invalid expression of reclassexpr for reclassarg of index %d . Returning original raster", i);
3781 for (k = 0; k < j; k++) pfree(exprset[k]);
3786 PG_FREE_IF_COPY(pgraster, 0);
3790 SET_VARSIZE(pgrtn, pgrtn->
size);
3791 PG_RETURN_POINTER(pgrtn);
3802 strchr(dash_set[c],
')') != NULL ||
3803 strchr(dash_set[c],
']') != NULL
3808 else if (strchr(dash_set[c],
'(') != NULL){
3818 strrchr(dash_set[c],
'(') != NULL ||
3819 strrchr(dash_set[c],
'[') != NULL
3824 else if (strrchr(dash_set[c],
']') != NULL) {
3832 POSTGIS_RT_DEBUGF(4,
"RASTER_reclass: exc_val %d inc_val %d", exc_val, inc_val);
3840 val = strtod(dash_set[c], &junk);
3841 if (errno != 0 || dash_set[c] == junk) {
3842 elog(NOTICE,
"Invalid argument for reclassargset. Invalid expression of reclassexpr for reclassarg of index %d . Returning original raster", i);
3843 for (k = 0; k < j; k++) pfree(exprset[k]);
3848 PG_FREE_IF_COPY(pgraster, 0);
3852 SET_VARSIZE(pgrtn, pgrtn->
size);
3853 PG_RETURN_POINTER(pgrtn);
3859 junk = strstr(colon_set[b], dash_set[c]);
3864 "(colon_set[%d], dash_set[%d], junk) = (%s, %s, %s)",
3865 b, c, colon_set[b], dash_set[c], junk
3868 if (junk != colon_set[b]) {
3870 if (*(junk - 1) ==
'-') {
3873 ((junk - 1) == colon_set[b]) ||
3874 (*(junk - 2) ==
'-') ||
3875 (*(junk - 2) ==
'[') ||
3876 (*(junk - 2) ==
'(')
3896 exprset[j]->
src.
min = val;
3902 exprset[j]->
src.
max = val;
3912 exprset[j]->
dst.
min = val;
3915 exprset[j]->
dst.
max = val;
3923 , exprset[j]->src.min
3924 , exprset[j]->src.max
3925 , exprset[j]->dst.min
3926 , exprset[j]->dst.max
3933 tupv = GetAttributeByName(tup,
"pixeltype", &isnull);
3935 elog(NOTICE,
"Invalid argument for reclassargset. Missing value of pixeltype for reclassarg of index %d . Returning original raster", i);
3939 PG_FREE_IF_COPY(pgraster, 0);
3943 SET_VARSIZE(pgrtn, pgrtn->
size);
3944 PG_RETURN_POINTER(pgrtn);
3946 pixeltypetext = (text *) DatumGetPointer(tupv);
3947 if (NULL == pixeltypetext) {
3948 elog(NOTICE,
"Invalid argument for reclassargset. Missing value of pixeltype for reclassarg of index %d . Returning original raster", i);
3952 PG_FREE_IF_COPY(pgraster, 0);
3956 SET_VARSIZE(pgrtn, pgrtn->
size);
3957 PG_RETURN_POINTER(pgrtn);
3964 tupv = GetAttributeByName(tup,
"nodataval", &isnull);
3970 nodataval = DatumGetFloat8(tupv);
3979 elog(NOTICE,
"Could not find raster band of index %d. Returning original raster",
nband);
3980 for (k = 0; k < j; k++) pfree(exprset[k]);
3985 PG_FREE_IF_COPY(pgraster, 0);
3989 SET_VARSIZE(pgrtn, pgrtn->
size);
3990 PG_RETURN_POINTER(pgrtn);
3994 for (k = 0; k < j; k++) pfree(exprset[k]);
3998 PG_FREE_IF_COPY(pgraster, 0);
4000 elog(ERROR,
"RASTER_reclass: Could not reclassify raster band of index %d",
nband);
4006 for (k = 0; k < j; k++) pfree(exprset[k]);
4011 PG_FREE_IF_COPY(pgraster, 0);
4013 elog(ERROR,
"RASTER_reclass: Could not replace raster band of index %d with reclassified band",
nband);
4021 for (k = 0; k < j; k++) pfree(exprset[k]);
4027 PG_FREE_IF_COPY(pgraster, 0);
4033 SET_VARSIZE(pgrtn, pgrtn->
size);
4034 PG_RETURN_POINTER(pgrtn);
rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, rt_reclassexpr *exprset, int exprcount)
Returns new band with values reclassified.
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
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_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): ...
char * text_to_cstring(const text *textptr)
char * rtpg_removespaces(char *str)
char * rtpg_chartrim(const char *input, char *remove)
char * rtpg_strrstr(const char *s1, const char *s2)
char ** rtpg_strsplit(const char *str, const char *delimiter, uint32_t *n)
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst