PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_raster_fully_within_distance()

static void test_raster_fully_within_distance ( )
static

Definition at line 3699 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_fully_within_distance(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), and rt_raster_set_skews().

Referenced by spatial_relationship_suite_setup().

3699  {
3700  rt_raster rast1;
3701  rt_raster rast2;
3702  rt_band band1;
3703  rt_band band2;
3704  double nodata;
3705  int rtn;
3706  int result;
3707 
3708  /*
3709  rast1
3710 
3711  (-1, -1)
3712  +-+-+
3713  |1|1|
3714  +-+-+
3715  |1|1|
3716  +-+-+
3717  (1, 1)
3718  */
3719  rast1 = rt_raster_new(2, 2);
3720  CU_ASSERT(rast1 != NULL);
3721  rt_raster_set_scale(rast1, 1, 1);
3722  rt_raster_set_offsets(rast1, -1, -1);
3723 
3724  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
3725  CU_ASSERT(band1 != NULL);
3726  rt_band_set_nodata(band1, 0, NULL);
3727  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
3728  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
3729  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
3730  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
3731 
3732  rt_band_get_nodata(band1, &nodata);
3733  CU_ASSERT_EQUAL(nodata, 0);
3734 
3736  rast1, 0,
3737  rast1, 0,
3738  0.,
3739  &result
3740  );
3741  CU_ASSERT_EQUAL(rtn, ES_NONE);
3742  CU_ASSERT_NOT_EQUAL(result, 1);
3743 
3745  rast1, 0,
3746  rast1, 0,
3747  -1.,
3748  &result
3749  );
3750  CU_ASSERT_NOT_EQUAL(rtn, ES_NONE);
3751 
3752  /*
3753  rast2
3754 
3755  (0, 0)
3756  +-+-+
3757  |1|1|
3758  +-+-+
3759  |1|1|
3760  +-+-+
3761  (2, 2)
3762  */
3763  rast2 = rt_raster_new(2, 2);
3764  CU_ASSERT(rast2 != NULL);
3765  rt_raster_set_scale(rast2, 1, 1);
3766 
3767  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3768  CU_ASSERT(band2 != NULL);
3769  rt_band_set_nodata(band2, 0, NULL);
3770  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3771  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3772  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3773  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3774 
3775  rt_band_get_nodata(band2, &nodata);
3776  CU_ASSERT_EQUAL(nodata, 0);
3777 
3779  rast1, 0,
3780  rast2, 0,
3781  0.,
3782  &result
3783  );
3784  CU_ASSERT_EQUAL(rtn, ES_NONE);
3785  CU_ASSERT_NOT_EQUAL(result, 1);
3786 
3788  rast1, 0,
3789  rast2, 0,
3790  1.,
3791  &result
3792  );
3793  CU_ASSERT_EQUAL(rtn, ES_NONE);
3794  CU_ASSERT_NOT_EQUAL(result, 1);
3795 
3797  rast1, -1,
3798  rast2, -1,
3799  5.,
3800  &result
3801  );
3802  CU_ASSERT_EQUAL(rtn, ES_NONE);
3803  CU_ASSERT_EQUAL(result, 1);
3804 
3805  /*
3806  rast2
3807 
3808  (0, 0)
3809  +-+-+
3810  |0|1|
3811  +-+-+
3812  |1|1|
3813  +-+-+
3814  (2, 2)
3815  */
3816  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3817 
3819  rast1, 0,
3820  rast2, 0,
3821  2.,
3822  &result
3823  );
3824  CU_ASSERT_EQUAL(rtn, ES_NONE);
3825  CU_ASSERT_NOT_EQUAL(result, 1);
3826 
3827  /*
3828  rast2
3829 
3830  (0, 0)
3831  +-+-+
3832  |1|0|
3833  +-+-+
3834  |1|1|
3835  +-+-+
3836  (2, 2)
3837  */
3838  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3839  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3840 
3842  rast1, 0,
3843  rast2, 0,
3844  5.,
3845  &result
3846  );
3847  CU_ASSERT_EQUAL(rtn, ES_NONE);
3848  CU_ASSERT_EQUAL(result, 1);
3849 
3850  /*
3851  rast2
3852 
3853  (0, 0)
3854  +-+-+
3855  |0|0|
3856  +-+-+
3857  |0|1|
3858  +-+-+
3859  (2, 2)
3860  */
3861  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3862  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3863  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3864 
3866  rast1, 0,
3867  rast2, 0,
3868  5,
3869  &result
3870  );
3871  CU_ASSERT_EQUAL(rtn, ES_NONE);
3872  CU_ASSERT_EQUAL(result, 1);
3873 
3874  /*
3875  rast2
3876 
3877  (0, 0)
3878  +-+-+
3879  |0|0|
3880  +-+-+
3881  |0|0|
3882  +-+-+
3883  (2, 2)
3884  */
3885  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3886  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3887  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3888  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3889 
3891  rast1, 0,
3892  rast2, 0,
3893  10,
3894  &result
3895  );
3896  CU_ASSERT_EQUAL(rtn, ES_NONE);
3897  CU_ASSERT_NOT_EQUAL(result, 1);
3898 
3899  /*
3900  rast2
3901 
3902  (2, 0)
3903  +-+-+
3904  |1|1|
3905  +-+-+
3906  |1|1|
3907  +-+-+
3908  (4, 2)
3909  */
3910  rt_raster_set_offsets(rast2, 2, 0);
3911 
3912  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3913  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3914  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3915  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3916 
3918  rast1, 0,
3919  rast2, 0,
3920  0,
3921  &result
3922  );
3923  CU_ASSERT_EQUAL(rtn, ES_NONE);
3924  CU_ASSERT_NOT_EQUAL(result, 1);
3925 
3927  rast1, 0,
3928  rast2, 0,
3929  5.9,
3930  &result
3931  );
3932  CU_ASSERT_EQUAL(rtn, ES_NONE);
3933  CU_ASSERT_EQUAL(result, 1);
3934 
3935  /*
3936  rast2
3937 
3938  (0.1, 0.1)
3939  +-+-+
3940  |1|1|
3941  +-+-+
3942  |1|1|
3943  +-+-+
3944  (0.9, 0.9)
3945  */
3946  rt_raster_set_offsets(rast2, 0.1, 0.1);
3947  rt_raster_set_scale(rast2, 0.4, 0.4);
3948 
3949  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3950  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3951  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3952  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3953 
3955  rast1, 0,
3956  rast2, 0,
3957  3,
3958  &result
3959  );
3960  CU_ASSERT_EQUAL(rtn, ES_NONE);
3961  CU_ASSERT_EQUAL(result, 1);
3962 
3963  /*
3964  rast2
3965 
3966  (-0.1, 0.1)
3967  +-+-+
3968  |1|1|
3969  +-+-+
3970  |1|1|
3971  +-+-+
3972  (0.9, 0.9)
3973  */
3974  rt_raster_set_offsets(rast2, -0.1, 0.1);
3975 
3977  rast1, 0,
3978  rast2, 0,
3979  2,
3980  &result
3981  );
3982  CU_ASSERT_EQUAL(rtn, ES_NONE);
3983  CU_ASSERT_NOT_EQUAL(result, 1);
3984 
3985  cu_free_raster(rast2);
3986 
3987  /*
3988  rast2
3989 
3990  (0, 0)
3991  +-+-+-+
3992  |1|1|1|
3993  +-+-+-+
3994  |1|1|1|
3995  +-+-+-+
3996  |1|1|1|
3997  +-+-+-+
3998  (3, 3)
3999  */
4000  rast2 = rt_raster_new(3, 3);
4001  CU_ASSERT(rast2 != NULL);
4002  rt_raster_set_scale(rast2, 1, 1);
4003 
4004  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4005  CU_ASSERT(band2 != NULL);
4006  rt_band_set_nodata(band2, 0, NULL);
4007  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4008  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4009  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4010  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4011  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4012  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4013  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4014  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4015  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4016 
4017  rt_band_get_nodata(band2, &nodata);
4018  CU_ASSERT_EQUAL(nodata, 0);
4019 
4021  rast1, 0,
4022  rast2, 0,
4023  6,
4024  &result
4025  );
4026  CU_ASSERT_EQUAL(rtn, ES_NONE);
4027  CU_ASSERT_EQUAL(result, 1);
4028 
4029  /*
4030  rast2
4031 
4032  (-2, -2)
4033  +-+-+-+
4034  |1|1|1|
4035  +-+-+-+
4036  |1|1|1|
4037  +-+-+-+
4038  |1|1|1|
4039  +-+-+-+
4040  (1, 1)
4041  */
4042  rt_raster_set_offsets(rast2, -2, -2);
4043 
4044  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4045  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4046  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4047  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4048  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4049  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4050  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4051  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4052  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4053 
4055  rast1, 0,
4056  rast2, 0,
4057  4.25,
4058  &result
4059  );
4060  CU_ASSERT_EQUAL(rtn, ES_NONE);
4061  CU_ASSERT_EQUAL(result, 1);
4062 
4063  /*
4064  rast2
4065 
4066  (-2, -2)
4067  +-+-+-+
4068  |0|1|1|
4069  +-+-+-+
4070  |1|0|1|
4071  +-+-+-+
4072  |1|1|0|
4073  +-+-+-+
4074  (1, 1)
4075  */
4076  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4077  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4078  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4079  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4080  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4081  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4082  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4083  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4084  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4085 
4087  rast1, 0,
4088  rast2, 0,
4089  3.5,
4090  &result
4091  );
4092  CU_ASSERT_EQUAL(rtn, ES_NONE);
4093  CU_ASSERT_NOT_EQUAL(result, 1);
4094 
4095  /*
4096  rast2
4097 
4098  (-2, -2)
4099  +-+-+-+
4100  |0|1|1|
4101  +-+-+-+
4102  |1|0|0|
4103  +-+-+-+
4104  |1|0|0|
4105  +-+-+-+
4106  (1, 1)
4107  */
4108  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4109  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4110  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4111  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4112  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4113  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4114  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4115  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4116  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4117 
4119  rast1, 0,
4120  rast2, 0,
4121  3.65,
4122  &result
4123  );
4124  CU_ASSERT_EQUAL(rtn, ES_NONE);
4125  CU_ASSERT_EQUAL(result, 1);
4126 
4127  /*
4128  rast2
4129 
4130  (-2, -2)
4131  +-+-+-+
4132  |0|1|0|
4133  +-+-+-+
4134  |1|0|0|
4135  +-+-+-+
4136  |0|0|0|
4137  +-+-+-+
4138  (1, 1)
4139  */
4140  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4141  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4142  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
4143  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4144  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4145  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4146  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
4147  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4148  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4149 
4151  rast1, 0,
4152  rast2, 0,
4153  3.6,
4154  &result
4155  );
4156  CU_ASSERT_EQUAL(rtn, ES_NONE);
4157  CU_ASSERT_NOT_EQUAL(result, 1);
4158 
4159  /*
4160  rast2
4161 
4162  (-10, -1)
4163  +-+-+-+
4164  |1|1|1|
4165  +-+-+-+
4166  |1|1|1|
4167  +-+-+-+
4168  |1|1|1|
4169  +-+-+-+
4170  (-7, 2)
4171  */
4172  rt_raster_set_offsets(rast2, -10, -1);
4173 
4174  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4175  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4176  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4177  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4178  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4179  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4180  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4181  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4182  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4183 
4185  rast1, 0,
4186  rast2, 0,
4187  5,
4188  &result
4189  );
4190  CU_ASSERT_EQUAL(rtn, ES_NONE);
4191  CU_ASSERT_NOT_EQUAL(result, 1);
4192 
4194  rast1, 0,
4195  rast2, 0,
4196  11.5,
4197  &result
4198  );
4199  CU_ASSERT_EQUAL(rtn, ES_NONE);
4200  CU_ASSERT_EQUAL(result, 1);
4201 
4202  cu_free_raster(rast2);
4203 
4204  /* skew tests */
4205  /* rast2 (skewed by -0.5, 0.5) */
4206  rast2 = rt_raster_new(3, 3);
4207  CU_ASSERT(rast2 != NULL);
4208  rt_raster_set_scale(rast2, 1, 1);
4209  rt_raster_set_skews(rast2, -0.5, 0.5);
4210 
4211  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4212  CU_ASSERT(band2 != NULL);
4213  rt_band_set_nodata(band2, 0, NULL);
4214  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4215  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
4216  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
4217  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4218  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
4219  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
4220  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4221  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
4222  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
4223 
4225  rast1, 0,
4226  rast2, 0,
4227  6.1,
4228  &result
4229  );
4230  CU_ASSERT_EQUAL(rtn, ES_NONE);
4231  CU_ASSERT_EQUAL(result, 1);
4232 
4233  /* rast2 (skewed by -1, 1) */
4234  rt_raster_set_skews(rast2, -1, 1);
4235 
4237  rast1, 0,
4238  rast2, 0,
4239  7.1,
4240  &result
4241  );
4242  CU_ASSERT_EQUAL(rtn, ES_NONE);
4243  CU_ASSERT_EQUAL(result, 1);
4244 
4245  /* rast2 (skewed by 1, -1) */
4246  rt_raster_set_skews(rast2, 1, -1);
4247 
4249  rast1, 0,
4250  rast2, 0,
4251  8,
4252  &result
4253  );
4254  CU_ASSERT_EQUAL(rtn, ES_NONE);
4255  CU_ASSERT_EQUAL(result, 1);
4256 
4257  cu_free_raster(rast2);
4258  cu_free_raster(rast1);
4259 }
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_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_raster_fully_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dfwithin)
Return ES_ERROR if error occurred in function.
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: