6229 int pgrastpos[2] = {-1, -1};
6232 int _isempty[2] = {0};
6236 int _hasnodata[2] = {0};
6237 double _nodataval[2] = {0};
6238 double _offset[4] = {0.};
6239 double _rastoffset[2][4] = {{0.}};
6240 int _haspixel[2] = {0};
6241 double _pixel[2] = {0};
6242 int _pos[2][2] = {{0}};
6243 uint16_t _dim[2][2] = {{0}};
6245 char *pixtypename = NULL;
6247 char *extenttypename = NULL;
6252 uint16_t dim[2] = {0};
6255 double nodataval = 0;
6256 double gt[6] = {0.};
6258 Oid calltype = InvalidOid;
6261 uint16_t spi_exprpos[3] = {4, 7, 8};
6265 SPIPlanPtr spi_plan[3] = {NULL};
6266 uint16_t spi_empty = 0;
6267 Oid *argtype = NULL;
6269 char *argkw[] = {
"[rast1.x]",
"[rast1.y]",
"[rast1.val]",
"[rast1]",
"[rast2.x]",
"[rast2.y]",
"[rast2.val]",
"[rast2]"};
6273 SPITupleTable *tuptable = NULL;
6276 bool isnull =
FALSE;
6277 int hasargval[3] = {0};
6278 double argval[3] = {0.};
6279 int hasnodatanodataval = 0;
6280 double nodatanodataval = 0;
6283 Oid ufc_noid = InvalidOid;
6285 #if POSTGIS_PGSQL_VERSION < 120
6286 FunctionCallInfoData ufc_info;
6288 LOCAL_FCINFO(ufc_info, FUNC_MAX_ARGS);
6290 int ufc_nullcount = 0;
6306 for (i = 0, j = 0; i < set_count; i++) {
6307 if (!PG_ARGISNULL(j)) {
6308 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
6315 for (k = 0; k <= i; k++) {
6316 if (k < i &&
rast[k] != NULL)
6318 if (pgrastpos[k] != -1)
6319 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6321 elog(ERROR,
"RASTER_mapAlgebra2: Could not deserialize the %s raster", i < 1 ?
"first" :
"second");
6329 if (!PG_ARGISNULL(j)) {
6330 bandindex[i] = PG_GETARG_INT32(j);
6343 if (
rast[0] == NULL &&
rast[1] == NULL) {
6344 elog(NOTICE,
"The two rasters provided are NULL. Returning NULL");
6345 for (k = 0; k < set_count; k++) {
6346 if (pgrastpos[k] != -1)
6347 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6353 if (_isempty[0] && _isempty[1]) {
6354 elog(NOTICE,
"The two rasters provided are empty. Returning empty raster");
6358 for (k = 0; k < set_count; k++) {
6359 if (
rast[k] != NULL)
6361 if (pgrastpos[k] != -1)
6362 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6364 elog(ERROR,
"RASTER_mapAlgebra2: Could not create empty raster");
6374 SET_VARSIZE(pgrtn, pgrtn->
size);
6375 PG_RETURN_POINTER(pgrtn);
6380 (
rast[0] == NULL || _isempty[0]) ||
6381 (
rast[1] == NULL || _isempty[1])
6384 if (
rast[0] == NULL || _isempty[0]) {
6397 if (_rast[i] != NULL)
6409 if (_rast[i] == NULL) {
6411 for (k = 0; k < set_count; k++) {
6412 if (pgrastpos[k] != -1)
6413 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6415 elog(ERROR,
"RASTER_mapAlgebra2: Could not create NODATA raster");
6449 for (k = 0; k < set_count; k++) {
6450 if (_rast[k] != NULL)
6452 if (pgrastpos[k] != -1)
6453 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6455 elog(ERROR,
"RASTER_mapAlgebra2: Could not test for alignment on the two rasters");
6459 elog(NOTICE,
"The two rasters provided do not have the same alignment. Returning NULL");
6460 for (k = 0; k < set_count; k++) {
6461 if (_rast[k] != NULL)
6463 if (pgrastpos[k] != -1)
6464 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6470 if (!PG_ARGISNULL(5)) {
6474 if (pixtype ==
PT_END ) {
6475 for (k = 0; k < set_count; k++) {
6476 if (_rast[k] != NULL)
6478 if (pgrastpos[k] != -1)
6479 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6481 elog(ERROR,
"RASTER_mapAlgebra2: Invalid pixel type: %s", pixtypename);
6487 if (!PG_ARGISNULL(6)) {
6500 for (k = 0; k < set_count; k++) {
6501 if (_rast[k] != NULL)
6503 if (pgrastpos[k] != -1)
6504 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6506 elog(ERROR,
"RASTER_mapAlgebra2: Could not get output raster of correct extent");
6511 _rastoffset[0][0] = _offset[0];
6512 _rastoffset[0][1] = _offset[1];
6513 _rastoffset[1][0] = _offset[2];
6514 _rastoffset[1][1] = _offset[3];
6522 switch (extenttype) {
6532 (extenttype ==
ET_FIRST && i == 0) ||
6536 elog(NOTICE,
"The %s raster is NULL. Returning NULL", (i != 1 ?
"FIRST" :
"SECOND"));
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]);
6549 elog(NOTICE,
"The %s raster does not have the band at index %d. Returning no band raster of correct extent",
6550 (i != 1 ?
"FIRST" :
"SECOND"), bandindex[i]
6553 for (k = 0; k < set_count; k++) {
6554 if (_rast[k] != NULL)
6556 if (pgrastpos[k] != -1)
6557 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6562 if (!pgrtn) PG_RETURN_NULL();
6564 SET_VARSIZE(pgrtn, pgrtn->
size);
6565 PG_RETURN_POINTER(pgrtn);
6573 _isempty[0] || _isempty[1] ||
6576 elog(NOTICE,
"The two rasters provided have no intersection. Returning no band raster");
6579 if (dim[0] || dim[1]) {
6584 for (k = 0; k < set_count; k++) {
6585 if (_rast[k] != NULL)
6587 if (pgrastpos[k] != -1)
6588 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6590 elog(ERROR,
"RASTER_mapAlgebra2: Could not create no band raster");
6598 for (k = 0; k < set_count; k++) {
6599 if (_rast[k] != NULL)
6601 if (pgrastpos[k] != -1)
6602 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6607 if (!pgrtn) PG_RETURN_NULL();
6609 SET_VARSIZE(pgrtn, pgrtn->
size);
6610 PG_RETURN_POINTER(pgrtn);
6615 for (k = 0; k < set_count; k++) {
6616 if (_rast[k] != NULL)
6618 if (pgrastpos[k] != -1)
6619 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6621 elog(ERROR,
"RASTER_mapAlgebra2: ET_LAST and ET_CUSTOM are not implemented");
6631 elog(NOTICE,
"The two rasters provided do not have the respectively specified band indices. Returning no band raster of correct extent");
6633 for (k = 0; k < set_count; k++) {
6634 if (_rast[k] != NULL)
6636 if (pgrastpos[k] != -1)
6637 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6642 if (!pgrtn) PG_RETURN_NULL();
6644 SET_VARSIZE(pgrtn, pgrtn->
size);
6645 PG_RETURN_POINTER(pgrtn);
6649 for (i = 0; i < set_count; i++) {
6658 if (_band[i] == NULL) {
6659 for (k = 0; k < set_count; k++) {
6660 if (_rast[k] != NULL)
6662 if (pgrastpos[k] != -1)
6663 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6666 elog(ERROR,
"RASTER_mapAlgebra2: Could not get band %d of the %s raster",
6668 (i < 1 ?
"FIRST" :
"SECOND")
6680 if ((extenttype ==
ET_SECOND && !_isempty[1]) || _isempty[0])
6687 if (extenttype ==
ET_SECOND && !_isempty[1] && _hasnodata[1]) {
6688 nodataval = _nodataval[1];
6690 else if (!_isempty[0] && _hasnodata[0]) {
6691 nodataval = _nodataval[0];
6693 else if (!_isempty[1] && _hasnodata[1]) {
6694 nodataval = _nodataval[1];
6697 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));
6709 for (k = 0; k < set_count; k++) {
6710 if (_rast[k] != NULL)
6712 if (pgrastpos[k] != -1)
6713 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6716 elog(ERROR,
"RASTER_mapAlgebra2: Could not add new band to output raster");
6723 for (k = 0; k < set_count; k++) {
6724 if (_rast[k] != NULL)
6726 if (pgrastpos[k] != -1)
6727 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6730 elog(ERROR,
"RASTER_mapAlgebra2: Could not get newly added band of output raster");
6735 (
int) _rastoffset[0][0],
6736 (
int) _rastoffset[0][1],
6737 (
int) _rastoffset[1][0],
6738 (
int) _rastoffset[1][1]
6741 POSTGIS_RT_DEBUGF(4,
"metadata = (%f, %f, %d, %d, %f, %f, %f, %f, %d)",
6758 calltype = get_fn_expr_argtype(fcinfo->flinfo, 4);
6765 if (SPI_connect() != SPI_OK_CONNECT) {
6766 for (k = 0; k < set_count; k++) {
6767 if (_rast[k] != NULL)
6769 if (pgrastpos[k] != -1)
6770 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6773 elog(ERROR,
"RASTER_mapAlgebra2: Could not connect to the SPI manager");
6778 memset(hasargval, 0,
sizeof(
int) * spi_count);
6788 for (i = 0; i < spi_count; i++) {
6789 if (!PG_ARGISNULL(spi_exprpos[i])) {
6791 char place[5] =
"$1";
6806 sprintf(place,
"$%d", k);
6812 len = strlen(
"SELECT (") + strlen(expr) + strlen(
")::double precision");
6813 sql = (
char *) palloc(len + 1);
6816 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6819 for (k = 0; k < set_count; k++) {
6820 if (_rast[k] != NULL)
6822 if (pgrastpos[k] != -1)
6823 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6827 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for expression parameter %d", spi_exprpos[i]);
6831 strncpy(
sql,
"SELECT (", strlen(
"SELECT ("));
6832 strncpy(
sql + strlen(
"SELECT ("), expr, strlen(expr));
6833 strncpy(
sql + strlen(
"SELECT (") + strlen(expr),
")::double precision", strlen(
")::double precision"));
6839 if (spi_argcount[i]) {
6840 argtype = (Oid *) palloc(spi_argcount[i] *
sizeof(Oid));
6841 if (argtype == NULL) {
6844 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6847 for (k = 0; k < set_count; k++) {
6848 if (_rast[k] != NULL)
6850 if (pgrastpos[k] != -1)
6851 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6855 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for prepared plan argtypes of expression parameter %d", spi_exprpos[i]);
6861 if (argpos[i][j] < 1)
continue;
6865 (strstr(argkw[j],
"[rast1.x]") != NULL) ||
6866 (strstr(argkw[j],
"[rast1.y]") != NULL) ||
6867 (strstr(argkw[j],
"[rast2.x]") != NULL) ||
6868 (strstr(argkw[j],
"[rast2.y]") != NULL)
6870 argtype[k] = INT4OID;
6874 argtype[k] = FLOAT8OID;
6880 spi_plan[i] = SPI_prepare(
sql, spi_argcount[i], argtype);
6883 if (spi_plan[i] == NULL) {
6886 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6889 for (k = 0; k < set_count; k++) {
6890 if (_rast[k] != NULL)
6892 if (pgrastpos[k] != -1)
6893 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6897 elog(ERROR,
"RASTER_mapAlgebra2: Could not create prepared plan of expression parameter %d", spi_exprpos[i]);
6903 err = SPI_execute(
sql,
TRUE, 0);
6904 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
6907 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6910 for (k = 0; k < set_count; k++) {
6911 if (_rast[k] != NULL)
6913 if (pgrastpos[k] != -1)
6914 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6918 elog(ERROR,
"RASTER_mapAlgebra2: Could not evaluate expression parameter %d", spi_exprpos[i]);
6923 tupdesc = SPI_tuptable->tupdesc;
6924 tuptable = SPI_tuptable;
6925 tuple = tuptable->vals[0];
6927 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
6928 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
6931 if (SPI_tuptable) SPI_freetuptable(tuptable);
6932 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6935 for (k = 0; k < set_count; k++) {
6936 if (_rast[k] != NULL)
6938 if (pgrastpos[k] != -1)
6939 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6943 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of expression parameter %d", spi_exprpos[i]);
6949 argval[i] = DatumGetFloat8(datum);
6952 if (SPI_tuptable) SPI_freetuptable(tuptable);
6962 if (!PG_ARGISNULL(9)) {
6963 hasnodatanodataval = 1;
6964 nodatanodataval = PG_GETARG_FLOAT8(9);
6967 hasnodatanodataval = 0;
6970 case REGPROCEDUREOID: {
6972 if (!PG_ARGISNULL(4)) {
6975 ufc_noid = PG_GETARG_OID(4);
6978 fmgr_info(ufc_noid, &ufl_info);
6982 if (ufl_info.fn_retset) {
6986 else if (ufl_info.fn_nargs < 3 || ufl_info.fn_nargs > 4) {
6996 for (k = 0; k < set_count; k++) {
6997 if (_rast[k] != NULL)
6999 if (pgrastpos[k] != -1)
7000 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7005 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must have three or four input parameters");
7007 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must return double precision not resultset");
7011 if (func_volatile(ufc_noid) ==
'v') {
7012 elog(NOTICE,
"Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
7016 #if POSTGIS_PGSQL_VERSION < 120
7017 InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7018 memset(ufc_info.argnull,
FALSE,
sizeof(
bool) * ufl_info.fn_nargs);
7020 InitFunctionCallInfoData(
7021 *ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7022 ufc_info->args[0].isnull =
FALSE;
7023 ufc_info->args[1].isnull =
FALSE;
7024 ufc_info->args[2].isnull =
FALSE;
7025 if (ufl_info.fn_nargs == 4)
7026 ufc_info->args[3].isnull =
FALSE;
7029 if (ufl_info.fn_nargs != 4)
7033 #if POSTGIS_PGSQL_VERSION < 120
7034 if (!PG_ARGISNULL(7)) {
7035 ufc_info.arg[k] = PG_GETARG_DATUM(7);
7038 ufc_info.arg[k] = (Datum) NULL;
7039 ufc_info.argnull[k] =
TRUE;
7043 if (!PG_ARGISNULL(7))
7045 ufc_info->args[k].value = PG_GETARG_DATUM(7);
7049 ufc_info->args[k].value = (Datum)NULL;
7050 ufc_info->args[k].isnull =
TRUE;
7058 for (k = 0; k < set_count; k++) {
7059 if (_rast[k] != NULL)
7061 if (pgrastpos[k] != -1)
7062 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7065 elog(ERROR,
"RASTER_mapAlgebra2: Invalid data type for expression or userfunction");
7073 (calltype == TEXTOID) && (
7074 (spi_empty != spi_count) || hasnodatanodataval
7077 (calltype == REGPROCEDUREOID) && (ufc_noid != InvalidOid)
7079 for (
x = 0;
x < dim[0];
x++) {
7080 for (
y = 0;
y < dim[1];
y++) {
7083 for (i = 0; i < set_count; i++) {
7088 _x =
x - (int) _rastoffset[i][0];
7089 _y =
y - (int) _rastoffset[i][1];
7092 _pos[i][0] = _x + 1;
7093 _pos[i][1] = _y + 1;
7096 if (_band[i] == NULL) {
7097 if (!_hasnodata[i]) {
7099 _pixel[i] = _nodataval[i];
7104 (_x >= 0 && _x < _dim[i][0]) &&
7105 (_y >= 0 && _y < _dim[i][1])
7110 if (calltype == TEXTOID) {
7111 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7115 for (k = 0; k < set_count; k++) {
7116 if (_rast[k] != NULL)
7118 if (pgrastpos[k] != -1)
7119 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7123 elog(ERROR,
"RASTER_mapAlgebra2: Could not get pixel of %s raster", (i < 1 ?
"FIRST" :
"SECOND"));
7127 if (!_hasnodata[i] || !isnodata)
7146 if (!_haspixel[0] && !_haspixel[1])
7150 else if (_haspixel[0] && !_haspixel[1])
7154 else if (!_haspixel[0] && _haspixel[1])
7163 if (hasnodatanodataval) {
7165 pixel = nodatanodataval;
7169 else if (hasargval[i]) {
7174 else if (spi_plan[i] != NULL) {
7178 memset(values, (Datum) NULL,
sizeof(Datum) *
ARGKWCOUNT);
7183 if (spi_argcount[i]) {
7187 if (idx < 1)
continue;
7190 if (strstr(argkw[j],
"[rast1.x]") != NULL) {
7191 values[idx] = _pos[0][0];
7193 else if (strstr(argkw[j],
"[rast1.y]") != NULL) {
7194 values[idx] = _pos[0][1];
7197 (strstr(argkw[j],
"[rast1.val]") != NULL) ||
7198 (strstr(argkw[j],
"[rast1]") != NULL)
7200 if (_isempty[0] || !_haspixel[0])
7203 values[idx] = Float8GetDatum(_pixel[0]);
7205 else if (strstr(argkw[j],
"[rast2.x]") != NULL) {
7206 values[idx] = _pos[1][0];
7208 else if (strstr(argkw[j],
"[rast2.y]") != NULL) {
7209 values[idx] = _pos[1][1];
7212 (strstr(argkw[j],
"[rast2.val]") != NULL) ||
7213 (strstr(argkw[j],
"[rast2]") != NULL)
7215 if (_isempty[1] || !_haspixel[1])
7218 values[idx] = Float8GetDatum(_pixel[1]);
7224 err = SPI_execute_plan(spi_plan[i], values, nulls,
TRUE, 1);
7225 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
7227 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7230 for (k = 0; k < set_count; k++) {
7231 if (_rast[k] != NULL)
7233 if (pgrastpos[k] != -1)
7234 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7238 elog(ERROR,
"RASTER_mapAlgebra2: Unexpected error when running prepared statement %d", i);
7243 tupdesc = SPI_tuptable->tupdesc;
7244 tuptable = SPI_tuptable;
7245 tuple = tuptable->vals[0];
7247 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
7248 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
7250 if (SPI_tuptable) SPI_freetuptable(tuptable);
7251 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7254 for (k = 0; k < set_count; k++) {
7255 if (_rast[k] != NULL)
7257 if (pgrastpos[k] != -1)
7258 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7262 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of prepared statement %d", i);
7268 pixel = DatumGetFloat8(datum);
7271 if (SPI_tuptable) SPI_freetuptable(tuptable);
7274 case REGPROCEDUREOID: {
7279 for (i = 0; i < set_count; i++) {
7280 #if POSTGIS_PGSQL_VERSION < 120
7281 ufc_info.arg[i] = Float8GetDatum(_pixel[i]);
7283 ufc_info->args[i].value = Float8GetDatum(_pixel[i]);
7287 #if POSTGIS_PGSQL_VERSION < 120
7288 ufc_info.argnull[i] =
FALSE;
7290 ufc_info->args[i].isnull =
FALSE;
7295 #if POSTGIS_PGSQL_VERSION < 120
7296 ufc_info.argnull[i] =
TRUE;
7298 ufc_info->args[i].isnull =
TRUE;
7306 if (ufl_info.fn_strict && ufc_nullcount)
7310 if (ufl_info.fn_nargs == 4) {
7313 for (i = 0; i < set_count; i++) {
7315 d[0] = Int32GetDatum(_pos[i][0]);
7316 d[1] = Int32GetDatum(_pos[i][1]);
7319 d[2] = Int32GetDatum(_pos[i][0]);
7320 d[3] = Int32GetDatum(_pos[i][1]);
7324 a = construct_array(d, 4, INT4OID,
sizeof(
int32),
true,
'i');
7325 #if POSTGIS_PGSQL_VERSION < 120
7326 ufc_info.arg[2] = PointerGetDatum(a);
7327 ufc_info.argnull[2] =
FALSE;
7329 ufc_info->args[2].value = PointerGetDatum(a);
7330 ufc_info->args[2].isnull =
FALSE;
7334 #if POSTGIS_PGSQL_VERSION < 120
7335 datum = FunctionCallInvoke(&ufc_info);
7338 if (!ufc_info.isnull) {
7340 pixel = DatumGetFloat8(datum);
7343 datum = FunctionCallInvoke(ufc_info);
7346 if (!ufc_info->isnull)
7349 pixel = DatumGetFloat8(datum);
7359 if (calltype == TEXTOID) {
7360 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7364 for (k = 0; k < set_count; k++) {
7365 if (_rast[k] != NULL)
7367 if (pgrastpos[k] != -1)
7368 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7372 elog(ERROR,
"RASTER_mapAlgebra2: Could not set pixel value of output raster");
7384 if (calltype == TEXTOID) {
7385 for (i = 0; i < spi_count; i++) {
7386 if (spi_plan[i] != NULL) SPI_freeplan(spi_plan[i]);
7391 for (k = 0; k < set_count; k++) {
7392 if (_rast[k] != NULL)
7394 if (pgrastpos[k] != -1)
7395 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7400 if (!pgrtn) PG_RETURN_NULL();
7404 SET_VARSIZE(pgrtn, pgrtn->
size);
7405 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 * text_to_cstring(const text *textptr)
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,...)