PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_raster_geos_covered_by()

static void test_raster_geos_covered_by ( )
static

Definition at line 2610 of file cu_spatial_relationship.c.

2610  {
2611  rt_raster rast1;
2612  rt_raster rast2;
2613  rt_band band1;
2614  rt_band band2;
2615  double nodata;
2616  int rtn;
2617  int result;
2618 
2619  /*
2620  rast1
2621 
2622  (-1, -1)
2623  +-+-+
2624  |1|1|
2625  +-+-+
2626  |1|1|
2627  +-+-+
2628  (1, 1)
2629  */
2630  rast1 = rt_raster_new(2, 2);
2631  CU_ASSERT(rast1 != NULL);
2632  rt_raster_set_scale(rast1, 1, 1);
2633  rt_raster_set_offsets(rast1, -1, -1);
2634 
2635  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
2636  CU_ASSERT(band1 != NULL);
2637  rt_band_set_nodata(band1, 0, NULL);
2638  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
2639  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
2640  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
2641  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
2642 
2643  rt_band_get_nodata(band1, &nodata);
2644  CU_ASSERT_EQUAL(nodata, 0);
2645 
2646  rtn = rt_raster_coveredby(
2647  rast1, 0,
2648  rast1, 0,
2649  &result
2650  );
2651  CU_ASSERT_EQUAL(rtn, ES_NONE);
2652  CU_ASSERT_EQUAL(result, 1);
2653 
2654  /*
2655  rast2
2656 
2657  (0, 0)
2658  +-+-+
2659  |1|1|
2660  +-+-+
2661  |1|1|
2662  +-+-+
2663  (2, 2)
2664  */
2665  rast2 = rt_raster_new(2, 2);
2666  CU_ASSERT(rast2 != NULL);
2667  rt_raster_set_scale(rast2, 1, 1);
2668 
2669  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2670  CU_ASSERT(band2 != NULL);
2671  rt_band_set_nodata(band2, 0, NULL);
2672  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2673  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2674  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2675  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2676 
2677  rt_band_get_nodata(band2, &nodata);
2678  CU_ASSERT_EQUAL(nodata, 0);
2679 
2680  rtn = rt_raster_coveredby(
2681  rast2, 0,
2682  rast1, 0,
2683  &result
2684  );
2685  CU_ASSERT_EQUAL(rtn, ES_NONE);
2686  CU_ASSERT_NOT_EQUAL(result, 1);
2687 
2688  rtn = rt_raster_coveredby(
2689  rast2, -1,
2690  rast1, -1,
2691  &result
2692  );
2693  CU_ASSERT_EQUAL(rtn, ES_NONE);
2694  CU_ASSERT_NOT_EQUAL(result, 1);
2695 
2696  /*
2697  rast2
2698 
2699  (0, 0)
2700  +-+-+
2701  |0|1|
2702  +-+-+
2703  |1|1|
2704  +-+-+
2705  (2, 2)
2706  */
2707  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2708 
2709  rtn = rt_raster_coveredby(
2710  rast2, 0,
2711  rast1, 0,
2712  &result
2713  );
2714  CU_ASSERT_EQUAL(rtn, ES_NONE);
2715  CU_ASSERT_NOT_EQUAL(result, 1);
2716 
2717  /*
2718  rast2
2719 
2720  (0, 0)
2721  +-+-+
2722  |1|0|
2723  +-+-+
2724  |1|1|
2725  +-+-+
2726  (2, 2)
2727  */
2728  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2729  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2730 
2731  rtn = rt_raster_coveredby(
2732  rast2, 0,
2733  rast1, 0,
2734  &result
2735  );
2736  CU_ASSERT_EQUAL(rtn, ES_NONE);
2737  CU_ASSERT_NOT_EQUAL(result, 1);
2738 
2739  /*
2740  rast2
2741 
2742  (0, 0)
2743  +-+-+
2744  |0|0|
2745  +-+-+
2746  |0|1|
2747  +-+-+
2748  (2, 2)
2749  */
2750  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2751  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2752  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2753 
2754  rtn = rt_raster_coveredby(
2755  rast2, 0,
2756  rast1, 0,
2757  &result
2758  );
2759  CU_ASSERT_EQUAL(rtn, ES_NONE);
2760  CU_ASSERT_NOT_EQUAL(result, 1);
2761 
2762  /*
2763  rast2
2764 
2765  (0, 0)
2766  +-+-+
2767  |0|0|
2768  +-+-+
2769  |0|0|
2770  +-+-+
2771  (2, 2)
2772  */
2773  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
2774  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
2775  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
2776  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
2777 
2778  rtn = rt_raster_coveredby(
2779  rast2, 0,
2780  rast1, 0,
2781  &result
2782  );
2783  CU_ASSERT_EQUAL(rtn, ES_NONE);
2784  CU_ASSERT_NOT_EQUAL(result, 1);
2785 
2786  /*
2787  rast2
2788 
2789  (2, 0)
2790  +-+-+
2791  |1|1|
2792  +-+-+
2793  |1|1|
2794  +-+-+
2795  (4, 2)
2796  */
2797  rt_raster_set_offsets(rast2, 2, 0);
2798 
2799  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2800  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2801  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2802  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2803 
2804  rtn = rt_raster_coveredby(
2805  rast2, 0,
2806  rast1, 0,
2807  &result
2808  );
2809  CU_ASSERT_EQUAL(rtn, ES_NONE);
2810  CU_ASSERT_NOT_EQUAL(result, 1);
2811 
2812  /*
2813  rast2
2814 
2815  (0, 1)
2816  +-+-+
2817  |1|1|
2818  +-+-+
2819  |1|1|
2820  +-+-+
2821  (2, 3)
2822  */
2823  rt_raster_set_offsets(rast2, 0, 1);
2824 
2825  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2826  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2827  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2828  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2829 
2830  rtn = rt_raster_coveredby(
2831  rast2, 0,
2832  rast1, 0,
2833  &result
2834  );
2835  CU_ASSERT_EQUAL(rtn, ES_NONE);
2836  CU_ASSERT_NOT_EQUAL(result, 1);
2837 
2838  /*
2839  rast2
2840 
2841  (-1, 1)
2842  +-+-+
2843  |1|1|
2844  +-+-+
2845  |1|1|
2846  +-+-+
2847  (1, 3)
2848  */
2849  rt_raster_set_offsets(rast2, -1, 1);
2850 
2851  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2852  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2853  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2854  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2855 
2856  rtn = rt_raster_coveredby(
2857  rast2, 0,
2858  rast1, 0,
2859  &result
2860  );
2861  CU_ASSERT_EQUAL(rtn, ES_NONE);
2862  CU_ASSERT_NOT_EQUAL(result, 1);
2863 
2864  /*
2865  rast2
2866 
2867  (0.1, 0.1)
2868  +-+-+
2869  |1|1|
2870  +-+-+
2871  |1|1|
2872  +-+-+
2873  (0.9, 0.9)
2874  */
2875  rt_raster_set_offsets(rast2, 0.1, 0.1);
2876  rt_raster_set_scale(rast2, 0.4, 0.4);
2877 
2878  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2879  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2880  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2881  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2882 
2883  rtn = rt_raster_coveredby(
2884  rast2, 0,
2885  rast1, 0,
2886  &result
2887  );
2888  CU_ASSERT_EQUAL(rtn, ES_NONE);
2889  CU_ASSERT_EQUAL(result, 1);
2890 
2891  /*
2892  rast2
2893 
2894  (-0.1, 0.1)
2895  +-+-+
2896  |1|1|
2897  +-+-+
2898  |1|1|
2899  +-+-+
2900  (0.9, 0.9)
2901  */
2902  rt_raster_set_offsets(rast2, -0.1, 0.1);
2903 
2904  rtn = rt_raster_coveredby(
2905  rast2, 0,
2906  rast1, 0,
2907  &result
2908  );
2909  CU_ASSERT_EQUAL(rtn, ES_NONE);
2910  CU_ASSERT_EQUAL(result, 1);
2911 
2912  cu_free_raster(rast2);
2913 
2914  /*
2915  rast2
2916 
2917  (0, 0)
2918  +-+-+-+
2919  |1|1|1|
2920  +-+-+-+
2921  |1|1|1|
2922  +-+-+-+
2923  |1|1|1|
2924  +-+-+-+
2925  (3, 3)
2926  */
2927  rast2 = rt_raster_new(3, 3);
2928  CU_ASSERT(rast2 != NULL);
2929  rt_raster_set_scale(rast2, 1, 1);
2930 
2931  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
2932  CU_ASSERT(band2 != NULL);
2933  rt_band_set_nodata(band2, 0, NULL);
2934  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2935  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2936  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2937  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2938  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2939  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2940  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2941  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2942  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2943 
2944  rt_band_get_nodata(band2, &nodata);
2945  CU_ASSERT_EQUAL(nodata, 0);
2946 
2947  rtn = rt_raster_coveredby(
2948  rast2, 0,
2949  rast1, 0,
2950  &result
2951  );
2952  CU_ASSERT_EQUAL(rtn, ES_NONE);
2953  CU_ASSERT_NOT_EQUAL(result, 1);
2954 
2955  /*
2956  rast2
2957 
2958  (-2, -2)
2959  +-+-+-+
2960  |1|1|1|
2961  +-+-+-+
2962  |1|1|1|
2963  +-+-+-+
2964  |1|1|1|
2965  +-+-+-+
2966  (1, 1)
2967  */
2968  rt_raster_set_offsets(rast2, -2, -2);
2969 
2970  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
2971  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
2972  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
2973  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
2974  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
2975  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
2976  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
2977  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
2978  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
2979 
2980  rtn = rt_raster_coveredby(
2981  rast2, 0,
2982  rast1, 0,
2983  &result
2984  );
2985  CU_ASSERT_EQUAL(rtn, ES_NONE);
2986  CU_ASSERT_NOT_EQUAL(result, 1);
2987 
2988  /*
2989  rast2
2990 
2991  (-2, -2)
2992  +-+-+-+
2993  |0|1|1|
2994  +-+-+-+
2995  |1|0|1|
2996  +-+-+-+
2997  |1|1|0|
2998  +-+-+-+
2999  (1, 1)
3000  */
3001  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3002  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3003  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3004  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3005  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3006  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3007  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3008  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3009  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3010 
3011  rtn = rt_raster_coveredby(
3012  rast2, 0,
3013  rast1, 0,
3014  &result
3015  );
3016  CU_ASSERT_EQUAL(rtn, ES_NONE);
3017  CU_ASSERT_NOT_EQUAL(result, 1);
3018 
3019  /*
3020  rast2
3021 
3022  (-2, -2)
3023  +-+-+-+
3024  |0|1|1|
3025  +-+-+-+
3026  |1|0|0|
3027  +-+-+-+
3028  |1|0|0|
3029  +-+-+-+
3030  (1, 1)
3031  */
3032  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3033  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3034  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3035  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3036  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3037  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3038  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3039  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3040  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3041 
3042  rtn = rt_raster_coveredby(
3043  rast2, 0,
3044  rast1, 0,
3045  &result
3046  );
3047  CU_ASSERT_EQUAL(rtn, ES_NONE);
3048  CU_ASSERT_NOT_EQUAL(result, 1);
3049 
3050  /*
3051  rast2
3052 
3053  (-2, -2)
3054  +-+-+-+
3055  |0|1|0|
3056  +-+-+-+
3057  |1|0|0|
3058  +-+-+-+
3059  |0|0|0|
3060  +-+-+-+
3061  (1, 1)
3062  */
3063  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3064  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3065  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
3066  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3067  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3068  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3069  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
3070  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3071  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3072 
3073  rtn = rt_raster_coveredby(
3074  rast2, 0,
3075  rast1, 0,
3076  &result
3077  );
3078  CU_ASSERT_EQUAL(rtn, ES_NONE);
3079  CU_ASSERT_NOT_EQUAL(result, 1);
3080 
3081  cu_free_raster(rast2);
3082 
3083  /* skew tests */
3084  /* rast2 (skewed by -0.5, 0.5) */
3085  rast2 = rt_raster_new(3, 3);
3086  CU_ASSERT(rast2 != NULL);
3087  rt_raster_set_scale(rast2, 1, 1);
3088  rt_raster_set_skews(rast2, -0.5, 0.5);
3089 
3090  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3091  CU_ASSERT(band2 != NULL);
3092  rt_band_set_nodata(band2, 0, NULL);
3093  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3094  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
3095  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
3096  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3097  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
3098  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
3099  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3100  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
3101  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
3102 
3103  rtn = rt_raster_coveredby(
3104  rast2, 0,
3105  rast1, 0,
3106  &result
3107  );
3108  CU_ASSERT_EQUAL(rtn, ES_NONE);
3109  CU_ASSERT_NOT_EQUAL(result, 1);
3110 
3111  /* rast2 (skewed by -1, 1) */
3112  rt_raster_set_skews(rast2, -1, 1);
3113 
3114  rtn = rt_raster_coveredby(
3115  rast2, 0,
3116  rast1, 0,
3117  &result
3118  );
3119  CU_ASSERT_EQUAL(rtn, ES_NONE);
3120  CU_ASSERT_NOT_EQUAL(result, 1);
3121 
3122  /* rast2 (skewed by 1, -1) */
3123  rt_raster_set_skews(rast2, 1, -1);
3124 
3125  rtn = rt_raster_coveredby(
3126  rast2, 0,
3127  rast1, 0,
3128  &result
3129  );
3130  CU_ASSERT_EQUAL(rtn, ES_NONE);
3131  CU_ASSERT_NOT_EQUAL(result, 1);
3132 
3133  cu_free_raster(rast2);
3134  cu_free_raster(rast1);
3135 }
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_raster_coveredby(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *coveredby)
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: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_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_coveredby(), rt_raster_new(), 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: