PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rt_band_get_pixel()

rt_errorstate rt_band_get_pixel ( rt_band  band,
int  x,
int  y,
double *  value,
int *  nodata 
)

Get pixel value.

If band's isnodata flag is TRUE, value returned will be the band's NODATA value

Parameters
band: the band to get pixel value from
x: pixel column (0-based)
y: pixel row (0-based)
*value: pixel value
*nodata: 0 if pixel is not NODATA
Returns
ES_NONE on success, ES_ERROR on error

If band's isnodata flag is TRUE, value returned will be the band's NODATA value

Parameters
band: the band to set nodata value to
x: x ordinate (0-based)
y: x ordinate (0-based)
*value: pixel value
*nodata: 0 if pixel is not NODATA
Returns
0 on success, -1 on error (value out of valid range).

Definition at line 1088 of file rt_band.c.

References ovdump::data, ES_ERROR, ES_NONE, rt_band_t::hasnodata, rt_band_t::height, rt_band_t::isnodata, rt_band_t::nodataval, rt_band_t::pixtype, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, PT_END, RASTER_DEBUG, rt_band_clamped_value_is_nodata(), rt_band_get_data(), rterror(), rtwarn(), and rt_band_t::width.

Referenced by _rti_raster_get_band_perimeter(), RASTER_dumpValues(), RASTER_getPixelPolygons(), RASTER_getPixelValue(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_mapAlgebraFct(), RASTER_mapAlgebraFctNgb(), RASTER_nearestValue(), RASTER_neighborhood(), RASTER_setPixelValuesArray(), RASTER_setPixelValuesGeomval(), rt_band_check_is_nodata(), rt_band_get_nearest_pixel(), rt_band_get_pixel_of_value(), rt_band_get_quantiles_stream(), rt_band_get_summary_stats(), rt_band_get_value_count(), rt_band_reclass(), rt_band_set_pixel_line(), rt_raster_gdal_rasterize(), rt_raster_intersects(), rt_raster_intersects_algorithm(), rt_raster_iterator(), rt_raster_to_gdal_mem(), test_band_metadata(), test_band_pixtype_16BSI(), test_band_pixtype_16BUI(), test_band_pixtype_1BB(), test_band_pixtype_2BUI(), test_band_pixtype_32BF(), test_band_pixtype_32BSI(), test_band_pixtype_32BUI(), test_band_pixtype_4BUI(), test_band_pixtype_64BF(), test_band_pixtype_8BSI(), test_band_pixtype_8BUI(), test_band_reclass(), test_gdal_to_raster(), test_gdal_warp(), test_pixel_set_to_array(), test_raster_colormap(), and test_raster_wkb().

1093  {
1094  rt_pixtype pixtype = PT_END;
1095  uint8_t* data = NULL;
1096  uint32_t offset = 0;
1097 
1098  assert(NULL != band);
1099  assert(NULL != value);
1100 
1101  /* set nodata to 0 */
1102  if (nodata != NULL)
1103  *nodata = 0;
1104 
1105  if (
1106  x < 0 || x >= band->width ||
1107  y < 0 || y >= band->height
1108  ) {
1109  rtwarn("Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
1110  return ES_ERROR;
1111  }
1112 
1113  /* band is NODATA */
1114  if (band->isnodata) {
1115  RASTER_DEBUG(3, "Band's isnodata flag is TRUE. Returning NODATA value");
1116  *value = band->nodataval;
1117  if (nodata != NULL) *nodata = 1;
1118  return ES_NONE;
1119  }
1120 
1121  data = rt_band_get_data(band);
1122  if (data == NULL) {
1123  rterror("rt_band_get_pixel: Cannot get band data");
1124  return ES_ERROR;
1125  }
1126 
1127  /* +1 for the nodata value */
1128  offset = x + (y * band->width);
1129 
1130  pixtype = band->pixtype;
1131 
1132  switch (pixtype) {
1133  case PT_1BB:
1134 #ifdef OPTIMIZE_SPACE
1135  {
1136  int byteOffset = offset / 8;
1137  int bitOffset = offset % 8;
1138  data += byteOffset;
1139 
1140  /* Bit to set is bitOffset into data */
1141  *value = getBits(data, val, 1, bitOffset);
1142  break;
1143  }
1144 #endif
1145  case PT_2BUI:
1146 #ifdef OPTIMIZE_SPACE
1147  {
1148  int byteOffset = offset / 4;
1149  int bitOffset = offset % 4;
1150  data += byteOffset;
1151 
1152  /* Bits to set start at bitOffset into data */
1153  *value = getBits(data, val, 2, bitOffset);
1154  break;
1155  }
1156 #endif
1157  case PT_4BUI:
1158 #ifdef OPTIMIZE_SPACE
1159  {
1160  int byteOffset = offset / 2;
1161  int bitOffset = offset % 2;
1162  data += byteOffset;
1163 
1164  /* Bits to set start at bitOffset into data */
1165  *value = getBits(data, val, 2, bitOffset);
1166  break;
1167  }
1168 #endif
1169  case PT_8BSI: {
1170  int8_t val = data[offset];
1171  *value = val;
1172  break;
1173  }
1174  case PT_8BUI: {
1175  uint8_t val = data[offset];
1176  *value = val;
1177  break;
1178  }
1179  case PT_16BSI: {
1180  int16_t *ptr = (int16_t*) data; /* we assume correct alignment */
1181  *value = ptr[offset];
1182  break;
1183  }
1184  case PT_16BUI: {
1185  uint16_t *ptr = (uint16_t*) data; /* we assume correct alignment */
1186  *value = ptr[offset];
1187  break;
1188  }
1189  case PT_32BSI: {
1190  int32_t *ptr = (int32_t*) data; /* we assume correct alignment */
1191  *value = ptr[offset];
1192  break;
1193  }
1194  case PT_32BUI: {
1195  uint32_t *ptr = (uint32_t*) data; /* we assume correct alignment */
1196  *value = ptr[offset];
1197  break;
1198  }
1199  case PT_32BF: {
1200  float *ptr = (float*) data; /* we assume correct alignment */
1201  *value = ptr[offset];
1202  break;
1203  }
1204  case PT_64BF: {
1205  double *ptr = (double*) data; /* we assume correct alignment */
1206  *value = ptr[offset];
1207  break;
1208  }
1209  default: {
1210  rterror("rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1211  return ES_ERROR;
1212  }
1213  }
1214 
1215  /* set NODATA flag */
1216  if (band->hasnodata && nodata != NULL) {
1218  *nodata = 1;
1219  }
1220 
1221  return ES_NONE;
1222 }
rt_pixtype pixtype
Definition: librtcore.h:2265
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
data
Definition: ovdump.py:103
uint16_t height
Definition: librtcore.h:2268
rt_pixtype
Definition: librtcore.h:185
unsigned int uint32_t
Definition: uthash.h:78
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
double nodataval
Definition: librtcore.h:2272
uint16_t width
Definition: librtcore.h:2267
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band&#39;s clamped NODATA value.
Definition: rt_band.c:1665
int32_t isnodata
Definition: librtcore.h:2270
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
int32_t hasnodata
Definition: librtcore.h:2269
int value
Definition: genraster.py:61
unsigned char uint8_t
Definition: uthash.h:79
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:302
Here is the call graph for this function:
Here is the caller graph for this function: