642 {
643 int i;
644 int byHeight = 1;
645 uint32_t dimValue;
646
647 uint32_t row;
648 uint32_t rowoffset;
649 uint32_t col;
650 uint32_t coloffset;
651
652 enum line_points {X1, Y1, X2, Y2};
653 enum point {pX, pY};
654 double line1[4] = {0.};
655 double line2[4] = {0.};
656 double P[2] = {0.};
657 double Qw[2] = {0.};
658 double Qr[2] = {0.};
659 double gt1[6] = {0.};
660 double gt2[6] = {0.};
661 double igt1[6] = {0};
662 double igt2[6] = {0};
663 double d;
664 double val1;
665 int noval1;
666 int isnodata1;
667 double val2;
668 int noval2;
669 int isnodata2;
670 uint32_t adjacent[8] = {0};
671
672 double xscale;
673 double yscale;
674
675 uint16_t width1;
676 uint16_t height1;
677 uint16_t width2;
678 uint16_t height2;
679
684
685
688
689
691 rast1,
692 0, 0,
693 &(line1[X1]), &(line1[Y1]),
694 gt1
695 );
696
698 rast1,
699 0, height1,
700 &(line1[X2]), &(line1[Y2]),
701 gt1
702 );
703
705 rast2,
706 0, 0,
707 &(line2[X1]), &(line2[Y1]),
708 gt2
709 );
710
712 rast2,
713 width2, 0,
714 &(line2[X2]), &(line2[Y2]),
715 gt2
716 );
717
718
719 if (
FLT_EQ(((line1[X2] - line1[X1]) * (line2[Y2] - line2[Y1])),
720 ((line2[X2] - line2[X1]) * (line1[Y2] - line1[Y1]))))
721 byHeight = 0;
722
723 if (byHeight)
724 dimValue = height2;
725 else
726 dimValue = width2;
727 RASTER_DEBUGF(4,
"byHeight: %d, dimValue: %d", byHeight, dimValue);
728
729
730 for (coloffset = 0; coloffset < 3; coloffset++) {
731 for (rowoffset = 0; rowoffset < 3; rowoffset++) {
732
733 for (col = coloffset; col <= width1; col += 3) {
734
736 rast1,
737 col, 0,
738 &(line1[X1]), &(line1[Y1]),
739 gt1
740 );
741
743 rast1,
744 col, height1,
745 &(line1[X2]), &(line1[Y2]),
746 gt1
747 );
748
749
750 for (row = rowoffset; row <= dimValue; row += 3) {
751
752 if (byHeight) {
754 rast2,
755 0, row,
756 &(line2[X1]), &(line2[Y1]),
757 gt2
758 );
759
761 rast2,
762 width2, row,
763 &(line2[X2]), &(line2[Y2]),
764 gt2
765 );
766 }
767 else {
769 rast2,
770 row, 0,
771 &(line2[X1]), &(line2[Y1]),
772 gt2
773 );
774
776 rast2,
777 row, height2,
778 &(line2[X2]), &(line2[Y2]),
779 gt2
780 );
781 }
782
785 line1[X1], line1[Y1], line1[X2], line1[Y2]);
787 line2[X1], line2[Y1], line2[X2], line2[Y2]);
788
789
790
791 d = ((line1[X1] - line1[X2]) * (line2[Y1] - line2[Y2])) - ((line1[Y1] - line1[Y2]) * (line2[X1] - line2[X2]));
792
794 continue;
795 }
796
797 P[pX] = (((line1[X1] * line1[Y2]) - (line1[Y1] * line1[X2])) * (line2[X1] - line2[X2])) -
798 ((line1[X1] - line1[X2]) * ((line2[X1] * line2[Y2]) - (line2[Y1] * line2[X2])));
799 P[pX] = P[pX] / d;
800
801 P[pY] = (((line1[X1] * line1[Y2]) - (line1[Y1] * line1[X2])) * (line2[Y1] - line2[Y2])) -
802 ((line1[Y1] - line1[Y2]) * ((line2[X1] * line2[Y2]) - (line2[Y1] * line2[X2])));
803 P[pY] = P[pY] / d;
804
806
807
808 if ((
809 (
FLT_EQ(P[pX], line1[X1]) ||
FLT_EQ(P[pX], line1[X2])) ||
810 (P[pX] > fmin(line1[X1], line1[X2]) && (P[pX] < fmax(line1[X1], line1[X2])))
811 ) && (
812 (
FLT_EQ(P[pY], line1[Y1]) ||
FLT_EQ(P[pY], line1[Y2])) ||
813 (P[pY] > fmin(line1[Y1], line1[Y2]) && (P[pY] < fmax(line1[Y1], line1[Y2])))
814 ) && (
815 (
FLT_EQ(P[pX], line2[X1]) ||
FLT_EQ(P[pX], line2[X2])) ||
816 (P[pX] > fmin(line2[X1], line2[X2]) && (P[pX] < fmax(line2[X1], line2[X2])))
817 ) && (
818 (
FLT_EQ(P[pY], line2[Y1]) ||
FLT_EQ(P[pY], line2[Y2])) ||
819 (P[pY] > fmin(line2[Y1], line2[Y2]) && (P[pY] < fmax(line2[Y1], line2[Y2])))
820 )) {
822
823 for (i = 0; i < 8; i++) adjacent[i] = 0;
824
825
826 for (i = 0; i < 8; i++) {
827 switch (i) {
828 case 7:
829 Qw[pX] = P[pX] - xscale;
830 Qw[pY] = P[pY] + yscale;
831 break;
832
833 case 6:
834 Qw[pX] = P[pX] - xscale;
835 Qw[pY] = P[pY];
836 break;
837 case 5:
838 Qw[pX] = P[pX] - xscale;
839 Qw[pY] = P[pY] - yscale;
840 break;
841
842 case 4:
843 Qw[pX] = P[pX];
844 Qw[pY] = P[pY] - yscale;
845 break;
846 case 3:
847 Qw[pX] = P[pX] + xscale;
848 Qw[pY] = P[pY] - yscale;
849 break;
850
851 case 2:
852 Qw[pX] = P[pX] + xscale;
853 Qw[pY] = P[pY];
854 break;
855
856 case 1:
857 Qw[pX] = P[pX] + xscale;
858 Qw[pY] = P[pY] + yscale;
859 break;
860
861 case 0:
862 Qw[pX] = P[pX];
863 Qw[pY] = P[pY] + yscale;
864 break;
865 }
866
867
868 noval1 = 0;
870 rast1,
871 Qw[pX], Qw[pY],
872 &(Qr[pX]), &(Qr[pY]),
873 igt1
875 noval1 = 1;
876 }
877
878 else if ((Qr[pX] < 0 || Qr[pX] >= width1) ||
879 (Qr[pY] < 0 || Qr[pY] >= height1))
880 {
881 noval1 = 1;
882 }
883 else if (hasnodata1 ==
FALSE)
884 val1 = 1;
885
887 noval1 = 1;
888
889
890 noval2 = 0;
892 rast2,
893 Qw[pX], Qw[pY],
894 &(Qr[pX]), &(Qr[pY]),
895 igt2
897 noval2 = 1;
898 }
899
900 else if ((Qr[pX] < 0 || Qr[pX] >= width2) ||
901 (Qr[pY] < 0 || Qr[pY] >= height2))
902 {
903 noval2 = 1;
904 }
905 else if (hasnodata2 ==
FALSE)
906 val2 = 1;
907
909 noval2 = 1;
910
911 if (!noval1) {
913 }
914 if (!noval2) {
916 }
917
918
919 if (!noval1 && (
920 (hasnodata1 ==
FALSE) || !isnodata1
921 )) {
922 adjacent[i]++;
923 }
924 if (!noval2 && (
925 (hasnodata2 ==
FALSE) || !isnodata2
926 )) {
927 adjacent[i] += 3;
928 }
929
930
931 if (noval1 || noval2) {
932 RASTER_DEBUGF(4,
"noval1 = %d, noval2 = %d", noval1, noval2);
933 continue;
934 }
935
936
937 if (
938 ((hasnodata1 ==
FALSE) || !isnodata1) &&
939 ((hasnodata2 ==
FALSE) || !isnodata2)
940 ) {
942
943 return 1;
944 }
945 }
946
947
948 for (i = 0; i < 4; i++) {
950 , i, adjacent[i], i + 4, adjacent[i + 4]);
951 if (adjacent[i] == 0) continue;
952
953 if (adjacent[i] + adjacent[i + 4] == 4) {
955
956 return 1;
957 }
958 }
959 }
960 else {
962 }
963 }
964 }
965 }
966 }
967
968 return 0;
969}
#define RASTER_DEBUG(level, msg)
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
#define RASTER_DEBUGF(level, msg,...)
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
uint16_t rt_raster_get_height(rt_raster raster)
uint16_t rt_raster_get_width(rt_raster raster)
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.