PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_raster_geos_covers()

static void test_raster_geos_covers ( )
static

Definition at line 2083 of file cu_spatial_relationship.c.

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_covers(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), and rt_raster_set_skews().

Referenced by spatial_relationship_suite_setup().

2083  {
2084  rt_raster rast1;
2085  rt_raster rast2;
2086  rt_band band1;
2087  rt_band band2;
2088  double nodata;
2089  int rtn;
2090  int result;
2091 
2092  /*
2093  rast1
2094 
2095  (-1, -1)
2096  +-+-+
2097  |1|1|
2098  +-+-+
2099  |1|1|
2100  +-+-+
2101  (1, 1)
2102  */
2103  rast1 = rt_raster_new(2, 2);
2104  CU_ASSERT(rast1 != NULL);
2105  rt_raster_set_scale(rast1, 1, 1);
2106  rt_raster_set_offsets(rast1, -1, -1);
2107 
2108  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
2109  CU_ASSERT(band1 != NULL);
2110  rt_band_set_nodata(band1, 0, NULL);
2111  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
2112  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
2113  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
2114  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
2115 
2116  rt_band_get_nodata(band1, &nodata);
2117  CU_ASSERT_EQUAL(nodata, 0);
2118 
2119  rtn = rt_raster_covers(
2120  rast1, 0,
2121  rast1, 0,
2122  &result
2123  );
2124  CU_ASSERT_EQUAL(rtn, ES_NONE);
2125  CU_ASSERT_EQUAL(result, 1);
2126 
2127  /*
2128  rast2
2129 
2130  (0, 0)
2131  +-+-+
2132  |1|1|
2133  +-+-+
2134  |1|1|
2135  +-+-+
2136  (2, 2)
2137  */
2138  rast2 = rt_raster_new(2, 2);
2139  CU_ASSERT(rast2 != NULL);
2140  rt_raster_set_scale(rast2, 1, 1);
2141 
2142  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2143  CU_ASSERT(band2 != NULL);
2144  rt_band_set_nodata(band2, 0, NULL);
2145  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2146  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2147  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2148  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2149 
2150  rt_band_get_nodata(band2, &nodata);
2151  CU_ASSERT_EQUAL(nodata, 0);
2152 
2153  rtn = rt_raster_covers(
2154  rast1, 0,
2155  rast2, 0,
2156  &result
2157  );
2158  CU_ASSERT_EQUAL(rtn, ES_NONE);
2159  CU_ASSERT_NOT_EQUAL(result, 1);
2160 
2161  rtn = rt_raster_covers(
2162  rast1, -1,
2163  rast2, -1,
2164  &result
2165  );
2166  CU_ASSERT_EQUAL(rtn, ES_NONE);
2167  CU_ASSERT_NOT_EQUAL(result, 1);
2168 
2169  /*
2170  rast2
2171 
2172  (0, 0)
2173  +-+-+
2174  |0|1|
2175  +-+-+
2176  |1|1|
2177  +-+-+
2178  (2, 2)
2179  */
2180  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2181 
2182  rtn = rt_raster_covers(
2183  rast1, 0,
2184  rast2, 0,
2185  &result
2186  );
2187  CU_ASSERT_EQUAL(rtn, ES_NONE);
2188  CU_ASSERT_NOT_EQUAL(result, 1);
2189 
2190  /*
2191  rast2
2192 
2193  (0, 0)
2194  +-+-+
2195  |1|0|
2196  +-+-+
2197  |1|1|
2198  +-+-+
2199  (2, 2)
2200  */
2201  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2202  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2203 
2204  rtn = rt_raster_covers(
2205  rast1, 0,
2206  rast2, 0,
2207  &result
2208  );
2209  CU_ASSERT_EQUAL(rtn, ES_NONE);
2210  CU_ASSERT_NOT_EQUAL(result, 1);
2211 
2212  /*
2213  rast2
2214 
2215  (0, 0)
2216  +-+-+
2217  |0|0|
2218  +-+-+
2219  |0|1|
2220  +-+-+
2221  (2, 2)
2222  */
2223  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2224  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2225  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2226 
2227  rtn = rt_raster_covers(
2228  rast1, 0,
2229  rast2, 0,
2230  &result
2231  );
2232  CU_ASSERT_EQUAL(rtn, ES_NONE);
2233  CU_ASSERT_NOT_EQUAL(result, 1);
2234 
2235  /*
2236  rast2
2237 
2238  (0, 0)
2239  +-+-+
2240  |0|0|
2241  +-+-+
2242  |0|0|
2243  +-+-+
2244  (2, 2)
2245  */
2246  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2247  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2248  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2249  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2250 
2251  rtn = rt_raster_covers(
2252  rast1, 0,
2253  rast2, 0,
2254  &result
2255  );
2256  CU_ASSERT_EQUAL(rtn, ES_NONE);
2257  CU_ASSERT_NOT_EQUAL(result, 1);
2258 
2259  /*
2260  rast2
2261 
2262  (2, 0)
2263  +-+-+
2264  |1|1|
2265  +-+-+
2266  |1|1|
2267  +-+-+
2268  (4, 2)
2269  */
2270  rt_raster_set_offsets(rast2, 2, 0);
2271 
2272  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2273  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2274  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2275  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2276 
2277  rtn = rt_raster_covers(
2278  rast1, 0,
2279  rast2, 0,
2280  &result
2281  );
2282  CU_ASSERT_EQUAL(rtn, ES_NONE);
2283  CU_ASSERT_NOT_EQUAL(result, 1);
2284 
2285  /*
2286  rast2
2287 
2288  (0, 1)
2289  +-+-+
2290  |1|1|
2291  +-+-+
2292  |1|1|
2293  +-+-+
2294  (2, 3)
2295  */
2296  rt_raster_set_offsets(rast2, 0, 1);
2297 
2298  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2299  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2300  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2301  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2302 
2303  rtn = rt_raster_covers(
2304  rast1, 0,
2305  rast2, 0,
2306  &result
2307  );
2308  CU_ASSERT_EQUAL(rtn, ES_NONE);
2309  CU_ASSERT_NOT_EQUAL(result, 1);
2310 
2311  /*
2312  rast2
2313 
2314  (-1, 1)
2315  +-+-+
2316  |1|1|
2317  +-+-+
2318  |1|1|
2319  +-+-+
2320  (1, 3)
2321  */
2322  rt_raster_set_offsets(rast2, -1, 1);
2323 
2324  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2325  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2326  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2327  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2328 
2329  rtn = rt_raster_covers(
2330  rast1, 0,
2331  rast2, 0,
2332  &result
2333  );
2334  CU_ASSERT_EQUAL(rtn, ES_NONE);
2335  CU_ASSERT_NOT_EQUAL(result, 1);
2336 
2337  /*
2338  rast2
2339 
2340  (0.1, 0.1)
2341  +-+-+
2342  |1|1|
2343  +-+-+
2344  |1|1|
2345  +-+-+
2346  (0.9, 0.9)
2347  */
2348  rt_raster_set_offsets(rast2, 0.1, 0.1);
2349  rt_raster_set_scale(rast2, 0.4, 0.4);
2350 
2351  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2352  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2353  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2354  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2355 
2356  rtn = rt_raster_covers(
2357  rast1, 0,
2358  rast2, 0,
2359  &result
2360  );
2361  CU_ASSERT_EQUAL(rtn, ES_NONE);
2362  CU_ASSERT_EQUAL(result, 1);
2363 
2364  /*
2365  rast2
2366 
2367  (-0.1, 0.1)
2368  +-+-+
2369  |1|1|
2370  +-+-+
2371  |1|1|
2372  +-+-+
2373  (0.9, 0.9)
2374  */
2375  rt_raster_set_offsets(rast2, -0.1, 0.1);
2376 
2377  rtn = rt_raster_covers(
2378  rast1, 0,
2379  rast2, 0,
2380  &result
2381  );
2382  CU_ASSERT_EQUAL(rtn, ES_NONE);
2383  CU_ASSERT_EQUAL(result, 1);
2384 
2385  cu_free_raster(rast2);
2386 
2387  /*
2388  rast2
2389 
2390  (0, 0)
2391  +-+-+-+
2392  |1|1|1|
2393  +-+-+-+
2394  |1|1|1|
2395  +-+-+-+
2396  |1|1|1|
2397  +-+-+-+
2398  (3, 3)
2399  */
2400  rast2 = rt_raster_new(3, 3);
2401  CU_ASSERT(rast2 != NULL);
2402  rt_raster_set_scale(rast2, 1, 1);
2403 
2404  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2405  CU_ASSERT(band2 != NULL);
2406  rt_band_set_nodata(band2, 0, NULL);
2407  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2408  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2409  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2410  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2411  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2412  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2413  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2414  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2415  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2416 
2417  rt_band_get_nodata(band2, &nodata);
2418  CU_ASSERT_EQUAL(nodata, 0);
2419 
2420  rtn = rt_raster_covers(
2421  rast1, 0,
2422  rast2, 0,
2423  &result
2424  );
2425  CU_ASSERT_EQUAL(rtn, ES_NONE);
2426  CU_ASSERT_NOT_EQUAL(result, 1);
2427 
2428  /*
2429  rast2
2430 
2431  (-2, -2)
2432  +-+-+-+
2433  |1|1|1|
2434  +-+-+-+
2435  |1|1|1|
2436  +-+-+-+
2437  |1|1|1|
2438  +-+-+-+
2439  (1, 1)
2440  */
2441  rt_raster_set_offsets(rast2, -2, -2);
2442 
2443  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2444  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2445  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2446  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2447  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2448  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2449  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2450  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2451  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2452 
2453  rtn = rt_raster_covers(
2454  rast1, 0,
2455  rast2, 0,
2456  &result
2457  );
2458  CU_ASSERT_EQUAL(rtn, ES_NONE);
2459  CU_ASSERT_NOT_EQUAL(result, 1);
2460 
2461  /*
2462  rast2
2463 
2464  (-2, -2)
2465  +-+-+-+
2466  |0|1|1|
2467  +-+-+-+
2468  |1|0|1|
2469  +-+-+-+
2470  |1|1|0|
2471  +-+-+-+
2472  (1, 1)
2473  */
2474  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2475  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2476  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2477  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2478  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2479  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2480  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2481  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2482  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2483 
2484  rtn = rt_raster_covers(
2485  rast1, 0,
2486  rast2, 0,
2487  &result
2488  );
2489  CU_ASSERT_EQUAL(rtn, ES_NONE);
2490  CU_ASSERT_NOT_EQUAL(result, 1);
2491 
2492  /*
2493  rast2
2494 
2495  (-2, -2)
2496  +-+-+-+
2497  |0|1|1|
2498  +-+-+-+
2499  |1|0|0|
2500  +-+-+-+
2501  |1|0|0|
2502  +-+-+-+
2503  (1, 1)
2504  */
2505  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2506  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2507  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2508  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2509  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2510  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
2511  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2512  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
2513  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2514 
2515  rtn = rt_raster_covers(
2516  rast1, 0,
2517  rast2, 0,
2518  &result
2519  );
2520  CU_ASSERT_EQUAL(rtn, ES_NONE);
2521  CU_ASSERT_NOT_EQUAL(result, 1);
2522 
2523  /*
2524  rast2
2525 
2526  (-2, -2)
2527  +-+-+-+
2528  |0|1|0|
2529  +-+-+-+
2530  |1|0|0|
2531  +-+-+-+
2532  |0|0|0|
2533  +-+-+-+
2534  (1, 1)
2535  */
2536  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2537  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2538  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
2539  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2540  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2541  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
2542  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
2543  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
2544  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
2545 
2546  rtn = rt_raster_covers(
2547  rast1, 0,
2548  rast2, 0,
2549  &result
2550  );
2551  CU_ASSERT_EQUAL(rtn, ES_NONE);
2552  CU_ASSERT_NOT_EQUAL(result, 1);
2553 
2554  cu_free_raster(rast2);
2555 
2556  /* skew tests */
2557  /* rast2 (skewed by -0.5, 0.5) */
2558  rast2 = rt_raster_new(3, 3);
2559  CU_ASSERT(rast2 != NULL);
2560  rt_raster_set_scale(rast2, 1, 1);
2561  rt_raster_set_skews(rast2, -0.5, 0.5);
2562 
2563  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2564  CU_ASSERT(band2 != NULL);
2565  rt_band_set_nodata(band2, 0, NULL);
2566  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2567  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
2568  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
2569  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2570  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
2571  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
2572  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2573  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
2574  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
2575 
2576  rtn = rt_raster_covers(
2577  rast1, 0,
2578  rast2, 0,
2579  &result
2580  );
2581  CU_ASSERT_EQUAL(rtn, ES_NONE);
2582  CU_ASSERT_NOT_EQUAL(result, 1);
2583 
2584  /* rast2 (skewed by -1, 1) */
2585  rt_raster_set_skews(rast2, -1, 1);
2586 
2587  rtn = rt_raster_covers(
2588  rast1, 0,
2589  rast2, 0,
2590  &result
2591  );
2592  CU_ASSERT_EQUAL(rtn, ES_NONE);
2593  CU_ASSERT_NOT_EQUAL(result, 1);
2594 
2595  /* rast2 (skewed by 1, -1) */
2596  rt_raster_set_skews(rast2, 1, -1);
2597 
2598  rtn = rt_raster_covers(
2599  rast1, 0,
2600  rast2, 0,
2601  &result
2602  );
2603  CU_ASSERT_EQUAL(rtn, ES_NONE);
2604  CU_ASSERT_NOT_EQUAL(result, 1);
2605 
2606  cu_free_raster(rast2);
2607  cu_free_raster(rast1);
2608 }
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_errorstate rt_raster_covers(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *covers)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
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:841
Here is the call graph for this function:
Here is the caller graph for this function: