908 const int set_count = 2;
910 int pgrastpos[2] = {-1, -1};
923 for (i = 0, j = 0; i < set_count; i++) {
925 if (PG_ARGISNULL(j)) {
926 for (k = 0; k < i; k++) {
928 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
932 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
939 for (k = 0; k <= i; k++) {
942 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
944 elog(ERROR,
"RASTER_dwithin: Could not deserialize the %s raster", i < 1 ?
"first" :
"second");
951 elog(NOTICE,
"The %s raster provided has no bands", i < 1 ?
"first" :
"second");
953 for (k = 0; k < i; k++) {
955 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
961 if (!PG_ARGISNULL(j)) {
962 bandindex[i] = PG_GETARG_INT32(j);
963 if (bandindex[i] < 1 || bandindex[i] > numBands) {
964 elog(NOTICE,
"Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ?
"first" :
"second");
966 for (k = 0; k < i; k++) {
968 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
982 if (PG_ARGISNULL(4)) {
983 elog(NOTICE,
"Distance cannot be NULL. Returning NULL");
984 for (k = 0; k < set_count; k++) {
986 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
991 distance = PG_GETARG_FLOAT8(4);
993 elog(NOTICE,
"Distance cannot be less than zero. Returning NULL");
994 for (k = 0; k < set_count; k++) {
996 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1003 (hasbandindex[0] && !hasbandindex[1]) ||
1004 (!hasbandindex[0] && hasbandindex[1])
1006 elog(NOTICE,
"Missing band index. Band indices must be provided for both rasters if any one is provided");
1007 for (k = 0; k < set_count; k++) {
1009 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1016 for (k = 0; k < set_count; k++) {
1018 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1020 elog(ERROR,
"The two rasters provided have different SRIDs");
1025 rast[0], (hasbandindex[0] ? bandindex[0] - 1 : -1),
1026 rast[1], (hasbandindex[1] ? bandindex[1] - 1 : -1),
1030 for (k = 0; k < set_count; k++) {
1032 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1036 elog(ERROR,
"RASTER_dwithin: Could not test that the two rasters are within the specified distance of each other");
1040 PG_RETURN_BOOL(result);
int rt_raster_get_num_bands(rt_raster raster)
#define POSTGIS_RT_DEBUGF(level, msg,...)
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.
Datum distance(PG_FUNCTION_ARGS)
rt_errorstate rt_raster_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dwithin)
Return ES_ERROR if error occurred in function.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.