PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_band_set_pixel_line ( rt_band  band,
int  x,
int  y,
void *  vals,
uint32_t  len 
)

Set values of multiple pixels.

Unlike rt_band_set_pixel, values in vals are expected to be of the band's pixel type as this function uses memcpy.

It is important to be careful when using this function as the number of values being set may exceed a pixel "row". Remember that the band values are stored in a stream (1-D array) regardless of what the raster's width and height might be. So, setting a number of values may cross multiple pixel "rows".

Parameters
band: the band to set value to
x: X coordinate (0-based)
y: Y coordinate (0-based)
vals: the pixel values to apply
len: # of elements in vals
Returns
ES_NONE on success, ES_ERROR on error

Definition at line 2181 of file rt_api.c.

References ovdump::data, ES_ERROR, ES_NONE, rt_band_t::height, rt_band_t::offline, 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_DEBUGF, rt_band_get_data(), rt_band_get_hasnodata_flag(), rt_band_get_pixel(), rt_band_set_isnodata_flag(), rt_pixtype_size(), rterror(), genraster::value, and rt_band_t::width.

Referenced by RASTER_tile(), RASTER_union_transfn(), and rt_raster_from_gdal_dataset().

2185  {
2186  rt_pixtype pixtype = PT_END;
2187  int size = 0;
2188  uint8_t *data = NULL;
2189  uint32_t offset = 0;
2190 
2191  assert(NULL != band);
2192  assert(vals != NULL && len > 0);
2193 
2194  RASTER_DEBUGF(3, "length of values = %d", len);
2195 
2196  if (band->offline) {
2197  rterror("rt_band_set_pixel_line not implemented yet for OFFDB bands");
2198  return ES_ERROR;
2199  }
2200 
2201  pixtype = band->pixtype;
2202  size = rt_pixtype_size(pixtype);
2203 
2204  if (
2205  x < 0 || x >= band->width ||
2206  y < 0 || y >= band->height
2207  ) {
2208  rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
2209  return ES_ERROR;
2210  }
2211 
2212  data = rt_band_get_data(band);
2213  offset = x + (y * band->width);
2214  RASTER_DEBUGF(4, "offset = %d", offset);
2215 
2216  /* make sure len of values to copy don't exceed end of data */
2217  if (len > (band->width * band->height) - offset) {
2218  rterror("rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
2219  return ES_ERROR;
2220  }
2221 
2222  switch (pixtype) {
2223  case PT_1BB:
2224  case PT_2BUI:
2225  case PT_4BUI:
2226  case PT_8BUI:
2227  case PT_8BSI: {
2228  uint8_t *ptr = data;
2229  ptr += offset;
2230  memcpy(ptr, vals, size * len);
2231  break;
2232  }
2233  case PT_16BUI: {
2234  uint16_t *ptr = (uint16_t *) data;
2235  ptr += offset;
2236  memcpy(ptr, vals, size * len);
2237  break;
2238  }
2239  case PT_16BSI: {
2240  int16_t *ptr = (int16_t *) data;
2241  ptr += offset;
2242  memcpy(ptr, vals, size * len);
2243  break;
2244  }
2245  case PT_32BUI: {
2246  uint32_t *ptr = (uint32_t *) data;
2247  ptr += offset;
2248  memcpy(ptr, vals, size * len);
2249  break;
2250  }
2251  case PT_32BSI: {
2252  int32_t *ptr = (int32_t *) data;
2253  ptr += offset;
2254  memcpy(ptr, vals, size * len);
2255  break;
2256  }
2257  case PT_32BF: {
2258  float *ptr = (float *) data;
2259  ptr += offset;
2260  memcpy(ptr, vals, size * len);
2261  break;
2262  }
2263  case PT_64BF: {
2264  double *ptr = (double *) data;
2265  ptr += offset;
2266  memcpy(ptr, vals, size * len);
2267  break;
2268  }
2269  default: {
2270  rterror("rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
2271  return ES_ERROR;
2272  }
2273  }
2274 
2275 #if POSTGIS_DEBUG_LEVEL > 0
2276  {
2277  double value;
2278  rt_band_get_pixel(band, x, y, &value, NULL);
2279  RASTER_DEBUGF(4, "pixel at (%d, %d) = %f", x, y, value);
2280  }
2281 #endif
2282 
2283  /* set band's isnodata flag to FALSE */
2284  if (rt_band_get_hasnodata_flag(band))
2285  rt_band_set_isnodata_flag(band, 0);
2286 
2287  return ES_NONE;
2288 }
tuple data
Definition: ovdump.py:103
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_api.c:1710
rt_pixtype pixtype
Definition: rt_api.h:2239
Definition: rt_api.h:184
uint16_t height
Definition: rt_api.h:2242
Definition: rt_api.h:173
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_api.c:1097
rt_pixtype
Definition: rt_api.h:172
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_api.c:2023
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_api.c:2549
uint16_t width
Definition: rt_api.h:2241
tuple x
Definition: pixval.py:53
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
int32_t offline
Definition: rt_api.h:2240
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_api.c:2002
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: