PostGIS  2.4.9dev-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 720 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().

724  {
725  rt_pixtype pixtype = PT_END;
726  int size = 0;
727  uint8_t *data = NULL;
728  uint32_t offset = 0;
729 
730  assert(NULL != band);
731  assert(vals != NULL && len > 0);
732 
733  RASTER_DEBUGF(3, "length of values = %d", len);
734 
735  if (band->offline) {
736  rterror("rt_band_set_pixel_line not implemented yet for OFFDB bands");
737  return ES_ERROR;
738  }
739 
740  pixtype = band->pixtype;
741  size = rt_pixtype_size(pixtype);
742 
743  if (
744  x < 0 || x >= band->width ||
745  y < 0 || y >= band->height
746  ) {
747  rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
748  return ES_ERROR;
749  }
750 
751  data = rt_band_get_data(band);
752  offset = x + (y * band->width);
753  RASTER_DEBUGF(4, "offset = %d", offset);
754 
755  /* make sure len of values to copy don't exceed end of data */
756  if (len > (band->width * band->height) - offset) {
757  rterror("rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
758  return ES_ERROR;
759  }
760 
761  switch (pixtype) {
762  case PT_1BB:
763  case PT_2BUI:
764  case PT_4BUI:
765  case PT_8BUI:
766  case PT_8BSI: {
767  uint8_t *ptr = data;
768  ptr += offset;
769  memcpy(ptr, vals, size * len);
770  break;
771  }
772  case PT_16BUI: {
773  uint16_t *ptr = (uint16_t *) data;
774  ptr += offset;
775  memcpy(ptr, vals, size * len);
776  break;
777  }
778  case PT_16BSI: {
779  int16_t *ptr = (int16_t *) data;
780  ptr += offset;
781  memcpy(ptr, vals, size * len);
782  break;
783  }
784  case PT_32BUI: {
785  uint32_t *ptr = (uint32_t *) data;
786  ptr += offset;
787  memcpy(ptr, vals, size * len);
788  break;
789  }
790  case PT_32BSI: {
791  int32_t *ptr = (int32_t *) data;
792  ptr += offset;
793  memcpy(ptr, vals, size * len);
794  break;
795  }
796  case PT_32BF: {
797  float *ptr = (float *) data;
798  ptr += offset;
799  memcpy(ptr, vals, size * len);
800  break;
801  }
802  case PT_64BF: {
803  double *ptr = (double *) data;
804  ptr += offset;
805  memcpy(ptr, vals, size * len);
806  break;
807  }
808  default: {
809  rterror("rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
810  return ES_ERROR;
811  }
812  }
813 
814 #if POSTGIS_DEBUG_LEVEL > 0
815  {
816  double value;
817  rt_band_get_pixel(band, x, y, &value, NULL);
818  RASTER_DEBUGF(4, "pixel at (%d, %d) = %f", x, y, value);
819  }
820 #endif
821 
822  /* set band's isnodata flag to FALSE */
823  if (rt_band_get_hasnodata_flag(band))
824  rt_band_set_isnodata_flag(band, 0);
825 
826  return ES_NONE;
827 }
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
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
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1088
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
uint16_t width
Definition: librtcore.h:2267
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:562
int32_t offline
Definition: librtcore.h:2266
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: