PostGIS  2.1.10dev-r@@SVN_REVISION@@
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.

Convert an xw, yw map point to a xr, yr raster point.

Parameters
raster: the raster to get info from
xw: X ordinate of the geographical point
yw: Y ordinate of the geographical point
xr: output parameter, the pixel's column
yr: output parameter, the pixel's row
igt: input/output parameter, inverse geotransform matrix
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 6105 of file rt_api.c.

References ES_ERROR, ES_NONE, FLT_EQ, RASTER_DEBUGF, ROUND, rt_raster_get_inverse_geotransform_matrix(), and rterror().

Referenced by RASTER_nearestValue(), RASTER_setPixelValuesGeomval(), RASTER_worldToRasterCoord(), rt_band_load_offline_data(), rt_raster_compute_skewed_raster(), rt_raster_from_two_rasters(), rt_raster_gdal_rasterize(), rt_raster_gdal_warp(), rt_raster_intersects(), rt_raster_intersects_algorithm(), rt_raster_same_alignment(), and test_raster_geopoint_to_cell().

6110  {
6111  double _igt[6] = {0};
6112  double rnd = 0;
6113 
6114  assert(NULL != raster);
6115  assert(NULL != xr && NULL != yr);
6116 
6117  if (igt != NULL)
6118  memcpy(_igt, igt, sizeof(double) * 6);
6119 
6120  /* matrix is not set */
6121  if (
6122  FLT_EQ(_igt[0], 0.) &&
6123  FLT_EQ(_igt[1], 0.) &&
6124  FLT_EQ(_igt[2], 0.) &&
6125  FLT_EQ(_igt[3], 0.) &&
6126  FLT_EQ(_igt[4], 0.) &&
6127  FLT_EQ(_igt[5], 0.)
6128  ) {
6129  if (rt_raster_get_inverse_geotransform_matrix(raster, NULL, _igt) != ES_NONE) {
6130  rterror("rt_raster_geopoint_to_cell: Could not get inverse geotransform matrix");
6131  return ES_ERROR;
6132  }
6133  }
6134 
6135  GDALApplyGeoTransform(_igt, xw, yw, xr, yr);
6136  RASTER_DEBUGF(4, "GDALApplyGeoTransform (g -> c) for (%f, %f) = (%f, %f)",
6137  xw, yw, *xr, *yr);
6138 
6139  rnd = ROUND(*xr, 0);
6140  if (FLT_EQ(rnd, *xr))
6141  *xr = rnd;
6142  else
6143  *xr = floor(*xr);
6144 
6145  rnd = ROUND(*yr, 0);
6146  if (FLT_EQ(rnd, *yr))
6147  *yr = rnd;
6148  else
6149  *yr = floor(*yr);
6150 
6151  RASTER_DEBUGF(4, "Corrected GDALApplyGeoTransform (g -> c) for (%f, %f) = (%f, %f)",
6152  xw, yw, *xr, *yr);
6153 
6154  return ES_NONE;
6155 }
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
rt_errorstate rt_raster_get_inverse_geotransform_matrix(rt_raster raster, double *gt, double *igt)
Get 6-element array of raster inverse geotransform matrix.
Definition: rt_api.c:5975
#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
#define ROUND(x, y)
Definition: rt_api.h:2166

Here is the call graph for this function:

Here is the caller graph for this function: