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

Definition at line 2657 of file rt_pg.c.

References ovdump::band, FALSE, rtrowdump::raster, result, rt_band_destroy(), rt_band_get_ext_path(), rt_raster_deserialize(), rt_raster_destroy(), and rt_raster_get_band().

2658 {
2659  rt_pgraster *pgraster = NULL;
2660  rt_raster raster = NULL;
2661  rt_band band = NULL;
2662  int32_t bandindex;
2663  const char *bandpath;
2664  text *result;
2665 
2666  /* Index is 1-based */
2667  bandindex = PG_GETARG_INT32(1);
2668  if (bandindex < 1) {
2669  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
2670  PG_RETURN_NULL();
2671  }
2672 
2673  /* Deserialize raster */
2674  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
2675  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2676 
2677  raster = rt_raster_deserialize(pgraster, FALSE);
2678  if (!raster) {
2679  PG_FREE_IF_COPY(pgraster, 0);
2680  elog(ERROR, "RASTER_getBandPath: Could not deserialize raster");
2681  PG_RETURN_NULL();
2682  }
2683 
2684  /* Fetch requested band and its nodata value */
2685  band = rt_raster_get_band(raster, bandindex - 1);
2686  if (!band) {
2687  elog(
2688  NOTICE,
2689  "Could not find raster band of index %d when getting band path. Returning NULL",
2690  bandindex
2691  );
2692  rt_raster_destroy(raster);
2693  PG_FREE_IF_COPY(pgraster, 0);
2694  PG_RETURN_NULL();
2695  }
2696 
2697  bandpath = rt_band_get_ext_path(band);
2698  if (!bandpath) {
2699  rt_band_destroy(band);
2700  rt_raster_destroy(raster);
2701  PG_FREE_IF_COPY(pgraster, 0);
2702  PG_RETURN_NULL();
2703  }
2704 
2705  result = (text *) palloc(VARHDRSZ + strlen(bandpath) + 1);
2706  SET_VARSIZE(result, VARHDRSZ + strlen(bandpath) + 1);
2707  strcpy((char *) VARDATA(result), bandpath);
2708 
2709  rt_band_destroy(band);
2710  rt_raster_destroy(raster);
2711  PG_FREE_IF_COPY(pgraster, 0);
2712 
2713  PG_RETURN_TEXT_P(result);
2714 }
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
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
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_api.c:1650
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
const char * rt_band_get_ext_path(rt_band band)
Return band's external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_api.c:1673

Here is the call graph for this function: