PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_getPixelValue()

Datum RASTER_getPixelValue ( PG_FUNCTION_ARGS  )

Definition at line 73 of file rtpg_pixel.c.

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

74 {
75  rt_pgraster *pgraster = NULL;
76  rt_raster raster = NULL;
77  rt_band band = NULL;
78  double pixvalue = 0;
79  int32_t bandindex = 0;
80  int32_t x = 0;
81  int32_t y = 0;
82  int result = 0;
83  bool exclude_nodata_value = TRUE;
84  int isnodata = 0;
85 
86  /* Index is 1-based */
87  bandindex = PG_GETARG_INT32(1);
88  if ( bandindex < 1 ) {
89  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
90  PG_RETURN_NULL();
91  }
92 
93  x = PG_GETARG_INT32(2);
94 
95  y = PG_GETARG_INT32(3);
96 
97  exclude_nodata_value = PG_GETARG_BOOL(4);
98 
99  POSTGIS_RT_DEBUGF(3, "Pixel coordinates (%d, %d)", x, y);
100 
101  /* Deserialize raster */
102  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
103  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
104 
105  raster = rt_raster_deserialize(pgraster, FALSE);
106  if (!raster) {
107  PG_FREE_IF_COPY(pgraster, 0);
108  elog(ERROR, "RASTER_getPixelValue: Could not deserialize raster");
109  PG_RETURN_NULL();
110  }
111 
112  /* Fetch Nth band using 0-based internal index */
113  band = rt_raster_get_band(raster, bandindex - 1);
114  if (! band) {
115  elog(NOTICE, "Could not find raster band of index %d when getting pixel "
116  "value. Returning NULL", bandindex);
117  rt_raster_destroy(raster);
118  PG_FREE_IF_COPY(pgraster, 0);
119  PG_RETURN_NULL();
120  }
121  /* Fetch pixel using 0-based coordinates */
122  result = rt_band_get_pixel(band, x - 1, y - 1, &pixvalue, &isnodata);
123 
124  /* If the result is -1 or the value is nodata and we take nodata into account
125  * then return nodata = NULL */
126  if (result != ES_NONE || (exclude_nodata_value && isnodata)) {
127  rt_raster_destroy(raster);
128  PG_FREE_IF_COPY(pgraster, 0);
129  PG_RETURN_NULL();
130  }
131 
132  rt_raster_destroy(raster);
133  PG_FREE_IF_COPY(pgraster, 0);
134 
135  PG_RETURN_FLOAT8(pixvalue);
136 }
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
band
Definition: ovdump.py:57
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1088
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2201
#define TRUE
Definition: dbfopen.c:169
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
Here is the call graph for this function: