PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_raster_same_alignment()

rt_errorstate rt_raster_same_alignment ( rt_raster  rast1,
rt_raster  rast2,
int *  aligned,
char **  reason 
)

Definition at line 45 of file rt_spatial_relationship.c.

49  {
50  double xr;
51  double yr;
52  double xw;
53  double yw;
54  int err = 0;
55 
56  assert(NULL != rast1);
57  assert(NULL != rast2);
58  assert(NULL != aligned);
59 
60  err = 0;
61  /* same srid */
62  if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
63  if (reason != NULL) *reason = "The rasters have different SRIDs";
64  err = 1;
65  }
66  /* scales must match */
67  else if (FLT_NEQ(fabs(rast1->scaleX), fabs(rast2->scaleX))) {
68  if (reason != NULL) *reason = "The rasters have different scales on the X axis";
69  err = 1;
70  }
71  else if (FLT_NEQ(fabs(rast1->scaleY), fabs(rast2->scaleY))) {
72  if (reason != NULL) *reason = "The rasters have different scales on the Y axis";
73  err = 1;
74  }
75  /* skews must match */
76  else if (FLT_NEQ(rast1->skewX, rast2->skewX)) {
77  if (reason != NULL) *reason = "The rasters have different skews on the X axis";
78  err = 1;
79  }
80  else if (FLT_NEQ(rast1->skewY, rast2->skewY)) {
81  if (reason != NULL) *reason = "The rasters have different skews on the Y axis";
82  err = 1;
83  }
84 
85  if (err) {
86  *aligned = 0;
87  return ES_NONE;
88  }
89 
90  /* raster coordinates in context of second raster of first raster's upper-left corner */
92  rast2,
93  rast1->ipX, rast1->ipY,
94  &xr, &yr,
95  NULL
96  ) != ES_NONE) {
97  rterror("rt_raster_same_alignment: Could not get raster coordinates of second raster from first raster's spatial coordinates");
98  *aligned = 0;
99  return ES_ERROR;
100  }
101 
102  /* spatial coordinates of raster coordinates from above */
104  rast2,
105  xr, yr,
106  &xw, &yw,
107  NULL
108  ) != ES_NONE) {
109  rterror("rt_raster_same_alignment: Could not get spatial coordinates of second raster from raster coordinates");
110  *aligned = 0;
111  return ES_ERROR;
112  }
113 
114  RASTER_DEBUGF(4, "rast1(ipX, ipxY) = (%f, %f)", rast1->ipX, rast1->ipY);
115  RASTER_DEBUGF(4, "rast2(xr, yr) = (%f, %f)", xr, yr);
116  RASTER_DEBUGF(4, "rast2(xw, yw) = (%f, %f)", xw, yw);
117 
118  /* spatial coordinates are identical to that of first raster's upper-left corner */
119  if (FLT_EQ(xw, rast1->ipX) && FLT_EQ(yw, rast1->ipY)) {
120  if (reason != NULL) *reason = "The rasters are aligned";
121  *aligned = 1;
122  return ES_NONE;
123  }
124 
125  /* no alignment */
126  if (reason != NULL) *reason = "The rasters (pixel corner coordinates) are not aligned";
127 
128  *aligned = 0;
129  return ES_NONE;
130 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
#define FLT_NEQ(x, y)
Definition: librtcore.h:2233
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_raster.c:755
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
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_raster.c:806
#define FLT_EQ(x, y)
Definition: librtcore.h:2234
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
double scaleX
Definition: librtcore.h:2293
double skewY
Definition: librtcore.h:2298
double ipX
Definition: librtcore.h:2295
double scaleY
Definition: librtcore.h:2294
double ipY
Definition: librtcore.h:2296
double skewX
Definition: librtcore.h:2297

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 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().

Here is the call graph for this function:
Here is the caller graph for this function: