1053{
1054 const uint32_t set_count = 2;
1056 int pgrastpos[2] = {-1, -1};
1058 uint32_t bandindex[2] = {0};
1059 uint32_t hasbandindex[2] = {0};
1061
1062 uint32_t i;
1063 uint32_t j;
1064 uint32_t k;
1065 uint32_t numBands;
1066 int rtn;
1068
1069 for (i = 0, j = 0; i < set_count; i++) {
1070
1071 if (PG_ARGISNULL(j)) {
1072 for (k = 0; k < i; k++) {
1074 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1075 }
1076 PG_RETURN_NULL();
1077 }
1078 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
1079 pgrastpos[i] = j;
1080 j++;
1081
1082
1084 if (!rast[i]) {
1085 for (k = 0; k <= i; k++) {
1086 if (k < i)
1088 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1089 }
1090 elog(ERROR, "RASTER_dfullywithin: Could not deserialize the %s raster", i < 1 ? "first" : "second");
1091 PG_RETURN_NULL();
1092 }
1093
1094
1096 if (numBands < 1) {
1097 elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
1098 if (i > 0) i++;
1099 for (k = 0; k < i; k++) {
1101 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1102 }
1103 PG_RETURN_NULL();
1104 }
1105
1106
1107 if (!PG_ARGISNULL(j)) {
1108 bandindex[i] = PG_GETARG_INT32(j);
1109 if (bandindex[i] < 1 || bandindex[i] > numBands) {
1110 elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
1111 if (i > 0) i++;
1112 for (k = 0; k < i; k++) {
1114 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1115 }
1116 PG_RETURN_NULL();
1117 }
1118 hasbandindex[i] = 1;
1119 }
1120 else
1121 hasbandindex[i] = 0;
1124 j++;
1125 }
1126
1127
1128 if (PG_ARGISNULL(4)) {
1129 elog(NOTICE, "Distance cannot be NULL. Returning NULL");
1130 for (k = 0; k < set_count; k++) {
1132 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1133 }
1134 PG_RETURN_NULL();
1135 }
1136
1139 elog(NOTICE, "Distance cannot be less than zero. Returning NULL");
1140 for (k = 0; k < set_count; k++) {
1142 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1143 }
1144 PG_RETURN_NULL();
1145 }
1146
1147
1148 if (
1149 (hasbandindex[0] && !hasbandindex[1]) ||
1150 (!hasbandindex[0] && hasbandindex[1])
1151 ) {
1152 elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
1153 for (k = 0; k < set_count; k++) {
1155 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1156 }
1157 PG_RETURN_NULL();
1158 }
1159
1160
1162 for (k = 0; k < set_count; k++) {
1164 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1165 }
1166 elog(ERROR, "The two rasters provided have different SRIDs");
1167 PG_RETURN_NULL();
1168 }
1169
1171 rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
1172 rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
1175 );
1176 for (k = 0; k < set_count; k++) {
1178 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1179 }
1180
1182 elog(ERROR, "RASTER_dfullywithin: Could not test that the two rasters are fully within the specified distance of each other");
1183 PG_RETURN_NULL();
1184 }
1185
1187}
char result[OUT_DOUBLE_BUFFER_SIZE]
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,...)