PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ RASTER_getBandPixelTypeName()

Datum RASTER_getBandPixelTypeName ( PG_FUNCTION_ARGS  )

Definition at line 120 of file rtpg_band_properties.c.

121 {
122  rt_pgraster *pgraster = NULL;
123  rt_raster raster = NULL;
124  rt_band band = NULL;
125  rt_pixtype pixtype;
126  int32_t bandindex;
127  const size_t name_size = 8; /* size of type name */
128  size_t size = 0;
129  char *ptr = NULL;
130  text *result = NULL;
131 
132  /* Deserialize raster */
133  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
134  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
135 
136  /* Index is 1-based */
137  bandindex = PG_GETARG_INT32(1);
138  if ( bandindex < 1 ) {
139  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
140  PG_FREE_IF_COPY(pgraster, 0);
141  PG_RETURN_NULL();
142  }
143 
144  raster = rt_raster_deserialize(pgraster, FALSE);
145  if ( ! raster ) {
146  PG_FREE_IF_COPY(pgraster, 0);
147  elog(ERROR, "RASTER_getBandPixelTypeName: Could not deserialize raster");
148  PG_RETURN_NULL();
149  }
150 
151  /* Fetch requested band and its pixel type */
152  band = rt_raster_get_band(raster, bandindex - 1);
153  if ( ! band ) {
154  elog(NOTICE, "Could not find raster band of index %d when getting pixel type name. Returning NULL", bandindex);
156  PG_FREE_IF_COPY(pgraster, 0);
157  PG_RETURN_NULL();
158  }
159 
160  pixtype = rt_band_get_pixtype(band);
161 
162  result = palloc(VARHDRSZ + name_size);
163  /* We don't need to check for NULL pointer, because if out of memory, palloc
164  * exit via elog(ERROR). It never returns NULL.
165  */
166 
167  memset(VARDATA(result), 0, name_size);
168  ptr = (char *)result + VARHDRSZ;
169  strcpy(ptr, rt_pixtype_name(pixtype));
170 
171  size = VARHDRSZ + strlen(ptr);
172  SET_VARSIZE(result, size);
173 
175  PG_FREE_IF_COPY(pgraster, 0);
176 
177  PG_RETURN_TEXT_P(result);
178 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define FALSE
Definition: dbfopen.c:72
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:86
rt_pixtype
Definition: librtcore.h:187
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:631
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:385
band
Definition: ovdump.py:58
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
Struct definitions.
Definition: librtcore.h:2396

References ovdump::band, FALSE, rtrowdump::raster, result, rt_band_get_pixtype(), rt_pixtype_name(), rt_raster_deserialize(), rt_raster_destroy(), and rt_raster_get_band().

Here is the call graph for this function: