123{
128 int32_t bandindex;
129 const size_t name_size = 8;
130 size_t size = 0;
131 char *ptr = NULL;
132 text *result = NULL;
133
134
135 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
136 pgraster = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
137
138
139 bandindex = PG_GETARG_INT32(1);
140 if ( bandindex < 1 ) {
141 elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
142 PG_FREE_IF_COPY(pgraster, 0);
143 PG_RETURN_NULL();
144 }
145
147 if ( ! raster ) {
148 PG_FREE_IF_COPY(pgraster, 0);
149 elog(ERROR, "RASTER_getBandPixelTypeName: Could not deserialize raster");
150 PG_RETURN_NULL();
151 }
152
153
155 if ( ! band ) {
156 elog(NOTICE, "Could not find raster band of index %d when getting pixel type name. Returning NULL", bandindex);
158 PG_FREE_IF_COPY(pgraster, 0);
159 PG_RETURN_NULL();
160 }
161
163
164 result = palloc(VARHDRSZ + name_size);
165
166
167
168
169 memset(VARDATA(result), 0, name_size);
170 ptr = (char *)result + VARHDRSZ;
172
173 size = VARHDRSZ + strlen(ptr);
174 SET_VARSIZE(result, size);
175
177 PG_FREE_IF_COPY(pgraster, 0);
178
179 PG_RETURN_TEXT_P(result);
180}
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
const char * rt_pixtype_name(rt_pixtype pixtype)
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): ...