PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_band_reclass ( )
static

Definition at line 788 of file cu_mapalgebra.c.

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().

788  {
789  rt_reclassexpr *exprset;
790 
792  rt_band band;
793  uint16_t x;
794  uint16_t y;
795  double nodata;
796  int cnt = 2;
797  int i = 0;
798  int rtn;
799  rt_band newband;
800  double val;
801 
802  raster = rt_raster_new(100, 10);
803  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
804  band = cu_add_band(raster, PT_16BUI, 0, 0);
805  CU_ASSERT(band != NULL);
806  rt_band_set_nodata(band, 0, NULL);
807 
808  for (x = 0; x < 100; x++) {
809  for (y = 0; y < 10; y++) {
810  rtn = rt_band_set_pixel(band, x, y, x * y + (x + y), NULL);
811  }
812  }
813 
814  rt_band_get_nodata(band, &nodata);
815  CU_ASSERT_DOUBLE_EQUAL(nodata, 0, DBL_EPSILON);
816 
817  exprset = rtalloc(cnt * sizeof(rt_reclassexpr));
818  CU_ASSERT(exprset != NULL);
819 
820  for (i = 0; i < cnt; i++) {
821  exprset[i] = rtalloc(sizeof(struct rt_reclassexpr_t));
822  CU_ASSERT(exprset[i] != NULL);
823 
824  if (i == 0) {
825  /* nodata */
826  exprset[i]->src.min = 0;
827  exprset[i]->src.inc_min = 0;
828  exprset[i]->src.exc_min = 0;
829 
830  exprset[i]->src.max = 0;
831  exprset[i]->src.inc_max = 0;
832  exprset[i]->src.exc_max = 0;
833 
834  exprset[i]->dst.min = 0;
835  exprset[i]->dst.max = 0;
836  }
837  else {
838  /* range */
839  exprset[i]->src.min = 0;
840  exprset[i]->src.inc_min = 0;
841  exprset[i]->src.exc_min = 0;
842 
843  exprset[i]->src.max = 1000;
844  exprset[i]->src.inc_max = 1;
845  exprset[i]->src.exc_max = 0;
846 
847  exprset[i]->dst.min = 1;
848  exprset[i]->dst.max = 255;
849  }
850  }
851 
852  newband = rt_band_reclass(band, PT_8BUI, 0, 0, exprset, cnt);
853  CU_ASSERT(newband != NULL);
854 
855  rtn = rt_band_get_pixel(newband, 0, 0, &val, NULL);
856  CU_ASSERT_EQUAL(rtn, ES_NONE);
857  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
858 
859  rtn = rt_band_get_pixel(newband, 49, 5, &val, NULL);
860  CU_ASSERT_EQUAL(rtn, ES_NONE);
861  CU_ASSERT_DOUBLE_EQUAL(val, 77, DBL_EPSILON);
862 
863  rtn = rt_band_get_pixel(newband, 99, 9, &val, NULL);
864  CU_ASSERT_EQUAL(rtn, ES_NONE);
865  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
866 
867  for (i = cnt - 1; i >= 0; i--) rtdealloc(exprset[i]);
868  rtdealloc(exprset);
869  cu_free_raster(raster);
870 
871  rt_band_destroy(newband);
872 }
void rtdealloc(void *mem)
Definition: rt_api.c:882
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_api.c:2061
struct rt_reclassexpr_t::rt_reclassrange dst
tuple band
Definition: ovdump.py:57
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
struct rt_reclassexpr_t::rt_reclassrange src
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_api.c:3058
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
tuple x
Definition: pixval.py:53
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_api.c:5009
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_api.c:1650
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
tuple y
Definition: pixval.py:54
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302

Here is the call graph for this function:

Here is the caller graph for this function: