PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_band_get_nearest_pixel()

static void test_band_get_nearest_pixel ( )
static

Definition at line 28 of file cu_band_misc.c.

28  {
30  rt_band band;
31  int x, y;
32  uint32_t rtn;
33  const int maxX = 10;
34  const int maxY = 10;
35  rt_pixel npixels = NULL;
36 
37  double **value;
38  int **nodata;
39  int dimx;
40  int dimy;
41 
42  rast = rt_raster_new(maxX, maxY);
43  CU_ASSERT(rast != NULL);
44 
45  band = cu_add_band(rast, PT_32BUI, 1, 0);
46  CU_ASSERT(band != NULL);
47 
48  for (x = 0; x < maxX; x++) {
49  for (y = 0; y < maxY; y++) {
50  rtn = rt_band_set_pixel(band, x, y, 1, NULL);
51  }
52  }
53 
54  rt_band_set_pixel(band, 0, 0, 0, NULL);
55  rt_band_set_pixel(band, 3, 0, 0, NULL);
56  rt_band_set_pixel(band, 6, 0, 0, NULL);
57  rt_band_set_pixel(band, 9, 0, 0, NULL);
58  rt_band_set_pixel(band, 1, 2, 0, NULL);
59  rt_band_set_pixel(band, 4, 2, 0, NULL);
60  rt_band_set_pixel(band, 7, 2, 0, NULL);
61  rt_band_set_pixel(band, 2, 4, 0, NULL);
62  rt_band_set_pixel(band, 5, 4, 0, NULL);
63  rt_band_set_pixel(band, 8, 4, 0, NULL);
64  rt_band_set_pixel(band, 0, 6, 0, NULL);
65  rt_band_set_pixel(band, 3, 6, 0, NULL);
66  rt_band_set_pixel(band, 6, 6, 0, NULL);
67  rt_band_set_pixel(band, 9, 6, 0, NULL);
68  rt_band_set_pixel(band, 1, 8, 0, NULL);
69  rt_band_set_pixel(band, 4, 8, 0, NULL);
70  rt_band_set_pixel(band, 7, 8, 0, NULL);
71 
72  /* 0,0 */
74  band,
75  0, 0,
76  0, 0,
77  1,
78  &npixels
79  );
80  CU_ASSERT_EQUAL(rtn, 3);
81  if (rtn)
82  rtdealloc(npixels);
83 
84  /* 1,1 */
86  band,
87  1, 1,
88  0, 0,
89  1,
90  &npixels
91  );
92  CU_ASSERT_EQUAL(rtn, 6);
93  if (rtn)
94  rtdealloc(npixels);
95 
96  /* 4,4 */
98  band,
99  4, 4,
100  0, 0,
101  1,
102  &npixels
103  );
104  CU_ASSERT_EQUAL(rtn, 7);
105  if (rtn)
106  rtdealloc(npixels);
107 
108  /* 4,4 distance 2 */
110  band,
111  4, 4,
112  2, 2,
113  1,
114  &npixels
115  );
116  CU_ASSERT_EQUAL(rtn, 19);
117  if (rtn)
118  rtdealloc(npixels);
119 
120  /* 10,10 */
122  band,
123  10, 10,
124  0, 0,
125  1,
126  &npixels
127  );
128  CU_ASSERT_EQUAL(rtn, 1);
129  if (rtn)
130  rtdealloc(npixels);
131 
132  /* 11,11 distance 1 */
134  band,
135  11, 11,
136  1, 1,
137  1,
138  &npixels
139  );
140  CU_ASSERT_EQUAL(rtn, 0);
141  if (rtn)
142  rtdealloc(npixels);
143 
144  /* -1,-1 */
146  band,
147  -1, -1,
148  0, 0,
149  1,
150  &npixels
151  );
152  CU_ASSERT_EQUAL(rtn, 3);
153  if (rtn)
154  rtdealloc(npixels);
155 
156  /* -1,-1 distance 1 */
158  band,
159  -1, -1,
160  1, 1,
161  1,
162  &npixels
163  );
164  CU_ASSERT_EQUAL(rtn, 0);
165  if (rtn)
166  rtdealloc(npixels);
167 
168  /* -1,1 distance 1 */
170  band,
171  -1, 1,
172  1, 1,
173  1,
174  &npixels
175  );
176  CU_ASSERT_EQUAL(rtn, 2);
177 
178  rtn = rt_pixel_set_to_array(
179  npixels, rtn, NULL,
180  -1, 1,
181  1, 1,
182  &value,
183  &nodata,
184  &dimx, &dimy
185  );
186  rtdealloc(npixels);
187  CU_ASSERT_EQUAL(rtn, ES_NONE);
188  CU_ASSERT_EQUAL(dimx, 3);
189  CU_ASSERT_EQUAL(dimy, 3);
190 
191  for (x = 0; x < dimx; x++) {
192  rtdealloc(nodata[x]);
193  rtdealloc(value[x]);
194  }
195 
196  rtdealloc(nodata);
197  rtdealloc(value);
198 
199  /* -2,2 distance 1 */
201  band,
202  -2, 2,
203  1, 1,
204  1,
205  &npixels
206  );
207  CU_ASSERT_EQUAL(rtn, 0);
208  if (rtn)
209  rtdealloc(npixels);
210 
211  /* -10,2 distance 3 */
213  band,
214  -10, 2,
215  3, 3,
216  1,
217  &npixels
218  );
219  CU_ASSERT_EQUAL(rtn, 0);
220  if (rtn)
221  rtdealloc(npixels);
222 
223  /* -10,2 distance 3 include NODATA */
225  band,
226  -10, 2,
227  3, 3,
228  0,
229  &npixels
230  );
231  CU_ASSERT_EQUAL(rtn, 48);
232  if (rtn)
233  rtdealloc(npixels);
234 
235  /* 4,4 distance 3,2 */
237  band,
238  4, 4,
239  3, 2,
240  1,
241  &npixels
242  );
243  CU_ASSERT_EQUAL(rtn, 27);
244  if (rtn)
245  rtdealloc(npixels);
246 
247  /* 2,7 distance 3,1 */
249  band,
250  2, 7,
251  3, 1,
252  1,
253  &npixels
254  );
255  CU_ASSERT_EQUAL(rtn, 13);
256  if (rtn)
257  rtdealloc(npixels);
258 
259  /* 10,10 distance 1,3 */
261  band,
262  10,10,
263  1, 3,
264  1,
265  &npixels
266  );
267  CU_ASSERT_EQUAL(rtn, 3);
268  if (rtn)
269  rtdealloc(npixels);
270 
271  /* band with no NODATA */
272  band = cu_add_band(rast, PT_32BUI, 0, 0);
273  CU_ASSERT(band != NULL);
274 
275  /* 0,0 */
277  band,
278  0, 0,
279  0, 0,
280  1,
281  &npixels
282  );
283  CU_ASSERT_EQUAL(rtn, 8);
284  if (rtn)
285  rtdealloc(npixels);
286 
288 }
@ PT_32BUI
Definition: librtcore.h:194
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_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
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, uint32_t count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
Definition: rt_pixel.c:286
uint32_t rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
Definition: rt_band.c:1374
void rtdealloc(void *mem)
Definition: rt_context.c:186
int value
Definition: genraster.py:61
band
Definition: ovdump.py:57
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)
unsigned int uint32_t
Definition: uthash.h:78

References ovdump::band, cu_add_band(), cu_free_raster(), ES_NONE, PT_32BUI, rtpixdump::rast, rt_band_get_nearest_pixel(), rt_band_set_pixel(), rt_pixel_set_to_array(), rt_raster_new(), rtdealloc(), genraster::value, pixval::x, and pixval::y.

Referenced by band_misc_suite_setup().

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