PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_band_reclass()

static void test_band_reclass ( )
static

Definition at line 796 of file cu_mapalgebra.c.

796  {
797  rt_reclassexpr *exprset;
798 
800  rt_band band;
801  uint16_t x;
802  uint16_t y;
803  double nodata;
804  int cnt = 2;
805  int i = 0;
806  int rtn;
807  rt_band newband;
808  double val;
809 
810  raster = rt_raster_new(100, 10);
811  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
812  band = cu_add_band(raster, PT_16BUI, 0, 0);
813  CU_ASSERT(band != NULL);
814  rt_band_set_nodata(band, 0, NULL);
815 
816  for (x = 0; x < 100; x++) {
817  for (y = 0; y < 10; y++) {
818  rtn = rt_band_set_pixel(band, x, y, x * y + (x + y), NULL);
819  }
820  }
821 
822  rt_band_get_nodata(band, &nodata);
823  CU_ASSERT_DOUBLE_EQUAL(nodata, 0, DBL_EPSILON);
824 
825  exprset = rtalloc(cnt * sizeof(rt_reclassexpr));
826  CU_ASSERT(exprset != NULL);
827 
828  for (i = 0; i < cnt; i++) {
829  exprset[i] = rtalloc(sizeof(struct rt_reclassexpr_t));
830  CU_ASSERT(exprset[i] != NULL);
831 
832  if (i == 0) {
833  /* nodata */
834  exprset[i]->src.min = 0;
835  exprset[i]->src.inc_min = 0;
836  exprset[i]->src.exc_min = 0;
837 
838  exprset[i]->src.max = 0;
839  exprset[i]->src.inc_max = 0;
840  exprset[i]->src.exc_max = 0;
841 
842  exprset[i]->dst.min = 0;
843  exprset[i]->dst.max = 0;
844  }
845  else {
846  /* range */
847  exprset[i]->src.min = 0;
848  exprset[i]->src.inc_min = 0;
849  exprset[i]->src.exc_min = 0;
850 
851  exprset[i]->src.max = 1000;
852  exprset[i]->src.inc_max = 1;
853  exprset[i]->src.exc_max = 0;
854 
855  exprset[i]->dst.min = 1;
856  exprset[i]->dst.max = 255;
857  }
858  }
859 
860  newband = rt_band_reclass(band, PT_8BUI, 0, 0, exprset, cnt);
861  CU_ASSERT(newband != NULL);
862 
863  rtn = rt_band_get_pixel(newband, 0, 0, &val, NULL);
864  CU_ASSERT_EQUAL(rtn, ES_NONE);
865  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
866 
867  rtn = rt_band_get_pixel(newband, 49, 5, &val, NULL);
868  CU_ASSERT_EQUAL(rtn, ES_NONE);
869  CU_ASSERT_DOUBLE_EQUAL(val, 77, DBL_EPSILON);
870 
871  rtn = rt_band_get_pixel(newband, 99, 9, &val, NULL);
872  CU_ASSERT_EQUAL(rtn, ES_NONE);
873  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
874 
875  for (i = cnt - 1; i >= 0; i--) rtdealloc(exprset[i]);
876  rtdealloc(exprset);
878 
879  rt_band_destroy(newband);
880 }
rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, rt_reclassexpr *exprset, int exprcount)
Returns new band with values reclassified.
Definition: rt_mapalgebra.c:50
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
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
@ PT_16BUI
Definition: librtcore.h:192
@ PT_8BUI
Definition: librtcore.h:190
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:733
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:974
@ ES_NONE
Definition: librtcore.h:180
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:340
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
void rtdealloc(void *mem)
Definition: rt_context.c:186
band
Definition: ovdump.py:57
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst

References ovdump::band, cu_add_band(), cu_free_raster(), rt_reclassexpr_t::dst, ES_NONE, rt_reclassexpr_t::rt_reclassrange::exc_max, rt_reclassexpr_t::rt_reclassrange::exc_min, rt_reclassexpr_t::rt_reclassrange::inc_max, rt_reclassexpr_t::rt_reclassrange::inc_min, rt_reclassexpr_t::rt_reclassrange::max, rt_reclassexpr_t::rt_reclassrange::min, PT_16BUI, PT_8BUI, rtrowdump::raster, rt_band_destroy(), rt_band_get_nodata(), rt_band_get_pixel(), rt_band_reclass(), rt_band_set_nodata(), rt_band_set_pixel(), rt_raster_new(), rtalloc(), rtdealloc(), rt_reclassexpr_t::src, pixval::x, and pixval::y.

Referenced by mapalgebra_suite_setup().

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