6215 const int set_count = 2;
6217 int pgrastpos[2] = {-1, -1};
6220 int _isempty[2] = {0};
6224 int _hasnodata[2] = {0};
6225 double _nodataval[2] = {0};
6226 double _offset[4] = {0.};
6227 double _rastoffset[2][4] = {{0.}};
6228 int _haspixel[2] = {0};
6229 double _pixel[2] = {0};
6230 int _pos[2][2] = {{0}};
6231 uint16_t _dim[2][2] = {{0}};
6233 char *pixtypename = NULL;
6235 char *extenttypename = NULL;
6240 uint16_t dim[2] = {0};
6243 double nodataval = 0;
6244 double gt[6] = {0.};
6246 Oid calltype = InvalidOid;
6248 const int spi_count = 3;
6249 uint16_t spi_exprpos[3] = {4, 7, 8};
6253 SPIPlanPtr spi_plan[3] = {NULL};
6254 uint16_t spi_empty = 0;
6255 Oid *argtype = NULL;
6257 char *argkw[] = {
"[rast1.x]",
"[rast1.y]",
"[rast1.val]",
"[rast1]",
"[rast2.x]",
"[rast2.y]",
"[rast2.val]",
"[rast2]"};
6261 SPITupleTable *tuptable = NULL;
6264 bool isnull =
FALSE;
6265 int hasargval[3] = {0};
6266 double argval[3] = {0.};
6267 int hasnodatanodataval = 0;
6268 double nodatanodataval = 0;
6271 Oid ufc_noid = InvalidOid;
6273 #if POSTGIS_PGSQL_VERSION < 120 6274 FunctionCallInfoData ufc_info;
6276 LOCAL_FCINFO(ufc_info, FUNC_MAX_ARGS);
6278 int ufc_nullcount = 0;
6294 for (i = 0, j = 0; i < set_count; i++) {
6295 if (!PG_ARGISNULL(j)) {
6296 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
6303 for (k = 0; k <= i; k++) {
6304 if (k < i && rast[k] != NULL)
6306 if (pgrastpos[k] != -1)
6307 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6309 elog(ERROR,
"RASTER_mapAlgebra2: Could not deserialize the %s raster", i < 1 ?
"first" :
"second");
6317 if (!PG_ARGISNULL(j)) {
6318 bandindex[i] = PG_GETARG_INT32(j);
6331 if (rast[0] == NULL && rast[1] == NULL) {
6332 elog(NOTICE,
"The two rasters provided are NULL. Returning NULL");
6333 for (k = 0; k < set_count; k++) {
6334 if (pgrastpos[k] != -1)
6335 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6341 if (_isempty[0] && _isempty[1]) {
6342 elog(NOTICE,
"The two rasters provided are empty. Returning empty raster");
6345 if (raster == NULL) {
6346 for (k = 0; k < set_count; k++) {
6347 if (rast[k] != NULL)
6349 if (pgrastpos[k] != -1)
6350 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6352 elog(ERROR,
"RASTER_mapAlgebra2: Could not create empty raster");
6362 SET_VARSIZE(pgrtn, pgrtn->
size);
6363 PG_RETURN_POINTER(pgrtn);
6368 (rast[0] == NULL || _isempty[0]) ||
6369 (rast[1] == NULL || _isempty[1])
6372 if (rast[0] == NULL || _isempty[0]) {
6385 if (_rast[i] != NULL)
6397 if (_rast[i] == NULL) {
6399 for (k = 0; k < set_count; k++) {
6400 if (pgrastpos[k] != -1)
6401 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6403 elog(ERROR,
"RASTER_mapAlgebra2: Could not create NODATA raster");
6437 for (k = 0; k < set_count; k++) {
6438 if (_rast[k] != NULL)
6440 if (pgrastpos[k] != -1)
6441 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6443 elog(ERROR,
"RASTER_mapAlgebra2: Could not test for alignment on the two rasters");
6447 elog(NOTICE,
"The two rasters provided do not have the same alignment. Returning NULL");
6448 for (k = 0; k < set_count; k++) {
6449 if (_rast[k] != NULL)
6451 if (pgrastpos[k] != -1)
6452 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6458 if (!PG_ARGISNULL(5)) {
6459 pixtypename = text_to_cstring(PG_GETARG_TEXT_P(5));
6462 if (pixtype ==
PT_END ) {
6463 for (k = 0; k < set_count; k++) {
6464 if (_rast[k] != NULL)
6466 if (pgrastpos[k] != -1)
6467 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6469 elog(ERROR,
"RASTER_mapAlgebra2: Invalid pixel type: %s", pixtypename);
6475 if (!PG_ARGISNULL(6)) {
6488 for (k = 0; k < set_count; k++) {
6489 if (_rast[k] != NULL)
6491 if (pgrastpos[k] != -1)
6492 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6494 elog(ERROR,
"RASTER_mapAlgebra2: Could not get output raster of correct extent");
6499 _rastoffset[0][0] = _offset[0];
6500 _rastoffset[0][1] = _offset[1];
6501 _rastoffset[1][0] = _offset[2];
6502 _rastoffset[1][1] = _offset[3];
6510 switch (extenttype) {
6520 (extenttype ==
ET_FIRST && i == 0) ||
6524 elog(NOTICE,
"The %s raster is NULL. Returning NULL", (i != 1 ?
"FIRST" :
"SECOND"));
6525 for (k = 0; k < set_count; k++) {
6526 if (_rast[k] != NULL)
6528 if (pgrastpos[k] != -1)
6529 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6537 elog(NOTICE,
"The %s raster does not have the band at index %d. Returning no band raster of correct extent",
6538 (i != 1 ?
"FIRST" :
"SECOND"), bandindex[i]
6541 for (k = 0; k < set_count; k++) {
6542 if (_rast[k] != NULL)
6544 if (pgrastpos[k] != -1)
6545 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6550 if (!pgrtn) PG_RETURN_NULL();
6552 SET_VARSIZE(pgrtn, pgrtn->
size);
6553 PG_RETURN_POINTER(pgrtn);
6561 _isempty[0] || _isempty[1] ||
6564 elog(NOTICE,
"The two rasters provided have no intersection. Returning no band raster");
6567 if (dim[0] || dim[1]) {
6571 if (raster == NULL) {
6572 for (k = 0; k < set_count; k++) {
6573 if (_rast[k] != NULL)
6575 if (pgrastpos[k] != -1)
6576 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6578 elog(ERROR,
"RASTER_mapAlgebra2: Could not create no band raster");
6586 for (k = 0; k < set_count; k++) {
6587 if (_rast[k] != NULL)
6589 if (pgrastpos[k] != -1)
6590 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6595 if (!pgrtn) PG_RETURN_NULL();
6597 SET_VARSIZE(pgrtn, pgrtn->
size);
6598 PG_RETURN_POINTER(pgrtn);
6603 for (k = 0; k < set_count; k++) {
6604 if (_rast[k] != NULL)
6606 if (pgrastpos[k] != -1)
6607 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6609 elog(ERROR,
"RASTER_mapAlgebra2: ET_LAST and ET_CUSTOM are not implemented");
6619 elog(NOTICE,
"The two rasters provided do not have the respectively specified band indices. Returning no band raster of correct extent");
6621 for (k = 0; k < set_count; k++) {
6622 if (_rast[k] != NULL)
6624 if (pgrastpos[k] != -1)
6625 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6630 if (!pgrtn) PG_RETURN_NULL();
6632 SET_VARSIZE(pgrtn, pgrtn->
size);
6633 PG_RETURN_POINTER(pgrtn);
6637 for (i = 0; i < set_count; i++) {
6646 if (_band[i] == NULL) {
6647 for (k = 0; k < set_count; k++) {
6648 if (_rast[k] != NULL)
6650 if (pgrastpos[k] != -1)
6651 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6654 elog(ERROR,
"RASTER_mapAlgebra2: Could not get band %d of the %s raster",
6656 (i < 1 ?
"FIRST" :
"SECOND")
6668 if ((extenttype ==
ET_SECOND && !_isempty[1]) || _isempty[0])
6675 if (extenttype ==
ET_SECOND && !_isempty[1] && _hasnodata[1]) {
6676 nodataval = _nodataval[1];
6678 else if (!_isempty[0] && _hasnodata[0]) {
6679 nodataval = _nodataval[0];
6681 else if (!_isempty[1] && _hasnodata[1]) {
6682 nodataval = _nodataval[1];
6685 elog(NOTICE,
"Neither raster provided has a NODATA value for the specified band indices. NODATA value set to minimum possible for %s",
rt_pixtype_name(pixtype));
6697 for (k = 0; k < set_count; k++) {
6698 if (_rast[k] != NULL)
6700 if (pgrastpos[k] != -1)
6701 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6704 elog(ERROR,
"RASTER_mapAlgebra2: Could not add new band to output raster");
6711 for (k = 0; k < set_count; k++) {
6712 if (_rast[k] != NULL)
6714 if (pgrastpos[k] != -1)
6715 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6718 elog(ERROR,
"RASTER_mapAlgebra2: Could not get newly added band of output raster");
6723 (
int) _rastoffset[0][0],
6724 (
int) _rastoffset[0][1],
6725 (
int) _rastoffset[1][0],
6726 (
int) _rastoffset[1][1]
6729 POSTGIS_RT_DEBUGF(4,
"metadata = (%f, %f, %d, %d, %f, %f, %f, %f, %d)",
6746 calltype = get_fn_expr_argtype(fcinfo->flinfo, 4);
6753 if (SPI_connect() != SPI_OK_CONNECT) {
6754 for (k = 0; k < set_count; k++) {
6755 if (_rast[k] != NULL)
6757 if (pgrastpos[k] != -1)
6758 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6761 elog(ERROR,
"RASTER_mapAlgebra2: Could not connect to the SPI manager");
6766 memset(hasargval, 0,
sizeof(
int) * spi_count);
6776 for (i = 0; i < spi_count; i++) {
6777 if (!PG_ARGISNULL(spi_exprpos[i])) {
6779 char place[5] =
"$1";
6780 expr = text_to_cstring(PG_GETARG_TEXT_P(spi_exprpos[i]));
6794 sprintf(place,
"$%d", k);
6800 len = strlen(
"SELECT (") + strlen(expr) + strlen(
")::double precision");
6801 sql = (
char *) palloc(len + 1);
6804 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6807 for (k = 0; k < set_count; k++) {
6808 if (_rast[k] != NULL)
6810 if (pgrastpos[k] != -1)
6811 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6815 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for expression parameter %d", spi_exprpos[i]);
6819 strncpy(sql,
"SELECT (", strlen(
"SELECT ("));
6820 strncpy(sql + strlen(
"SELECT ("), expr, strlen(expr));
6821 strncpy(sql + strlen(
"SELECT (") + strlen(expr),
")::double precision", strlen(
")::double precision"));
6827 if (spi_argcount[i]) {
6828 argtype = (Oid *) palloc(spi_argcount[i] *
sizeof(Oid));
6829 if (argtype == NULL) {
6832 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6835 for (k = 0; k < set_count; k++) {
6836 if (_rast[k] != NULL)
6838 if (pgrastpos[k] != -1)
6839 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6843 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for prepared plan argtypes of expression parameter %d", spi_exprpos[i]);
6849 if (argpos[i][j] < 1)
continue;
6853 (strstr(argkw[j],
"[rast1.x]") != NULL) ||
6854 (strstr(argkw[j],
"[rast1.y]") != NULL) ||
6855 (strstr(argkw[j],
"[rast2.x]") != NULL) ||
6856 (strstr(argkw[j],
"[rast2.y]") != NULL)
6858 argtype[k] = INT4OID;
6862 argtype[k] = FLOAT8OID;
6868 spi_plan[i] = SPI_prepare(sql, spi_argcount[i], argtype);
6871 if (spi_plan[i] == NULL) {
6874 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6877 for (k = 0; k < set_count; k++) {
6878 if (_rast[k] != NULL)
6880 if (pgrastpos[k] != -1)
6881 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6885 elog(ERROR,
"RASTER_mapAlgebra2: Could not create prepared plan of expression parameter %d", spi_exprpos[i]);
6891 err = SPI_execute(sql,
TRUE, 0);
6892 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
6895 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6898 for (k = 0; k < set_count; k++) {
6899 if (_rast[k] != NULL)
6901 if (pgrastpos[k] != -1)
6902 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6906 elog(ERROR,
"RASTER_mapAlgebra2: Could not evaluate expression parameter %d", spi_exprpos[i]);
6911 tupdesc = SPI_tuptable->tupdesc;
6912 tuptable = SPI_tuptable;
6913 tuple = tuptable->vals[0];
6915 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
6916 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
6919 if (SPI_tuptable) SPI_freetuptable(tuptable);
6920 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6923 for (k = 0; k < set_count; k++) {
6924 if (_rast[k] != NULL)
6926 if (pgrastpos[k] != -1)
6927 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6931 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of expression parameter %d", spi_exprpos[i]);
6937 argval[i] = DatumGetFloat8(datum);
6940 if (SPI_tuptable) SPI_freetuptable(tuptable);
6950 if (!PG_ARGISNULL(9)) {
6951 hasnodatanodataval = 1;
6952 nodatanodataval = PG_GETARG_FLOAT8(9);
6955 hasnodatanodataval = 0;
6958 case REGPROCEDUREOID: {
6960 if (!PG_ARGISNULL(4)) {
6963 ufc_noid = PG_GETARG_OID(4);
6966 fmgr_info(ufc_noid, &ufl_info);
6970 if (ufl_info.fn_retset) {
6974 else if (ufl_info.fn_nargs < 3 || ufl_info.fn_nargs > 4) {
6984 for (k = 0; k < set_count; k++) {
6985 if (_rast[k] != NULL)
6987 if (pgrastpos[k] != -1)
6988 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6993 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must have three or four input parameters");
6995 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must return double precision not resultset");
6999 if (func_volatile(ufc_noid) ==
'v') {
7000 elog(NOTICE,
"Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
7004 #if POSTGIS_PGSQL_VERSION < 120 7005 InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7006 memset(ufc_info.argnull,
FALSE,
sizeof(
bool) * ufl_info.fn_nargs);
7008 InitFunctionCallInfoData(
7009 *ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7010 ufc_info->args[0].isnull =
FALSE;
7011 ufc_info->args[1].isnull =
FALSE;
7012 ufc_info->args[2].isnull =
FALSE;
7013 if (ufl_info.fn_nargs == 4)
7014 ufc_info->args[3].isnull =
FALSE;
7017 if (ufl_info.fn_nargs != 4)
7021 #if POSTGIS_PGSQL_VERSION < 120 7022 if (!PG_ARGISNULL(7)) {
7023 ufc_info.arg[k] = PG_GETARG_DATUM(7);
7026 ufc_info.arg[k] = (Datum) NULL;
7027 ufc_info.argnull[k] =
TRUE;
7031 if (!PG_ARGISNULL(7))
7033 ufc_info->args[k].value = PG_GETARG_DATUM(7);
7037 ufc_info->args[k].value = (Datum)NULL;
7038 ufc_info->args[k].isnull =
TRUE;
7046 for (k = 0; k < set_count; k++) {
7047 if (_rast[k] != NULL)
7049 if (pgrastpos[k] != -1)
7050 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7053 elog(ERROR,
"RASTER_mapAlgebra2: Invalid data type for expression or userfunction");
7061 (calltype == TEXTOID) && (
7062 (spi_empty != spi_count) || hasnodatanodataval
7065 (calltype == REGPROCEDUREOID) && (ufc_noid != InvalidOid)
7067 for (x = 0; x < dim[0]; x++) {
7068 for (y = 0; y < dim[1]; y++) {
7071 for (i = 0; i < set_count; i++) {
7076 _x = x - (int) _rastoffset[i][0];
7077 _y = y - (int) _rastoffset[i][1];
7080 _pos[i][0] = _x + 1;
7081 _pos[i][1] = _y + 1;
7084 if (_band[i] == NULL) {
7085 if (!_hasnodata[i]) {
7087 _pixel[i] = _nodataval[i];
7092 (_x >= 0 && _x < _dim[i][0]) &&
7093 (_y >= 0 && _y < _dim[i][1])
7098 if (calltype == TEXTOID) {
7099 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7103 for (k = 0; k < set_count; k++) {
7104 if (_rast[k] != NULL)
7106 if (pgrastpos[k] != -1)
7107 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7111 elog(ERROR,
"RASTER_mapAlgebra2: Could not get pixel of %s raster", (i < 1 ?
"FIRST" :
"SECOND"));
7115 if (!_hasnodata[i] || !isnodata)
7134 if (!_haspixel[0] && !_haspixel[1])
7138 else if (_haspixel[0] && !_haspixel[1])
7142 else if (!_haspixel[0] && _haspixel[1])
7151 if (hasnodatanodataval) {
7153 pixel = nodatanodataval;
7157 else if (hasargval[i]) {
7162 else if (spi_plan[i] != NULL) {
7166 if (spi_argcount[i]) {
7168 memset(values, (Datum) NULL,
sizeof(Datum) * ARGKWCOUNT);
7170 memset(nulls,
FALSE,
sizeof(
bool) * ARGKWCOUNT);
7175 if (idx < 1)
continue;
7178 if (strstr(argkw[j],
"[rast1.x]") != NULL) {
7179 values[idx] = _pos[0][0];
7181 else if (strstr(argkw[j],
"[rast1.y]") != NULL) {
7182 values[idx] = _pos[0][1];
7185 (strstr(argkw[j],
"[rast1.val]") != NULL) ||
7186 (strstr(argkw[j],
"[rast1]") != NULL)
7188 if (_isempty[0] || !_haspixel[0])
7191 values[idx] = Float8GetDatum(_pixel[0]);
7193 else if (strstr(argkw[j],
"[rast2.x]") != NULL) {
7194 values[idx] = _pos[1][0];
7196 else if (strstr(argkw[j],
"[rast2.y]") != NULL) {
7197 values[idx] = _pos[1][1];
7200 (strstr(argkw[j],
"[rast2.val]") != NULL) ||
7201 (strstr(argkw[j],
"[rast2]") != NULL)
7203 if (_isempty[1] || !_haspixel[1])
7206 values[idx] = Float8GetDatum(_pixel[1]);
7212 err = SPI_execute_plan(spi_plan[i], values, nulls,
TRUE, 1);
7213 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
7215 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7218 for (k = 0; k < set_count; k++) {
7219 if (_rast[k] != NULL)
7221 if (pgrastpos[k] != -1)
7222 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7226 elog(ERROR,
"RASTER_mapAlgebra2: Unexpected error when running prepared statement %d", i);
7231 tupdesc = SPI_tuptable->tupdesc;
7232 tuptable = SPI_tuptable;
7233 tuple = tuptable->vals[0];
7235 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
7236 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
7238 if (SPI_tuptable) SPI_freetuptable(tuptable);
7239 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7242 for (k = 0; k < set_count; k++) {
7243 if (_rast[k] != NULL)
7245 if (pgrastpos[k] != -1)
7246 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7250 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of prepared statement %d", i);
7256 pixel = DatumGetFloat8(datum);
7259 if (SPI_tuptable) SPI_freetuptable(tuptable);
7262 case REGPROCEDUREOID: {
7267 for (i = 0; i < set_count; i++) {
7268 #if POSTGIS_PGSQL_VERSION < 120 7269 ufc_info.arg[i] = Float8GetDatum(_pixel[i]);
7271 ufc_info->args[i].value = Float8GetDatum(_pixel[i]);
7275 #if POSTGIS_PGSQL_VERSION < 120 7276 ufc_info.argnull[i] =
FALSE;
7278 ufc_info->args[i].isnull =
FALSE;
7283 #if POSTGIS_PGSQL_VERSION < 120 7284 ufc_info.argnull[i] =
TRUE;
7286 ufc_info->args[i].isnull =
TRUE;
7294 if (ufl_info.fn_strict && ufc_nullcount)
7298 if (ufl_info.fn_nargs == 4) {
7301 for (i = 0; i < set_count; i++) {
7303 d[0] = Int32GetDatum(_pos[i][0]);
7304 d[1] = Int32GetDatum(_pos[i][1]);
7307 d[2] = Int32GetDatum(_pos[i][0]);
7308 d[3] = Int32GetDatum(_pos[i][1]);
7312 a = construct_array(d, 4, INT4OID,
sizeof(
int32),
true,
'i');
7313 #if POSTGIS_PGSQL_VERSION < 120 7314 ufc_info.arg[2] = PointerGetDatum(a);
7315 ufc_info.argnull[2] =
FALSE;
7317 ufc_info->args[2].value = PointerGetDatum(a);
7318 ufc_info->args[2].isnull =
FALSE;
7322 #if POSTGIS_PGSQL_VERSION < 120 7323 datum = FunctionCallInvoke(&ufc_info);
7326 if (!ufc_info.isnull) {
7328 pixel = DatumGetFloat8(datum);
7331 datum = FunctionCallInvoke(ufc_info);
7334 if (!ufc_info->isnull)
7337 pixel = DatumGetFloat8(datum);
7347 if (calltype == TEXTOID) {
7348 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7352 for (k = 0; k < set_count; k++) {
7353 if (_rast[k] != NULL)
7355 if (pgrastpos[k] != -1)
7356 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7360 elog(ERROR,
"RASTER_mapAlgebra2: Could not set pixel value of output raster");
7365 POSTGIS_RT_DEBUGF(5,
"(x, y, val) = (%d, %d, %f)", x, y, haspixel ? pixel : nodataval);
7372 if (calltype == TEXTOID) {
7373 for (i = 0; i < spi_count; i++) {
7374 if (spi_plan[i] != NULL) SPI_freeplan(spi_plan[i]);
7379 for (k = 0; k < set_count; k++) {
7380 if (_rast[k] != NULL)
7382 if (pgrastpos[k] != -1)
7383 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7388 if (!pgrtn) PG_RETURN_NULL();
7392 SET_VARSIZE(pgrtn, pgrtn->
size);
7393 PG_RETURN_POINTER(pgrtn);
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
char * rtpg_strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
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.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
rt_extenttype rt_util_extent_type(const char *name)
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
int rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype, double initialvalue, uint32_t hasnodata, double nodatavalue, int index)
Generate a new inline band and add it to a raster.
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.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
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.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
uint16_t rt_raster_get_width(rt_raster raster)
const char * rt_pixtype_name(rt_pixtype pixtype)
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
uint16_t rt_raster_get_height(rt_raster raster)
#define POSTGIS_RT_DEBUG(level, msg)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
char * rtpg_strtoupper(char *str)