4073 if (PG_ARGISNULL(0))
4079 elog(ERROR,
"RASTER_colorMap: Could not initialize argument structure");
4084 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4090 PG_FREE_IF_COPY(pgraster, 0);
4091 elog(ERROR,
"RASTER_colorMap: Could not deserialize raster");
4096 if (!PG_ARGISNULL(1))
4097 arg->
nband = PG_GETARG_INT32(1);
4102 elog(NOTICE,
"Raster does not have band at index %d. Returning empty raster", arg->
nband);
4107 PG_FREE_IF_COPY(pgraster, 0);
4108 elog(ERROR,
"RASTER_colorMap: Could not create empty raster");
4113 PG_FREE_IF_COPY(pgraster, 0);
4117 if (pgraster == NULL)
4120 SET_VARSIZE(pgraster, ((
rt_pgraster*) pgraster)->size);
4121 PG_RETURN_POINTER(pgraster);
4126 if (arg->
band == NULL) {
4129 PG_FREE_IF_COPY(pgraster, 0);
4130 elog(ERROR,
"RASTER_colorMap: Could not get band at index %d",
nband);
4135 if (!PG_ARGISNULL(3)) {
4136 char *method = NULL;
4137 char *tmp = text_to_cstring(PG_GETARG_TEXT_P(3));
4144 if (strcmp(method,
"INTERPOLATE") == 0)
4146 else if (strcmp(method,
"EXACT") == 0)
4148 else if (strcmp(method,
"NEAREST") == 0)
4151 elog(NOTICE,
"Unknown value provided for method. Defaulting to INTERPOLATE");
4161 if (PG_ARGISNULL(2)) {
4163 PG_FREE_IF_COPY(pgraster, 0);
4164 elog(ERROR,
"RASTER_colorMap: Value must be provided for colormap");
4169 char *colormap = text_to_cstring(PG_GETARG_TEXT_P(2));
4178 if (!strlen(colormap)) {
4180 PG_FREE_IF_COPY(pgraster, 0);
4181 elog(ERROR,
"RASTER_colorMap: Value must be provided for colormap");
4189 PG_FREE_IF_COPY(pgraster, 0);
4190 elog(ERROR,
"RASTER_colorMap: Could not process the value provided for colormap");
4198 PG_FREE_IF_COPY(pgraster, 0);
4199 elog(ERROR,
"RASTER_colorMap: Could not allocate memory for colormap entries");
4205 for (i = 0; i < arg->
nentry; i++) {
4219 if (!strlen(_entry)) {
4229 PG_FREE_IF_COPY(pgraster, 0);
4230 elog(ERROR,
"RASTER_colorMap: Could not process colormap entry %d", i + 1);
4234 elog(NOTICE,
"More than five elements in colormap entry %d. Using at most five elements", i + 1);
4243 for (j = 0; j < arg->
nelement; j++) {
4252 char *percent = NULL;
4256 strcmp(_element,
"NV") == 0 ||
4257 strcmp(_element,
"NULL") == 0 ||
4258 strcmp(_element,
"NODATA") == 0
4263 elog(NOTICE,
"More than one NODATA entry found. Using only the first one");
4272 else if ((percent = strchr(_element,
'%')) != NULL) {
4284 PG_FREE_IF_COPY(pgraster, 0);
4285 elog(ERROR,
"RASTER_colorMap: Could not get band's summary stats to process percentages");
4291 tmp = palloc(
sizeof(
char) * (percent - _element + 1));
4295 PG_FREE_IF_COPY(pgraster, 0);
4296 elog(ERROR,
"RASTER_colorMap: Could not allocate memory for value of percentage");
4300 memcpy(tmp, _element, percent - _element);
4301 tmp[percent - _element] =
'\0';
4306 value = strtod(tmp, NULL);
4308 if (errno != 0 || _element == junk) {
4311 PG_FREE_IF_COPY(pgraster, 0);
4312 elog(ERROR,
"RASTER_colorMap: Could not process percent string to value");
4318 elog(NOTICE,
"Percentage values cannot be less than zero. Defaulting to zero");
4321 else if (
value > 100.) {
4322 elog(NOTICE,
"Percentage values cannot be greater than 100. Defaulting to 100");
4334 if (errno != 0 || _element == junk) {
4337 PG_FREE_IF_COPY(pgraster, 0);
4338 elog(ERROR,
"RASTER_colorMap: Could not process string to value");
4349 value = (int) strtod(_element, &junk);
4350 if (errno != 0 || _element == junk) {
4353 PG_FREE_IF_COPY(pgraster, 0);
4354 elog(ERROR,
"RASTER_colorMap: Could not process string to value");
4359 elog(NOTICE,
"RGBA value cannot be greater than 255. Defaulting to 255");
4362 else if (
value < 0) {
4363 elog(NOTICE,
"RGBA value cannot be less than zero. Defaulting to zero");
4372 POSTGIS_RT_DEBUGF(4,
"colormap->entry[%d] (isnodata, value, R, G, B, A) = (%d, %f, %d, %d, %d, %d)",
4393 PG_FREE_IF_COPY(pgraster, 0);
4394 elog(ERROR,
"RASTER_colorMap: Could not create new raster with applied colormap");
4399 PG_FREE_IF_COPY(pgraster, 0);
4405 if (pgraster == NULL)
4408 SET_VARSIZE(pgraster, ((
rt_pgraster*) pgraster)->size);
4409 PG_RETURN_POINTER(pgraster);
rt_raster rt_raster_colormap(rt_raster raster, int nband, rt_colormap colormap)
Returns a new raster with up to four 8BUI bands (RGBA) from applying a colormap to the user-specified...
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ)
Compute summary statistics for a 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): ...
char * rtpg_strtoupper(char *str)
char * rtpg_trim(const char *input)
char ** rtpg_strsplit(const char *str, const char *delimiter, uint32_t *n)
char * rtpg_strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
static void rtpg_colormap_arg_destroy(rtpg_colormap_arg arg)
static rtpg_colormap_arg rtpg_colormap_arg_init()
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)
enum rt_colormap_t::@12 method