PostGIS  2.1.10dev-r@@SVN_REVISION@@
static rt_errorstate _rti_raster_get_band_perimeter ( rt_band  band,
uint16_t *  trim 
)
static

Definition at line 14540 of file rt_api.c.

References ES_ERROR, ES_NONE, rt_band_t::raster, RASTER_DEBUGF, rt_band_get_height(), rt_band_get_pixel(), rt_band_get_width(), rterror(), genraster::value, pixval::x, and pixval::y.

Referenced by rt_raster_get_perimeter().

14540  {
14541  uint16_t width = 0;
14542  uint16_t height = 0;
14543  int x = 0;
14544  int y = 0;
14545  int offset = 0;
14546  int done[4] = {0};
14547  double value = 0;
14548  int nodata = 0;
14549 
14550  assert(band != NULL);
14551  assert(band->raster != NULL);
14552  assert(trim != NULL);
14553 
14554  memset(trim, 0, sizeof(uint16_t) * 4);
14555 
14556  width = rt_band_get_width(band);
14557  height = rt_band_get_height(band);
14558 
14559  /* top */
14560  for (y = 0; y < height; y++) {
14561  for (offset = 0; offset < 3; offset++) {
14562  /* every third pixel */
14563  for (x = offset; x < width; x += 3) {
14564  if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
14565  rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
14566  return ES_ERROR;
14567  }
14568 
14569  RASTER_DEBUGF(4, "top (x, y, value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
14570  if (!nodata) {
14571  trim[0] = y;
14572  done[0] = 1;
14573  break;
14574  }
14575  }
14576 
14577  if (done[0])
14578  break;
14579  }
14580 
14581  if (done[0])
14582  break;
14583  }
14584 
14585  /* right */
14586  for (x = width - 1; x >= 0; x--) {
14587  for (offset = 0; offset < 3; offset++) {
14588  /* every third pixel */
14589  for (y = offset; y < height; y += 3) {
14590  if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
14591  rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
14592  return ES_ERROR;
14593  }
14594 
14595  RASTER_DEBUGF(4, "right (x, y, value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
14596  if (!nodata) {
14597  trim[1] = width - (x + 1);
14598  done[1] = 1;
14599  break;
14600  }
14601  }
14602 
14603  if (done[1])
14604  break;
14605  }
14606 
14607  if (done[1])
14608  break;
14609  }
14610 
14611  /* bottom */
14612  for (y = height - 1; y >= 0; y--) {
14613  for (offset = 0; offset < 3; offset++) {
14614  /* every third pixel */
14615  for (x = offset; x < width; x += 3) {
14616  if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
14617  rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
14618  return ES_ERROR;
14619  }
14620 
14621  RASTER_DEBUGF(4, "bottom (x, y, value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
14622  if (!nodata) {
14623  trim[2] = height - (y + 1);
14624  done[2] = 1;
14625  break;
14626  }
14627  }
14628 
14629  if (done[2])
14630  break;
14631  }
14632 
14633  if (done[2])
14634  break;
14635  }
14636 
14637  /* left */
14638  for (x = 0; x < width; x++) {
14639  for (offset = 0; offset < 3; offset++) {
14640  /* every third pixel */
14641  for (y = offset; y < height; y += 3) {
14642  if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
14643  rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
14644  return ES_ERROR;
14645  }
14646 
14647  RASTER_DEBUGF(4, "left (x, , value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
14648  if (!nodata) {
14649  trim[3] = x;
14650  done[3] = 1;
14651  break;
14652  }
14653  }
14654 
14655  if (done[3])
14656  break;
14657  }
14658 
14659  if (done[3])
14660  break;
14661  }
14662 
14663  RASTER_DEBUGF(4, "trim = (%d, %d, %d, %d)",
14664  trim[0], trim[1], trim[2], trim[3]);
14665 
14666  return ES_NONE;
14667 }
rt_raster raster
Definition: rt_api.h:2249
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_api.c:2549
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_api.c:1909
tuple x
Definition: pixval.py:53
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_api.c:1918
static char * trim(const char *input)
Definition: raster2pgsql.c:263
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: