189 {
190 Oid etype;
191 Datum *e;
192 bool *nulls;
193 int16 typlen;
194 bool typbyval;
195 char typalign;
196 int n = 0;
197
198 HeapTupleHeader tup;
199 bool isnull;
200 Datum tupv;
201
202 int i;
203 int j;
205
206 if (arg == NULL || array == NULL) {
207 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: NULL values not permitted for parameters");
208 return 0;
209 }
210
211 etype = ARR_ELEMTYPE(array);
212 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
213
214 deconstruct_array(
215 array,
216 etype,
217 typlen, typbyval, typalign,
218 &e, &nulls, &n
219 );
220
221 if (!n) {
222 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: Invalid argument for rastbandarg");
223 return 0;
224 }
225
226
235 if (
240 arg->
nband == NULL ||
243 ) {
244 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: Could not allocate memory for processing rastbandarg");
245 return 0;
246 }
247
248 *allnull = 0;
249 *allempty = 0;
250 *noband = 0;
251
252
253 for (i = 0; i < n; i++) {
254 if (nulls[i]) {
256 continue;
257 }
258
260
266
267
268 tup = (HeapTupleHeader) DatumGetPointer(e[i]);
269 if (NULL == tup) {
270 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: Invalid argument for rastbandarg at index %d", i);
271 return 0;
272 }
273
274
276 tupv = GetAttributeByName(tup, "rast", &isnull);
277 if (isnull) {
278 elog(NOTICE, "First argument (nband) of rastbandarg at index %d is NULL. Assuming NULL raster", i);
281
282 (*allnull)++;
283 (*allempty)++;
284 (*noband)++;
285
286 continue;
287 }
288
290
291
292 for (j = 0; j < i; j++) {
297 break;
298 }
299 }
300
304 if (arg->
raster[i] == NULL) {
305 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: Could not deserialize raster at index %d", i);
306 return 0;
307 }
308 }
309
310
313 (*allempty)++;
314 (*noband)++;
315
316 continue;
317 }
318
319
321 tupv = GetAttributeByName(tup, "nband", &isnull);
322 if (isnull) {
324 elog(NOTICE, "First argument (nband) of rastbandarg at index %d is NULL. Assuming nband = %d", i, nband);
325 }
326 else
327 nband = DatumGetInt32(tupv);
328
329 if (nband < 1) {
330 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: Band number provided for rastbandarg at index %d must be greater than zero (1-based)", i);
331 return 0;
332 }
333
337 (*noband)++;
339 }
340 }
341
349 if (
354 arg->
nband == NULL ||
356 ) {
357 elog(ERROR, "rtpg_nmapalgebra_rastbandarg_process: Could not reallocate memory for processed rastbandarg");
358 return 0;
359 }
360 }
361
363
364 return 1;
365}
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)