PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ rt_raster_get_envelope()

rt_errorstate rt_raster_get_envelope ( rt_raster  raster,
rt_envelope env 
)

Get raster's envelope.

The envelope is the minimum bounding rectangle of the raster

Parameters
raster: the raster to get envelope of
env: pointer to rt_envelope
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 873 of file rt_raster.c.

References ES_ERROR, ES_NONE, rt_raster_t::height, rt_envelope::MaxX, rt_envelope::MaxY, rt_envelope::MinX, rt_envelope::MinY, rt_raster_cell_to_geopoint(), rt_raster_get_geotransform_matrix(), rterror(), and rt_raster_t::width.

Referenced by rt_raster_get_envelope_geom(), and test_raster_envelope().

876  {
877  int i;
878  int rtn;
879  int set = 0;
880  double _r[2] = {0.};
881  double _w[2] = {0.};
882  double _gt[6] = {0.};
883 
884  assert(raster != NULL);
885  assert(env != NULL);
886 
888 
889  for (i = 0; i < 4; i++) {
890  switch (i) {
891  case 0:
892  _r[0] = 0;
893  _r[1] = 0;
894  break;
895  case 1:
896  _r[0] = 0;
897  _r[1] = raster->height;
898  break;
899  case 2:
900  _r[0] = raster->width;
901  _r[1] = raster->height;
902  break;
903  case 3:
904  _r[0] = raster->width;
905  _r[1] = 0;
906  break;
907  }
908 
910  raster,
911  _r[0], _r[1],
912  &(_w[0]), &(_w[1]),
913  _gt
914  );
915  if (rtn != ES_NONE) {
916  rterror("rt_raster_get_envelope: Could not compute spatial coordinates for raster pixel");
917  return ES_ERROR;
918  }
919 
920  if (!set) {
921  set = 1;
922  env->MinX = _w[0];
923  env->MaxX = _w[0];
924  env->MinY = _w[1];
925  env->MaxY = _w[1];
926  }
927  else {
928  if (_w[0] < env->MinX)
929  env->MinX = _w[0];
930  else if (_w[0] > env->MaxX)
931  env->MaxX = _w[0];
932 
933  if (_w[1] < env->MinY)
934  env->MinY = _w[1];
935  else if (_w[1] > env->MaxY)
936  env->MaxY = _w[1];
937  }
938  }
939 
940  return ES_NONE;
941 }
double MinY
Definition: librtcore.h:167
double MaxY
Definition: librtcore.h:168
double MaxX
Definition: librtcore.h:166
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
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
uint16_t height
Definition: librtcore.h:2302
uint16_t width
Definition: librtcore.h:2301
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:706
double MinX
Definition: librtcore.h:165
Here is the call graph for this function:
Here is the caller graph for this function: