4072 if (PG_ARGISNULL(0))
4078 elog(ERROR,
"RASTER_colorMap: Could not initialize argument structure");
4083 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4089 PG_FREE_IF_COPY(pgraster, 0);
4090 elog(ERROR,
"RASTER_colorMap: Could not deserialize raster");
4095 if (!PG_ARGISNULL(1))
4096 arg->
nband = PG_GETARG_INT32(1);
4101 elog(NOTICE,
"Raster does not have band at index %d. Returning empty raster", arg->
nband);
4104 if (raster == NULL) {
4106 PG_FREE_IF_COPY(pgraster, 0);
4107 elog(ERROR,
"RASTER_colorMap: Could not create empty raster");
4112 PG_FREE_IF_COPY(pgraster, 0);
4116 if (pgraster == NULL)
4120 PG_RETURN_POINTER(pgraster);
4125 if (arg->
band == NULL) {
4128 PG_FREE_IF_COPY(pgraster, 0);
4129 elog(ERROR,
"RASTER_colorMap: Could not get band at index %d", nband);
4134 if (!PG_ARGISNULL(3)) {
4135 char *method = NULL;
4136 char *tmp = text_to_cstring(PG_GETARG_TEXT_P(3));
4143 if (strcmp(method,
"INTERPOLATE") == 0)
4145 else if (strcmp(method,
"EXACT") == 0)
4147 else if (strcmp(method,
"NEAREST") == 0)
4150 elog(NOTICE,
"Unknown value provided for method. Defaulting to INTERPOLATE");
4160 if (PG_ARGISNULL(2)) {
4162 PG_FREE_IF_COPY(pgraster, 0);
4163 elog(ERROR,
"RASTER_colorMap: Value must be provided for colormap");
4168 char *colormap = text_to_cstring(PG_GETARG_TEXT_P(2));
4177 if (!strlen(colormap)) {
4179 PG_FREE_IF_COPY(pgraster, 0);
4180 elog(ERROR,
"RASTER_colorMap: Value must be provided for colormap");
4188 PG_FREE_IF_COPY(pgraster, 0);
4189 elog(ERROR,
"RASTER_colorMap: Could not process the value provided for colormap");
4197 PG_FREE_IF_COPY(pgraster, 0);
4198 elog(ERROR,
"RASTER_colorMap: Could not allocate memory for colormap entries");
4204 for (i = 0; i < arg->
nentry; i++) {
4218 if (!strlen(_entry)) {
4228 PG_FREE_IF_COPY(pgraster, 0);
4229 elog(ERROR,
"RASTER_colorMap: Could not process colormap entry %d", i + 1);
4233 elog(NOTICE,
"More than five elements in colormap entry %d. Using at most five elements", i + 1);
4242 for (j = 0; j < arg->
nelement; j++) {
4251 char *percent = NULL;
4255 strcmp(_element,
"NV") == 0 ||
4256 strcmp(_element,
"NULL") == 0 ||
4257 strcmp(_element,
"NODATA") == 0
4262 elog(NOTICE,
"More than one NODATA entry found. Using only the first one");
4271 else if ((percent = strchr(_element,
'%')) != NULL) {
4283 PG_FREE_IF_COPY(pgraster, 0);
4284 elog(ERROR,
"RASTER_colorMap: Could not get band's summary stats to process percentages");
4290 tmp = palloc(
sizeof(
char) * (percent - _element + 1));
4294 PG_FREE_IF_COPY(pgraster, 0);
4295 elog(ERROR,
"RASTER_colorMap: Could not allocate memory for value of percentage");
4299 memcpy(tmp, _element, percent - _element);
4300 tmp[percent - _element] =
'\0';
4305 value = strtod(tmp, NULL);
4307 if (errno != 0 || _element == junk) {
4310 PG_FREE_IF_COPY(pgraster, 0);
4311 elog(ERROR,
"RASTER_colorMap: Could not process percent string to value");
4317 elog(NOTICE,
"Percentage values cannot be less than zero. Defaulting to zero");
4320 else if (value > 100.) {
4321 elog(NOTICE,
"Percentage values cannot be greater than 100. Defaulting to 100");
4333 if (errno != 0 || _element == junk) {
4336 PG_FREE_IF_COPY(pgraster, 0);
4337 elog(ERROR,
"RASTER_colorMap: Could not process string to value");
4348 value = (int) strtod(_element, &junk);
4349 if (errno != 0 || _element == junk) {
4352 PG_FREE_IF_COPY(pgraster, 0);
4353 elog(ERROR,
"RASTER_colorMap: Could not process string to value");
4358 elog(NOTICE,
"RGBA value cannot be greater than 255. Defaulting to 255");
4361 else if (value < 0) {
4362 elog(NOTICE,
"RGBA value cannot be less than zero. Defaulting to zero");
4371 POSTGIS_RT_DEBUGF(4,
"colormap->entry[%d] (isnodata, value, R, G, B, A) = (%d, %f, %d, %d, %d, %d)",
4390 if (raster == NULL) {
4392 PG_FREE_IF_COPY(pgraster, 0);
4393 elog(ERROR,
"RASTER_colorMap: Could not create new raster with applied colormap");
4398 PG_FREE_IF_COPY(pgraster, 0);
4404 if (pgraster == NULL)
4408 PG_RETURN_POINTER(pgraster);
char ** rtpg_strsplit(const char *str, const char *delimiter, int *n)
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
char * rtpg_strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
static void rtpg_colormap_arg_destroy(rtpg_colormap_arg arg)
#define POSTGIS_RT_DEBUGF(level, msg,...)
enum rt_colormap_t::@7 method
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
char * rtpg_trim(const char *input)
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
static rtpg_colormap_arg rtpg_colormap_arg_init()
void rt_raster_destroy(rt_raster raster)
Release memory associated to a 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.
#define POSTGIS_RT_DEBUG(level, msg)
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...
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
char * rtpg_strtoupper(char *str)