PostGIS  2.5.0dev-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: 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 805 of file rt_band.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().

809  {
810  rt_pixtype pixtype = PT_END;
811  int size = 0;
812  uint8_t *data = NULL;
813  uint32_t offset = 0;
814 
815  assert(NULL != band);
816  assert(vals != NULL && len > 0);
817 
818  RASTER_DEBUGF(3, "length of values = %d", len);
819 
820  if (band->offline) {
821  rterror("rt_band_set_pixel_line not implemented yet for OFFDB bands");
822  return ES_ERROR;
823  }
824 
825  pixtype = band->pixtype;
826  size = rt_pixtype_size(pixtype);
827 
828  if (
829  x < 0 || x >= band->width ||
830  y < 0 || y >= band->height
831  ) {
832  rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
833  return ES_ERROR;
834  }
835 
836  data = rt_band_get_data(band);
837  offset = x + (y * band->width);
838  RASTER_DEBUGF(4, "offset = %d", offset);
839 
840  /* make sure len of values to copy don't exceed end of data */
841  if (len > (band->width * band->height) - offset) {
842  rterror("rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
843  return ES_ERROR;
844  }
845 
846  switch (pixtype) {
847  case PT_1BB:
848  case PT_2BUI:
849  case PT_4BUI:
850  case PT_8BUI:
851  case PT_8BSI: {
852  uint8_t *ptr = data;
853  ptr += offset;
854  memcpy(ptr, vals, size * len);
855  break;
856  }
857  case PT_16BUI: {
858  uint16_t *ptr = (uint16_t *) data;
859  ptr += offset;
860  memcpy(ptr, vals, size * len);
861  break;
862  }
863  case PT_16BSI: {
864  int16_t *ptr = (int16_t *) data;
865  ptr += offset;
866  memcpy(ptr, vals, size * len);
867  break;
868  }
869  case PT_32BUI: {
870  uint32_t *ptr = (uint32_t *) data;
871  ptr += offset;
872  memcpy(ptr, vals, size * len);
873  break;
874  }
875  case PT_32BSI: {
876  int32_t *ptr = (int32_t *) data;
877  ptr += offset;
878  memcpy(ptr, vals, size * len);
879  break;
880  }
881  case PT_32BF: {
882  float *ptr = (float *) data;
883  ptr += offset;
884  memcpy(ptr, vals, size * len);
885  break;
886  }
887  case PT_64BF: {
888  double *ptr = (double *) data;
889  ptr += offset;
890  memcpy(ptr, vals, size * len);
891  break;
892  }
893  default: {
894  rterror("rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
895  return ES_ERROR;
896  }
897  }
898 
899 #if POSTGIS_DEBUG_LEVEL > 0
900  {
901  double value;
902  rt_band_get_pixel(band, x, y, &value, NULL);
903  RASTER_DEBUGF(4, "pixel at (%d, %d) = %f", x, y, value);
904  }
905 #endif
906 
907  /* set band's isnodata flag to FALSE */
908  if (rt_band_get_hasnodata_flag(band))
909  rt_band_set_isnodata_flag(band, 0);
910 
911  return ES_NONE;
912 }
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:626
rt_pixtype pixtype
Definition: librtcore.h:2294
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:2297
rt_pixtype
Definition: librtcore.h:185
unsigned int uint32_t
Definition: uthash.h:78
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
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
uint16_t width
Definition: librtcore.h:2296
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_band.c:647
int32_t offline
Definition: librtcore.h:2295
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:396
Here is the call graph for this function:
Here is the caller graph for this function: