PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_getBandPixelTypeName ( PG_FUNCTION_ARGS  )

Definition at line 2357 of file rt_pg.c.

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

2358 {
2359  rt_pgraster *pgraster = NULL;
2360  rt_raster raster = NULL;
2361  rt_band band = NULL;
2362  rt_pixtype pixtype;
2363  int32_t bandindex;
2364  const size_t name_size = 8; /* size of type name */
2365  size_t size = 0;
2366  char *ptr = NULL;
2367  text *result = NULL;
2368 
2369  /* Deserialize raster */
2370  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
2371  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2372 
2373  /* Index is 1-based */
2374  bandindex = PG_GETARG_INT32(1);
2375  if ( bandindex < 1 ) {
2376  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
2377  PG_FREE_IF_COPY(pgraster, 0);
2378  PG_RETURN_NULL();
2379  }
2380 
2381  raster = rt_raster_deserialize(pgraster, FALSE);
2382  if ( ! raster ) {
2383  PG_FREE_IF_COPY(pgraster, 0);
2384  elog(ERROR, "RASTER_getBandPixelTypeName: Could not deserialize raster");
2385  PG_RETURN_NULL();
2386  }
2387 
2388  /* Fetch requested band and its pixel type */
2389  band = rt_raster_get_band(raster, bandindex - 1);
2390  if ( ! band ) {
2391  elog(NOTICE, "Could not find raster band of index %d when getting pixel type name. Returning NULL", bandindex);
2392  rt_raster_destroy(raster);
2393  PG_FREE_IF_COPY(pgraster, 0);
2394  PG_RETURN_NULL();
2395  }
2396 
2397  pixtype = rt_band_get_pixtype(band);
2398 
2399  result = palloc(VARHDRSZ + name_size);
2400  /* We don't need to check for NULL pointer, because if out of memory, palloc
2401  * exit via elog(ERROR). It never returns NULL.
2402  */
2403 
2404  memset(VARDATA(result), 0, name_size);
2405  ptr = (char *)result + VARHDRSZ;
2406  strcpy(ptr, rt_pixtype_name(pixtype));
2407 
2408  size = VARHDRSZ + strlen(ptr);
2409  SET_VARSIZE(result, size);
2410 
2411  rt_raster_destroy(raster);
2412  PG_FREE_IF_COPY(pgraster, 0);
2413 
2414  PG_RETURN_TEXT_P(result);
2415 }
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_api.c:1168
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_api.c:1900
tuple band
Definition: ovdump.py:57
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
char ** result
Definition: liblwgeom.h:218
rt_pixtype
Definition: rt_api.h:172
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350

Here is the call graph for this function: