6232 const uint32_t set_count = 2;
6234 int pgrastpos[2] = {-1, -1};
6237 int _isempty[2] = {0};
6238 uint32_t bandindex[2] = {0};
6241 int _hasnodata[2] = {0};
6242 double _nodataval[2] = {0};
6243 double _offset[4] = {0.};
6244 double _rastoffset[2][4] = {{0.}};
6245 int _haspixel[2] = {0};
6246 double _pixel[2] = {0};
6247 int _pos[2][2] = {{0}};
6248 uint16_t _dim[2][2] = {{0}};
6250 char *pixtypename = NULL;
6252 char *extenttypename = NULL;
6257 uint16_t dim[2] = {0};
6260 double nodataval = 0;
6261 double gt[6] = {0.};
6263 Oid calltype = InvalidOid;
6265 const uint32_t spi_count = 3;
6266 uint16_t spi_exprpos[3] = {4, 7, 8};
6267 uint32_t spi_argcount[3] = {0};
6270 SPIPlanPtr spi_plan[3] = {NULL};
6271 uint16_t spi_empty = 0;
6272 Oid *argtype = NULL;
6273 uint8_t argpos[3][8] = {{0}};
6274 char *argkw[] = {
"[rast1.x]",
"[rast1.y]",
"[rast1.val]",
"[rast1]",
"[rast2.x]",
"[rast2.y]",
"[rast2.val]",
"[rast2]"};
6278 SPITupleTable *tuptable = NULL;
6281 bool isnull =
FALSE;
6282 int hasargval[3] = {0};
6283 double argval[3] = {0.};
6284 int hasnodatanodataval = 0;
6285 double nodatanodataval = 0;
6288 Oid ufc_noid = InvalidOid;
6290 #if POSTGIS_PGSQL_VERSION < 120
6291 FunctionCallInfoData ufc_info;
6293 LOCAL_FCINFO(ufc_info, FUNC_MAX_ARGS);
6295 int ufc_nullcount = 0;
6311 for (i = 0, j = 0; i < set_count; i++) {
6312 if (!PG_ARGISNULL(j)) {
6313 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
6320 for (k = 0; k <= i; k++) {
6321 if (k < i &&
rast[k] != NULL)
6323 if (pgrastpos[k] != -1)
6324 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6326 elog(ERROR,
"RASTER_mapAlgebra2: Could not deserialize the %s raster", i < 1 ?
"first" :
"second");
6334 if (!PG_ARGISNULL(j)) {
6335 bandindex[i] = PG_GETARG_INT32(j);
6348 if (
rast[0] == NULL &&
rast[1] == NULL) {
6349 elog(NOTICE,
"The two rasters provided are NULL. Returning NULL");
6350 for (k = 0; k < set_count; k++) {
6351 if (pgrastpos[k] != -1)
6352 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6358 if (_isempty[0] && _isempty[1]) {
6359 elog(NOTICE,
"The two rasters provided are empty. Returning empty raster");
6363 for (k = 0; k < set_count; k++) {
6364 if (
rast[k] != NULL)
6366 if (pgrastpos[k] != -1)
6367 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6369 elog(ERROR,
"RASTER_mapAlgebra2: Could not create empty raster");
6379 SET_VARSIZE(pgrtn, pgrtn->
size);
6380 PG_RETURN_POINTER(pgrtn);
6385 (
rast[0] == NULL || _isempty[0]) ||
6386 (
rast[1] == NULL || _isempty[1])
6389 if (
rast[0] == NULL || _isempty[0]) {
6402 if (_rast[i] != NULL)
6414 if (_rast[i] == NULL) {
6416 for (k = 0; k < set_count; k++) {
6417 if (pgrastpos[k] != -1)
6418 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6420 elog(ERROR,
"RASTER_mapAlgebra2: Could not create NODATA raster");
6454 for (k = 0; k < set_count; k++) {
6455 if (_rast[k] != NULL)
6457 if (pgrastpos[k] != -1)
6458 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6460 elog(ERROR,
"RASTER_mapAlgebra2: Could not test for alignment on the two rasters");
6464 elog(NOTICE,
"The two rasters provided do not have the same alignment. Returning NULL");
6465 for (k = 0; k < set_count; k++) {
6466 if (_rast[k] != NULL)
6468 if (pgrastpos[k] != -1)
6469 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6475 if (!PG_ARGISNULL(5)) {
6476 pixtypename = text_to_cstring(PG_GETARG_TEXT_P(5));
6479 if (pixtype ==
PT_END ) {
6480 for (k = 0; k < set_count; k++) {
6481 if (_rast[k] != NULL)
6483 if (pgrastpos[k] != -1)
6484 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6486 elog(ERROR,
"RASTER_mapAlgebra2: Invalid pixel type: %s", pixtypename);
6492 if (!PG_ARGISNULL(6)) {
6505 for (k = 0; k < set_count; k++) {
6506 if (_rast[k] != NULL)
6508 if (pgrastpos[k] != -1)
6509 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6511 elog(ERROR,
"RASTER_mapAlgebra2: Could not get output raster of correct extent");
6516 _rastoffset[0][0] = _offset[0];
6517 _rastoffset[0][1] = _offset[1];
6518 _rastoffset[1][0] = _offset[2];
6519 _rastoffset[1][1] = _offset[3];
6527 switch (extenttype) {
6537 (extenttype ==
ET_FIRST && i == 0) ||
6541 elog(NOTICE,
"The %s raster is NULL. Returning NULL", (i != 1 ?
"FIRST" :
"SECOND"));
6542 for (k = 0; k < set_count; k++) {
6543 if (_rast[k] != NULL)
6545 if (pgrastpos[k] != -1)
6546 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6554 elog(NOTICE,
"The %s raster does not have the band at index %d. Returning no band raster of correct extent",
6555 (i != 1 ?
"FIRST" :
"SECOND"), bandindex[i]
6558 for (k = 0; k < set_count; k++) {
6559 if (_rast[k] != NULL)
6561 if (pgrastpos[k] != -1)
6562 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6567 if (!pgrtn) PG_RETURN_NULL();
6569 SET_VARSIZE(pgrtn, pgrtn->
size);
6570 PG_RETURN_POINTER(pgrtn);
6578 _isempty[0] || _isempty[1] ||
6581 elog(NOTICE,
"The two rasters provided have no intersection. Returning no band raster");
6584 if (dim[0] || dim[1]) {
6589 for (k = 0; k < set_count; k++) {
6590 if (_rast[k] != NULL)
6592 if (pgrastpos[k] != -1)
6593 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6595 elog(ERROR,
"RASTER_mapAlgebra2: Could not create no band raster");
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]);
6612 if (!pgrtn) PG_RETURN_NULL();
6614 SET_VARSIZE(pgrtn, pgrtn->
size);
6615 PG_RETURN_POINTER(pgrtn);
6620 for (k = 0; k < set_count; k++) {
6621 if (_rast[k] != NULL)
6623 if (pgrastpos[k] != -1)
6624 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6626 elog(ERROR,
"RASTER_mapAlgebra2: ET_LAST and ET_CUSTOM are not implemented");
6636 elog(NOTICE,
"The two rasters provided do not have the respectively specified band indices. Returning no band raster of correct extent");
6638 for (k = 0; k < set_count; k++) {
6639 if (_rast[k] != NULL)
6641 if (pgrastpos[k] != -1)
6642 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6647 if (!pgrtn) PG_RETURN_NULL();
6649 SET_VARSIZE(pgrtn, pgrtn->
size);
6650 PG_RETURN_POINTER(pgrtn);
6654 for (i = 0; i < set_count; i++) {
6663 if (_band[i] == NULL) {
6664 for (k = 0; k < set_count; k++) {
6665 if (_rast[k] != NULL)
6667 if (pgrastpos[k] != -1)
6668 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6671 elog(ERROR,
"RASTER_mapAlgebra2: Could not get band %d of the %s raster",
6673 (i < 1 ?
"FIRST" :
"SECOND")
6685 if ((extenttype ==
ET_SECOND && !_isempty[1]) || _isempty[0])
6692 if (extenttype ==
ET_SECOND && !_isempty[1] && _hasnodata[1]) {
6693 nodataval = _nodataval[1];
6695 else if (!_isempty[0] && _hasnodata[0]) {
6696 nodataval = _nodataval[0];
6698 else if (!_isempty[1] && _hasnodata[1]) {
6699 nodataval = _nodataval[1];
6702 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));
6714 for (k = 0; k < set_count; k++) {
6715 if (_rast[k] != NULL)
6717 if (pgrastpos[k] != -1)
6718 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6721 elog(ERROR,
"RASTER_mapAlgebra2: Could not add new band to output raster");
6728 for (k = 0; k < set_count; k++) {
6729 if (_rast[k] != NULL)
6731 if (pgrastpos[k] != -1)
6732 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6735 elog(ERROR,
"RASTER_mapAlgebra2: Could not get newly added band of output raster");
6740 (
int) _rastoffset[0][0],
6741 (
int) _rastoffset[0][1],
6742 (
int) _rastoffset[1][0],
6743 (
int) _rastoffset[1][1]
6746 POSTGIS_RT_DEBUGF(4,
"metadata = (%f, %f, %d, %d, %f, %f, %f, %f, %d)",
6763 calltype = get_fn_expr_argtype(fcinfo->flinfo, 4);
6770 if (SPI_connect() != SPI_OK_CONNECT) {
6771 for (k = 0; k < set_count; k++) {
6772 if (_rast[k] != NULL)
6774 if (pgrastpos[k] != -1)
6775 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6778 elog(ERROR,
"RASTER_mapAlgebra2: Could not connect to the SPI manager");
6783 memset(hasargval, 0,
sizeof(
int) * spi_count);
6793 for (i = 0; i < spi_count; i++) {
6794 if (!PG_ARGISNULL(spi_exprpos[i])) {
6796 char place[5] =
"$1";
6797 expr = text_to_cstring(PG_GETARG_TEXT_P(spi_exprpos[i]));
6811 sprintf(place,
"$%d", k);
6817 len = strlen(
"SELECT (") + strlen(expr) + strlen(
")::double precision");
6818 sql = (
char *) palloc(len + 1);
6821 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6824 for (k = 0; k < set_count; k++) {
6825 if (_rast[k] != NULL)
6827 if (pgrastpos[k] != -1)
6828 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6832 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for expression parameter %d", spi_exprpos[i]);
6836 memcpy(
sql,
"SELECT (", strlen(
"SELECT ("));
6837 memcpy(
sql + strlen(
"SELECT ("), expr, strlen(expr));
6838 memcpy(
sql + strlen(
"SELECT (") + strlen(expr),
")::double precision", strlen(
")::double precision"));
6844 if (spi_argcount[i]) {
6845 argtype = (Oid *) palloc(spi_argcount[i] *
sizeof(Oid));
6846 if (argtype == NULL) {
6849 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6852 for (k = 0; k < set_count; k++) {
6853 if (_rast[k] != NULL)
6855 if (pgrastpos[k] != -1)
6856 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6860 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for prepared plan argtypes of expression parameter %d", spi_exprpos[i]);
6866 if (argpos[i][j] < 1)
continue;
6870 (strstr(argkw[j],
"[rast1.x]") != NULL) ||
6871 (strstr(argkw[j],
"[rast1.y]") != NULL) ||
6872 (strstr(argkw[j],
"[rast2.x]") != NULL) ||
6873 (strstr(argkw[j],
"[rast2.y]") != NULL)
6875 argtype[k] = INT4OID;
6879 argtype[k] = FLOAT8OID;
6885 spi_plan[i] = SPI_prepare(
sql, spi_argcount[i], argtype);
6888 if (spi_plan[i] == NULL) {
6891 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6894 for (k = 0; k < set_count; k++) {
6895 if (_rast[k] != NULL)
6897 if (pgrastpos[k] != -1)
6898 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6902 elog(ERROR,
"RASTER_mapAlgebra2: Could not create prepared plan of expression parameter %d", spi_exprpos[i]);
6908 err = SPI_execute(
sql,
TRUE, 0);
6909 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
6912 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6915 for (k = 0; k < set_count; k++) {
6916 if (_rast[k] != NULL)
6918 if (pgrastpos[k] != -1)
6919 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6923 elog(ERROR,
"RASTER_mapAlgebra2: Could not evaluate expression parameter %d", spi_exprpos[i]);
6928 tupdesc = SPI_tuptable->tupdesc;
6929 tuptable = SPI_tuptable;
6930 tuple = tuptable->vals[0];
6932 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
6933 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
6936 if (SPI_tuptable) SPI_freetuptable(tuptable);
6937 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6940 for (k = 0; k < set_count; k++) {
6941 if (_rast[k] != NULL)
6943 if (pgrastpos[k] != -1)
6944 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6948 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of expression parameter %d", spi_exprpos[i]);
6954 argval[i] = DatumGetFloat8(datum);
6957 if (SPI_tuptable) SPI_freetuptable(tuptable);
6967 if (!PG_ARGISNULL(9)) {
6968 hasnodatanodataval = 1;
6969 nodatanodataval = PG_GETARG_FLOAT8(9);
6972 hasnodatanodataval = 0;
6975 case REGPROCEDUREOID: {
6977 if (!PG_ARGISNULL(4)) {
6980 ufc_noid = PG_GETARG_OID(4);
6983 fmgr_info(ufc_noid, &ufl_info);
6987 if (ufl_info.fn_retset) {
6991 else if (ufl_info.fn_nargs < 3 || ufl_info.fn_nargs > 4) {
7001 for (k = 0; k < set_count; k++) {
7002 if (_rast[k] != NULL)
7004 if (pgrastpos[k] != -1)
7005 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7010 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must have three or four input parameters");
7012 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must return double precision not resultset");
7016 if (func_volatile(ufc_noid) ==
'v') {
7017 elog(NOTICE,
"Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
7021 #if POSTGIS_PGSQL_VERSION < 120
7022 InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7023 memset(ufc_info.argnull,
FALSE,
sizeof(
bool) * ufl_info.fn_nargs);
7025 InitFunctionCallInfoData(
7026 *ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7027 ufc_info->args[0].isnull =
FALSE;
7028 ufc_info->args[1].isnull =
FALSE;
7029 ufc_info->args[2].isnull =
FALSE;
7030 if (ufl_info.fn_nargs == 4)
7031 ufc_info->args[3].isnull =
FALSE;
7034 if (ufl_info.fn_nargs != 4)
7038 #if POSTGIS_PGSQL_VERSION < 120
7039 if (!PG_ARGISNULL(7)) {
7040 ufc_info.arg[k] = PG_GETARG_DATUM(7);
7043 ufc_info.arg[k] = (Datum) NULL;
7044 ufc_info.argnull[k] =
TRUE;
7048 if (!PG_ARGISNULL(7))
7050 ufc_info->args[k].value = PG_GETARG_DATUM(7);
7054 ufc_info->args[k].value = (Datum)NULL;
7055 ufc_info->args[k].isnull =
TRUE;
7063 for (k = 0; k < set_count; k++) {
7064 if (_rast[k] != NULL)
7066 if (pgrastpos[k] != -1)
7067 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7070 elog(ERROR,
"RASTER_mapAlgebra2: Invalid data type for expression or userfunction");
7078 (calltype == TEXTOID) && (
7079 (spi_empty != spi_count) || hasnodatanodataval
7082 (calltype == REGPROCEDUREOID) && (ufc_noid != InvalidOid)
7084 for (
x = 0;
x < dim[0];
x++) {
7085 for (
y = 0;
y < dim[1];
y++) {
7088 for (i = 0; i < set_count; i++) {
7093 _x = (int)
x - (
int)_rastoffset[i][0];
7094 _y = (int)
y - (
int)_rastoffset[i][1];
7097 _pos[i][0] = _x + 1;
7098 _pos[i][1] = _y + 1;
7101 if (_band[i] == NULL) {
7102 if (!_hasnodata[i]) {
7104 _pixel[i] = _nodataval[i];
7109 (_x >= 0 && _x < _dim[i][0]) &&
7110 (_y >= 0 && _y < _dim[i][1])
7115 if (calltype == TEXTOID) {
7116 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7120 for (k = 0; k < set_count; k++) {
7121 if (_rast[k] != NULL)
7123 if (pgrastpos[k] != -1)
7124 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7128 elog(ERROR,
"RASTER_mapAlgebra2: Could not get pixel of %s raster", (i < 1 ?
"FIRST" :
"SECOND"));
7132 if (!_hasnodata[i] || !isnodata)
7151 if (!_haspixel[0] && !_haspixel[1])
7155 else if (_haspixel[0] && !_haspixel[1])
7159 else if (!_haspixel[0] && _haspixel[1])
7168 if (hasnodatanodataval) {
7170 pixel = nodatanodataval;
7174 else if (hasargval[i]) {
7179 else if (spi_plan[i] != NULL) {
7183 memset(values, (Datum) NULL,
sizeof(Datum) *
ARGKWCOUNT);
7188 if (spi_argcount[i]) {
7192 if (idx < 1)
continue;
7195 if (strstr(argkw[j],
"[rast1.x]") != NULL) {
7196 values[idx] = _pos[0][0];
7198 else if (strstr(argkw[j],
"[rast1.y]") != NULL) {
7199 values[idx] = _pos[0][1];
7202 (strstr(argkw[j],
"[rast1.val]") != NULL) ||
7203 (strstr(argkw[j],
"[rast1]") != NULL)
7205 if (_isempty[0] || !_haspixel[0])
7208 values[idx] = Float8GetDatum(_pixel[0]);
7210 else if (strstr(argkw[j],
"[rast2.x]") != NULL) {
7211 values[idx] = _pos[1][0];
7213 else if (strstr(argkw[j],
"[rast2.y]") != NULL) {
7214 values[idx] = _pos[1][1];
7217 (strstr(argkw[j],
"[rast2.val]") != NULL) ||
7218 (strstr(argkw[j],
"[rast2]") != NULL)
7220 if (_isempty[1] || !_haspixel[1])
7223 values[idx] = Float8GetDatum(_pixel[1]);
7229 err = SPI_execute_plan(spi_plan[i], values, nulls,
TRUE, 1);
7230 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
7232 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7235 for (k = 0; k < set_count; k++) {
7236 if (_rast[k] != NULL)
7238 if (pgrastpos[k] != -1)
7239 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7243 elog(ERROR,
"RASTER_mapAlgebra2: Unexpected error when running prepared statement %d", i);
7248 tupdesc = SPI_tuptable->tupdesc;
7249 tuptable = SPI_tuptable;
7250 tuple = tuptable->vals[0];
7252 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
7253 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
7255 if (SPI_tuptable) SPI_freetuptable(tuptable);
7256 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7259 for (k = 0; k < set_count; k++) {
7260 if (_rast[k] != NULL)
7262 if (pgrastpos[k] != -1)
7263 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7267 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of prepared statement %d", i);
7273 pixel = DatumGetFloat8(datum);
7276 if (SPI_tuptable) SPI_freetuptable(tuptable);
7279 case REGPROCEDUREOID: {
7284 for (i = 0; i < set_count; i++) {
7285 #if POSTGIS_PGSQL_VERSION < 120
7286 ufc_info.arg[i] = Float8GetDatum(_pixel[i]);
7288 ufc_info->args[i].value = Float8GetDatum(_pixel[i]);
7292 #if POSTGIS_PGSQL_VERSION < 120
7293 ufc_info.argnull[i] =
FALSE;
7295 ufc_info->args[i].isnull =
FALSE;
7300 #if POSTGIS_PGSQL_VERSION < 120
7301 ufc_info.argnull[i] =
TRUE;
7303 ufc_info->args[i].isnull =
TRUE;
7311 if (ufl_info.fn_strict && ufc_nullcount)
7315 if (ufl_info.fn_nargs == 4) {
7318 for (i = 0; i < set_count; i++) {
7320 d[0] = Int32GetDatum(_pos[i][0]);
7321 d[1] = Int32GetDatum(_pos[i][1]);
7324 d[2] = Int32GetDatum(_pos[i][0]);
7325 d[3] = Int32GetDatum(_pos[i][1]);
7329 a = construct_array(d, 4, INT4OID,
sizeof(
int32),
true,
'i');
7330 #if POSTGIS_PGSQL_VERSION < 120
7331 ufc_info.arg[2] = PointerGetDatum(a);
7332 ufc_info.argnull[2] =
FALSE;
7334 ufc_info->args[2].value = PointerGetDatum(a);
7335 ufc_info->args[2].isnull =
FALSE;
7339 #if POSTGIS_PGSQL_VERSION < 120
7340 datum = FunctionCallInvoke(&ufc_info);
7343 if (!ufc_info.isnull) {
7345 pixel = DatumGetFloat8(datum);
7348 datum = FunctionCallInvoke(ufc_info);
7351 if (!ufc_info->isnull)
7354 pixel = DatumGetFloat8(datum);
7364 if (calltype == TEXTOID) {
7365 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7369 for (k = 0; k < set_count; k++) {
7370 if (_rast[k] != NULL)
7372 if (pgrastpos[k] != -1)
7373 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7377 elog(ERROR,
"RASTER_mapAlgebra2: Could not set pixel value of output raster");
7389 if (calltype == TEXTOID) {
7390 for (i = 0; i < spi_count; i++) {
7391 if (spi_plan[i] != NULL) SPI_freeplan(spi_plan[i]);
7396 for (k = 0; k < set_count; k++) {
7397 if (_rast[k] != NULL)
7399 if (pgrastpos[k] != -1)
7400 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7405 if (!pgrtn) PG_RETURN_NULL();
7409 SET_VARSIZE(pgrtn, pgrtn->
size);
7410 PG_RETURN_POINTER(pgrtn);
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, 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.
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
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.
rt_extenttype rt_util_extent_type(const char *name)
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
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)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
const char * rt_pixtype_name(rt_pixtype pixtype)
uint16_t rt_raster_get_width(rt_raster raster)
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
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.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
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): ...
char * rtpg_strtoupper(char *str)
char * rtpg_trim(const char *input)
char * rtpg_strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)