PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_metadata()

static void test_band_metadata ( )
static

Definition at line 27 of file cu_band_basics.c.

References ovdump::band, cu_free_raster(), ovdump::data, rt_band_t::data, ES_NONE, FALSE, rt_band_t::offline, PT_8BUI, rtpixdump::rast, rt_band_check_is_nodata(), rt_band_destroy(), rt_band_get_data(), rt_band_get_ext_band_num(), rt_band_get_ext_path(), rt_band_get_hasnodata_flag(), rt_band_get_height(), rt_band_get_isnodata_flag(), rt_band_get_nodata(), rt_band_get_ownsdata_flag(), rt_band_get_pixel(), rt_band_get_pixtype(), rt_band_get_width(), rt_band_is_offline(), rt_band_load_offline_data(), rt_band_new_inline(), rt_band_new_offline(), rt_band_set_hasnodata_flag(), rt_band_set_nodata(), rt_band_set_ownsdata_flag(), rt_raster_add_band(), rt_raster_new(), rt_raster_set_offsets(), rtalloc(), rtdealloc(), pixval::x, and pixval::y.

Referenced by band_basics_suite_setup().

27  {
28  rt_raster rast = NULL;
29  uint8_t *data = NULL;
30  rt_band band = NULL;
31  int width = 5;
32  int height = 5;
33  int temp = 0;
34  double val = 0;
35  char *path = "../regress/loader/testraster.tif";
36  uint8_t extband = 0;
37  int x;
38  int y;
39 
40  /* inline band */
41  data = rtalloc(sizeof(uint8_t) * width * height);
42  CU_ASSERT(data != NULL);
43  memset(data, 0, sizeof(uint8_t) * width * height);
44 
45  band = rt_band_new_inline(
46  width, height,
47  PT_8BUI,
48  0, 0,
49  data
50  );
51  CU_ASSERT(band != NULL);
52 
53  /* isoffline */
54  CU_ASSERT(!rt_band_is_offline(band));
55 
56  /* data */
57  CU_ASSERT(rt_band_get_data(band) != NULL);
58 
59  /* ownsdata */
60  CU_ASSERT(!rt_band_get_ownsdata_flag(band));
62  CU_ASSERT(rt_band_get_ownsdata_flag(band));
63 
64  /* dimensions */
65  CU_ASSERT_EQUAL(rt_band_get_width(band), width);
66  CU_ASSERT_EQUAL(rt_band_get_height(band), height);
67 
68  /* pixtype */
69  CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_8BUI);
70 
71  /* hasnodata */
72  CU_ASSERT(!rt_band_get_hasnodata_flag(band));
74  CU_ASSERT(rt_band_get_hasnodata_flag(band));
75 
76  /* nodataval */
77  CU_ASSERT_EQUAL(rt_band_set_nodata(band, 0, &temp), ES_NONE);
78  CU_ASSERT(!temp);
79  CU_ASSERT_EQUAL(rt_band_get_nodata(band, &val), ES_NONE);
80  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
81 
82  /* clamped nodataval */
83  CU_ASSERT_EQUAL(rt_band_set_nodata(band, -1, &temp), ES_NONE);
84  CU_ASSERT(temp);
85  CU_ASSERT_EQUAL(rt_band_get_nodata(band, &val), ES_NONE);
86  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
87 
88  /* isnodata */
89  CU_ASSERT(!rt_band_get_isnodata_flag(band));
91  CU_ASSERT(rt_band_get_isnodata_flag(band));
92 
93  rt_band_destroy(band);
94  band = NULL;
95  data = NULL;
96  rast = NULL;
97 
98  /* offline band */
99  width = 10;
100  height = 10;
101  band = rt_band_new_offline(
102  width, height,
103  PT_8BUI,
104  0, 0,
105  2, path
106  );
107  CU_ASSERT(band != NULL);
108 
109  rast = rt_raster_new(width, height);
110  CU_ASSERT(rast != NULL);
111  rt_raster_set_offsets(rast, 80, 80);
112  CU_ASSERT_NOT_EQUAL(rt_raster_add_band(rast, band, 0), -1);
113 
114  /* isoffline */
115  CU_ASSERT(rt_band_is_offline(band));
116 
117  /* ext path */
118  CU_ASSERT_STRING_EQUAL(rt_band_get_ext_path(band), path);
119 
120  /* ext band number */
121  CU_ASSERT_EQUAL(rt_band_get_ext_band_num(band, &extband), ES_NONE);
122  CU_ASSERT_EQUAL(extband, 2);
123 
124  /* band data */
125  CU_ASSERT_EQUAL(rt_band_load_offline_data(band), ES_NONE);
126  CU_ASSERT(rt_band_get_data(band) != NULL);
127 
128  for (x = 0; x < width; x++) {
129  for (y = 0; y < height; y++) {
130  CU_ASSERT_EQUAL(rt_band_get_pixel(band, x, y, &val, NULL), ES_NONE);
131  CU_ASSERT_DOUBLE_EQUAL(val, 0, 1.);
132  }
133  }
134 
135  /* test rt_band_check_is_nodata */
136  rtdealloc(band->data.offline.mem);
137  band->data.offline.mem = NULL;
138  CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
139 
140  cu_free_raster(rast);
141 }
band
Definition: ovdump.py:57
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_band.c:228
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
data
Definition: ovdump.py:103
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:242
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
const char * rt_band_get_ext_path(rt_band band)
Return band&#39;s external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:265
void cu_free_raster(rt_raster raster)
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:534
int rt_band_get_ownsdata_flag(rt_band band)
Return 0 (FALSE) or non-zero (TRUE) indicating if rt_band is responsible for managing the memory for ...
Definition: rt_band.c:526
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
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
union rt_band_t::@6 data
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band&#39;s data.
Definition: rt_band.c:331
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1619
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:507
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:516
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:302
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
Definition: rt_band.c:58
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands&#39; external band number (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:278
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_band.c:548
int32_t offline
Definition: librtcore.h:2266
void rtdealloc(void *mem)
Definition: rt_context.c:186
#define FALSE
Definition: dbfopen.c:168
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:498
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_raster.c:405
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:581
unsigned char uint8_t
Definition: uthash.h:79
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
Definition: rt_band.c:119
Here is the call graph for this function:
Here is the caller graph for this function: