198{
199 const uint32_t set_count = 2;
201 int pgrastpos[2] = {-1, -1};
203 uint32_t bandindex[2] = {0};
204 uint32_t hasbandindex[2] = {0};
205
206 uint32_t i;
207 uint32_t j;
208 uint32_t k;
209 uint32_t numBands;
210 int rtn;
212
213 for (i = 0, j = 0; i < set_count; i++) {
214
215 if (PG_ARGISNULL(j)) {
216 for (k = 0; k < i; k++) {
218 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
219 }
220 PG_RETURN_NULL();
221 }
222 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
223 pgrastpos[i] = j;
224 j++;
225
226
228 if (!rast[i]) {
229 for (k = 0; k <= i; k++) {
230 if (k < i)
232 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
233 }
234 elog(ERROR, "RASTER_overlaps: Could not deserialize the %s raster", i < 1 ? "first" : "second");
235 PG_RETURN_NULL();
236 }
237
238
240 if (numBands < 1) {
241 elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
242 if (i > 0) i++;
243 for (k = 0; k < i; k++) {
245 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
246 }
247 PG_RETURN_NULL();
248 }
249
250
251 if (!PG_ARGISNULL(j)) {
252 bandindex[i] = PG_GETARG_INT32(j);
253 if (bandindex[i] < 1 || bandindex[i] > numBands) {
254 elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
255 if (i > 0) i++;
256 for (k = 0; k < i; k++) {
258 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
259 }
260 PG_RETURN_NULL();
261 }
262 hasbandindex[i] = 1;
263 }
264 else
265 hasbandindex[i] = 0;
268 j++;
269 }
270
271
272 if (
273 (hasbandindex[0] && !hasbandindex[1]) ||
274 (!hasbandindex[0] && hasbandindex[1])
275 ) {
276 elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
277 for (k = 0; k < set_count; k++) {
279 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
280 }
281 PG_RETURN_NULL();
282 }
283
284
286 for (k = 0; k < set_count; k++) {
288 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
289 }
290 elog(ERROR, "The two rasters provided have different SRIDs");
291 PG_RETURN_NULL();
292 }
293
295 rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
296 rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
298 );
299 for (k = 0; k < set_count; k++) {
301 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
302 }
303
305 elog(ERROR, "RASTER_overlaps: Could not test for overlap on the two rasters");
306 PG_RETURN_NULL();
307 }
308
310}
char result[OUT_DOUBLE_BUFFER_SIZE]
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.
rt_errorstate rt_raster_overlaps(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *overlaps)
Return ES_ERROR if error occurred in function.
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.
#define POSTGIS_RT_DEBUGF(level, msg,...)