PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_raster_geos_overlaps()

static void test_raster_geos_overlaps ( )
static

Definition at line 27 of file cu_spatial_relationship.c.

27  {
28  rt_raster rast1;
29  rt_raster rast2;
30  rt_band band1;
31  rt_band band2;
32  double nodata;
33  int rtn;
34  int result;
35 
36  /*
37  rast1
38 
39  (-1, -1)
40  +-+-+
41  |1|1|
42  +-+-+
43  |1|1|
44  +-+-+
45  (1, 1)
46  */
47  rast1 = rt_raster_new(2, 2);
48  CU_ASSERT(rast1 != NULL);
49  rt_raster_set_scale(rast1, 1, 1);
50  rt_raster_set_offsets(rast1, -1, -1);
51 
52  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
53  CU_ASSERT(band1 != NULL);
54  rt_band_set_nodata(band1, 0, NULL);
55  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
56  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
57  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
58  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
59 
60  rt_band_get_nodata(band1, &nodata);
61  CU_ASSERT_EQUAL(nodata, 0);
62 
63  rtn = rt_raster_overlaps(
64  rast1, 0,
65  rast1, 0,
66  &result
67  );
68  CU_ASSERT_EQUAL(rtn, ES_NONE);
69  CU_ASSERT_NOT_EQUAL(result, 1);
70 
71  /*
72  rast2
73 
74  (0, 0)
75  +-+-+
76  |1|1|
77  +-+-+
78  |1|1|
79  +-+-+
80  (2, 2)
81  */
82  rast2 = rt_raster_new(2, 2);
83  CU_ASSERT(rast2 != NULL);
84  rt_raster_set_scale(rast2, 1, 1);
85 
86  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
87  CU_ASSERT(band2 != NULL);
88  rt_band_set_nodata(band2, 0, NULL);
89  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
90  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
91  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
92  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
93 
94  rt_band_get_nodata(band2, &nodata);
95  CU_ASSERT_EQUAL(nodata, 0);
96 
97  rtn = rt_raster_overlaps(
98  rast1, 0,
99  rast2, 0,
100  &result
101  );
102  CU_ASSERT_EQUAL(rtn, ES_NONE);
103  CU_ASSERT_EQUAL(result, 1);
104 
105  rtn = rt_raster_overlaps(
106  rast1, -1,
107  rast2, -1,
108  &result
109  );
110  CU_ASSERT_EQUAL(rtn, ES_NONE);
111  CU_ASSERT_EQUAL(result, 1);
112 
113  /*
114  rast2
115 
116  (0, 0)
117  +-+-+
118  |0|1|
119  +-+-+
120  |1|1|
121  +-+-+
122  (2, 2)
123  */
124  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
125 
126  rtn = rt_raster_overlaps(
127  rast1, 0,
128  rast2, 0,
129  &result
130  );
131  CU_ASSERT_EQUAL(rtn, ES_NONE);
132  CU_ASSERT_NOT_EQUAL(result, 1);
133 
134  /*
135  rast2
136 
137  (0, 0)
138  +-+-+
139  |1|0|
140  +-+-+
141  |1|1|
142  +-+-+
143  (2, 2)
144  */
145  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
146  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
147 
148  rtn = rt_raster_overlaps(
149  rast1, 0,
150  rast2, 0,
151  &result
152  );
153  CU_ASSERT_EQUAL(rtn, ES_NONE);
154  CU_ASSERT_EQUAL(result, 1);
155 
156  /*
157  rast2
158 
159  (0, 0)
160  +-+-+
161  |0|0|
162  +-+-+
163  |0|1|
164  +-+-+
165  (2, 2)
166  */
167  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
168  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
169  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
170 
171  rtn = rt_raster_overlaps(
172  rast1, 0,
173  rast2, 0,
174  &result
175  );
176  CU_ASSERT_EQUAL(rtn, ES_NONE);
177  CU_ASSERT_NOT_EQUAL(result, 1);
178 
179  /*
180  rast2
181 
182  (0, 0)
183  +-+-+
184  |0|0|
185  +-+-+
186  |0|0|
187  +-+-+
188  (2, 2)
189  */
190  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
191  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
192  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
193  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
194 
195  rtn = rt_raster_overlaps(
196  rast1, 0,
197  rast2, 0,
198  &result
199  );
200  CU_ASSERT_EQUAL(rtn, ES_NONE);
201  CU_ASSERT_NOT_EQUAL(result, 1);
202 
203  /*
204  rast2
205 
206  (2, 0)
207  +-+-+
208  |1|1|
209  +-+-+
210  |1|1|
211  +-+-+
212  (4, 2)
213  */
214  rt_raster_set_offsets(rast2, 2, 0);
215 
216  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
217  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
218  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
219  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
220 
221  rtn = rt_raster_overlaps(
222  rast1, 0,
223  rast2, 0,
224  &result
225  );
226  CU_ASSERT_EQUAL(rtn, ES_NONE);
227  CU_ASSERT_NOT_EQUAL(result, 1);
228 
229  /*
230  rast2
231 
232  (0.1, 0.1)
233  +-+-+
234  |1|1|
235  +-+-+
236  |1|1|
237  +-+-+
238  (0.9, 0.9)
239  */
240  rt_raster_set_offsets(rast2, 0.1, 0.1);
241  rt_raster_set_scale(rast2, 0.4, 0.4);
242 
243  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
244  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
245  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
246  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
247 
248  rtn = rt_raster_overlaps(
249  rast1, 0,
250  rast2, 0,
251  &result
252  );
253  CU_ASSERT_EQUAL(rtn, ES_NONE);
254  CU_ASSERT_NOT_EQUAL(result, 1);
255 
256  /*
257  rast2
258 
259  (-0.1, 0.1)
260  +-+-+
261  |1|1|
262  +-+-+
263  |1|1|
264  +-+-+
265  (0.9, 0.9)
266  */
267  rt_raster_set_offsets(rast2, -0.1, 0.1);
268 
269  rtn = rt_raster_overlaps(
270  rast1, 0,
271  rast2, 0,
272  &result
273  );
274  CU_ASSERT_EQUAL(rtn, ES_NONE);
275  CU_ASSERT_NOT_EQUAL(result, 1);
276 
277  cu_free_raster(rast2);
278 
279  /*
280  rast2
281 
282  (0, 0)
283  +-+-+-+
284  |1|1|1|
285  +-+-+-+
286  |1|1|1|
287  +-+-+-+
288  |1|1|1|
289  +-+-+-+
290  (3, 3)
291  */
292  rast2 = rt_raster_new(3, 3);
293  CU_ASSERT(rast2 != NULL);
294  rt_raster_set_scale(rast2, 1, 1);
295 
296  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
297  CU_ASSERT(band2 != NULL);
298  rt_band_set_nodata(band2, 0, NULL);
299  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
300  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
301  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
302  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
303  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
304  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
305  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
306  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
307  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
308 
309  rt_band_get_nodata(band2, &nodata);
310  CU_ASSERT_EQUAL(nodata, 0);
311 
312  rtn = rt_raster_overlaps(
313  rast1, 0,
314  rast2, 0,
315  &result
316  );
317  CU_ASSERT_EQUAL(rtn, ES_NONE);
318  CU_ASSERT_EQUAL(result, 1);
319 
320  /*
321  rast2
322 
323  (-2, -2)
324  +-+-+-+
325  |1|1|1|
326  +-+-+-+
327  |1|1|1|
328  +-+-+-+
329  |1|1|1|
330  +-+-+-+
331  (1, 1)
332  */
333  rt_raster_set_offsets(rast2, -2, -2);
334 
335  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
336  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
337  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
338  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
339  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
340  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
341  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
342  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
343  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
344 
345  rtn = rt_raster_overlaps(
346  rast1, 0,
347  rast2, 0,
348  &result
349  );
350  CU_ASSERT_EQUAL(rtn, ES_NONE);
351  CU_ASSERT_NOT_EQUAL(result, 1);
352 
353  /*
354  rast2
355 
356  (-2, -2)
357  +-+-+-+
358  |0|1|1|
359  +-+-+-+
360  |1|0|1|
361  +-+-+-+
362  |1|1|0|
363  +-+-+-+
364  (1, 1)
365  */
366  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
367  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
368  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
369  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
370  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
371  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
372  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
373  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
374  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
375 
376  rtn = rt_raster_overlaps(
377  rast1, 0,
378  rast2, 0,
379  &result
380  );
381  CU_ASSERT_EQUAL(rtn, ES_NONE);
382  CU_ASSERT_EQUAL(result, 1);
383 
384  /*
385  rast2
386 
387  (-2, -2)
388  +-+-+-+
389  |0|1|1|
390  +-+-+-+
391  |1|0|0|
392  +-+-+-+
393  |1|0|0|
394  +-+-+-+
395  (1, 1)
396  */
397  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
398  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
399  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
400  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
401  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
402  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
403  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
404  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
405  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
406 
407  rtn = rt_raster_overlaps(
408  rast1, 0,
409  rast2, 0,
410  &result
411  );
412  CU_ASSERT_EQUAL(rtn, ES_NONE);
413  CU_ASSERT_NOT_EQUAL(result, 1);
414 
415  /*
416  rast2
417 
418  (-2, -2)
419  +-+-+-+
420  |0|1|0|
421  +-+-+-+
422  |1|0|0|
423  +-+-+-+
424  |0|0|0|
425  +-+-+-+
426  (1, 1)
427  */
428  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
429  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
430  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
431  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
432  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
433  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
434  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
435  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
436  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
437 
438  rtn = rt_raster_overlaps(
439  rast1, 0,
440  rast2, 0,
441  &result
442  );
443  CU_ASSERT_EQUAL(rtn, ES_NONE);
444  CU_ASSERT_NOT_EQUAL(result, 1);
445 
446  cu_free_raster(rast2);
447 
448  /* skew tests */
449  /* rast2 (skewed by -0.5, 0.5) */
450  rast2 = rt_raster_new(3, 3);
451  CU_ASSERT(rast2 != NULL);
452  rt_raster_set_scale(rast2, 1, 1);
453  rt_raster_set_skews(rast2, -0.5, 0.5);
454 
455  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
456  CU_ASSERT(band2 != NULL);
457  rt_band_set_nodata(band2, 0, NULL);
458  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
459  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
460  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
461  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
462  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
463  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
464  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
465  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
466  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
467 
468  rtn = rt_raster_overlaps(
469  rast1, 0,
470  rast2, 0,
471  &result
472  );
473  CU_ASSERT_EQUAL(rtn, ES_NONE);
474  CU_ASSERT_EQUAL(result, 1);
475 
476  /* rast2 (skewed by -1, 1) */
477  rt_raster_set_skews(rast2, -1, 1);
478 
479  rtn = rt_raster_overlaps(
480  rast1, 0,
481  rast2, 0,
482  &result
483  );
484  CU_ASSERT_EQUAL(rtn, ES_NONE);
485  CU_ASSERT_EQUAL(result, 1);
486 
487  /* rast2 (skewed by 1, -1) */
488  rt_raster_set_skews(rast2, 1, -1);
489 
490  rtn = rt_raster_overlaps(
491  rast1, 0,
492  rast2, 0,
493  &result
494  );
495  CU_ASSERT_EQUAL(rtn, ES_NONE);
496  CU_ASSERT_EQUAL(result, 1);
497 
498  cu_free_raster(rast2);
499  cu_free_raster(rast1);
500 }
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
@ PT_8BUI
Definition: librtcore.h:190
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_raster.c:168
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_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:733
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_raster_overlaps(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *overlaps)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)

References cu_add_band(), cu_free_raster(), ES_NONE, PT_8BUI, rt_band_get_nodata(), rt_band_set_nodata(), rt_band_set_pixel(), rt_raster_new(), rt_raster_overlaps(), rt_raster_set_offsets(), rt_raster_set_scale(), and rt_raster_set_skews().

Referenced by spatial_relationship_suite_setup().

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