PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_notSameAlignmentReason()

Datum RASTER_notSameAlignmentReason ( PG_FUNCTION_ARGS  )

Definition at line 1255 of file rtpg_spatial_relationship.c.

References ES_NONE, rtpixdump::rast, rt_raster_deserialize(), rt_raster_destroy(), rt_raster_same_alignment(), and TRUE.

Referenced by RASTER_sameAlignment().

1256 {
1257  const int set_count = 2;
1258  rt_pgraster *pgrast[2];
1259  int pgrastpos[2] = {-1, -1};
1260  rt_raster rast[2] = {NULL};
1261 
1262  uint32_t i;
1263  uint32_t j;
1264  uint32_t k;
1265  int rtn;
1266  int aligned = 0;
1267  char *reason = NULL;
1268  text *result = NULL;
1269 
1270  for (i = 0, j = 0; i < set_count; i++) {
1271  /* pgrast is null, return null */
1272  if (PG_ARGISNULL(j)) {
1273  for (k = 0; k < i; k++) {
1274  rt_raster_destroy(rast[k]);
1275  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1276  }
1277  PG_RETURN_NULL();
1278  }
1279  pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(j), 0, sizeof(struct rt_raster_serialized_t));
1280  pgrastpos[i] = j;
1281  j++;
1282 
1283  /* raster */
1284  rast[i] = rt_raster_deserialize(pgrast[i], TRUE);
1285  if (!rast[i]) {
1286  for (k = 0; k <= i; k++) {
1287  if (k < i)
1288  rt_raster_destroy(rast[k]);
1289  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1290  }
1291  elog(ERROR, "RASTER_notSameAlignmentReason: Could not deserialize the %s raster", i < 1 ? "first" : "second");
1292  PG_RETURN_NULL();
1293  }
1294  }
1295 
1297  rast[0],
1298  rast[1],
1299  &aligned,
1300  &reason
1301  );
1302  for (k = 0; k < set_count; k++) {
1303  rt_raster_destroy(rast[k]);
1304  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
1305  }
1306 
1307  if (rtn != ES_NONE) {
1308  elog(ERROR, "RASTER_notSameAlignmentReason: Could not test for alignment on the two rasters");
1309  PG_RETURN_NULL();
1310  }
1311 
1312  result = cstring2text(reason);
1313  PG_RETURN_TEXT_P(result);
1314 }
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
unsigned int uint32_t
Definition: uthash.h:78
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
Struct definitions.
Definition: librtcore.h:2201
#define TRUE
Definition: dbfopen.c:169
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
Here is the call graph for this function:
Here is the caller graph for this function: