PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ rt_raster_iterator()

rt_errorstate rt_raster_iterator ( rt_iterator  itrset,
uint16_t  itrcount,
rt_extenttype  extenttype,
rt_raster  customextent,
rt_pixtype  pixtype,
uint8_t  hasnodata,
double  nodataval,
uint16_t  distancex,
uint16_t  distancey,
rt_mask  mask,
void *  userarg,
int(*)(rt_iterator_arg arg, void *userarg, double *value, int *nodata)  callback,
rt_raster rtnraster 
)

n-raster iterator.

Returns a raster with one band. The raster returned should be freed by the caller

Parameters
itrset: set of rt_iterator objects.
itrcount: number of objects in itrset.
extenttype: type of extent for the output raster.
customextent: raster specifying custom extent. is only used if extenttype is ET_CUSTOM.
pixtype: the desired pixel type of the output raster's band.
hasnodata: indicates if the band has nodata value
nodataval: the nodata value, will be appropriately truncated to fit the pixtype size.
distancex: the number of pixels around the specified pixel along the X axis
distancey: the number of pixels around the specified pixel along the Y axis
*userarg: pointer to any argument that is passed as-is to callback.
*callback: callback function for actual processing of pixel values.
*rtnraster: return one band raster from iterator process

The callback function must have the following signature.

int FNAME(rt_iterator_arg arg, void *userarg, double *value, int *nodata)

The callback function must return zero (error) or non-zero (success) indicating whether the function ran successfully. The parameters passed to the callback function are as follows.

  • rt_iterator_arg arg : struct containing pixel values, NODATA flags and metadata
  • void *userarg : NULL or calling function provides to rt_raster_iterator() for use by callback function
  • double *value : value of pixel to be burned by rt_raster_iterator()
  • int *nodata : flag (0 or 1) indicating that pixel to be burned is NODATA
Returns
ES_NONE on success, ES_ERROR on error

The raster returned should be freed by the caller

Parameters
itrset: set of rt_iterator objects.
itrcount: number of objects in itrset.
extenttype: type of extent for the output raster.
customextent: raster specifying custom extent. is only used if extenttype is ET_CUSTOM.
pixtype: the desired pixel type of the output raster's band.
hasnodata: indicates if the band has nodata value
nodataval: the nodata value, will be appropriately truncated to fit the pixtype size.
distancex: the number of pixels around the specified pixel along the X axis
distancey: the number of pixels around the specified pixel along the Y axis
mask: the object of mask
userarg: pointer to any argument that is passed as-is to callback.
callback: callback function for actual processing of pixel values.
*rtnraster: return one band raster from iterator process

The callback function must have the following signature.

int FNAME(rt_iterator_arg arg, void *userarg, double *value, int *nodata)

The callback function must return zero (error) or non-zero (success) indicating whether the function ran successfully. The parameters passed to the callback function are as follows.

  • rt_iterator_arg arg: struct containing pixel values, NODATA flags and metadata
  • void *userarg: NULL or calling function provides to rt_raster_iterator() for use by callback function
  • double *value: value of pixel to be burned by rt_raster_iterator()
  • int *nodata: flag (0 or 1) indicating that pixel to be burned is NODATA
Returns
ES_NONE on success, ES_ERROR on error

Definition at line 812 of file rt_mapalgebra.c.

References _rti_iterator_arg_callback_clean(), _rti_iterator_arg_callback_init(), _rti_iterator_arg_destroy(), _rti_iterator_arg_empty_init(), _rti_iterator_arg_init(), _rti_iterator_arg_populate(), _rti_iterator_arg_t::arg, _rti_iterator_arg_t::band, rt_raster_t::bands, rt_iterator_arg_t::dst_pixel, _rti_iterator_arg_t::empty, ES_ERROR, ES_NONE, ET_CUSTOM, ET_FIRST, ET_INTERSECTION, ET_LAST, ET_SECOND, ET_UNION, _rti_iterator_arg_t::hasnodata, _rti_iterator_arg_t::height, _rti_iterator_arg_t::isempty, _rti_iterator_arg_t::isnodata, _rti_iterator_arg_t::minval, rt_iterator_t::nbnodata, _rti_iterator_arg_t::nodata, rt_pixel_t::nodata, rt_iterator_arg_t::nodata, _rti_iterator_arg_t::nodataval, rt_raster_t::numBands, _rti_iterator_arg_t::offset, PT_END, rtpixdump::rast, _rti_iterator_arg_t::raster, RASTER_DEBUG, RASTER_DEBUGF, rt_band_destroy(), rt_band_get_min_value(), rt_band_get_nearest_pixel(), rt_band_get_pixel(), rt_band_set_pixel(), rt_pixel_set_to_array(), rt_raster_destroy(), rt_raster_from_two_rasters(), rt_raster_generate_new_band(), rt_raster_get_band(), rt_raster_get_height(), rt_raster_get_srid(), rt_raster_get_width(), rt_raster_get_x_offset(), rt_raster_get_x_scale(), rt_raster_get_x_skew(), rt_raster_get_y_offset(), rt_raster_get_y_scale(), rt_raster_get_y_skew(), rt_raster_is_empty(), rt_raster_new(), rt_raster_same_alignment(), rt_raster_set_scale(), rtalloc(), _rti_iterator_arg_t::rtband, rtdealloc(), rterror(), rtinfo(), rtrealloc(), rt_iterator_arg_t::src_pixel, genraster::value, rt_pixel_t::value, _rti_iterator_arg_t::values, rt_iterator_arg_t::values, _rti_iterator_arg_t::width, _rti_iterator_arg_t::x, rt_pixel_t::x, _rti_iterator_arg_t::y, and rt_pixel_t::y.

Referenced by RASTER_clip(), RASTER_nMapAlgebra(), RASTER_nMapAlgebraExpr(), RASTER_setPixelValuesGeomval(), RASTER_union_finalfn(), RASTER_union_transfn(), and test_raster_iterator().

827  {
828  /* output raster */
829  rt_raster rtnrast = NULL;
830  /* output raster's band */
831  rt_band rtnband = NULL;
832 
833  /* working raster */
834  rt_raster rast = NULL;
835 
836  _rti_iterator_arg _param = NULL;
837  int allnull = 0;
838  int allempty = 0;
839  int aligned = 0;
840  double offset[4] = {0.};
841  rt_pixel npixels;
842 
843  int i = 0;
844  int status = 0;
845  int inextent = 0;
846  int x = 0;
847  int y = 0;
848  int _x = 0;
849  int _y = 0;
850 
851  int _width = 0;
852  int _height = 0;
853 
854  double minval;
855  double value;
856  int isnodata;
857  int nodata;
858 
859  RASTER_DEBUG(3, "Starting...");
860 
861  assert(itrset != NULL && itrcount > 0);
862  assert(rtnraster != NULL);
863 
864  /* init rtnraster to NULL */
865  *rtnraster = NULL;
866 
867  /* check that callback function is not NULL */
868  if (callback == NULL) {
869  rterror("rt_raster_iterator: Callback function not provided");
870  return ES_ERROR;
871  }
872 
873  /* check that custom extent is provided if extenttype = ET_CUSTOM */
874  if (extenttype == ET_CUSTOM && rt_raster_is_empty(customextent)) {
875  rterror("rt_raster_iterator: Custom extent cannot be empty if extent type is ET_CUSTOM");
876  return ES_ERROR;
877  }
878 
879  /* check that pixtype != PT_END */
880  if (pixtype == PT_END) {
881  rterror("rt_raster_iterator: Pixel type cannot be PT_END");
882  return ES_ERROR;
883  }
884 
885  /* initialize _param */
886  if ((_param = _rti_iterator_arg_init()) == NULL) {
887  rterror("rt_raster_iterator: Could not initialize internal variables");
888  return ES_ERROR;
889  }
890 
891  /* fill _param */
892  if (!_rti_iterator_arg_populate(_param, itrset, itrcount, distancex, distancey, &allnull, &allempty)) {
893  rterror("rt_raster_iterator: Could not populate for internal variables");
895  return ES_ERROR;
896  }
897 
898  /* shortcut if all null, return NULL */
899  if (allnull == itrcount) {
900  RASTER_DEBUG(3, "all rasters are NULL, returning NULL");
901 
903 
904  return ES_NONE;
905  }
906  /* shortcut if all empty, return empty raster */
907  else if (allempty == itrcount) {
908  RASTER_DEBUG(3, "all rasters are empty, returning empty raster");
909 
911 
912  rtnrast = rt_raster_new(0, 0);
913  if (rtnrast == NULL) {
914  rterror("rt_raster_iterator: Could not create empty raster");
915  return ES_ERROR;
916  }
917  rt_raster_set_scale(rtnrast, 0, 0);
918 
919  *rtnraster = rtnrast;
920  return ES_NONE;
921  }
922 
923  /* check that all rasters are aligned */
924  RASTER_DEBUG(3, "checking alignment of all rasters");
925  rast = NULL;
926 
927  /* find raster to use as reference */
928  /* use custom if provided */
929  if (extenttype == ET_CUSTOM) {
930  RASTER_DEBUG(4, "using custom extent as reference raster");
931  rast = customextent;
932  }
933  /* use first valid one in _param->raster */
934  else {
935  for (i = 0; i < itrcount; i++) {
936  if (!_param->isempty[i]) {
937  RASTER_DEBUGF(4, "using raster at index %d as reference raster", i);
938  rast = _param->raster[i];
939  break;
940  }
941  }
942  }
943 
944  /* no rasters found, SHOULD NEVER BE HERE! */
945  if (rast == NULL) {
946  rterror("rt_raster_iterator: Could not find reference raster to use for alignment tests");
947 
949 
950  return ES_ERROR;
951  }
952 
953  do {
954  aligned = 1;
955 
956  /* check custom first if set. also skip if rasters are the same */
957  if (extenttype == ET_CUSTOM && rast != customextent) {
958  if (rt_raster_same_alignment(rast, customextent, &aligned, NULL) != ES_NONE) {
959  rterror("rt_raster_iterator: Could not test for alignment between reference raster and custom extent");
960 
962 
963  return ES_ERROR;
964  }
965 
966  RASTER_DEBUGF(5, "custom extent alignment: %d", aligned);
967  if (!aligned)
968  break;
969  }
970 
971  for (i = 0; i < itrcount; i++) {
972  /* skip NULL rasters and if rasters are the same */
973  if (_param->isempty[i] || rast == _param->raster[i])
974  continue;
975 
976  if (rt_raster_same_alignment(rast, _param->raster[i], &aligned, NULL) != ES_NONE) {
977  rterror("rt_raster_iterator: Could not test for alignment between reference raster and raster %d", i);
978 
980 
981  return ES_ERROR;
982  }
983  RASTER_DEBUGF(5, "raster at index %d alignment: %d", i, aligned);
984 
985  /* abort checking since a raster isn't aligned */
986  if (!aligned)
987  break;
988  }
989  }
990  while (0);
991 
992  /* not aligned, error */
993  if (!aligned) {
994  rterror("rt_raster_iterator: The set of rasters provided (custom extent included, if appropriate) do not have the same alignment");
995 
997 
998  return ES_ERROR;
999  }
1000 
1001  /* use extenttype to build output raster (no bands though) */
1002  i = -1;
1003  switch (extenttype) {
1004  case ET_INTERSECTION:
1005  case ET_UNION:
1006  /* make copy of first "real" raster */
1007  rtnrast = rtalloc(sizeof(struct rt_raster_t));
1008  if (rtnrast == NULL) {
1009  rterror("rt_raster_iterator: Could not allocate memory for output raster");
1010 
1011  _rti_iterator_arg_destroy(_param);
1012 
1013  return ES_ERROR;
1014  }
1015 
1016  for (i = 0; i < itrcount; i++) {
1017  if (!_param->isempty[i]) {
1018  memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t));
1019  break;
1020  }
1021  }
1022  rtnrast->numBands = 0;
1023  rtnrast->bands = NULL;
1024 
1025  /* get extent of output raster */
1026  rast = NULL;
1027  for (i = i + 1; i < itrcount; i++) {
1028  if (_param->isempty[i])
1029  continue;
1030 
1031  status = rt_raster_from_two_rasters(rtnrast, _param->raster[i], extenttype, &rast, NULL);
1032  rtdealloc(rtnrast);
1033 
1034  if (rast == NULL || status != ES_NONE) {
1035  rterror("rt_raster_iterator: Could not compute %s extent of rasters",
1036  extenttype == ET_UNION ? "union" : "intersection"
1037  );
1038 
1039  _rti_iterator_arg_destroy(_param);
1040 
1041  return ES_ERROR;
1042  }
1043  else if (rt_raster_is_empty(rast)) {
1044  rtinfo("rt_raster_iterator: Computed raster for %s extent is empty",
1045  extenttype == ET_UNION ? "union" : "intersection"
1046  );
1047 
1048  _rti_iterator_arg_destroy(_param);
1049 
1050  *rtnraster = rast;
1051  return ES_NONE;
1052  }
1053 
1054  rtnrast = rast;
1055  rast = NULL;
1056  }
1057 
1058  break;
1059  /*
1060  first, second and last have similar checks
1061  and continue into custom
1062  */
1063  case ET_FIRST:
1064  i = 0;
1065  case ET_SECOND:
1066  if (i < 0) {
1067  if (itrcount < 2)
1068  i = 0;
1069  else
1070  i = 1;
1071  }
1072  case ET_LAST:
1073  if (i < 0) i = itrcount - 1;
1074 
1075  /* input raster is null, return NULL */
1076  if (_param->raster[i] == NULL) {
1077  RASTER_DEBUGF(3, "returning NULL as %s raster is NULL and extent type is ET_%s",
1078  (i == 0 ? "first" : (i == 1 ? "second" : "last")),
1079  (i == 0 ? "FIRST" : (i == 1 ? "SECOND" : "LAST"))
1080  );
1081 
1082  _rti_iterator_arg_destroy(_param);
1083 
1084  return ES_NONE;
1085  }
1086  /* input raster is empty, return empty raster */
1087  else if (_param->isempty[i]) {
1088  RASTER_DEBUGF(3, "returning empty raster as %s raster is empty and extent type is ET_%s",
1089  (i == 0 ? "first" : (i == 1 ? "second" : "last")),
1090  (i == 0 ? "FIRST" : (i == 1 ? "SECOND" : "LAST"))
1091  );
1092 
1093  _rti_iterator_arg_destroy(_param);
1094 
1095  rtnrast = rt_raster_new(0, 0);
1096  if (rtnrast == NULL) {
1097  rterror("rt_raster_iterator: Could not create empty raster");
1098  return ES_ERROR;
1099  }
1100  rt_raster_set_scale(rtnrast, 0, 0);
1101 
1102  *rtnraster = rtnrast;
1103  return ES_NONE;
1104  }
1105  /* copy the custom extent raster */
1106  case ET_CUSTOM:
1107  rtnrast = rtalloc(sizeof(struct rt_raster_t));
1108  if (rtnrast == NULL) {
1109  rterror("rt_raster_iterator: Could not allocate memory for output raster");
1110 
1111  _rti_iterator_arg_destroy(_param);
1112 
1113  return ES_ERROR;
1114  }
1115 
1116  switch (extenttype) {
1117  case ET_CUSTOM:
1118  memcpy(rtnrast, customextent, sizeof(struct rt_raster_serialized_t));
1119  break;
1120  /* first, second, last */
1121  default:
1122  memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t));
1123  break;
1124  }
1125  rtnrast->numBands = 0;
1126  rtnrast->bands = NULL;
1127  break;
1128  }
1129 
1130  _width = rt_raster_get_width(rtnrast);
1131  _height = rt_raster_get_height(rtnrast);
1132 
1133  RASTER_DEBUGF(4, "rtnrast (width, height, ulx, uly, scalex, scaley, skewx, skewy, srid) = (%d, %d, %f, %f, %f, %f, %f, %f, %d)",
1134  _width,
1135  _height,
1136  rt_raster_get_x_offset(rtnrast),
1137  rt_raster_get_y_offset(rtnrast),
1138  rt_raster_get_x_scale(rtnrast),
1139  rt_raster_get_y_scale(rtnrast),
1140  rt_raster_get_x_skew(rtnrast),
1141  rt_raster_get_y_skew(rtnrast),
1142  rt_raster_get_srid(rtnrast)
1143  );
1144 
1145  /* init values and NODATA for use with empty rasters */
1146  if (!_rti_iterator_arg_empty_init(_param)) {
1147  rterror("rt_raster_iterator: Could not initialize empty values and NODATA");
1148 
1149  _rti_iterator_arg_destroy(_param);
1150  rt_raster_destroy(rtnrast);
1151 
1152  return ES_ERROR;
1153  }
1154 
1155  /* create output band */
1157  rtnrast,
1158  pixtype,
1159  nodataval,
1160  hasnodata, nodataval,
1161  0
1162  ) < 0) {
1163  rterror("rt_raster_iterator: Could not add new band to output raster");
1164 
1165  _rti_iterator_arg_destroy(_param);
1166  rt_raster_destroy(rtnrast);
1167 
1168  return ES_ERROR;
1169  }
1170 
1171  /* get output band */
1172  rtnband = rt_raster_get_band(rtnrast, 0);
1173  if (rtnband == NULL) {
1174  rterror("rt_raster_iterator: Could not get new band from output raster");
1175 
1176  _rti_iterator_arg_destroy(_param);
1177  rt_raster_destroy(rtnrast);
1178 
1179  return ES_ERROR;
1180  }
1181 
1182  /* output band's minimum value */
1183  minval = rt_band_get_min_value(rtnband);
1184 
1185  /* initialize argument for callback function */
1186  if (!_rti_iterator_arg_callback_init(_param)) {
1187  rterror("rt_raster_iterator: Could not initialize callback function argument");
1188 
1189  _rti_iterator_arg_destroy(_param);
1190  rt_band_destroy(rtnband);
1191  rt_raster_destroy(rtnrast);
1192 
1193  return ES_ERROR;
1194  }
1195 
1196  /* fill _param->offset */
1197  for (i = 0; i < itrcount; i++) {
1198  if (_param->isempty[i])
1199  continue;
1200 
1201  status = rt_raster_from_two_rasters(rtnrast, _param->raster[i], ET_FIRST, &rast, offset);
1202  rtdealloc(rast);
1203  if (status != ES_NONE) {
1204  rterror("rt_raster_iterator: Could not compute raster offsets");
1205 
1206  _rti_iterator_arg_destroy(_param);
1207  rt_band_destroy(rtnband);
1208  rt_raster_destroy(rtnrast);
1209 
1210  return ES_ERROR;
1211  }
1212 
1213  _param->offset[i][0] = offset[2];
1214  _param->offset[i][1] = offset[3];
1215  RASTER_DEBUGF(4, "rast %d offset: %f %f", i, offset[2], offset[3]);
1216  }
1217 
1218  /* loop over each pixel (POI) of output raster */
1219  /* _x,_y are for output raster */
1220  /* x,y are for input raster */
1221  for (_y = 0; _y < _height; _y++) {
1222  for (_x = 0; _x < _width; _x++) {
1223  RASTER_DEBUGF(4, "iterating output pixel (x, y) = (%d, %d)", _x, _y);
1224  _param->arg->dst_pixel[0] = _x;
1225  _param->arg->dst_pixel[1] = _y;
1226 
1227  /* loop through each input raster */
1228  for (i = 0; i < itrcount; i++) {
1229  RASTER_DEBUGF(4, "raster %d", i);
1230 
1231  /*
1232  empty raster
1233  OR band does not exist and flag set to use NODATA
1234  OR band is NODATA
1235  */
1236  if (
1237  _param->isempty[i] ||
1238  (_param->band.rtband[i] == NULL && itrset[i].nbnodata) ||
1239  _param->band.isnodata[i]
1240  ) {
1241  RASTER_DEBUG(4, "empty raster, band does not exist or band is NODATA. using empty values and NODATA");
1242 
1243  x = _x;
1244  y = _y;
1245 
1246  _param->arg->values[i] = _param->empty.values;
1247  _param->arg->nodata[i] = _param->empty.nodata;
1248 
1249  continue;
1250  }
1251 
1252  /* input raster's X,Y */
1253  x = _x - (int) _param->offset[i][0];
1254  y = _y - (int) _param->offset[i][1];
1255  RASTER_DEBUGF(4, "source pixel (x, y) = (%d, %d)", x, y);
1256 
1257  _param->arg->src_pixel[i][0] = x;
1258  _param->arg->src_pixel[i][1] = y;
1259 
1260  /* neighborhood */
1261  npixels = NULL;
1262  status = 0;
1263  if (distancex > 0 && distancey > 0) {
1264  RASTER_DEBUG(4, "getting neighborhood");
1265 
1266  status = rt_band_get_nearest_pixel(
1267  _param->band.rtband[i],
1268  x, y,
1269  distancex, distancey,
1270  1,
1271  &npixels
1272  );
1273  if (status < 0) {
1274  rterror("rt_raster_iterator: Could not get pixel neighborhood");
1275 
1276  _rti_iterator_arg_destroy(_param);
1277  rt_band_destroy(rtnband);
1278  rt_raster_destroy(rtnrast);
1279 
1280  return ES_ERROR;
1281  }
1282  }
1283 
1284  /* get value of POI */
1285  /* get pixel's value */
1286  if (
1287  (x >= 0 && x < _param->width[i]) &&
1288  (y >= 0 && y < _param->height[i])
1289  ) {
1290  RASTER_DEBUG(4, "getting value of POI");
1291  if (rt_band_get_pixel(
1292  _param->band.rtband[i],
1293  x, y,
1294  &value,
1295  &isnodata
1296  ) != ES_NONE) {
1297  rterror("rt_raster_iterator: Could not get the pixel value of band");
1298 
1299  _rti_iterator_arg_destroy(_param);
1300  rt_band_destroy(rtnband);
1301  rt_raster_destroy(rtnrast);
1302 
1303  return ES_ERROR;
1304  }
1305  inextent = 1;
1306  }
1307  /* outside band extent, set to NODATA */
1308  else {
1309  RASTER_DEBUG(4, "Outside band extent, setting value to NODATA");
1310  /* has NODATA, use NODATA */
1311  if (_param->band.hasnodata[i])
1312  value = _param->band.nodataval[i];
1313  /* no NODATA, use min possible value */
1314  else
1315  value = _param->band.minval[i];
1316 
1317  inextent = 0;
1318  isnodata = 1;
1319  }
1320 
1321  /* add pixel to neighborhood */
1322  status++;
1323  if (status > 1)
1324  npixels = (rt_pixel) rtrealloc(npixels, sizeof(struct rt_pixel_t) * status);
1325  else
1326  npixels = (rt_pixel) rtalloc(sizeof(struct rt_pixel_t));
1327 
1328  if (npixels == NULL) {
1329  rterror("rt_raster_iterator: Could not reallocate memory for neighborhood");
1330 
1331  _rti_iterator_arg_destroy(_param);
1332  rt_band_destroy(rtnband);
1333  rt_raster_destroy(rtnrast);
1334 
1335  return ES_ERROR;
1336  }
1337 
1338  npixels[status - 1].x = x;
1339  npixels[status - 1].y = y;
1340  npixels[status - 1].nodata = 1;
1341  npixels[status - 1].value = value;
1342 
1343  /* set nodata flag */
1344  if ((!_param->band.hasnodata[i] && inextent) || !isnodata) {
1345  npixels[status - 1].nodata = 0;
1346  }
1347  RASTER_DEBUGF(4, "value, nodata: %f, %d", value, npixels[status - 1].nodata);
1348 
1349  /* convert set of rt_pixel to 2D array */
1350  status = rt_pixel_set_to_array(
1351  npixels, status, mask,
1352  x, y,
1353  distancex, distancey,
1354  &(_param->arg->values[i]),
1355  &(_param->arg->nodata[i]),
1356  NULL, NULL
1357  );
1358  rtdealloc(npixels);
1359  if (status != ES_NONE) {
1360  rterror("rt_raster_iterator: Could not create 2D array of neighborhood");
1361 
1362  _rti_iterator_arg_destroy(_param);
1363  rt_band_destroy(rtnband);
1364  rt_raster_destroy(rtnrast);
1365 
1366  return ES_ERROR;
1367  }
1368  }
1369 
1370  /* callback */
1371  RASTER_DEBUG(4, "calling callback function");
1372  value = 0;
1373  nodata = 0;
1374  status = callback(_param->arg, userarg, &value, &nodata);
1375 
1376  /* free memory from callback */
1378 
1379  /* handle callback status */
1380  if (status == 0) {
1381  rterror("rt_raster_iterator: Callback function returned an error");
1382 
1383  _rti_iterator_arg_destroy(_param);
1384  rt_band_destroy(rtnband);
1385  rt_raster_destroy(rtnrast);
1386 
1387  return ES_ERROR;
1388  }
1389 
1390  /* burn value to pixel */
1391  status = 0;
1392  if (!nodata) {
1393  status = rt_band_set_pixel(rtnband, _x, _y, value, NULL);
1394  RASTER_DEBUGF(4, "burning pixel (%d, %d) with value: %f", _x, _y, value);
1395  }
1396  else if (!hasnodata) {
1397  status = rt_band_set_pixel(rtnband, _x, _y, minval, NULL);
1398  RASTER_DEBUGF(4, "burning pixel (%d, %d) with minval: %f", _x, _y, minval);
1399  }
1400  else {
1401  RASTER_DEBUGF(4, "NOT burning pixel (%d, %d)", _x, _y);
1402  }
1403  if (status != ES_NONE) {
1404  rterror("rt_raster_iterator: Could not set pixel value");
1405 
1406  _rti_iterator_arg_destroy(_param);
1407  rt_band_destroy(rtnband);
1408  rt_raster_destroy(rtnrast);
1409 
1410  return ES_ERROR;
1411  }
1412  }
1413  }
1414 
1415  /* lots of cleanup */
1416  _rti_iterator_arg_destroy(_param);
1417 
1418  *rtnraster = rtnrast;
1419  return ES_NONE;
1420 }
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
uint16_t numBands
Definition: librtcore.h:2270
struct rt_pixel_t * rt_pixel
Definition: librtcore.h:147
static _rti_iterator_arg _rti_iterator_arg_init()
static int _rti_iterator_arg_empty_init(_rti_iterator_arg _param)
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
Definition: rt_raster.c:3465
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
rt_iterator_arg arg
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:179
double value
Definition: librtcore.h:2318
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:336
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1338
struct _rti_iterator_arg_t::@13 empty
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1173
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
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.
Definition: rt_raster.c:485
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
void rtinfo(const char *fmt,...)
Definition: rt_context.c:211
struct _rti_iterator_arg_t::@10 band
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
int32_t rt_raster_get_srid(rt_raster raster)
Get raster&#39;s SRID.
Definition: rt_raster.c:356
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
uint8_t nodata
Definition: librtcore.h:2317
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:159
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
static void _rti_iterator_arg_callback_clean(_rti_iterator_arg _param)
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, uint32_t count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
Definition: rt_pixel.c:286
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
double *** values
Definition: librtcore.h:2439
void rtdealloc(void *mem)
Definition: rt_context.c:186
static int _rti_iterator_arg_callback_init(_rti_iterator_arg _param)
uint8_t nbnodata
Definition: librtcore.h:2425
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
Struct definitions.
Definition: librtcore.h:2230
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_band.c:1697
rt_band * bands
Definition: librtcore.h:2283
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:926
static int _rti_iterator_arg_populate(_rti_iterator_arg _param, rt_iterator itrset, uint16_t itrcount, uint16_t distancex, uint16_t distancey, int *allnull, int *allempty)
int value
Definition: genraster.py:61
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
static void _rti_iterator_arg_destroy(_rti_iterator_arg _param)
uint32_t rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
Definition: rt_band.c:1326
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
Here is the call graph for this function:
Here is the caller graph for this function: