PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ RASTER_setBandPath()

Datum RASTER_setBandPath ( PG_FUNCTION_ARGS  )

Definition at line 931 of file rtpg_band_properties.c.

932 {
933  rt_pgraster *pgraster = NULL;
934  rt_pgraster *pgrtn = NULL;
935  rt_raster raster = NULL;
936  rt_band band = NULL;
937  int32_t bandindex = 1;
938  const char *outdbpathchar = NULL;
939  int32_t outdbindex = 1;
940  bool forceset = FALSE;
941  rt_band newband = NULL;
942 
943  int hasnodata;
944  double nodataval = 0.;
945 
946  if (PG_ARGISNULL(0))
947  PG_RETURN_NULL();
948  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
949 
950  raster = rt_raster_deserialize(pgraster, FALSE);
951  if (!raster) {
952  PG_FREE_IF_COPY(pgraster, 0);
953  elog(ERROR, "RASTER_setBandPath: Cannot deserialize raster");
954  PG_RETURN_NULL();
955  }
956 
957  /* Check index is not NULL or smaller than 1 */
958  if (!PG_ARGISNULL(1))
959  bandindex = PG_GETARG_INT32(1);
960 
961  if (bandindex < 1)
962  elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
963  else {
964  /* Fetch requested band */
965  band = rt_raster_get_band(raster, bandindex - 1);
966 
967  if (!band)
968  elog(NOTICE, "Cannot find raster band of index %d. Returning original raster", bandindex);
969  else if (!rt_band_is_offline(band)) {
970  elog(NOTICE, "Band of index %d is not out-db. Returning original raster", bandindex);
971  }
972  else {
973  /* outdbpath */
974  if (!PG_ARGISNULL(2))
975  outdbpathchar = text_to_cstring(PG_GETARG_TEXT_P(2));
976  else
977  outdbpathchar = rt_band_get_ext_path(band);
978 
979  /* outdbindex, is 1-based */
980  if (!PG_ARGISNULL(3))
981  outdbindex = PG_GETARG_INT32(3);
982 
983  /* force */
984  if (!PG_ARGISNULL(4))
985  forceset = PG_GETARG_BOOL(4);
986 
987  hasnodata = rt_band_get_hasnodata_flag(band);
988  if (hasnodata)
989  rt_band_get_nodata(band, &nodataval);
990 
994  hasnodata,
995  nodataval,
996  outdbindex,
997  outdbpathchar,
998  forceset
999  );
1000 
1001  if (rt_raster_replace_band(raster, newband, bandindex - 1) == NULL)
1002  elog(NOTICE, "Cannot change path of band. Returning original raster");
1003  else
1004  /* old band is in the variable band */
1006  }
1007  }
1008 
1009  /* Serialize raster again */
1010  pgrtn = rt_raster_serialize(raster);
1012  PG_FREE_IF_COPY(pgraster, 0);
1013  if (!pgrtn) PG_RETURN_NULL();
1014 
1015  SET_VARSIZE(pgrtn, pgrtn->size);
1016  PG_RETURN_POINTER(pgrtn);
1017 }
#define FALSE
Definition: dbfopen.c:72
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:86
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:1526
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:133
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1887
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:125
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:385
band
Definition: ovdump.py:58
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
Struct definitions.
Definition: librtcore.h:2396

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(), and rt_raster_serialized_t::size.

Here is the call graph for this function: