PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_band_metadata()

static void test_band_metadata ( )
static

Definition at line 28 of file cu_band_basics.c.

28 {
29 rt_raster rast = NULL;
30 uint8_t *data = NULL;
31 rt_band band = NULL;
32 int width = 5;
33 int height = 5;
34 int temp = 0;
35 double val = 0;
36 char *path = POSTGIS_TOP_SRC_DIR "/raster/test/regress/loader/testraster.tif";
37 uint8_t extband = 0;
38 int x;
39 int y;
40
41 /* inline band */
42 data = rtalloc(sizeof(uint8_t) * width * height);
43 CU_ASSERT(data != NULL);
44 memset(data, 0, sizeof(uint8_t) * width * height);
45
47 width, height,
48 PT_8BUI,
49 0, 0,
50 data
51 );
52 CU_ASSERT(band != NULL);
53
54 /* isoffline */
55 CU_ASSERT(!rt_band_is_offline(band));
56
57 CU_ASSERT_EQUAL(rt_band_get_file_size(band), 0);
58 CU_ASSERT_EQUAL(rt_band_get_file_timestamp(band), 0);
59
60 /* data */
61 CU_ASSERT(rt_band_get_data(band) != NULL);
62
63 /* ownsdata */
64 CU_ASSERT(!rt_band_get_ownsdata_flag(band));
66 CU_ASSERT(rt_band_get_ownsdata_flag(band));
67
68 /* dimensions */
69 CU_ASSERT_EQUAL(rt_band_get_width(band), width);
70 CU_ASSERT_EQUAL(rt_band_get_height(band), height);
71
72 /* pixtype */
73 CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_8BUI);
74
75 /* hasnodata */
76 CU_ASSERT(!rt_band_get_hasnodata_flag(band));
78 CU_ASSERT(rt_band_get_hasnodata_flag(band));
79
80 /* nodataval */
81 CU_ASSERT_EQUAL(rt_band_set_nodata(band, 0, &temp), ES_NONE);
82 CU_ASSERT(!temp);
83 CU_ASSERT_EQUAL(rt_band_get_nodata(band, &val), ES_NONE);
84 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
85
86 /* clamped nodataval */
87 CU_ASSERT_EQUAL(rt_band_set_nodata(band, -1, &temp), ES_NONE);
88 CU_ASSERT(temp);
89 CU_ASSERT_EQUAL(rt_band_get_nodata(band, &val), ES_NONE);
90 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
91
92 /* isnodata */
93 CU_ASSERT(!rt_band_get_isnodata_flag(band));
95 CU_ASSERT(rt_band_get_isnodata_flag(band));
96
97 rt_band_destroy(band);
98 band = NULL;
99 data = NULL;
100 rast = NULL;
101
102 /* offline band */
103 width = 10;
104 height = 10;
106 width, height,
107 PT_8BUI,
108 0, 0,
109 2, path
110 );
111 CU_ASSERT(band != NULL);
112
113 rast = rt_raster_new(width, height);
114 CU_ASSERT(rast != NULL);
115 rt_raster_set_offsets(rast, 80, 80);
116 CU_ASSERT_NOT_EQUAL(rt_raster_add_band(rast, band, 0), -1);
117
118 /* isoffline */
119 CU_ASSERT(rt_band_is_offline(band));
120
121 /* ext path */
122 CU_ASSERT_STRING_EQUAL(rt_band_get_ext_path(band), path);
123
124 CU_ASSERT_EQUAL(rt_band_get_file_size(band), 13674);
125 CU_ASSERT_NOT_EQUAL(rt_band_get_file_timestamp(band), 0);
126
127 /* ext band number */
128 CU_ASSERT_EQUAL(rt_band_get_ext_band_num(band, &extband), ES_NONE);
129 CU_ASSERT_EQUAL(extband, 2);
130
131 /* band data */
132 CU_ASSERT_EQUAL(rt_band_load_offline_data(band), ES_NONE);
133 CU_ASSERT(rt_band_get_data(band) != NULL);
134
135 for (x = 0; x < width; x++) {
136 for (y = 0; y < height; y++) {
137 CU_ASSERT_EQUAL(rt_band_get_pixel(band, x, y, &val, NULL), ES_NONE);
138 CU_ASSERT_DOUBLE_EQUAL(val, 0, 1.);
139 }
140 }
141
142 /* test rt_band_check_is_nodata */
143 rtdealloc(band->data.offline.mem);
144 band->data.offline.mem = NULL;
145 CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
146
147 cu_free_raster(rast);
148}
#define FALSE
Definition dbfopen.c:72
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:64
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition rt_band.c:826
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition rt_band.c:799
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition rt_band.c:840
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band's data.
Definition rt_band.c:588
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition rt_raster.c:409
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition rt_band.c:833
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition rt_band.c:559
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1551
@ PT_8BUI
Definition librtcore.h:193
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition rt_band.c:873
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition rt_raster.c:52
uint64_t rt_band_get_file_size(rt_band band)
Return file size in bytes.
Definition rt_band.c:745
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition rt_band.c:2089
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:892
@ ES_NONE
Definition librtcore.h:182
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition rt_band.c:499
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:283
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands' external band number (only valid when rt_band_is_offline returns non-zero).
Definition rt_band.c:535
uint64_t rt_band_get_file_timestamp(rt_band band)
Return file timestamp.
Definition rt_band.c:767
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:2067
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition rt_band.c:790
const char * rt_band_get_ext_path(rt_band band)
Return band's external path (only valid when rt_band_is_offline returns non-zero).
Definition rt_band.c:522
void rtdealloc(void *mem)
Definition rt_context.c:206
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:818
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition rt_band.c:488
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition rt_raster.c:203
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition rt_band.c:808
void cu_free_raster(rt_raster raster)

References cu_free_raster(), ES_NONE, FALSE, PT_8BUI, 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_file_size(), rt_band_get_file_timestamp(), 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(), and rtdealloc().

Referenced by band_basics_suite_setup().

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