PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_getBandPixelTypeName()

Datum RASTER_getBandPixelTypeName ( PG_FUNCTION_ARGS  )

Definition at line 115 of file rtpg_band_properties.c.

References ovdump::band, FALSE, PG_FUNCTION_INFO_V1(), rtrowdump::raster, RASTER_getBandNoDataValue(), rt_band_get_pixtype(), rt_pixtype_name(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), and rt_raster_serialized_t::size.

Referenced by RASTER_getBandPixelType().

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