4122 if (PG_ARGISNULL(0))
4128 elog(ERROR,
"RASTER_colorMap: Could not initialize argument structure");
4133 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
4139 PG_FREE_IF_COPY(pgraster, 0);
4140 elog(ERROR,
"RASTER_colorMap: Could not deserialize raster");
4145 if (!PG_ARGISNULL(1))
4146 arg->
nband = PG_GETARG_INT32(1);
4151 elog(NOTICE,
"Raster does not have band at index %d. Returning empty raster", arg->
nband);
4154 if (raster == NULL) {
4156 PG_FREE_IF_COPY(pgraster, 0);
4157 elog(ERROR,
"RASTER_colorMap: Could not create empty raster");
4162 PG_FREE_IF_COPY(pgraster, 0);
4166 if (pgraster == NULL)
4170 PG_RETURN_POINTER(pgraster);
4175 if (arg->
band == NULL) {
4178 PG_FREE_IF_COPY(pgraster, 0);
4179 elog(ERROR,
"RASTER_colorMap: Could not get band at index %d", nband);
4184 if (!PG_ARGISNULL(3)) {
4185 char *method = NULL;
4186 char *tmp = text_to_cstring(PG_GETARG_TEXT_P(3));
4193 if (strcmp(method,
"INTERPOLATE") == 0)
4195 else if (strcmp(method,
"EXACT") == 0)
4197 else if (strcmp(method,
"NEAREST") == 0)
4200 elog(NOTICE,
"Unknown value provided for method. Defaulting to INTERPOLATE");
4210 if (PG_ARGISNULL(2)) {
4212 PG_FREE_IF_COPY(pgraster, 0);
4213 elog(ERROR,
"RASTER_colorMap: Value must be provided for colormap");
4218 char *colormap = text_to_cstring(PG_GETARG_TEXT_P(2));
4227 if (!strlen(colormap)) {
4229 PG_FREE_IF_COPY(pgraster, 0);
4230 elog(ERROR,
"RASTER_colorMap: Value must be provided for colormap");
4238 PG_FREE_IF_COPY(pgraster, 0);
4239 elog(ERROR,
"RASTER_colorMap: Could not process the value provided for colormap");
4247 PG_FREE_IF_COPY(pgraster, 0);
4248 elog(ERROR,
"RASTER_colorMap: Could not allocate memory for colormap entries");
4254 for (i = 0; i < arg->
nentry; i++) {
4268 if (!strlen(_entry)) {
4278 PG_FREE_IF_COPY(pgraster, 0);
4279 elog(ERROR,
"RASTER_colorMap: Could not process colormap entry %d", i + 1);
4283 elog(NOTICE,
"More than five elements in colormap entry %d. Using at most five elements", i + 1);
4292 for (j = 0; j < arg->
nelement; j++) {
4301 char *percent = NULL;
4305 strcmp(_element,
"NV") == 0 ||
4306 strcmp(_element,
"NULL") == 0 ||
4307 strcmp(_element,
"NODATA") == 0
4312 elog(NOTICE,
"More than one NODATA entry found. Using only the first one");
4321 else if ((percent = strchr(_element,
'%')) != NULL) {
4333 PG_FREE_IF_COPY(pgraster, 0);
4334 elog(ERROR,
"RASTER_colorMap: Could not get band's summary stats to process percentages");
4340 tmp = palloc(
sizeof(
char) * (percent - _element + 1));
4344 PG_FREE_IF_COPY(pgraster, 0);
4345 elog(ERROR,
"RASTER_colorMap: Could not allocate memory for value of percentage");
4349 memcpy(tmp, _element, percent - _element);
4350 tmp[percent - _element] =
'\0';
4355 value = strtod(tmp, NULL);
4357 if (errno != 0 || _element == junk) {
4360 PG_FREE_IF_COPY(pgraster, 0);
4361 elog(ERROR,
"RASTER_colorMap: Could not process percent string to value");
4367 elog(NOTICE,
"Percentage values cannot be less than zero. Defaulting to zero");
4370 else if (value > 100.) {
4371 elog(NOTICE,
"Percentage values cannot be greater than 100. Defaulting to 100");
4383 if (errno != 0 || _element == junk) {
4386 PG_FREE_IF_COPY(pgraster, 0);
4387 elog(ERROR,
"RASTER_colorMap: Could not process string to value");
4398 value = (int) strtod(_element, &junk);
4399 if (errno != 0 || _element == junk) {
4402 PG_FREE_IF_COPY(pgraster, 0);
4403 elog(ERROR,
"RASTER_colorMap: Could not process string to value");
4408 elog(NOTICE,
"RGBA value cannot be greater than 255. Defaulting to 255");
4411 else if (value < 0) {
4412 elog(NOTICE,
"RGBA value cannot be less than zero. Defaulting to zero");
4421 POSTGIS_RT_DEBUGF(4,
"colormap->entry[%d] (isnodata, value, R, G, B, A) = (%d, %f, %d, %d, %d, %d)",
4440 if (raster == NULL) {
4442 PG_FREE_IF_COPY(pgraster, 0);
4443 elog(ERROR,
"RASTER_colorMap: Could not create new raster with applied colormap");
4448 PG_FREE_IF_COPY(pgraster, 0);
4454 if (pgraster == NULL)
4458 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)