PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_getBandPixelTypeName()

Datum RASTER_getBandPixelTypeName ( PG_FUNCTION_ARGS  )

Definition at line 122 of file rtpg_band_properties.c.

123 {
124  rt_pgraster *pgraster = NULL;
125  rt_raster raster = NULL;
126  rt_band band = NULL;
127  rt_pixtype pixtype;
128  int32_t bandindex;
129  const size_t name_size = 8; /* size of type name */
130  size_t size = 0;
131  char *ptr = NULL;
132  text *result = NULL;
133 
134  /* Deserialize raster */
135  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
136  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
137 
138  /* Index is 1-based */
139  bandindex = PG_GETARG_INT32(1);
140  if ( bandindex < 1 ) {
141  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
142  PG_FREE_IF_COPY(pgraster, 0);
143  PG_RETURN_NULL();
144  }
145 
146  raster = rt_raster_deserialize(pgraster, FALSE);
147  if ( ! raster ) {
148  PG_FREE_IF_COPY(pgraster, 0);
149  elog(ERROR, "RASTER_getBandPixelTypeName: Could not deserialize raster");
150  PG_RETURN_NULL();
151  }
152 
153  /* Fetch requested band and its pixel type */
154  band = rt_raster_get_band(raster, bandindex - 1);
155  if ( ! band ) {
156  elog(NOTICE, "Could not find raster band of index %d when getting pixel type name. Returning NULL", bandindex);
158  PG_FREE_IF_COPY(pgraster, 0);
159  PG_RETURN_NULL();
160  }
161 
162  pixtype = rt_band_get_pixtype(band);
163 
164  result = palloc(VARHDRSZ + name_size);
165  /* We don't need to check for NULL pointer, because if out of memory, palloc
166  * exit via elog(ERROR). It never returns NULL.
167  */
168 
169  memset(VARDATA(result), 0, name_size);
170  ptr = (char *)result + VARHDRSZ;
171  strcpy(ptr, rt_pixtype_name(pixtype));
172 
173  size = VARHDRSZ + strlen(ptr);
174  SET_VARSIZE(result, size);
175 
177  PG_FREE_IF_COPY(pgraster, 0);
178 
179  PG_RETURN_TEXT_P(result);
180 }
#define FALSE
Definition: dbfopen.c:168
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_pixtype
Definition: librtcore.h:185
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:381
band
Definition: ovdump.py:57
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:2250

References ovdump::band, FALSE, rtrowdump::raster, 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: