PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_band_set_pixel_line()

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: pixel column (0-based)
y: pixel row (0-based)
vals: the pixel values to apply
len: # of elements in vals
Returns
ES_NONE on success, ES_ERROR on error

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 853 of file rt_band.c.

857  {
858  rt_pixtype pixtype = PT_END;
859  int size = 0;
860  uint8_t *data = NULL;
861  uint32_t offset = 0;
862 
863  assert(NULL != band);
864  assert(vals != NULL && len > 0);
865 
866  RASTER_DEBUGF(3, "length of values = %d", len);
867 
868  if (band->offline) {
869  rterror("rt_band_set_pixel_line not implemented yet for OFFDB bands");
870  return ES_ERROR;
871  }
872 
873  pixtype = band->pixtype;
874  size = rt_pixtype_size(pixtype);
875 
876  if (
877  x < 0 || x >= band->width ||
878  y < 0 || y >= band->height
879  ) {
880  rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
881  return ES_ERROR;
882  }
883 
885  offset = x + (y * band->width);
886  RASTER_DEBUGF(4, "offset = %d", offset);
887 
888  /* make sure len of values to copy don't exceed end of data */
889  if (len > (band->width * band->height) - offset) {
890  rterror("rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
891  return ES_ERROR;
892  }
893 
894  switch (pixtype) {
895  case PT_1BB:
896  case PT_2BUI:
897  case PT_4BUI:
898  case PT_8BUI:
899  case PT_8BSI: {
900  uint8_t *ptr = data;
901  ptr += offset;
902  memcpy(ptr, vals, size * len);
903  break;
904  }
905  case PT_16BUI: {
906  uint16_t *ptr = (uint16_t *) data;
907  ptr += offset;
908  memcpy(ptr, vals, size * len);
909  break;
910  }
911  case PT_16BSI: {
912  int16_t *ptr = (int16_t *) data;
913  ptr += offset;
914  memcpy(ptr, vals, size * len);
915  break;
916  }
917  case PT_32BUI: {
918  uint32_t *ptr = (uint32_t *) data;
919  ptr += offset;
920  memcpy(ptr, vals, size * len);
921  break;
922  }
923  case PT_32BSI: {
924  int32_t *ptr = (int32_t *) data;
925  ptr += offset;
926  memcpy(ptr, vals, size * len);
927  break;
928  }
929  case PT_32BF: {
930  float *ptr = (float *) data;
931  ptr += offset;
932  memcpy(ptr, vals, size * len);
933  break;
934  }
935  case PT_64BF: {
936  double *ptr = (double *) data;
937  ptr += offset;
938  memcpy(ptr, vals, size * len);
939  break;
940  }
941  default: {
942  rterror("rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
943  return ES_ERROR;
944  }
945  }
946 
947 #if POSTGIS_DEBUG_LEVEL > 0
948  {
949  double value;
950  rt_band_get_pixel(band, x, y, &value, NULL);
951  RASTER_DEBUGF(4, "pixel at (%d, %d) = %f", x, y, value);
952  }
953 #endif
954 
955  /* set band's isnodata flag to FALSE */
958 
959  return ES_NONE;
960 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
rt_pixtype
Definition: librtcore.h:185
@ PT_32BUI
Definition: librtcore.h:194
@ PT_2BUI
Definition: librtcore.h:187
@ PT_32BSI
Definition: librtcore.h:193
@ PT_END
Definition: librtcore.h:197
@ PT_4BUI
Definition: librtcore.h:188
@ PT_32BF
Definition: librtcore.h:195
@ PT_1BB
Definition: librtcore.h:186
@ PT_16BUI
Definition: librtcore.h:192
@ PT_8BSI
Definition: librtcore.h:189
@ PT_16BSI
Definition: librtcore.h:191
@ PT_64BF
Definition: librtcore.h:196
@ PT_8BUI
Definition: librtcore.h:190
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
int value
Definition: genraster.py:61
band
Definition: ovdump.py:57
data
Definition: ovdump.py:103
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_band.c:695
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1221
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:400
unsigned int uint32_t
Definition: uthash.h:78
unsigned char uint8_t
Definition: uthash.h:79

References ovdump::band, ovdump::data, ES_ERROR, ES_NONE, 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, pixval::x, and pixval::y.

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

Here is the call graph for this function:
Here is the caller graph for this function: