PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_raster_geos_touches()

static void test_raster_geos_touches ( )
static

Definition at line 502 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_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rt_raster_set_skews(), and rt_raster_touches().

Referenced by spatial_relationship_suite_setup().

502  {
503  rt_raster rast1;
504  rt_raster rast2;
505  rt_band band1;
506  rt_band band2;
507  double nodata;
508  int rtn;
509  int result;
510 
511  /*
512  rast1
513 
514  (-1, -1)
515  +-+-+
516  |1|1|
517  +-+-+
518  |1|1|
519  +-+-+
520  (1, 1)
521  */
522  rast1 = rt_raster_new(2, 2);
523  CU_ASSERT(rast1 != NULL);
524  rt_raster_set_scale(rast1, 1, 1);
525  rt_raster_set_offsets(rast1, -1, -1);
526 
527  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
528  CU_ASSERT(band1 != NULL);
529  rt_band_set_nodata(band1, 0, NULL);
530  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
531  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
532  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
533  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
534 
535  rt_band_get_nodata(band1, &nodata);
536  CU_ASSERT_EQUAL(nodata, 0);
537 
538  rtn = rt_raster_touches(
539  rast1, 0,
540  rast1, 0,
541  &result
542  );
543  CU_ASSERT_EQUAL(rtn, ES_NONE);
544  CU_ASSERT_NOT_EQUAL(result, 1);
545 
546  /*
547  rast2
548 
549  (0, 0)
550  +-+-+
551  |1|1|
552  +-+-+
553  |1|1|
554  +-+-+
555  (2, 2)
556  */
557  rast2 = rt_raster_new(2, 2);
558  CU_ASSERT(rast2 != NULL);
559  rt_raster_set_scale(rast2, 1, 1);
560 
561  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
562  CU_ASSERT(band2 != NULL);
563  rt_band_set_nodata(band2, 0, NULL);
564  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
565  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
566  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
567  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
568 
569  rt_band_get_nodata(band2, &nodata);
570  CU_ASSERT_EQUAL(nodata, 0);
571 
572  rtn = rt_raster_touches(
573  rast1, 0,
574  rast2, 0,
575  &result
576  );
577  CU_ASSERT_EQUAL(rtn, ES_NONE);
578  CU_ASSERT_NOT_EQUAL(result, 1);
579 
580  rtn = rt_raster_touches(
581  rast1, -1,
582  rast2, -1,
583  &result
584  );
585  CU_ASSERT_EQUAL(rtn, ES_NONE);
586  CU_ASSERT_NOT_EQUAL(result, 1);
587 
588  /*
589  rast2
590 
591  (0, 0)
592  +-+-+
593  |0|1|
594  +-+-+
595  |1|1|
596  +-+-+
597  (2, 2)
598  */
599  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
600 
601  rtn = rt_raster_touches(
602  rast1, 0,
603  rast2, 0,
604  &result
605  );
606  CU_ASSERT_EQUAL(rtn, ES_NONE);
607  CU_ASSERT_EQUAL(result, 1);
608 
609  /*
610  rast2
611 
612  (0, 0)
613  +-+-+
614  |1|0|
615  +-+-+
616  |1|1|
617  +-+-+
618  (2, 2)
619  */
620  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
621  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
622 
623  rtn = rt_raster_touches(
624  rast1, 0,
625  rast2, 0,
626  &result
627  );
628  CU_ASSERT_EQUAL(rtn, ES_NONE);
629  CU_ASSERT_NOT_EQUAL(result, 1);
630 
631  /*
632  rast2
633 
634  (0, 0)
635  +-+-+
636  |0|0|
637  +-+-+
638  |0|1|
639  +-+-+
640  (2, 2)
641  */
642  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
643  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
644  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
645 
646  rtn = rt_raster_touches(
647  rast1, 0,
648  rast2, 0,
649  &result
650  );
651  CU_ASSERT_EQUAL(rtn, ES_NONE);
652  CU_ASSERT_EQUAL(result, 1);
653 
654  /*
655  rast2
656 
657  (0, 0)
658  +-+-+
659  |0|0|
660  +-+-+
661  |0|0|
662  +-+-+
663  (2, 2)
664  */
665  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
666  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
667  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
668  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
669 
670  rtn = rt_raster_touches(
671  rast1, 0,
672  rast2, 0,
673  &result
674  );
675  CU_ASSERT_EQUAL(rtn, ES_NONE);
676  CU_ASSERT_NOT_EQUAL(result, 1);
677 
678  /*
679  rast2
680 
681  (2, 0)
682  +-+-+
683  |1|1|
684  +-+-+
685  |1|1|
686  +-+-+
687  (4, 2)
688  */
689  rt_raster_set_offsets(rast2, 2, 0);
690 
691  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
692  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
693  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
694  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
695 
696  rtn = rt_raster_touches(
697  rast1, 0,
698  rast2, 0,
699  &result
700  );
701  CU_ASSERT_EQUAL(rtn, ES_NONE);
702  CU_ASSERT_NOT_EQUAL(result, 1);
703 
704  /*
705  rast2
706 
707  (0, 1)
708  +-+-+
709  |1|1|
710  +-+-+
711  |1|1|
712  +-+-+
713  (2, 3)
714  */
715  rt_raster_set_offsets(rast2, 0, 1);
716 
717  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
718  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
719  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
720  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
721 
722  rtn = rt_raster_touches(
723  rast1, 0,
724  rast2, 0,
725  &result
726  );
727  CU_ASSERT_EQUAL(rtn, ES_NONE);
728  CU_ASSERT_EQUAL(result, 1);
729 
730  /*
731  rast2
732 
733  (-1, 1)
734  +-+-+
735  |1|1|
736  +-+-+
737  |1|1|
738  +-+-+
739  (1, 3)
740  */
741  rt_raster_set_offsets(rast2, -1, 1);
742 
743  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
744  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
745  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
746  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
747 
748  rtn = rt_raster_touches(
749  rast1, 0,
750  rast2, 0,
751  &result
752  );
753  CU_ASSERT_EQUAL(rtn, ES_NONE);
754  CU_ASSERT_EQUAL(result, 1);
755 
756  /*
757  rast2
758 
759  (0.1, 0.1)
760  +-+-+
761  |1|1|
762  +-+-+
763  |1|1|
764  +-+-+
765  (0.9, 0.9)
766  */
767  rt_raster_set_offsets(rast2, 0.1, 0.1);
768  rt_raster_set_scale(rast2, 0.4, 0.4);
769 
770  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
771  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
772  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
773  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
774 
775  rtn = rt_raster_touches(
776  rast1, 0,
777  rast2, 0,
778  &result
779  );
780  CU_ASSERT_EQUAL(rtn, ES_NONE);
781  CU_ASSERT_NOT_EQUAL(result, 1);
782 
783  /*
784  rast2
785 
786  (-0.1, 0.1)
787  +-+-+
788  |1|1|
789  +-+-+
790  |1|1|
791  +-+-+
792  (0.9, 0.9)
793  */
794  rt_raster_set_offsets(rast2, -0.1, 0.1);
795 
796  rtn = rt_raster_touches(
797  rast1, 0,
798  rast2, 0,
799  &result
800  );
801  CU_ASSERT_EQUAL(rtn, ES_NONE);
802  CU_ASSERT_NOT_EQUAL(result, 1);
803 
804  cu_free_raster(rast2);
805 
806  /*
807  rast2
808 
809  (0, 0)
810  +-+-+-+
811  |1|1|1|
812  +-+-+-+
813  |1|1|1|
814  +-+-+-+
815  |1|1|1|
816  +-+-+-+
817  (3, 3)
818  */
819  rast2 = rt_raster_new(3, 3);
820  CU_ASSERT(rast2 != NULL);
821  rt_raster_set_scale(rast2, 1, 1);
822 
823  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
824  CU_ASSERT(band2 != NULL);
825  rt_band_set_nodata(band2, 0, NULL);
826  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
827  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
828  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
829  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
830  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
831  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
832  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
833  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
834  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
835 
836  rt_band_get_nodata(band2, &nodata);
837  CU_ASSERT_EQUAL(nodata, 0);
838 
839  rtn = rt_raster_touches(
840  rast1, 0,
841  rast2, 0,
842  &result
843  );
844  CU_ASSERT_EQUAL(rtn, ES_NONE);
845  CU_ASSERT_NOT_EQUAL(result, 1);
846 
847  /*
848  rast2
849 
850  (-2, -2)
851  +-+-+-+
852  |1|1|1|
853  +-+-+-+
854  |1|1|1|
855  +-+-+-+
856  |1|1|1|
857  +-+-+-+
858  (1, 1)
859  */
860  rt_raster_set_offsets(rast2, -2, -2);
861 
862  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
863  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
864  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
865  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
866  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
867  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
868  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
869  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
870  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
871 
872  rtn = rt_raster_touches(
873  rast1, 0,
874  rast2, 0,
875  &result
876  );
877  CU_ASSERT_EQUAL(rtn, ES_NONE);
878  CU_ASSERT_NOT_EQUAL(result, 1);
879 
880  /*
881  rast2
882 
883  (-2, -2)
884  +-+-+-+
885  |0|1|1|
886  +-+-+-+
887  |1|0|1|
888  +-+-+-+
889  |1|1|0|
890  +-+-+-+
891  (1, 1)
892  */
893  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
894  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
895  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
896  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
897  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
898  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
899  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
900  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
901  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
902 
903  rtn = rt_raster_touches(
904  rast1, 0,
905  rast2, 0,
906  &result
907  );
908  CU_ASSERT_EQUAL(rtn, ES_NONE);
909  CU_ASSERT_NOT_EQUAL(result, 1);
910 
911  /*
912  rast2
913 
914  (-2, -2)
915  +-+-+-+
916  |0|1|1|
917  +-+-+-+
918  |1|0|0|
919  +-+-+-+
920  |1|0|0|
921  +-+-+-+
922  (1, 1)
923  */
924  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
925  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
926  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
927  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
928  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
929  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
930  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
931  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
932  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
933 
934  rtn = rt_raster_touches(
935  rast1, 0,
936  rast2, 0,
937  &result
938  );
939  CU_ASSERT_EQUAL(rtn, ES_NONE);
940  CU_ASSERT_EQUAL(result, 1);
941 
942  /*
943  rast2
944 
945  (-2, -2)
946  +-+-+-+
947  |0|1|0|
948  +-+-+-+
949  |1|0|0|
950  +-+-+-+
951  |0|0|0|
952  +-+-+-+
953  (1, 1)
954  */
955  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
956  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
957  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
958  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
959  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
960  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
961  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
962  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
963  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
964 
965  rtn = rt_raster_touches(
966  rast1, 0,
967  rast2, 0,
968  &result
969  );
970  CU_ASSERT_EQUAL(rtn, ES_NONE);
971  CU_ASSERT_EQUAL(result, 1);
972 
973  cu_free_raster(rast2);
974 
975  /* skew tests */
976  /* rast2 (skewed by -0.5, 0.5) */
977  rast2 = rt_raster_new(3, 3);
978  CU_ASSERT(rast2 != NULL);
979  rt_raster_set_scale(rast2, 1, 1);
980  rt_raster_set_skews(rast2, -0.5, 0.5);
981 
982  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
983  CU_ASSERT(band2 != NULL);
984  rt_band_set_nodata(band2, 0, NULL);
985  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
986  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
987  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
988  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
989  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
990  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
991  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
992  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
993  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
994 
995  rtn = rt_raster_touches(
996  rast1, 0,
997  rast2, 0,
998  &result
999  );
1000  CU_ASSERT_EQUAL(rtn, ES_NONE);
1001  CU_ASSERT_NOT_EQUAL(result, 1);
1002 
1003  /* rast2 (skewed by -1, 1) */
1004  rt_raster_set_skews(rast2, -1, 1);
1005 
1006  rtn = rt_raster_touches(
1007  rast1, 0,
1008  rast2, 0,
1009  &result
1010  );
1011  CU_ASSERT_EQUAL(rtn, ES_NONE);
1012  CU_ASSERT_NOT_EQUAL(result, 1);
1013 
1014  /* rast2 (skewed by 1, -1) */
1015  rt_raster_set_skews(rast2, 1, -1);
1016 
1017  rtn = rt_raster_touches(
1018  rast1, 0,
1019  rast2, 0,
1020  &result
1021  );
1022  CU_ASSERT_EQUAL(rtn, ES_NONE);
1023  CU_ASSERT_NOT_EQUAL(result, 1);
1024 
1025  cu_free_raster(rast2);
1026  cu_free_raster(rast1);
1027 }
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_touches(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *touches)
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: