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

Definition at line 27 of file cu_band_misc.c.

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

27  {
29  rt_band band;
30  uint32_t x, y;
31  int rtn;
32  const int maxX = 10;
33  const int maxY = 10;
34  rt_pixel npixels = NULL;
35 
36  double **value;
37  int **nodata;
38  int dimx;
39  int dimy;
40 
41  rast = rt_raster_new(maxX, maxY);
42  CU_ASSERT(rast != NULL);
43 
44  band = cu_add_band(rast, PT_32BUI, 1, 0);
45  CU_ASSERT(band != NULL);
46 
47  for (x = 0; x < maxX; x++) {
48  for (y = 0; y < maxY; y++) {
49  rtn = rt_band_set_pixel(band, x, y, 1, NULL);
50  }
51  }
52 
53  rt_band_set_pixel(band, 0, 0, 0, NULL);
54  rt_band_set_pixel(band, 3, 0, 0, NULL);
55  rt_band_set_pixel(band, 6, 0, 0, NULL);
56  rt_band_set_pixel(band, 9, 0, 0, NULL);
57  rt_band_set_pixel(band, 1, 2, 0, NULL);
58  rt_band_set_pixel(band, 4, 2, 0, NULL);
59  rt_band_set_pixel(band, 7, 2, 0, NULL);
60  rt_band_set_pixel(band, 2, 4, 0, NULL);
61  rt_band_set_pixel(band, 5, 4, 0, NULL);
62  rt_band_set_pixel(band, 8, 4, 0, NULL);
63  rt_band_set_pixel(band, 0, 6, 0, NULL);
64  rt_band_set_pixel(band, 3, 6, 0, NULL);
65  rt_band_set_pixel(band, 6, 6, 0, NULL);
66  rt_band_set_pixel(band, 9, 6, 0, NULL);
67  rt_band_set_pixel(band, 1, 8, 0, NULL);
68  rt_band_set_pixel(band, 4, 8, 0, NULL);
69  rt_band_set_pixel(band, 7, 8, 0, NULL);
70 
71  /* 0,0 */
73  band,
74  0, 0,
75  0, 0,
76  1,
77  &npixels
78  );
79  CU_ASSERT_EQUAL(rtn, 3);
80  if (rtn)
81  rtdealloc(npixels);
82 
83  /* 1,1 */
85  band,
86  1, 1,
87  0, 0,
88  1,
89  &npixels
90  );
91  CU_ASSERT_EQUAL(rtn, 6);
92  if (rtn)
93  rtdealloc(npixels);
94 
95  /* 4,4 */
97  band,
98  4, 4,
99  0, 0,
100  1,
101  &npixels
102  );
103  CU_ASSERT_EQUAL(rtn, 7);
104  if (rtn)
105  rtdealloc(npixels);
106 
107  /* 4,4 distance 2 */
109  band,
110  4, 4,
111  2, 2,
112  1,
113  &npixels
114  );
115  CU_ASSERT_EQUAL(rtn, 19);
116  if (rtn)
117  rtdealloc(npixels);
118 
119  /* 10,10 */
121  band,
122  10, 10,
123  0, 0,
124  1,
125  &npixels
126  );
127  CU_ASSERT_EQUAL(rtn, 1);
128  if (rtn)
129  rtdealloc(npixels);
130 
131  /* 11,11 distance 1 */
133  band,
134  11, 11,
135  1, 1,
136  1,
137  &npixels
138  );
139  CU_ASSERT_EQUAL(rtn, 0);
140  if (rtn)
141  rtdealloc(npixels);
142 
143  /* -1,-1 */
145  band,
146  -1, -1,
147  0, 0,
148  1,
149  &npixels
150  );
151  CU_ASSERT_EQUAL(rtn, 3);
152  if (rtn)
153  rtdealloc(npixels);
154 
155  /* -1,-1 distance 1 */
157  band,
158  -1, -1,
159  1, 1,
160  1,
161  &npixels
162  );
163  CU_ASSERT_EQUAL(rtn, 0);
164  if (rtn)
165  rtdealloc(npixels);
166 
167  /* -1,1 distance 1 */
169  band,
170  -1, 1,
171  1, 1,
172  1,
173  &npixels
174  );
175  CU_ASSERT_EQUAL(rtn, 2);
176 
177  rtn = rt_pixel_set_to_array(
178  npixels, rtn,
179  -1, 1,
180  1, 1,
181  &value,
182  &nodata,
183  &dimx, &dimy
184  );
185  rtdealloc(npixels);
186  CU_ASSERT_EQUAL(rtn, ES_NONE);
187  CU_ASSERT_EQUAL(dimx, 3);
188  CU_ASSERT_EQUAL(dimy, 3);
189 
190  for (x = 0; x < dimx; x++) {
191  rtdealloc(nodata[x]);
192  rtdealloc(value[x]);
193  }
194 
195  rtdealloc(nodata);
196  rtdealloc(value);
197 
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 
287  cu_free_raster(rast);
288 }
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, int count, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
Definition: rt_api.c:1341
void rtdealloc(void *mem)
Definition: rt_api.c:882
int 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_api.c:2702
tuple band
Definition: ovdump.py:57
tuple rast
Definition: rtpixdump.py:62
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
tuple x
Definition: pixval.py:53
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: