PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_raster_within_distance()

static void test_raster_within_distance ( )
static

Definition at line 3137 of file cu_spatial_relationship.c.

3137 {
3138 rt_raster rast1;
3139 rt_raster rast2;
3140 rt_band band1;
3141 rt_band band2;
3142 double nodata;
3143 int rtn;
3144 int result;
3145
3146 /*
3147 rast1
3148
3149 (-1, -1)
3150 +-+-+
3151 |1|1|
3152 +-+-+
3153 |1|1|
3154 +-+-+
3155 (1, 1)
3156 */
3157 rast1 = rt_raster_new(2, 2);
3158 CU_ASSERT(rast1 != NULL);
3159 rt_raster_set_scale(rast1, 1, 1);
3160 rt_raster_set_offsets(rast1, -1, -1);
3161
3162 band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
3163 CU_ASSERT(band1 != NULL);
3164 rt_band_set_nodata(band1, 0, NULL);
3165 rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
3166 rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
3167 rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
3168 rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
3169
3170 rt_band_get_nodata(band1, &nodata);
3171 CU_ASSERT_EQUAL(nodata, 0);
3172
3174 rast1, 0,
3175 rast1, 0,
3176 0.,
3177 &result
3178 );
3179 CU_ASSERT_EQUAL(rtn, ES_NONE);
3180 CU_ASSERT_EQUAL(result, 1);
3181
3183 rast1, 0,
3184 rast1, 0,
3185 -1.,
3186 &result
3187 );
3188 CU_ASSERT_NOT_EQUAL(rtn, ES_NONE);
3189
3190 /*
3191 rast2
3192
3193 (0, 0)
3194 +-+-+
3195 |1|1|
3196 +-+-+
3197 |1|1|
3198 +-+-+
3199 (2, 2)
3200 */
3201 rast2 = rt_raster_new(2, 2);
3202 CU_ASSERT(rast2 != NULL);
3203 rt_raster_set_scale(rast2, 1, 1);
3204
3205 band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3206 CU_ASSERT(band2 != NULL);
3207 rt_band_set_nodata(band2, 0, NULL);
3208 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3209 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3210 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3211 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3212
3213 rt_band_get_nodata(band2, &nodata);
3214 CU_ASSERT_EQUAL(nodata, 0);
3215
3217 rast1, 0,
3218 rast2, 0,
3219 0.,
3220 &result
3221 );
3222 CU_ASSERT_EQUAL(rtn, ES_NONE);
3223 CU_ASSERT_EQUAL(result, 1);
3224
3226 rast1, 0,
3227 rast2, 0,
3228 1.,
3229 &result
3230 );
3231 CU_ASSERT_EQUAL(rtn, ES_NONE);
3232 CU_ASSERT_EQUAL(result, 1);
3233
3235 rast1, -1,
3236 rast2, -1,
3237 2.,
3238 &result
3239 );
3240 CU_ASSERT_EQUAL(rtn, ES_NONE);
3241 CU_ASSERT_EQUAL(result, 1);
3242
3243 /*
3244 rast2
3245
3246 (0, 0)
3247 +-+-+
3248 |0|1|
3249 +-+-+
3250 |1|1|
3251 +-+-+
3252 (2, 2)
3253 */
3254 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3255
3257 rast1, 0,
3258 rast2, 0,
3259 0.,
3260 &result
3261 );
3262 CU_ASSERT_EQUAL(rtn, ES_NONE);
3263 CU_ASSERT_EQUAL(result, 1);
3264
3265 /*
3266 rast2
3267
3268 (0, 0)
3269 +-+-+
3270 |1|0|
3271 +-+-+
3272 |1|1|
3273 +-+-+
3274 (2, 2)
3275 */
3276 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3277 rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3278
3280 rast1, 0,
3281 rast2, 0,
3282 0.,
3283 &result
3284 );
3285 CU_ASSERT_EQUAL(rtn, ES_NONE);
3286 CU_ASSERT_EQUAL(result, 1);
3287
3288 /*
3289 rast2
3290
3291 (0, 0)
3292 +-+-+
3293 |0|0|
3294 +-+-+
3295 |0|1|
3296 +-+-+
3297 (2, 2)
3298 */
3299 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3300 rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3301 rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3302
3304 rast1, 0,
3305 rast2, 0,
3306 0,
3307 &result
3308 );
3309 CU_ASSERT_EQUAL(rtn, ES_NONE);
3310 CU_ASSERT_EQUAL(result, 1);
3311
3312 /*
3313 rast2
3314
3315 (0, 0)
3316 +-+-+
3317 |0|0|
3318 +-+-+
3319 |0|0|
3320 +-+-+
3321 (2, 2)
3322 */
3323 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3324 rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
3325 rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
3326 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3327
3329 rast1, 0,
3330 rast2, 0,
3331 0,
3332 &result
3333 );
3334 CU_ASSERT_EQUAL(rtn, ES_NONE);
3335 CU_ASSERT_NOT_EQUAL(result, 1);
3336
3337 /*
3338 rast2
3339
3340 (2, 0)
3341 +-+-+
3342 |1|1|
3343 +-+-+
3344 |1|1|
3345 +-+-+
3346 (4, 2)
3347 */
3348 rt_raster_set_offsets(rast2, 2, 0);
3349
3350 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3351 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3352 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3353 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3354
3356 rast1, 0,
3357 rast2, 0,
3358 0,
3359 &result
3360 );
3361 CU_ASSERT_EQUAL(rtn, ES_NONE);
3362 CU_ASSERT_NOT_EQUAL(result, 1);
3363
3365 rast1, 0,
3366 rast2, 0,
3367 1.1,
3368 &result
3369 );
3370 CU_ASSERT_EQUAL(rtn, ES_NONE);
3371 CU_ASSERT_EQUAL(result, 1);
3372
3373 /*
3374 rast2
3375
3376 (0.1, 0.1)
3377 +-+-+
3378 |1|1|
3379 +-+-+
3380 |1|1|
3381 +-+-+
3382 (0.9, 0.9)
3383 */
3384 rt_raster_set_offsets(rast2, 0.1, 0.1);
3385 rt_raster_set_scale(rast2, 0.4, 0.4);
3386
3387 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3388 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3389 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3390 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3391
3393 rast1, 0,
3394 rast2, 0,
3395 0,
3396 &result
3397 );
3398 CU_ASSERT_EQUAL(rtn, ES_NONE);
3399 CU_ASSERT_EQUAL(result, 1);
3400
3401 /*
3402 rast2
3403
3404 (-0.1, 0.1)
3405 +-+-+
3406 |1|1|
3407 +-+-+
3408 |1|1|
3409 +-+-+
3410 (0.9, 0.9)
3411 */
3412 rt_raster_set_offsets(rast2, -0.1, 0.1);
3413
3415 rast1, 0,
3416 rast2, 0,
3417 0,
3418 &result
3419 );
3420 CU_ASSERT_EQUAL(rtn, ES_NONE);
3421 CU_ASSERT_EQUAL(result, 1);
3422
3423 cu_free_raster(rast2);
3424
3425 /*
3426 rast2
3427
3428 (0, 0)
3429 +-+-+-+
3430 |1|1|1|
3431 +-+-+-+
3432 |1|1|1|
3433 +-+-+-+
3434 |1|1|1|
3435 +-+-+-+
3436 (3, 3)
3437 */
3438 rast2 = rt_raster_new(3, 3);
3439 CU_ASSERT(rast2 != NULL);
3440 rt_raster_set_scale(rast2, 1, 1);
3441
3442 band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3443 CU_ASSERT(band2 != NULL);
3444 rt_band_set_nodata(band2, 0, NULL);
3445 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3446 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3447 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3448 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3449 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3450 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3451 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3452 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3453 rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
3454
3455 rt_band_get_nodata(band2, &nodata);
3456 CU_ASSERT_EQUAL(nodata, 0);
3457
3459 rast1, 0,
3460 rast2, 0,
3461 0,
3462 &result
3463 );
3464 CU_ASSERT_EQUAL(rtn, ES_NONE);
3465 CU_ASSERT_EQUAL(result, 1);
3466
3467 /*
3468 rast2
3469
3470 (-2, -2)
3471 +-+-+-+
3472 |1|1|1|
3473 +-+-+-+
3474 |1|1|1|
3475 +-+-+-+
3476 |1|1|1|
3477 +-+-+-+
3478 (1, 1)
3479 */
3480 rt_raster_set_offsets(rast2, -2, -2);
3481
3482 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3483 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3484 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3485 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3486 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3487 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3488 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3489 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3490 rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
3491
3493 rast1, 0,
3494 rast2, 0,
3495 0,
3496 &result
3497 );
3498 CU_ASSERT_EQUAL(rtn, ES_NONE);
3499 CU_ASSERT_EQUAL(result, 1);
3500
3501 /*
3502 rast2
3503
3504 (-2, -2)
3505 +-+-+-+
3506 |0|1|1|
3507 +-+-+-+
3508 |1|0|1|
3509 +-+-+-+
3510 |1|1|0|
3511 +-+-+-+
3512 (1, 1)
3513 */
3514 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3515 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3516 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3517 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3518 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3519 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3520 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3521 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3522 rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3523
3525 rast1, 0,
3526 rast2, 0,
3527 0,
3528 &result
3529 );
3530 CU_ASSERT_EQUAL(rtn, ES_NONE);
3531 CU_ASSERT_EQUAL(result, 1);
3532
3533 /*
3534 rast2
3535
3536 (-2, -2)
3537 +-+-+-+
3538 |0|1|1|
3539 +-+-+-+
3540 |1|0|0|
3541 +-+-+-+
3542 |1|0|0|
3543 +-+-+-+
3544 (1, 1)
3545 */
3546 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3547 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3548 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3549 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3550 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3551 rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3552 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3553 rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3554 rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3555
3557 rast1, 0,
3558 rast2, 0,
3559 0,
3560 &result
3561 );
3562 CU_ASSERT_EQUAL(rtn, ES_NONE);
3563 CU_ASSERT_EQUAL(result, 1);
3564
3565 /*
3566 rast2
3567
3568 (-2, -2)
3569 +-+-+-+
3570 |0|1|0|
3571 +-+-+-+
3572 |1|0|0|
3573 +-+-+-+
3574 |0|0|0|
3575 +-+-+-+
3576 (1, 1)
3577 */
3578 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
3579 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3580 rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
3581 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3582 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
3583 rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
3584 rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
3585 rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
3586 rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
3587
3589 rast1, 0,
3590 rast2, 0,
3591 0,
3592 &result
3593 );
3594 CU_ASSERT_EQUAL(rtn, ES_NONE);
3595 CU_ASSERT_EQUAL(result, 1);
3596
3597 /*
3598 rast2
3599
3600 (-10, -1)
3601 +-+-+-+
3602 |1|1|1|
3603 +-+-+-+
3604 |1|1|1|
3605 +-+-+-+
3606 |1|1|1|
3607 +-+-+-+
3608 (-7, 2)
3609 */
3610 rt_raster_set_offsets(rast2, -10, -1);
3611
3612 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3613 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
3614 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
3615 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3616 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
3617 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
3618 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3619 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
3620 rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
3621
3623 rast1, 0,
3624 rast2, 0,
3625 5,
3626 &result
3627 );
3628 CU_ASSERT_EQUAL(rtn, ES_NONE);
3629 CU_ASSERT_NOT_EQUAL(result, 1);
3630
3632 rast1, 0,
3633 rast2, 0,
3634 6,
3635 &result
3636 );
3637 CU_ASSERT_EQUAL(rtn, ES_NONE);
3638 CU_ASSERT_EQUAL(result, 1);
3639
3640 cu_free_raster(rast2);
3641
3642 /* skew tests */
3643 /* rast2 (skewed by -0.5, 0.5) */
3644 rast2 = rt_raster_new(3, 3);
3645 CU_ASSERT(rast2 != NULL);
3646 rt_raster_set_scale(rast2, 1, 1);
3647 rt_raster_set_skews(rast2, -0.5, 0.5);
3648
3649 band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
3650 CU_ASSERT(band2 != NULL);
3651 rt_band_set_nodata(band2, 0, NULL);
3652 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
3653 rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
3654 rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
3655 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
3656 rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
3657 rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
3658 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
3659 rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
3660 rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
3661
3663 rast1, 0,
3664 rast2, 0,
3665 0,
3666 &result
3667 );
3668 CU_ASSERT_EQUAL(rtn, ES_NONE);
3669 CU_ASSERT_EQUAL(result, 1);
3670
3671 /* rast2 (skewed by -1, 1) */
3672 rt_raster_set_skews(rast2, -1, 1);
3673
3675 rast1, 0,
3676 rast2, 0,
3677 0,
3678 &result
3679 );
3680 CU_ASSERT_EQUAL(rtn, ES_NONE);
3681 CU_ASSERT_EQUAL(result, 1);
3682
3683 /* rast2 (skewed by 1, -1) */
3684 rt_raster_set_skews(rast2, 1, -1);
3685
3687 rast1, 0,
3688 rast2, 0,
3689 0,
3690 &result
3691 );
3692 CU_ASSERT_EQUAL(rtn, ES_NONE);
3693 CU_ASSERT_EQUAL(result, 1);
3694
3695 cu_free_raster(rast2);
3696 cu_free_raster(rast1);
3697}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition rt_raster.c:141
@ PT_8BUI
Definition librtcore.h:193
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition rt_raster.c:172
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition rt_raster.c:52
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:892
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:1140
@ ES_NONE
Definition librtcore.h:182
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:2067
rt_errorstate rt_raster_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dwithin)
Return ES_ERROR if error occurred in function.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition rt_raster.c:203
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, result, rt_band_get_nodata(), rt_band_set_nodata(), rt_band_set_pixel(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rt_raster_set_skews(), and rt_raster_within_distance().

Referenced by spatial_relationship_suite_setup().

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