PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_raster_geopoint_to_cell()

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.

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

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 806 of file rt_raster.c.

811  {
812  double _igt[6] = {0};
813  double rnd = 0;
814 
815  assert(NULL != raster);
816  assert(NULL != xr && NULL != yr);
817 
818  if (igt != NULL)
819  memcpy(_igt, igt, sizeof(double) * 6);
820 
821  /* matrix is not set */
822  if (
823  FLT_EQ(_igt[0], 0.) &&
824  FLT_EQ(_igt[1], 0.) &&
825  FLT_EQ(_igt[2], 0.) &&
826  FLT_EQ(_igt[3], 0.) &&
827  FLT_EQ(_igt[4], 0.) &&
828  FLT_EQ(_igt[5], 0.)
829  ) {
831  rterror("rt_raster_geopoint_to_cell: Could not get inverse geotransform matrix");
832  return ES_ERROR;
833  }
834  }
835 
836  GDALApplyGeoTransform(_igt, xw, yw, xr, yr);
837  RASTER_DEBUGF(4, "GDALApplyGeoTransform (g -> c) for (%f, %f) = (%f, %f)",
838  xw, yw, *xr, *yr);
839 
840  rnd = ROUND(*xr, 0);
841  if (FLT_EQ(rnd, *xr))
842  *xr = rnd;
843  else
844  *xr = floor(*xr);
845 
846  rnd = ROUND(*yr, 0);
847  if (FLT_EQ(rnd, *yr))
848  *yr = rnd;
849  else
850  *yr = floor(*yr);
851 
852  RASTER_DEBUGF(4, "Corrected GDALApplyGeoTransform (g -> c) for (%f, %f) = (%f, %f)",
853  xw, yw, *xr, *yr);
854 
855  return ES_NONE;
856 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
#define ROUND(x, y)
Definition: librtcore.h:2241
#define FLT_EQ(x, y)
Definition: librtcore.h:2234
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
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_raster.c:676

References ES_ERROR, ES_NONE, FLT_EQ, rtrowdump::raster, 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().

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