PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_getBandPath()

Datum RASTER_getBandPath ( PG_FUNCTION_ARGS  )

Definition at line 284 of file rtpg_band_properties.c.

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

Referenced by RASTER_bandIsNoData().

285 {
286  rt_pgraster *pgraster = NULL;
287  rt_raster raster = NULL;
288  rt_band band = NULL;
289  int32_t bandindex;
290  const char *bandpath;
291  text *result;
292 
293  /* Index is 1-based */
294  bandindex = PG_GETARG_INT32(1);
295  if ( bandindex < 1 ) {
296  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
297  PG_RETURN_NULL();
298  }
299 
300  /* Deserialize raster */
301  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
302  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
303 
304  raster = rt_raster_deserialize(pgraster, FALSE);
305  if (!raster) {
306  PG_FREE_IF_COPY(pgraster, 0);
307  elog(ERROR, "RASTER_getBandPath: Could not deserialize raster");
308  PG_RETURN_NULL();
309  }
310 
311  /* Fetch requested band */
312  band = rt_raster_get_band(raster, bandindex - 1);
313  if (!band) {
314  elog(
315  NOTICE,
316  "Could not find raster band of index %d when getting band path. Returning NULL",
317  bandindex
318  );
319  rt_raster_destroy(raster);
320  PG_FREE_IF_COPY(pgraster, 0);
321  PG_RETURN_NULL();
322  }
323 
324  bandpath = rt_band_get_ext_path(band);
325  if (!bandpath) {
326  rt_band_destroy(band);
327  rt_raster_destroy(raster);
328  PG_FREE_IF_COPY(pgraster, 0);
329  PG_RETURN_NULL();
330  }
331 
332  result = (text *) palloc(VARHDRSZ + strlen(bandpath) + 1);
333  SET_VARSIZE(result, VARHDRSZ + strlen(bandpath) + 1);
334  strcpy((char *) VARDATA(result), bandpath);
335 
336  rt_band_destroy(band);
337  rt_raster_destroy(raster);
338  PG_FREE_IF_COPY(pgraster, 0);
339 
340  PG_RETURN_TEXT_P(result);
341 }
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
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:242
const char * rt_band_get_ext_path(rt_band band)
Return band&#39;s external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:265
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
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: