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

◆ test_raster_intersects()

static void test_raster_intersects ( )
static

Definition at line 4261 of file cu_spatial_relationship.c.

4261 {
4262 rt_raster rast1;
4263 rt_raster rast2;
4264 rt_band band1;
4265 rt_band band2;
4266 double nodata;
4267 int rtn;
4268 int result;
4269
4270 /*
4271 rast1
4272
4273 (-1, -1)
4274 +-+-+
4275 |1|1|
4276 +-+-+
4277 |1|1|
4278 +-+-+
4279 (1, 1)
4280 */
4281 rast1 = rt_raster_new(2, 2);
4282 CU_ASSERT(rast1 != NULL);
4283 rt_raster_set_scale(rast1, 1, 1);
4284 rt_raster_set_offsets(rast1, -1, -1);
4285
4286 band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
4287 CU_ASSERT(band1 != NULL);
4288 rt_band_set_nodata(band1, 0, NULL);
4289 rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
4290 rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
4291 rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
4292 rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
4293
4294 rt_band_get_nodata(band1, &nodata);
4295 CU_ASSERT_EQUAL(nodata, 0);
4296
4297 /*
4298 rast2
4299
4300 (0, 0)
4301 +-+-+
4302 |1|1|
4303 +-+-+
4304 |1|1|
4305 +-+-+
4306 (2, 2)
4307 */
4308 rast2 = rt_raster_new(2, 2);
4309 CU_ASSERT(rast2 != NULL);
4310 rt_raster_set_scale(rast2, 1, 1);
4311
4312 band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4313 CU_ASSERT(band2 != NULL);
4314 rt_band_set_nodata(band2, 0, NULL);
4315 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4316 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4317 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4318 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4319
4320 rt_band_get_nodata(band2, &nodata);
4321 CU_ASSERT_EQUAL(nodata, 0);
4322
4324 rast1, 0,
4325 rast2, 0,
4326 &result
4327 );
4328 CU_ASSERT_EQUAL(rtn, ES_NONE);
4329 CU_ASSERT_EQUAL(result, 1);
4330
4332 rast1, -1,
4333 rast2, -1,
4334 &result
4335 );
4336 CU_ASSERT_EQUAL(rtn, ES_NONE);
4337 CU_ASSERT_EQUAL(result, 1);
4338
4339 /*
4340 rast2
4341
4342 (0, 0)
4343 +-+-+
4344 |0|1|
4345 +-+-+
4346 |1|1|
4347 +-+-+
4348 (2, 2)
4349 */
4350 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4351
4353 rast1, 0,
4354 rast2, 0,
4355 &result
4356 );
4357 CU_ASSERT_EQUAL(rtn, ES_NONE);
4358 CU_ASSERT_EQUAL(result, 1);
4359
4360 /*
4361 rast2
4362
4363 (0, 0)
4364 +-+-+
4365 |1|0|
4366 +-+-+
4367 |1|1|
4368 +-+-+
4369 (2, 2)
4370 */
4371 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4372 rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
4373
4375 rast1, 0,
4376 rast2, 0,
4377 &result
4378 );
4379 CU_ASSERT_EQUAL(rtn, ES_NONE);
4380 CU_ASSERT_EQUAL(result, 1);
4381
4382 /*
4383 rast2
4384
4385 (0, 0)
4386 +-+-+
4387 |0|0|
4388 +-+-+
4389 |0|1|
4390 +-+-+
4391 (2, 2)
4392 */
4393 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4394 rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
4395 rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
4396
4398 rast1, 0,
4399 rast2, 0,
4400 &result
4401 );
4402 CU_ASSERT_EQUAL(rtn, ES_NONE);
4403 CU_ASSERT_EQUAL(result, 1);
4404
4405 /*
4406 rast2
4407
4408 (0, 0)
4409 +-+-+
4410 |0|0|
4411 +-+-+
4412 |0|0|
4413 +-+-+
4414 (2, 2)
4415 */
4416 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4417 rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
4418 rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
4419 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4420
4422 rast1, 0,
4423 rast2, 0,
4424 &result
4425 );
4426 CU_ASSERT_EQUAL(rtn, ES_NONE);
4427 CU_ASSERT_NOT_EQUAL(result, 1);
4428
4429 /*
4430 rast2
4431
4432 (2, 0)
4433 +-+-+
4434 |1|1|
4435 +-+-+
4436 |1|1|
4437 +-+-+
4438 (4, 2)
4439 */
4440 rt_raster_set_offsets(rast2, 2, 0);
4441
4442 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4443 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4444 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4445 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4446
4448 rast1, 0,
4449 rast2, 0,
4450 &result
4451 );
4452 CU_ASSERT_EQUAL(rtn, ES_NONE);
4453 CU_ASSERT_NOT_EQUAL(result, 1);
4454
4455 /*
4456 rast2
4457
4458 (0.1, 0.1)
4459 +-+-+
4460 |1|1|
4461 +-+-+
4462 |1|1|
4463 +-+-+
4464 (0.9, 0.9)
4465 */
4466 rt_raster_set_offsets(rast2, 0.1, 0.1);
4467 rt_raster_set_scale(rast2, 0.4, 0.4);
4468
4469 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4470 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4471 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4472 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4473
4475 rast1, 0,
4476 rast2, 0,
4477 &result
4478 );
4479 CU_ASSERT_EQUAL(rtn, ES_NONE);
4480 CU_ASSERT_EQUAL(result, 1);
4481
4482 /*
4483 rast2
4484
4485 (-0.1, 0.1)
4486 +-+-+
4487 |1|1|
4488 +-+-+
4489 |1|1|
4490 +-+-+
4491 (0.9, 0.9)
4492 */
4493 rt_raster_set_offsets(rast2, -0.1, 0.1);
4494
4496 rast1, 0,
4497 rast2, 0,
4498 &result
4499 );
4500 CU_ASSERT_EQUAL(rtn, ES_NONE);
4501 CU_ASSERT_EQUAL(result, 1);
4502
4503 cu_free_raster(rast2);
4504
4505 /*
4506 rast2
4507
4508 (0, 0)
4509 +-+-+-+
4510 |1|1|1|
4511 +-+-+-+
4512 |1|1|1|
4513 +-+-+-+
4514 |1|1|1|
4515 +-+-+-+
4516 (3, 3)
4517 */
4518 rast2 = rt_raster_new(3, 3);
4519 CU_ASSERT(rast2 != NULL);
4520 rt_raster_set_scale(rast2, 1, 1);
4521
4522 band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4523 CU_ASSERT(band2 != NULL);
4524 rt_band_set_nodata(band2, 0, NULL);
4525 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4526 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4527 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4528 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4529 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4530 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4531 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4532 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4533 rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4534
4535 rt_band_get_nodata(band2, &nodata);
4536 CU_ASSERT_EQUAL(nodata, 0);
4537
4539 rast1, 0,
4540 rast2, 0,
4541 &result
4542 );
4543 CU_ASSERT_EQUAL(rtn, ES_NONE);
4544 CU_ASSERT_EQUAL(result, 1);
4545
4546 /*
4547 rast2
4548
4549 (-2, -2)
4550 +-+-+-+
4551 |1|1|1|
4552 +-+-+-+
4553 |1|1|1|
4554 +-+-+-+
4555 |1|1|1|
4556 +-+-+-+
4557 (1, 1)
4558 */
4559 rt_raster_set_offsets(rast2, -2, -2);
4560
4561 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4562 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4563 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4564 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4565 rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
4566 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4567 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4568 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4569 rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
4570
4572 rast1, 0,
4573 rast2, 0,
4574 &result
4575 );
4576 CU_ASSERT_EQUAL(rtn, ES_NONE);
4577 CU_ASSERT_EQUAL(result, 1);
4578
4579 /*
4580 rast2
4581
4582 (-2, -2)
4583 +-+-+-+
4584 |0|1|1|
4585 +-+-+-+
4586 |1|0|1|
4587 +-+-+-+
4588 |1|1|0|
4589 +-+-+-+
4590 (1, 1)
4591 */
4592 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4593 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4594 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4595 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4596 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4597 rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
4598 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4599 rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
4600 rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4601
4603 rast1, 0,
4604 rast2, 0,
4605 &result
4606 );
4607 CU_ASSERT_EQUAL(rtn, ES_NONE);
4608 CU_ASSERT_EQUAL(result, 1);
4609
4610 /*
4611 rast2
4612
4613 (-2, -2)
4614 +-+-+-+
4615 |0|1|1|
4616 +-+-+-+
4617 |1|0|0|
4618 +-+-+-+
4619 |1|0|0|
4620 +-+-+-+
4621 (1, 1)
4622 */
4623 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4624 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4625 rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
4626 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4627 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4628 rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4629 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4630 rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4631 rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4632
4634 rast1, 0,
4635 rast2, 0,
4636 &result
4637 );
4638 CU_ASSERT_EQUAL(rtn, ES_NONE);
4639 CU_ASSERT_EQUAL(result, 1);
4640
4641 /*
4642 rast2
4643
4644 (-2, -2)
4645 +-+-+-+
4646 |0|1|0|
4647 +-+-+-+
4648 |1|0|0|
4649 +-+-+-+
4650 |0|0|0|
4651 +-+-+-+
4652 (1, 1)
4653 */
4654 rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
4655 rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
4656 rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
4657 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4658 rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
4659 rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
4660 rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
4661 rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
4662 rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
4663
4665 rast1, 0,
4666 rast2, 0,
4667 &result
4668 );
4669 CU_ASSERT_EQUAL(rtn, ES_NONE);
4670 CU_ASSERT_EQUAL(result, 1);
4671
4672 cu_free_raster(rast2);
4673
4674 /* skew tests */
4675 /* rast2 (skewed by -0.5, 0.5) */
4676 rast2 = rt_raster_new(3, 3);
4677 CU_ASSERT(rast2 != NULL);
4678 rt_raster_set_scale(rast2, 1, 1);
4679 rt_raster_set_skews(rast2, -0.5, 0.5);
4680
4681 band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
4682 CU_ASSERT(band2 != NULL);
4683 rt_band_set_nodata(band2, 0, NULL);
4684 rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
4685 rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
4686 rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
4687 rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
4688 rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
4689 rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
4690 rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
4691 rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
4692 rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
4693
4695 rast1, 0,
4696 rast2, 0,
4697 &result
4698 );
4699 CU_ASSERT_EQUAL(rtn, ES_NONE);
4700 CU_ASSERT_EQUAL(result, 1);
4701
4702 /* rast2 (skewed by -1, 1) */
4703 rt_raster_set_skews(rast2, -1, 1);
4704
4706 rast1, 0,
4707 rast2, 0,
4708 &result
4709 );
4710 CU_ASSERT_EQUAL(rtn, ES_NONE);
4711 CU_ASSERT_EQUAL(result, 1);
4712
4713 /* rast2 (skewed by 1, -1) */
4714 rt_raster_set_skews(rast2, 1, -1);
4715
4717 rast1, 0,
4718 rast2, 0,
4719 &result
4720 );
4721 CU_ASSERT_EQUAL(rtn, ES_NONE);
4722 CU_ASSERT_EQUAL(result, 1);
4723
4724 cu_free_raster(rast2);
4725 cu_free_raster(rast1);
4726}
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_raster_intersects(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *intersects)
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: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
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_intersects(), 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: