PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_raster_same_alignment ( rt_raster  rast1,
rt_raster  rast2,
int *  aligned,
char **  reason 
)

Definition at line 12774 of file rt_api.c.

References ES_ERROR, ES_NONE, FLT_EQ, FLT_NEQ, rt_raster_t::ipX, rt_raster_t::ipY, RASTER_DEBUGF, rt_raster_cell_to_geopoint(), rt_raster_geopoint_to_cell(), rt_raster_get_srid(), rterror(), rt_raster_t::scaleX, rt_raster_t::scaleY, rt_raster_t::skewX, and rt_raster_t::skewY.

Referenced by diff_rastinfo(), RASTER_addBandOutDB(), RASTER_mapAlgebra2(), RASTER_notSameAlignmentReason(), RASTER_sameAlignment(), rt_band_load_offline_data(), rt_raster_from_two_rasters(), rt_raster_iterator(), and test_raster_same_alignment().

12778  {
12779  double xr;
12780  double yr;
12781  double xw;
12782  double yw;
12783  int err = 0;
12784 
12785  assert(NULL != rast1);
12786  assert(NULL != rast2);
12787  assert(NULL != aligned);
12788 
12789  err = 0;
12790  /* same srid */
12791  if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
12792  if (reason != NULL) *reason = "The rasters have different SRIDs";
12793  err = 1;
12794  }
12795  /* scales must match */
12796  else if (FLT_NEQ(fabs(rast1->scaleX), fabs(rast2->scaleX))) {
12797  if (reason != NULL) *reason = "The rasters have different scales on the X axis";
12798  err = 1;
12799  }
12800  else if (FLT_NEQ(fabs(rast1->scaleY), fabs(rast2->scaleY))) {
12801  if (reason != NULL) *reason = "The rasters have different scales on the Y axis";
12802  err = 1;
12803  }
12804  /* skews must match */
12805  else if (FLT_NEQ(rast1->skewX, rast2->skewX)) {
12806  if (reason != NULL) *reason = "The rasters have different skews on the X axis";
12807  err = 1;
12808  }
12809  else if (FLT_NEQ(rast1->skewY, rast2->skewY)) {
12810  if (reason != NULL) *reason = "The rasters have different skews on the Y axis";
12811  err = 1;
12812  }
12813 
12814  if (err) {
12815  *aligned = 0;
12816  return ES_NONE;
12817  }
12818 
12819  /* raster coordinates in context of second raster of first raster's upper-left corner */
12821  rast2,
12822  rast1->ipX, rast1->ipY,
12823  &xr, &yr,
12824  NULL
12825  ) != ES_NONE) {
12826  rterror("rt_raster_same_alignment: Could not get raster coordinates of second raster from first raster's spatial coordinates");
12827  *aligned = 0;
12828  return ES_ERROR;
12829  }
12830 
12831  /* spatial coordinates of raster coordinates from above */
12833  rast2,
12834  xr, yr,
12835  &xw, &yw,
12836  NULL
12837  ) != ES_NONE) {
12838  rterror("rt_raster_same_alignment: Could not get spatial coordinates of second raster from raster coordinates");
12839  *aligned = 0;
12840  return ES_ERROR;
12841  }
12842 
12843  RASTER_DEBUGF(4, "rast1(ipX, ipxY) = (%f, %f)", rast1->ipX, rast1->ipY);
12844  RASTER_DEBUGF(4, "rast2(xr, yr) = (%f, %f)", xr, yr);
12845  RASTER_DEBUGF(4, "rast2(xw, yw) = (%f, %f)", xw, yw);
12846 
12847  /* spatial coordinates are identical to that of first raster's upper-left corner */
12848  if (FLT_EQ(xw, rast1->ipX) && FLT_EQ(yw, rast1->ipY)) {
12849  if (reason != NULL) *reason = "The rasters are aligned";
12850  *aligned = 1;
12851  return ES_NONE;
12852  }
12853 
12854  /* no alignment */
12855  if (reason != NULL) *reason = "The rasters (pixel corner coordinates) are not aligned";
12856 
12857  *aligned = 0;
12858  return ES_NONE;
12859 }
#define FLT_NEQ(x, y)
Definition: rt_api.h:2158
double skewY
Definition: rt_api.h:2223
double ipY
Definition: rt_api.h:2221
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
Definition: rt_api.c:6054
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
double skewX
Definition: rt_api.h:2222
#define FLT_EQ(x, y)
Definition: rt_api.h:2159
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw,yw map point to a xr,yr raster point.
Definition: rt_api.c:6105
double ipX
Definition: rt_api.h:2220
double scaleX
Definition: rt_api.h:2218
double scaleY
Definition: rt_api.h:2219

Here is the call graph for this function:

Here is the caller graph for this function: