6211 const uint32_t set_count = 2;
6213 int pgrastpos[2] = {-1, -1};
6216 int _isempty[2] = {0};
6217 uint32_t bandindex[2] = {0};
6220 int _hasnodata[2] = {0};
6221 double _nodataval[2] = {0};
6222 double _offset[4] = {0.};
6223 double _rastoffset[2][4] = {{0.}};
6224 int _haspixel[2] = {0};
6225 double _pixel[2] = {0};
6226 int _pos[2][2] = {{0}};
6227 uint16_t _dim[2][2] = {{0}};
6229 char *pixtypename = NULL;
6231 char *extenttypename = NULL;
6236 uint16_t dim[2] = {0};
6239 double nodataval = 0;
6240 double gt[6] = {0.};
6242 Oid calltype = InvalidOid;
6244 const uint32_t spi_count = 3;
6245 uint16_t spi_exprpos[3] = {4, 7, 8};
6246 uint32_t spi_argcount[3] = {0};
6249 SPIPlanPtr spi_plan[3] = {NULL};
6250 uint16_t spi_empty = 0;
6251 Oid *argtype = NULL;
6252 uint8_t argpos[3][8] = {{0}};
6253 char *argkw[] = {
"[rast1.x]",
"[rast1.y]",
"[rast1.val]",
"[rast1]",
"[rast2.x]",
"[rast2.y]",
"[rast2.val]",
"[rast2]"};
6257 SPITupleTable *tuptable = NULL;
6260 bool isnull =
FALSE;
6261 int hasargval[3] = {0};
6262 double argval[3] = {0.};
6263 int hasnodatanodataval = 0;
6264 double nodatanodataval = 0;
6267 Oid ufc_noid = InvalidOid;
6269 #if POSTGIS_PGSQL_VERSION < 120
6270 FunctionCallInfoData ufc_info;
6272 LOCAL_FCINFO(ufc_info, FUNC_MAX_ARGS);
6274 int ufc_nullcount = 0;
6290 for (i = 0, j = 0; i < set_count; i++) {
6291 if (!PG_ARGISNULL(j)) {
6292 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
6299 for (k = 0; k <= i; k++) {
6300 if (k < i &&
rast[k] != NULL)
6302 if (pgrastpos[k] != -1)
6303 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6305 elog(ERROR,
"RASTER_mapAlgebra2: Could not deserialize the %s raster", i < 1 ?
"first" :
"second");
6313 if (!PG_ARGISNULL(j)) {
6314 bandindex[i] = PG_GETARG_INT32(j);
6327 if (
rast[0] == NULL &&
rast[1] == NULL) {
6328 elog(NOTICE,
"The two rasters provided are NULL. Returning NULL");
6329 for (k = 0; k < set_count; k++) {
6330 if (pgrastpos[k] != -1)
6331 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6337 if (_isempty[0] && _isempty[1]) {
6338 elog(NOTICE,
"The two rasters provided are empty. Returning empty raster");
6342 for (k = 0; k < set_count; k++) {
6343 if (
rast[k] != NULL)
6345 if (pgrastpos[k] != -1)
6346 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6348 elog(ERROR,
"RASTER_mapAlgebra2: Could not create empty raster");
6358 SET_VARSIZE(pgrtn, pgrtn->
size);
6359 PG_RETURN_POINTER(pgrtn);
6364 (
rast[0] == NULL || _isempty[0]) ||
6365 (
rast[1] == NULL || _isempty[1])
6368 if (
rast[0] == NULL || _isempty[0]) {
6381 if (_rast[i] != NULL)
6393 if (_rast[i] == NULL) {
6395 for (k = 0; k < set_count; k++) {
6396 if (pgrastpos[k] != -1)
6397 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6399 elog(ERROR,
"RASTER_mapAlgebra2: Could not create NODATA raster");
6433 for (k = 0; k < set_count; k++) {
6434 if (_rast[k] != NULL)
6436 if (pgrastpos[k] != -1)
6437 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6439 elog(ERROR,
"RASTER_mapAlgebra2: Could not test for alignment on the two rasters");
6443 elog(NOTICE,
"The two rasters provided do not have the same alignment. Returning NULL");
6444 for (k = 0; k < set_count; k++) {
6445 if (_rast[k] != NULL)
6447 if (pgrastpos[k] != -1)
6448 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6454 if (!PG_ARGISNULL(5)) {
6455 pixtypename = text_to_cstring(PG_GETARG_TEXT_P(5));
6458 if (pixtype ==
PT_END ) {
6459 for (k = 0; k < set_count; k++) {
6460 if (_rast[k] != NULL)
6462 if (pgrastpos[k] != -1)
6463 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6465 elog(ERROR,
"RASTER_mapAlgebra2: Invalid pixel type: %s", pixtypename);
6471 if (!PG_ARGISNULL(6)) {
6484 for (k = 0; k < set_count; k++) {
6485 if (_rast[k] != NULL)
6487 if (pgrastpos[k] != -1)
6488 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6490 elog(ERROR,
"RASTER_mapAlgebra2: Could not get output raster of correct extent");
6495 _rastoffset[0][0] = _offset[0];
6496 _rastoffset[0][1] = _offset[1];
6497 _rastoffset[1][0] = _offset[2];
6498 _rastoffset[1][1] = _offset[3];
6506 switch (extenttype) {
6516 (extenttype ==
ET_FIRST && i == 0) ||
6520 elog(NOTICE,
"The %s raster is NULL. Returning NULL", (i != 1 ?
"FIRST" :
"SECOND"));
6521 for (k = 0; k < set_count; k++) {
6522 if (_rast[k] != NULL)
6524 if (pgrastpos[k] != -1)
6525 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6533 elog(NOTICE,
"The %s raster does not have the band at index %d. Returning no band raster of correct extent",
6534 (i != 1 ?
"FIRST" :
"SECOND"), bandindex[i]
6537 for (k = 0; k < set_count; k++) {
6538 if (_rast[k] != NULL)
6540 if (pgrastpos[k] != -1)
6541 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6546 if (!pgrtn) PG_RETURN_NULL();
6548 SET_VARSIZE(pgrtn, pgrtn->
size);
6549 PG_RETURN_POINTER(pgrtn);
6557 _isempty[0] || _isempty[1] ||
6560 elog(NOTICE,
"The two rasters provided have no intersection. Returning no band raster");
6563 if (dim[0] || dim[1]) {
6568 for (k = 0; k < set_count; k++) {
6569 if (_rast[k] != NULL)
6571 if (pgrastpos[k] != -1)
6572 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6574 elog(ERROR,
"RASTER_mapAlgebra2: Could not create no band raster");
6582 for (k = 0; k < set_count; k++) {
6583 if (_rast[k] != NULL)
6585 if (pgrastpos[k] != -1)
6586 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6591 if (!pgrtn) PG_RETURN_NULL();
6593 SET_VARSIZE(pgrtn, pgrtn->
size);
6594 PG_RETURN_POINTER(pgrtn);
6599 for (k = 0; k < set_count; k++) {
6600 if (_rast[k] != NULL)
6602 if (pgrastpos[k] != -1)
6603 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6605 elog(ERROR,
"RASTER_mapAlgebra2: ET_LAST and ET_CUSTOM are not implemented");
6615 elog(NOTICE,
"The two rasters provided do not have the respectively specified band indices. Returning no band raster of correct extent");
6617 for (k = 0; k < set_count; k++) {
6618 if (_rast[k] != NULL)
6620 if (pgrastpos[k] != -1)
6621 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6626 if (!pgrtn) PG_RETURN_NULL();
6628 SET_VARSIZE(pgrtn, pgrtn->
size);
6629 PG_RETURN_POINTER(pgrtn);
6633 for (i = 0; i < set_count; i++) {
6642 if (_band[i] == NULL) {
6643 for (k = 0; k < set_count; k++) {
6644 if (_rast[k] != NULL)
6646 if (pgrastpos[k] != -1)
6647 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6650 elog(ERROR,
"RASTER_mapAlgebra2: Could not get band %d of the %s raster",
6652 (i < 1 ?
"FIRST" :
"SECOND")
6664 if ((extenttype ==
ET_SECOND && !_isempty[1]) || _isempty[0])
6671 if (extenttype ==
ET_SECOND && !_isempty[1] && _hasnodata[1]) {
6672 nodataval = _nodataval[1];
6674 else if (!_isempty[0] && _hasnodata[0]) {
6675 nodataval = _nodataval[0];
6677 else if (!_isempty[1] && _hasnodata[1]) {
6678 nodataval = _nodataval[1];
6681 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));
6693 for (k = 0; k < set_count; k++) {
6694 if (_rast[k] != NULL)
6696 if (pgrastpos[k] != -1)
6697 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6700 elog(ERROR,
"RASTER_mapAlgebra2: Could not add new band to output raster");
6707 for (k = 0; k < set_count; k++) {
6708 if (_rast[k] != NULL)
6710 if (pgrastpos[k] != -1)
6711 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6714 elog(ERROR,
"RASTER_mapAlgebra2: Could not get newly added band of output raster");
6719 (
int) _rastoffset[0][0],
6720 (
int) _rastoffset[0][1],
6721 (
int) _rastoffset[1][0],
6722 (
int) _rastoffset[1][1]
6725 POSTGIS_RT_DEBUGF(4,
"metadata = (%f, %f, %d, %d, %f, %f, %f, %f, %d)",
6742 calltype = get_fn_expr_argtype(fcinfo->flinfo, 4);
6749 if (SPI_connect() != SPI_OK_CONNECT) {
6750 for (k = 0; k < set_count; k++) {
6751 if (_rast[k] != NULL)
6753 if (pgrastpos[k] != -1)
6754 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6757 elog(ERROR,
"RASTER_mapAlgebra2: Could not connect to the SPI manager");
6762 memset(hasargval, 0,
sizeof(
int) * spi_count);
6772 for (i = 0; i < spi_count; i++) {
6773 if (!PG_ARGISNULL(spi_exprpos[i])) {
6775 char place[5] =
"$1";
6776 expr = text_to_cstring(PG_GETARG_TEXT_P(spi_exprpos[i]));
6790 sprintf(place,
"$%d", k);
6796 len = strlen(
"SELECT (") + strlen(expr) + strlen(
")::double precision");
6797 sql = (
char *) palloc(len + 1);
6800 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6803 for (k = 0; k < set_count; k++) {
6804 if (_rast[k] != NULL)
6806 if (pgrastpos[k] != -1)
6807 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6811 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for expression parameter %d", spi_exprpos[i]);
6815 memcpy(
sql,
"SELECT (", strlen(
"SELECT ("));
6816 memcpy(
sql + strlen(
"SELECT ("), expr, strlen(expr));
6817 memcpy(
sql + strlen(
"SELECT (") + strlen(expr),
")::double precision", strlen(
")::double precision"));
6823 if (spi_argcount[i]) {
6824 argtype = (Oid *) palloc(spi_argcount[i] *
sizeof(Oid));
6825 if (argtype == NULL) {
6828 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6831 for (k = 0; k < set_count; k++) {
6832 if (_rast[k] != NULL)
6834 if (pgrastpos[k] != -1)
6835 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6839 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for prepared plan argtypes of expression parameter %d", spi_exprpos[i]);
6845 if (argpos[i][j] < 1)
continue;
6849 (strstr(argkw[j],
"[rast1.x]") != NULL) ||
6850 (strstr(argkw[j],
"[rast1.y]") != NULL) ||
6851 (strstr(argkw[j],
"[rast2.x]") != NULL) ||
6852 (strstr(argkw[j],
"[rast2.y]") != NULL)
6854 argtype[k] = INT4OID;
6858 argtype[k] = FLOAT8OID;
6864 spi_plan[i] = SPI_prepare(
sql, spi_argcount[i], argtype);
6867 if (spi_plan[i] == NULL) {
6870 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6873 for (k = 0; k < set_count; k++) {
6874 if (_rast[k] != NULL)
6876 if (pgrastpos[k] != -1)
6877 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6881 elog(ERROR,
"RASTER_mapAlgebra2: Could not create prepared plan of expression parameter %d", spi_exprpos[i]);
6887 err = SPI_execute(
sql,
TRUE, 0);
6888 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
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 evaluate expression parameter %d", spi_exprpos[i]);
6907 tupdesc = SPI_tuptable->tupdesc;
6908 tuptable = SPI_tuptable;
6909 tuple = tuptable->vals[0];
6911 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
6912 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
6915 if (SPI_tuptable) SPI_freetuptable(tuptable);
6916 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6919 for (k = 0; k < set_count; k++) {
6920 if (_rast[k] != NULL)
6922 if (pgrastpos[k] != -1)
6923 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6927 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of expression parameter %d", spi_exprpos[i]);
6933 argval[i] = DatumGetFloat8(datum);
6936 if (SPI_tuptable) SPI_freetuptable(tuptable);
6946 if (!PG_ARGISNULL(9)) {
6947 hasnodatanodataval = 1;
6948 nodatanodataval = PG_GETARG_FLOAT8(9);
6951 hasnodatanodataval = 0;
6954 case REGPROCEDUREOID: {
6956 if (!PG_ARGISNULL(4)) {
6959 ufc_noid = PG_GETARG_OID(4);
6962 fmgr_info(ufc_noid, &ufl_info);
6966 if (ufl_info.fn_retset) {
6970 else if (ufl_info.fn_nargs < 3 || ufl_info.fn_nargs > 4) {
6980 for (k = 0; k < set_count; k++) {
6981 if (_rast[k] != NULL)
6983 if (pgrastpos[k] != -1)
6984 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6989 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must have three or four input parameters");
6991 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must return double precision not resultset");
6995 if (func_volatile(ufc_noid) ==
'v') {
6996 elog(NOTICE,
"Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
7000 #if POSTGIS_PGSQL_VERSION < 120
7001 InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7002 memset(ufc_info.argnull,
FALSE,
sizeof(
bool) * ufl_info.fn_nargs);
7004 InitFunctionCallInfoData(
7005 *ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7006 ufc_info->args[0].isnull =
FALSE;
7007 ufc_info->args[1].isnull =
FALSE;
7008 ufc_info->args[2].isnull =
FALSE;
7009 if (ufl_info.fn_nargs == 4)
7010 ufc_info->args[3].isnull =
FALSE;
7013 if (ufl_info.fn_nargs != 4)
7017 #if POSTGIS_PGSQL_VERSION < 120
7018 if (!PG_ARGISNULL(7)) {
7019 ufc_info.arg[k] = PG_GETARG_DATUM(7);
7022 ufc_info.arg[k] = (Datum) NULL;
7023 ufc_info.argnull[k] =
TRUE;
7027 if (!PG_ARGISNULL(7))
7029 ufc_info->args[k].value = PG_GETARG_DATUM(7);
7033 ufc_info->args[k].value = (Datum)NULL;
7034 ufc_info->args[k].isnull =
TRUE;
7042 for (k = 0; k < set_count; k++) {
7043 if (_rast[k] != NULL)
7045 if (pgrastpos[k] != -1)
7046 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7049 elog(ERROR,
"RASTER_mapAlgebra2: Invalid data type for expression or userfunction");
7057 (calltype == TEXTOID) && (
7058 (spi_empty != spi_count) || hasnodatanodataval
7061 (calltype == REGPROCEDUREOID) && (ufc_noid != InvalidOid)
7063 for (
x = 0;
x < dim[0];
x++) {
7064 for (
y = 0;
y < dim[1];
y++) {
7067 for (i = 0; i < set_count; i++) {
7072 _x = (int)
x - (
int)_rastoffset[i][0];
7073 _y = (int)
y - (
int)_rastoffset[i][1];
7076 _pos[i][0] = _x + 1;
7077 _pos[i][1] = _y + 1;
7080 if (_band[i] == NULL) {
7081 if (!_hasnodata[i]) {
7083 _pixel[i] = _nodataval[i];
7088 (_x >= 0 && _x < _dim[i][0]) &&
7089 (_y >= 0 && _y < _dim[i][1])
7094 if (calltype == TEXTOID) {
7095 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7099 for (k = 0; k < set_count; k++) {
7100 if (_rast[k] != NULL)
7102 if (pgrastpos[k] != -1)
7103 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7107 elog(ERROR,
"RASTER_mapAlgebra2: Could not get pixel of %s raster", (i < 1 ?
"FIRST" :
"SECOND"));
7111 if (!_hasnodata[i] || !isnodata)
7130 if (!_haspixel[0] && !_haspixel[1])
7134 else if (_haspixel[0] && !_haspixel[1])
7138 else if (!_haspixel[0] && _haspixel[1])
7147 if (hasnodatanodataval) {
7149 pixel = nodatanodataval;
7153 else if (hasargval[i]) {
7158 else if (spi_plan[i] != NULL) {
7162 memset(values, (Datum) NULL,
sizeof(Datum) *
ARGKWCOUNT);
7167 if (spi_argcount[i]) {
7171 if (idx < 1)
continue;
7174 if (strstr(argkw[j],
"[rast1.x]") != NULL) {
7175 values[idx] = _pos[0][0];
7177 else if (strstr(argkw[j],
"[rast1.y]") != NULL) {
7178 values[idx] = _pos[0][1];
7181 (strstr(argkw[j],
"[rast1.val]") != NULL) ||
7182 (strstr(argkw[j],
"[rast1]") != NULL)
7184 if (_isempty[0] || !_haspixel[0])
7187 values[idx] = Float8GetDatum(_pixel[0]);
7189 else if (strstr(argkw[j],
"[rast2.x]") != NULL) {
7190 values[idx] = _pos[1][0];
7192 else if (strstr(argkw[j],
"[rast2.y]") != NULL) {
7193 values[idx] = _pos[1][1];
7196 (strstr(argkw[j],
"[rast2.val]") != NULL) ||
7197 (strstr(argkw[j],
"[rast2]") != NULL)
7199 if (_isempty[1] || !_haspixel[1])
7202 values[idx] = Float8GetDatum(_pixel[1]);
7208 err = SPI_execute_plan(spi_plan[i], values, nulls,
TRUE, 1);
7209 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
7211 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7214 for (k = 0; k < set_count; k++) {
7215 if (_rast[k] != NULL)
7217 if (pgrastpos[k] != -1)
7218 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7222 elog(ERROR,
"RASTER_mapAlgebra2: Unexpected error when running prepared statement %d", i);
7227 tupdesc = SPI_tuptable->tupdesc;
7228 tuptable = SPI_tuptable;
7229 tuple = tuptable->vals[0];
7231 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
7232 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
7234 if (SPI_tuptable) SPI_freetuptable(tuptable);
7235 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7238 for (k = 0; k < set_count; k++) {
7239 if (_rast[k] != NULL)
7241 if (pgrastpos[k] != -1)
7242 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7246 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of prepared statement %d", i);
7252 pixel = DatumGetFloat8(datum);
7255 if (SPI_tuptable) SPI_freetuptable(tuptable);
7258 case REGPROCEDUREOID: {
7263 for (i = 0; i < set_count; i++) {
7264 #if POSTGIS_PGSQL_VERSION < 120
7265 ufc_info.arg[i] = Float8GetDatum(_pixel[i]);
7267 ufc_info->args[i].value = Float8GetDatum(_pixel[i]);
7271 #if POSTGIS_PGSQL_VERSION < 120
7272 ufc_info.argnull[i] =
FALSE;
7274 ufc_info->args[i].isnull =
FALSE;
7279 #if POSTGIS_PGSQL_VERSION < 120
7280 ufc_info.argnull[i] =
TRUE;
7282 ufc_info->args[i].isnull =
TRUE;
7290 if (ufl_info.fn_strict && ufc_nullcount)
7294 if (ufl_info.fn_nargs == 4) {
7297 for (i = 0; i < set_count; i++) {
7299 d[0] = Int32GetDatum(_pos[i][0]);
7300 d[1] = Int32GetDatum(_pos[i][1]);
7303 d[2] = Int32GetDatum(_pos[i][0]);
7304 d[3] = Int32GetDatum(_pos[i][1]);
7308 a = construct_array(d, 4, INT4OID,
sizeof(
int32),
true,
'i');
7309 #if POSTGIS_PGSQL_VERSION < 120
7310 ufc_info.arg[2] = PointerGetDatum(a);
7311 ufc_info.argnull[2] =
FALSE;
7313 ufc_info->args[2].value = PointerGetDatum(a);
7314 ufc_info->args[2].isnull =
FALSE;
7318 #if POSTGIS_PGSQL_VERSION < 120
7319 datum = FunctionCallInvoke(&ufc_info);
7322 if (!ufc_info.isnull) {
7324 pixel = DatumGetFloat8(datum);
7327 datum = FunctionCallInvoke(ufc_info);
7330 if (!ufc_info->isnull)
7333 pixel = DatumGetFloat8(datum);
7343 if (calltype == TEXTOID) {
7344 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7348 for (k = 0; k < set_count; k++) {
7349 if (_rast[k] != NULL)
7351 if (pgrastpos[k] != -1)
7352 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7356 elog(ERROR,
"RASTER_mapAlgebra2: Could not set pixel value of output raster");
7368 if (calltype == TEXTOID) {
7369 for (i = 0; i < spi_count; i++) {
7370 if (spi_plan[i] != NULL) SPI_freeplan(spi_plan[i]);
7375 for (k = 0; k < set_count; k++) {
7376 if (_rast[k] != NULL)
7378 if (pgrastpos[k] != -1)
7379 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7384 if (!pgrtn) PG_RETURN_NULL();
7388 SET_VARSIZE(pgrtn, pgrtn->
size);
7389 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,...)