373 {
375
376 int16 typlen;
377 bool typbyval;
378 char typalign;
379
380 ArrayType *mdValues = NULL;
381 Datum *_values = NULL;
382 bool *_nodata = NULL;
383
384 ArrayType *mdPos = NULL;
385 Datum *_pos = NULL;
386 bool *_null = NULL;
387
388 int i = 0;
391 int z = 0;
392 int dim[3] = {0};
393 int lbound[3] = {1, 1, 1};
394 Datum datum = (Datum) NULL;
395
396 if (arg == NULL)
397 return 0;
398
400 *nodata = 0;
401
405
408 if (_values == NULL || _nodata == NULL) {
409 elog(ERROR, "rtpg_nmapalgebra_callback: Could not allocate memory for values array");
410 return 0;
411 }
412
413
414 i = 0;
415
416 for (z = 0; z < arg->
rasters; z++) {
417
418 for (y = 0;
y < arg->
rows;
y++) {
419
423
424 _nodata[i] = (bool) arg->
nodata[z][y][x];
425 if (!_nodata[i])
426 _values[i] = Float8GetDatum(arg->
values[z][y][x]);
427 else
428 _values[i] = (Datum) NULL;
429
430 i++;
431 }
432 }
433 }
434
435
436 get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
437
438
439 mdValues = construct_md_array(
440 _values, _nodata,
441 3, dim, lbound,
442 FLOAT8OID,
443 typlen, typbyval, typalign
444 );
445 pfree(_nodata);
446 pfree(_values);
447
448 _pos = palloc(
sizeof(Datum) * (arg->
rasters + 1) * 2);
449 _null = palloc(
sizeof(
bool) * (arg->
rasters + 1) * 2);
450 if (_pos == NULL || _null == NULL) {
451 pfree(mdValues);
452 elog(ERROR, "rtpg_nmapalgebra_callback: Could not allocate memory for position array");
453 return 0;
454 }
455 memset(_null, 0,
sizeof(
bool) * (arg->
rasters + 1) * 2);
456
457
458 i = 0;
460 i++;
462 i++;
463
464 for (z = 0; z < arg->
rasters; z++) {
465 _pos[i] = (Datum)arg->
src_pixel[z][0] + 1;
466 i++;
467
468 _pos[i] = (Datum)arg->
src_pixel[z][1] + 1;
469 i++;
470 }
471
472
473 get_typlenbyvalalign(INT4OID, &typlen, &typbyval, &typalign);
474
475
477 dim[1] = 2;
478 lbound[0] = 0;
479
480
481 mdPos = construct_md_array(
482 _pos, _null,
483 2, dim, lbound,
484 INT4OID,
485 typlen, typbyval, typalign
486 );
487 pfree(_pos);
488 pfree(_null);
489
490 callback->
ufc_info->args[0].value = PointerGetDatum(mdValues);
491 callback->
ufc_info->args[1].value = PointerGetDatum(mdPos);
492
493
494 datum = FunctionCallInvoke(callback->
ufc_info);
495 pfree(mdValues);
496 pfree(mdPos);
497
498
500 {
502 case FLOAT8OID:
503 *
value = DatumGetFloat8(datum);
504 break;
505 case FLOAT4OID:
506 *
value = (double) DatumGetFloat4(datum);
507 break;
508 case INT4OID:
509 *
value = (double) DatumGetInt32(datum);
510 break;
511 case INT2OID:
512 *
value = (double) DatumGetInt16(datum);
513 break;
514 }
515 }
516 else
517 *nodata = 1;
518
519 return 1;
520}
#define POSTGIS_RT_DEBUGF(level, msg,...)
FunctionCallInfo ufc_info