PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_getPixelValue ( PG_FUNCTION_ARGS  )

Definition at line 2724 of file rt_pg.c.

References ovdump::band, ES_NONE, FALSE, POSTGIS_RT_DEBUGF, rtrowdump::raster, result, rt_band_get_pixel(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), TRUE, pixval::x, and pixval::y.

2725 {
2726  rt_pgraster *pgraster = NULL;
2727  rt_raster raster = NULL;
2728  rt_band band = NULL;
2729  double pixvalue = 0;
2730  int32_t bandindex = 0;
2731  int32_t x = 0;
2732  int32_t y = 0;
2733  int result = 0;
2734  bool exclude_nodata_value = TRUE;
2735  int isnodata = 0;
2736 
2737  /* Index is 1-based */
2738  bandindex = PG_GETARG_INT32(1);
2739  if ( bandindex < 1 ) {
2740  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
2741  PG_RETURN_NULL();
2742  }
2743 
2744  x = PG_GETARG_INT32(2);
2745 
2746  y = PG_GETARG_INT32(3);
2747 
2748  exclude_nodata_value = PG_GETARG_BOOL(4);
2749 
2750  POSTGIS_RT_DEBUGF(3, "Pixel coordinates (%d, %d)", x, y);
2751 
2752  /* Deserialize raster */
2753  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
2754  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2755 
2756  raster = rt_raster_deserialize(pgraster, FALSE);
2757  if (!raster) {
2758  PG_FREE_IF_COPY(pgraster, 0);
2759  elog(ERROR, "RASTER_getPixelValue: Could not deserialize raster");
2760  PG_RETURN_NULL();
2761  }
2762 
2763  /* Fetch Nth band using 0-based internal index */
2764  band = rt_raster_get_band(raster, bandindex - 1);
2765  if (! band) {
2766  elog(NOTICE, "Could not find raster band of index %d when getting pixel "
2767  "value. Returning NULL", bandindex);
2768  rt_raster_destroy(raster);
2769  PG_FREE_IF_COPY(pgraster, 0);
2770  PG_RETURN_NULL();
2771  }
2772  /* Fetch pixel using 0-based coordinates */
2773  result = rt_band_get_pixel(band, x - 1, y - 1, &pixvalue, &isnodata);
2774 
2775  /* If the result is -1 or the value is nodata and we take nodata into account
2776  * then return nodata = NULL */
2777  if (result != ES_NONE || (exclude_nodata_value && isnodata)) {
2778  rt_raster_destroy(raster);
2779  PG_FREE_IF_COPY(pgraster, 0);
2780  PG_RETURN_NULL();
2781  }
2782 
2783  rt_raster_destroy(raster);
2784  PG_FREE_IF_COPY(pgraster, 0);
2785 
2786  PG_RETURN_FLOAT8(pixvalue);
2787 }
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
tuple band
Definition: ovdump.py:57
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
char ** result
Definition: liblwgeom.h:218
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
tuple x
Definition: pixval.py:53
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
#define TRUE
Definition: dbfopen.c:170
tuple y
Definition: pixval.py:54

Here is the call graph for this function: