PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_setBandPath()

Datum RASTER_setBandPath ( PG_FUNCTION_ARGS  )

Definition at line 910 of file rtpg_band_properties.c.

911 {
912  rt_pgraster *pgraster = NULL;
913  rt_pgraster *pgrtn = NULL;
914  rt_raster raster = NULL;
915  rt_band band = NULL;
916  int32_t bandindex = 1;
917  const char *outdbpathchar = NULL;
918  int32_t outdbindex = 1;
919  bool forceset = FALSE;
920  rt_band newband = NULL;
921 
922  int hasnodata;
923  double nodataval = 0.;
924 
925  if (PG_ARGISNULL(0))
926  PG_RETURN_NULL();
927  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
928 
929  raster = rt_raster_deserialize(pgraster, FALSE);
930  if (!raster) {
931  PG_FREE_IF_COPY(pgraster, 0);
932  elog(ERROR, "RASTER_setBandPath: Cannot deserialize raster");
933  PG_RETURN_NULL();
934  }
935 
936  /* Check index is not NULL or smaller than 1 */
937  if (!PG_ARGISNULL(1))
938  bandindex = PG_GETARG_INT32(1);
939 
940  if (bandindex < 1)
941  elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
942  else {
943  /* Fetch requested band */
944  band = rt_raster_get_band(raster, bandindex - 1);
945 
946  if (!band)
947  elog(NOTICE, "Cannot find raster band of index %d. Returning original raster", bandindex);
948  else if (!rt_band_is_offline(band)) {
949  elog(NOTICE, "Band of index %d is not out-db. Returning original raster", bandindex);
950  }
951  else {
952  /* outdbpath */
953  if (!PG_ARGISNULL(2))
954  outdbpathchar = text_to_cstring(PG_GETARG_TEXT_P(2));
955  else
956  outdbpathchar = rt_band_get_ext_path(band);
957 
958  /* outdbindex, is 1-based */
959  if (!PG_ARGISNULL(3))
960  outdbindex = PG_GETARG_INT32(3);
961 
962  /* force */
963  if (!PG_ARGISNULL(4))
964  forceset = PG_GETARG_BOOL(4);
965 
966  hasnodata = rt_band_get_hasnodata_flag(band);
967  if (hasnodata)
968  rt_band_get_nodata(band, &nodataval);
969 
973  hasnodata,
974  nodataval,
975  outdbindex,
976  outdbpathchar,
977  forceset
978  );
979 
980  if (rt_raster_replace_band(raster, newband, bandindex - 1) == NULL)
981  elog(NOTICE, "Cannot change path of band. Returning original raster");
982  else
983  /* old band is in the variable band */
985  }
986  }
987 
988  /* Serialize raster again */
989  pgrtn = rt_raster_serialize(raster);
991  PG_FREE_IF_COPY(pgraster, 0);
992  if (!pgrtn) PG_RETURN_NULL();
993 
994  SET_VARSIZE(pgrtn, pgrtn->size);
995  PG_RETURN_POINTER(pgrtn);
996 }
#define FALSE
Definition: dbfopen.c:168
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_band.c:363
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index)
Replace band at provided index with new band.
Definition: rt_raster.c:1498
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:340
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
rt_band rt_band_new_offline_from_path(uint16_t width, uint16_t height, int hasnodata, double nodataval, uint8_t bandNum, const char *path, int force)
Create an out-db rt_band from path.
Definition: rt_band.c:199
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_band.c:329
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
band
Definition: ovdump.py:57
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
char * text_to_cstring(const text *textptr)
Struct definitions.
Definition: librtcore.h:2250

References ovdump::band, FALSE, rtrowdump::raster, rt_band_destroy(), rt_band_get_ext_path(), rt_band_get_hasnodata_flag(), rt_band_get_nodata(), rt_band_is_offline(), rt_band_new_offline_from_path(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), rt_raster_get_height(), rt_raster_get_width(), rt_raster_replace_band(), rt_raster_serialize(), rt_raster_serialized_t::size, and text_to_cstring().

Here is the call graph for this function: