PostGIS  3.0.6dev-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.

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

809  {
810  double _igt[6] = {0};
811  double rnd = 0;
812 
813  assert(NULL != raster);
814  assert(NULL != xr && NULL != yr);
815 
816  if (igt != NULL)
817  memcpy(_igt, igt, sizeof(double) * 6);
818 
819  /* matrix is not set */
820  if (
821  FLT_EQ(_igt[0], 0.) &&
822  FLT_EQ(_igt[1], 0.) &&
823  FLT_EQ(_igt[2], 0.) &&
824  FLT_EQ(_igt[3], 0.) &&
825  FLT_EQ(_igt[4], 0.) &&
826  FLT_EQ(_igt[5], 0.)
827  ) {
829  rterror("rt_raster_geopoint_to_cell: Could not get inverse geotransform matrix");
830  return ES_ERROR;
831  }
832  }
833 
834  GDALApplyGeoTransform(_igt, xw, yw, xr, yr);
835  RASTER_DEBUGF(4, "GDALApplyGeoTransform (g -> c) for (%f, %f) = (%f, %f)",
836  xw, yw, *xr, *yr);
837 
838  rnd = ROUND(*xr, 0);
839  if (FLT_EQ(rnd, *xr))
840  *xr = rnd;
841  else
842  *xr = floor(*xr);
843 
844  rnd = ROUND(*yr, 0);
845  if (FLT_EQ(rnd, *yr))
846  *yr = rnd;
847  else
848  *yr = floor(*yr);
849 
850  RASTER_DEBUGF(4, "Corrected GDALApplyGeoTransform (g -> c) for (%f, %f) = (%f, %f)",
851  xw, yw, *xr, *yr);
852 
853  return ES_NONE;
854 }
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:2242
#define FLT_EQ(x, y)
Definition: librtcore.h:2235
@ 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: