PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ RASTER_getBandPixelTypeName()

Datum RASTER_getBandPixelTypeName ( PG_FUNCTION_ARGS  )

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

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);
157  rt_raster_destroy(raster);
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 
176  rt_raster_destroy(raster);
177  PG_FREE_IF_COPY(pgraster, 0);
178 
179  PG_RETURN_TEXT_P(result);
180 }
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:2250
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:631
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:715
Here is the call graph for this function:
Here is the caller graph for this function: