1049{
1050 const uint32_t set_count = 2;
1052 int pgrastpos[2] = {-1, -1};
1054 uint32_t bandindex[2] = {0};
1055 uint32_t hasbandindex[2] = {0};
1057
1058 uint32_t i;
1059 uint32_t j;
1060 uint32_t k;
1061 uint32_t numBands;
1062 int rtn;
1063 int result;
1064
1065 for (i = 0, j = 0; i < set_count; i++) {
1066
1067 if (PG_ARGISNULL(j)) {
1068 for (k = 0; k < i; k++) {
1070 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1071 }
1072 PG_RETURN_NULL();
1073 }
1074 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
1075 pgrastpos[i] = j;
1076 j++;
1077
1078
1080 if (!rast[i]) {
1081 for (k = 0; k <= i; k++) {
1082 if (k < i)
1084 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1085 }
1086 elog(ERROR, "RASTER_dfullywithin: Could not deserialize the %s raster", i < 1 ? "first" : "second");
1087 PG_RETURN_NULL();
1088 }
1089
1090
1092 if (numBands < 1) {
1093 elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
1094 if (i > 0) i++;
1095 for (k = 0; k < i; k++) {
1097 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1098 }
1099 PG_RETURN_NULL();
1100 }
1101
1102
1103 if (!PG_ARGISNULL(j)) {
1104 bandindex[i] = PG_GETARG_INT32(j);
1105 if (bandindex[i] < 1 || bandindex[i] > numBands) {
1106 elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
1107 if (i > 0) i++;
1108 for (k = 0; k < i; k++) {
1110 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1111 }
1112 PG_RETURN_NULL();
1113 }
1114 hasbandindex[i] = 1;
1115 }
1116 else
1117 hasbandindex[i] = 0;
1120 j++;
1121 }
1122
1123
1124 if (PG_ARGISNULL(4)) {
1125 elog(NOTICE, "Distance cannot be NULL. Returning NULL");
1126 for (k = 0; k < set_count; k++) {
1128 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1129 }
1130 PG_RETURN_NULL();
1131 }
1132
1135 elog(NOTICE, "Distance cannot be less than zero. Returning NULL");
1136 for (k = 0; k < set_count; k++) {
1138 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1139 }
1140 PG_RETURN_NULL();
1141 }
1142
1143
1144 if (
1145 (hasbandindex[0] && !hasbandindex[1]) ||
1146 (!hasbandindex[0] && hasbandindex[1])
1147 ) {
1148 elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
1149 for (k = 0; k < set_count; k++) {
1151 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1152 }
1153 PG_RETURN_NULL();
1154 }
1155
1156
1158 for (k = 0; k < set_count; k++) {
1160 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1161 }
1162 elog(ERROR, "The two rasters provided have different SRIDs");
1163 PG_RETURN_NULL();
1164 }
1165
1167 rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
1168 rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
1170 &result
1171 );
1172 for (k = 0; k < set_count; k++) {
1174 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1175 }
1176
1178 elog(ERROR, "RASTER_dfullywithin: Could not test that the two rasters are fully within the specified distance of each other");
1179 PG_RETURN_NULL();
1180 }
1181
1182 PG_RETURN_BOOL(result);
1183}
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.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
static double distance(double x1, double y1, double x2, double y2)
#define POSTGIS_RT_DEBUGF(level, msg,...)