538 ArrayType *maskArray;
569 elog(ERROR,
"RASTER_nMapAlgebra: Could not initialize argument structure");
576 elog(ERROR,
"RASTER_nMapAlgebra: Could not process rastbandarg");
580 POSTGIS_RT_DEBUGF(4,
"allnull, allempty, noband = %d, %d, %d", allnull, allempty, noband);
584 elog(NOTICE,
"All input rasters are NULL. Returning NULL");
590 if (!PG_ARGISNULL(2)) {
591 char *pixtypename = text_to_cstring(PG_GETARG_TEXT_P(2));
597 elog(ERROR,
"RASTER_nMapAlgebra: Invalid pixel type: %s", pixtypename);
603 if (!PG_ARGISNULL(3)){
604 arg->
distance[0] = PG_GETARG_INT32(3);
609 if (!PG_ARGISNULL(4)){
610 arg->
distance[1] = PG_GETARG_INT32(4);
616 elog(ERROR,
"RASTER_nMapAlgebra: Distance for X and Y axis must be greater than or equal to zero");
621 if (!PG_ARGISNULL(5)) {
629 if (PG_ARGISNULL(6)) {
630 elog(NOTICE,
"Custom extent is NULL. Returning NULL");
641 elog(ERROR,
"RASTER_nMapAlgebra: Could not deserialize custom extent");
645 elog(NOTICE,
"Custom extent is an empty raster. Returning empty raster");
649 if (raster == NULL) {
650 elog(ERROR,
"RASTER_nMapAlgebra: Could not create empty raster");
656 if (!pgraster) PG_RETURN_NULL();
658 SET_VARSIZE(pgraster, pgraster->
size);
659 PG_RETURN_POINTER(pgraster);
665 if( PG_ARGISNULL(7) ){
670 maskArray = PG_GETARG_ARRAYTYPE_P(7);
671 etype = ARR_ELEMTYPE(maskArray);
672 get_typlenbyvalalign(etype,&typlen,&typbyval,&typalign);
680 elog(ERROR,
"RASTER_nMapAlgebra: Mask data type must be FLOAT8 or FLOAT4");
684 ndims = ARR_NDIM(maskArray);
687 elog(ERROR,
"RASTER_nMapAlgebra: Mask Must be a 2D array");
692 maskDims = ARR_DIMS(maskArray);
694 if (maskDims[0] % 2 == 0 || maskDims[1] % 2 == 0) {
695 elog(ERROR,
"RASTER_nMapAlgebra: Mask dimensions must be odd");
703 typlen, typbyval,typalign,
704 &maskElements,&maskNulls,&num
707 if (num < 1 || num != (maskDims[0] * maskDims[1])) {
712 elog(ERROR,
"RASTER_nMapAlgebra: Could not deconstruct new values array");
718 arg->
mask->
values = palloc(
sizeof(
double*)* maskDims[0]);
719 arg->
mask->
nodata = palloc(
sizeof(
int*)*maskDims[0]);
720 for (i = 0; i < maskDims[0]; i++) {
721 arg->
mask->
values[i] = (
double*) palloc(
sizeof(
double) * maskDims[1]);
722 arg->
mask->
nodata[i] = (
int*) palloc(
sizeof(
int) * maskDims[1]);
727 for (y = 0; y < maskDims[0]; y++) {
728 for (x = 0; x < maskDims[1]; x++) {
736 arg->
mask->
values[
y][
x] = (double) DatumGetFloat4(maskElements[i]);
740 arg->
mask->
values[
y][
x] = (double) DatumGetFloat8(maskElements[i]);
751 if (maskDims[0] == 1 && maskDims[1] == 1) {
762 if (PG_ARGISNULL(8) || !PG_GETARG_BOOL(8)) {
763 if (arg->
mask != NULL)
774 elog(NOTICE,
"All input rasters are empty. Returning empty raster");
779 elog(NOTICE,
"All input rasters do not have bands at indicated indexes. Returning empty raster");
786 if (raster == NULL) {
787 elog(ERROR,
"RASTER_nMapAlgebra: Could not create empty raster");
793 if (!pgraster) PG_RETURN_NULL();
795 SET_VARSIZE(pgraster, pgraster->
size);
796 PG_RETURN_POINTER(pgraster);
800 if (!PG_ARGISNULL(1) || get_fn_expr_argtype(fcinfo->flinfo, 1) == REGPROCEDUREOID) {
819 get_func_result_type(
846 elog(ERROR,
"RASTER_nMapAlgebra: Function provided must return a double precision, float, int or smallint");
849 elog(ERROR,
"RASTER_nMapAlgebra: Function provided must return scalar (double precision, float, int, smallint)");
852 elog(ERROR,
"RASTER_nMapAlgebra: Function provided must have three input parameters");
855 elog(ERROR,
"RASTER_nMapAlgebra: Function provided must return double precision, not resultset");
862 elog(NOTICE,
"Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
865 #if POSTGIS_PGSQL_VERSION < 120 883 if (!PG_ARGISNULL(9))
884 #if POSTGIS_PGSQL_VERSION < 120 893 #if POSTGIS_PGSQL_VERSION < 120 895 construct_empty_array(TEXTOID)
899 arg->
callback.
ufc_info->args[2].value = PointerGetDatum(construct_empty_array(TEXTOID));
904 #if POSTGIS_PGSQL_VERSION < 120 916 elog(ERROR,
"RASTER_nMapAlgebra: callbackfunc must be provided");
961 if (itrset == NULL) {
963 elog(ERROR,
"RASTER_nMapAlgebra: Could not allocate memory for iterator arguments");
992 elog(ERROR,
"RASTER_nMapAlgebra: Could not run raster iterator function");
995 else if (raster == NULL)
1006 SET_VARSIZE(pgraster, pgraster->
size);
1007 PG_RETURN_POINTER(pgraster);
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
static int rtpg_nmapalgebra_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
#define POSTGIS_RT_DEBUGF(level, msg,...)
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
static void rtpg_nmapalgebra_arg_destroy(rtpg_nmapalgebra_arg arg)
rtpg_nmapalgebra_callback_arg callback
rt_extenttype rt_util_extent_type(const char *name)
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
static int rtpg_nmapalgebra_rastbandarg_process(rtpg_nmapalgebra_arg arg, ArrayType *array, int *allnull, int *allempty, int *noband)
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
char * rtpg_trim(const char *input)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
const char * rt_pixtype_name(rt_pixtype pixtype)
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
#define POSTGIS_RT_DEBUG(level, msg)
static rtpg_nmapalgebra_arg rtpg_nmapalgebra_arg_init()
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
char * rtpg_strtoupper(char *str)
FunctionCallInfoData ufc_info