PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ RASTER_getBandPixelTypeName()

Datum RASTER_getBandPixelTypeName ( PG_FUNCTION_ARGS  )

Definition at line 117 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().

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