6226 const uint32_t set_count = 2;
6228 int pgrastpos[2] = {-1, -1};
6231 int _isempty[2] = {0};
6232 uint32_t bandindex[2] = {0};
6235 int _hasnodata[2] = {0};
6236 double _nodataval[2] = {0};
6237 double _offset[4] = {0.};
6238 double _rastoffset[2][4] = {{0.}};
6239 int _haspixel[2] = {0};
6240 double _pixel[2] = {0};
6241 int _pos[2][2] = {{0}};
6242 uint16_t _dim[2][2] = {{0}};
6244 char *pixtypename = NULL;
6246 char *extenttypename = NULL;
6251 uint16_t dim[2] = {0};
6254 double nodataval = 0;
6255 double gt[6] = {0.};
6257 Oid calltype = InvalidOid;
6259 const uint32_t spi_count = 3;
6260 uint16_t spi_exprpos[3] = {4, 7, 8};
6261 uint32_t spi_argcount[3] = {0};
6264 SPIPlanPtr spi_plan[3] = {NULL};
6265 uint16_t spi_empty = 0;
6266 Oid *argtype = NULL;
6267 uint8_t argpos[3][8] = {{0}};
6268 char *argkw[] = {
"[rast1.x]",
"[rast1.y]",
"[rast1.val]",
"[rast1]",
"[rast2.x]",
"[rast2.y]",
"[rast2.val]",
"[rast2]"};
6272 SPITupleTable *tuptable = NULL;
6275 bool isnull =
FALSE;
6276 int hasargval[3] = {0};
6277 double argval[3] = {0.};
6278 int hasnodatanodataval = 0;
6279 double nodatanodataval = 0;
6282 Oid ufc_noid = InvalidOid;
6284 #if POSTGIS_PGSQL_VERSION < 120
6285 FunctionCallInfoData ufc_info;
6287 LOCAL_FCINFO(ufc_info, FUNC_MAX_ARGS);
6289 int ufc_nullcount = 0;
6305 for (i = 0, j = 0; i < set_count; i++) {
6306 if (!PG_ARGISNULL(j)) {
6307 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
6314 for (k = 0; k <= i; k++) {
6315 if (k < i &&
rast[k] != NULL)
6317 if (pgrastpos[k] != -1)
6318 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6320 elog(ERROR,
"RASTER_mapAlgebra2: Could not deserialize the %s raster", i < 1 ?
"first" :
"second");
6328 if (!PG_ARGISNULL(j)) {
6329 bandindex[i] = PG_GETARG_INT32(j);
6342 if (
rast[0] == NULL &&
rast[1] == NULL) {
6343 elog(NOTICE,
"The two rasters provided are NULL. Returning NULL");
6344 for (k = 0; k < set_count; k++) {
6345 if (pgrastpos[k] != -1)
6346 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6352 if (_isempty[0] && _isempty[1]) {
6353 elog(NOTICE,
"The two rasters provided are empty. Returning empty raster");
6357 for (k = 0; k < set_count; k++) {
6358 if (
rast[k] != NULL)
6360 if (pgrastpos[k] != -1)
6361 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6363 elog(ERROR,
"RASTER_mapAlgebra2: Could not create empty raster");
6373 SET_VARSIZE(pgrtn, pgrtn->
size);
6374 PG_RETURN_POINTER(pgrtn);
6379 (
rast[0] == NULL || _isempty[0]) ||
6380 (
rast[1] == NULL || _isempty[1])
6383 if (
rast[0] == NULL || _isempty[0]) {
6396 if (_rast[i] != NULL)
6408 if (_rast[i] == NULL) {
6410 for (k = 0; k < set_count; k++) {
6411 if (pgrastpos[k] != -1)
6412 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6414 elog(ERROR,
"RASTER_mapAlgebra2: Could not create NODATA raster");
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]);
6454 elog(ERROR,
"RASTER_mapAlgebra2: Could not test for alignment on the two rasters");
6458 elog(NOTICE,
"The two rasters provided do not have the same alignment. Returning NULL");
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]);
6469 if (!PG_ARGISNULL(5)) {
6473 if (pixtype ==
PT_END ) {
6474 for (k = 0; k < set_count; k++) {
6475 if (_rast[k] != NULL)
6477 if (pgrastpos[k] != -1)
6478 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6480 elog(ERROR,
"RASTER_mapAlgebra2: Invalid pixel type: %s", pixtypename);
6486 if (!PG_ARGISNULL(6)) {
6499 for (k = 0; k < set_count; k++) {
6500 if (_rast[k] != NULL)
6502 if (pgrastpos[k] != -1)
6503 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6505 elog(ERROR,
"RASTER_mapAlgebra2: Could not get output raster of correct extent");
6510 _rastoffset[0][0] = _offset[0];
6511 _rastoffset[0][1] = _offset[1];
6512 _rastoffset[1][0] = _offset[2];
6513 _rastoffset[1][1] = _offset[3];
6521 switch (extenttype) {
6531 (extenttype ==
ET_FIRST && i == 0) ||
6535 elog(NOTICE,
"The %s raster is NULL. Returning NULL", (i != 1 ?
"FIRST" :
"SECOND"));
6536 for (k = 0; k < set_count; k++) {
6537 if (_rast[k] != NULL)
6539 if (pgrastpos[k] != -1)
6540 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6548 elog(NOTICE,
"The %s raster does not have the band at index %d. Returning no band raster of correct extent",
6549 (i != 1 ?
"FIRST" :
"SECOND"), bandindex[i]
6552 for (k = 0; k < set_count; k++) {
6553 if (_rast[k] != NULL)
6555 if (pgrastpos[k] != -1)
6556 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6561 if (!pgrtn) PG_RETURN_NULL();
6563 SET_VARSIZE(pgrtn, pgrtn->
size);
6564 PG_RETURN_POINTER(pgrtn);
6572 _isempty[0] || _isempty[1] ||
6575 elog(NOTICE,
"The two rasters provided have no intersection. Returning no band raster");
6578 if (dim[0] || dim[1]) {
6583 for (k = 0; k < set_count; k++) {
6584 if (_rast[k] != NULL)
6586 if (pgrastpos[k] != -1)
6587 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6589 elog(ERROR,
"RASTER_mapAlgebra2: Could not create no band raster");
6597 for (k = 0; k < set_count; k++) {
6598 if (_rast[k] != NULL)
6600 if (pgrastpos[k] != -1)
6601 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6606 if (!pgrtn) PG_RETURN_NULL();
6608 SET_VARSIZE(pgrtn, pgrtn->
size);
6609 PG_RETURN_POINTER(pgrtn);
6614 for (k = 0; k < set_count; k++) {
6615 if (_rast[k] != NULL)
6617 if (pgrastpos[k] != -1)
6618 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6620 elog(ERROR,
"RASTER_mapAlgebra2: ET_LAST and ET_CUSTOM are not implemented");
6630 elog(NOTICE,
"The two rasters provided do not have the respectively specified band indices. Returning no band raster of correct extent");
6632 for (k = 0; k < set_count; k++) {
6633 if (_rast[k] != NULL)
6635 if (pgrastpos[k] != -1)
6636 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6641 if (!pgrtn) PG_RETURN_NULL();
6643 SET_VARSIZE(pgrtn, pgrtn->
size);
6644 PG_RETURN_POINTER(pgrtn);
6648 for (i = 0; i < set_count; i++) {
6657 if (_band[i] == NULL) {
6658 for (k = 0; k < set_count; k++) {
6659 if (_rast[k] != NULL)
6661 if (pgrastpos[k] != -1)
6662 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6665 elog(ERROR,
"RASTER_mapAlgebra2: Could not get band %d of the %s raster",
6667 (i < 1 ?
"FIRST" :
"SECOND")
6679 if ((extenttype ==
ET_SECOND && !_isempty[1]) || _isempty[0])
6686 if (extenttype ==
ET_SECOND && !_isempty[1] && _hasnodata[1]) {
6687 nodataval = _nodataval[1];
6689 else if (!_isempty[0] && _hasnodata[0]) {
6690 nodataval = _nodataval[0];
6692 else if (!_isempty[1] && _hasnodata[1]) {
6693 nodataval = _nodataval[1];
6696 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));
6708 for (k = 0; k < set_count; k++) {
6709 if (_rast[k] != NULL)
6711 if (pgrastpos[k] != -1)
6712 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6715 elog(ERROR,
"RASTER_mapAlgebra2: Could not add new band to output raster");
6722 for (k = 0; k < set_count; k++) {
6723 if (_rast[k] != NULL)
6725 if (pgrastpos[k] != -1)
6726 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6729 elog(ERROR,
"RASTER_mapAlgebra2: Could not get newly added band of output raster");
6734 (
int) _rastoffset[0][0],
6735 (
int) _rastoffset[0][1],
6736 (
int) _rastoffset[1][0],
6737 (
int) _rastoffset[1][1]
6740 POSTGIS_RT_DEBUGF(4,
"metadata = (%f, %f, %d, %d, %f, %f, %f, %f, %d)",
6757 calltype = get_fn_expr_argtype(fcinfo->flinfo, 4);
6764 if (SPI_connect() != SPI_OK_CONNECT) {
6765 for (k = 0; k < set_count; k++) {
6766 if (_rast[k] != NULL)
6768 if (pgrastpos[k] != -1)
6769 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6772 elog(ERROR,
"RASTER_mapAlgebra2: Could not connect to the SPI manager");
6777 memset(hasargval, 0,
sizeof(
int) * spi_count);
6787 for (i = 0; i < spi_count; i++) {
6788 if (!PG_ARGISNULL(spi_exprpos[i])) {
6790 char place[5] =
"$1";
6805 sprintf(place,
"$%d", k);
6811 len = strlen(
"SELECT (") + strlen(expr) + strlen(
")::double precision");
6812 sql = (
char *) palloc(len + 1);
6815 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6818 for (k = 0; k < set_count; k++) {
6819 if (_rast[k] != NULL)
6821 if (pgrastpos[k] != -1)
6822 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6826 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for expression parameter %d", spi_exprpos[i]);
6830 memcpy(
sql,
"SELECT (", strlen(
"SELECT ("));
6831 memcpy(
sql + strlen(
"SELECT ("), expr, strlen(expr));
6832 memcpy(
sql + strlen(
"SELECT (") + strlen(expr),
")::double precision", strlen(
")::double precision"));
6838 if (spi_argcount[i]) {
6839 argtype = (Oid *) palloc(spi_argcount[i] *
sizeof(Oid));
6840 if (argtype == NULL) {
6843 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6846 for (k = 0; k < set_count; k++) {
6847 if (_rast[k] != NULL)
6849 if (pgrastpos[k] != -1)
6850 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6854 elog(ERROR,
"RASTER_mapAlgebra2: Could not allocate memory for prepared plan argtypes of expression parameter %d", spi_exprpos[i]);
6860 if (argpos[i][j] < 1)
continue;
6864 (strstr(argkw[j],
"[rast1.x]") != NULL) ||
6865 (strstr(argkw[j],
"[rast1.y]") != NULL) ||
6866 (strstr(argkw[j],
"[rast2.x]") != NULL) ||
6867 (strstr(argkw[j],
"[rast2.y]") != NULL)
6869 argtype[k] = INT4OID;
6873 argtype[k] = FLOAT8OID;
6879 spi_plan[i] = SPI_prepare(
sql, spi_argcount[i], argtype);
6882 if (spi_plan[i] == NULL) {
6885 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6888 for (k = 0; k < set_count; k++) {
6889 if (_rast[k] != NULL)
6891 if (pgrastpos[k] != -1)
6892 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6896 elog(ERROR,
"RASTER_mapAlgebra2: Could not create prepared plan of expression parameter %d", spi_exprpos[i]);
6902 err = SPI_execute(
sql,
TRUE, 0);
6903 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
6906 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6909 for (k = 0; k < set_count; k++) {
6910 if (_rast[k] != NULL)
6912 if (pgrastpos[k] != -1)
6913 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6917 elog(ERROR,
"RASTER_mapAlgebra2: Could not evaluate expression parameter %d", spi_exprpos[i]);
6922 tupdesc = SPI_tuptable->tupdesc;
6923 tuptable = SPI_tuptable;
6924 tuple = tuptable->vals[0];
6926 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
6927 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
6930 if (SPI_tuptable) SPI_freetuptable(tuptable);
6931 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
6934 for (k = 0; k < set_count; k++) {
6935 if (_rast[k] != NULL)
6937 if (pgrastpos[k] != -1)
6938 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
6942 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of expression parameter %d", spi_exprpos[i]);
6948 argval[i] = DatumGetFloat8(datum);
6951 if (SPI_tuptable) SPI_freetuptable(tuptable);
6961 if (!PG_ARGISNULL(9)) {
6962 hasnodatanodataval = 1;
6963 nodatanodataval = PG_GETARG_FLOAT8(9);
6966 hasnodatanodataval = 0;
6969 case REGPROCEDUREOID: {
6971 if (!PG_ARGISNULL(4)) {
6974 ufc_noid = PG_GETARG_OID(4);
6977 fmgr_info(ufc_noid, &ufl_info);
6981 if (ufl_info.fn_retset) {
6985 else if (ufl_info.fn_nargs < 3 || ufl_info.fn_nargs > 4) {
6995 for (k = 0; k < set_count; k++) {
6996 if (_rast[k] != NULL)
6998 if (pgrastpos[k] != -1)
6999 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7004 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must have three or four input parameters");
7006 elog(ERROR,
"RASTER_mapAlgebra2: Function provided must return double precision not resultset");
7010 if (func_volatile(ufc_noid) ==
'v') {
7011 elog(NOTICE,
"Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE");
7015 #if POSTGIS_PGSQL_VERSION < 120
7016 InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7017 memset(ufc_info.argnull,
FALSE,
sizeof(
bool) * ufl_info.fn_nargs);
7019 InitFunctionCallInfoData(
7020 *ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL);
7021 ufc_info->args[0].isnull =
FALSE;
7022 ufc_info->args[1].isnull =
FALSE;
7023 ufc_info->args[2].isnull =
FALSE;
7024 if (ufl_info.fn_nargs == 4)
7025 ufc_info->args[3].isnull =
FALSE;
7028 if (ufl_info.fn_nargs != 4)
7032 #if POSTGIS_PGSQL_VERSION < 120
7033 if (!PG_ARGISNULL(7)) {
7034 ufc_info.arg[k] = PG_GETARG_DATUM(7);
7037 ufc_info.arg[k] = (Datum) NULL;
7038 ufc_info.argnull[k] =
TRUE;
7042 if (!PG_ARGISNULL(7))
7044 ufc_info->args[k].value = PG_GETARG_DATUM(7);
7048 ufc_info->args[k].value = (Datum)NULL;
7049 ufc_info->args[k].isnull =
TRUE;
7057 for (k = 0; k < set_count; k++) {
7058 if (_rast[k] != NULL)
7060 if (pgrastpos[k] != -1)
7061 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7064 elog(ERROR,
"RASTER_mapAlgebra2: Invalid data type for expression or userfunction");
7072 (calltype == TEXTOID) && (
7073 (spi_empty != spi_count) || hasnodatanodataval
7076 (calltype == REGPROCEDUREOID) && (ufc_noid != InvalidOid)
7078 for (
x = 0;
x < dim[0];
x++) {
7079 for (
y = 0;
y < dim[1];
y++) {
7082 for (i = 0; i < set_count; i++) {
7087 _x = (int)
x - (
int)_rastoffset[i][0];
7088 _y = (int)
y - (
int)_rastoffset[i][1];
7091 _pos[i][0] = _x + 1;
7092 _pos[i][1] = _y + 1;
7095 if (_band[i] == NULL) {
7096 if (!_hasnodata[i]) {
7098 _pixel[i] = _nodataval[i];
7103 (_x >= 0 && _x < _dim[i][0]) &&
7104 (_y >= 0 && _y < _dim[i][1])
7109 if (calltype == TEXTOID) {
7110 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7114 for (k = 0; k < set_count; k++) {
7115 if (_rast[k] != NULL)
7117 if (pgrastpos[k] != -1)
7118 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7122 elog(ERROR,
"RASTER_mapAlgebra2: Could not get pixel of %s raster", (i < 1 ?
"FIRST" :
"SECOND"));
7126 if (!_hasnodata[i] || !isnodata)
7145 if (!_haspixel[0] && !_haspixel[1])
7149 else if (_haspixel[0] && !_haspixel[1])
7153 else if (!_haspixel[0] && _haspixel[1])
7162 if (hasnodatanodataval) {
7164 pixel = nodatanodataval;
7168 else if (hasargval[i]) {
7173 else if (spi_plan[i] != NULL) {
7177 memset(values, (Datum) NULL,
sizeof(Datum) *
ARGKWCOUNT);
7182 if (spi_argcount[i]) {
7186 if (idx < 1)
continue;
7189 if (strstr(argkw[j],
"[rast1.x]") != NULL) {
7190 values[idx] = _pos[0][0];
7192 else if (strstr(argkw[j],
"[rast1.y]") != NULL) {
7193 values[idx] = _pos[0][1];
7196 (strstr(argkw[j],
"[rast1.val]") != NULL) ||
7197 (strstr(argkw[j],
"[rast1]") != NULL)
7199 if (_isempty[0] || !_haspixel[0])
7202 values[idx] = Float8GetDatum(_pixel[0]);
7204 else if (strstr(argkw[j],
"[rast2.x]") != NULL) {
7205 values[idx] = _pos[1][0];
7207 else if (strstr(argkw[j],
"[rast2.y]") != NULL) {
7208 values[idx] = _pos[1][1];
7211 (strstr(argkw[j],
"[rast2.val]") != NULL) ||
7212 (strstr(argkw[j],
"[rast2]") != NULL)
7214 if (_isempty[1] || !_haspixel[1])
7217 values[idx] = Float8GetDatum(_pixel[1]);
7223 err = SPI_execute_plan(spi_plan[i], values, nulls,
TRUE, 1);
7224 if (err != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
7226 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7229 for (k = 0; k < set_count; k++) {
7230 if (_rast[k] != NULL)
7232 if (pgrastpos[k] != -1)
7233 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7237 elog(ERROR,
"RASTER_mapAlgebra2: Unexpected error when running prepared statement %d", i);
7242 tupdesc = SPI_tuptable->tupdesc;
7243 tuptable = SPI_tuptable;
7244 tuple = tuptable->vals[0];
7246 datum = SPI_getbinval(tuple, tupdesc, 1, &isnull);
7247 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
7249 if (SPI_tuptable) SPI_freetuptable(tuptable);
7250 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7253 for (k = 0; k < set_count; k++) {
7254 if (_rast[k] != NULL)
7256 if (pgrastpos[k] != -1)
7257 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7261 elog(ERROR,
"RASTER_mapAlgebra2: Could not get result of prepared statement %d", i);
7267 pixel = DatumGetFloat8(datum);
7270 if (SPI_tuptable) SPI_freetuptable(tuptable);
7273 case REGPROCEDUREOID: {
7278 for (i = 0; i < set_count; i++) {
7279 #if POSTGIS_PGSQL_VERSION < 120
7280 ufc_info.arg[i] = Float8GetDatum(_pixel[i]);
7282 ufc_info->args[i].value = Float8GetDatum(_pixel[i]);
7286 #if POSTGIS_PGSQL_VERSION < 120
7287 ufc_info.argnull[i] =
FALSE;
7289 ufc_info->args[i].isnull =
FALSE;
7294 #if POSTGIS_PGSQL_VERSION < 120
7295 ufc_info.argnull[i] =
TRUE;
7297 ufc_info->args[i].isnull =
TRUE;
7305 if (ufl_info.fn_strict && ufc_nullcount)
7309 if (ufl_info.fn_nargs == 4) {
7312 for (i = 0; i < set_count; i++) {
7314 d[0] = Int32GetDatum(_pos[i][0]);
7315 d[1] = Int32GetDatum(_pos[i][1]);
7318 d[2] = Int32GetDatum(_pos[i][0]);
7319 d[3] = Int32GetDatum(_pos[i][1]);
7323 a = construct_array(d, 4, INT4OID,
sizeof(
int32),
true,
'i');
7324 #if POSTGIS_PGSQL_VERSION < 120
7325 ufc_info.arg[2] = PointerGetDatum(a);
7326 ufc_info.argnull[2] =
FALSE;
7328 ufc_info->args[2].value = PointerGetDatum(a);
7329 ufc_info->args[2].isnull =
FALSE;
7333 #if POSTGIS_PGSQL_VERSION < 120
7334 datum = FunctionCallInvoke(&ufc_info);
7337 if (!ufc_info.isnull) {
7339 pixel = DatumGetFloat8(datum);
7342 datum = FunctionCallInvoke(ufc_info);
7345 if (!ufc_info->isnull)
7348 pixel = DatumGetFloat8(datum);
7358 if (calltype == TEXTOID) {
7359 for (k = 0; k < spi_count; k++) SPI_freeplan(spi_plan[k]);
7363 for (k = 0; k < set_count; k++) {
7364 if (_rast[k] != NULL)
7366 if (pgrastpos[k] != -1)
7367 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7371 elog(ERROR,
"RASTER_mapAlgebra2: Could not set pixel value of output raster");
7383 if (calltype == TEXTOID) {
7384 for (i = 0; i < spi_count; i++) {
7385 if (spi_plan[i] != NULL) SPI_freeplan(spi_plan[i]);
7390 for (k = 0; k < set_count; k++) {
7391 if (_rast[k] != NULL)
7393 if (pgrastpos[k] != -1)
7394 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
7399 if (!pgrtn) PG_RETURN_NULL();
7403 SET_VARSIZE(pgrtn, pgrtn->
size);
7404 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,...)