PostGIS  2.5.0rc1-r@@SVN_REVISION@@

◆ RASTER_setBandPath()

Datum RASTER_setBandPath ( PG_FUNCTION_ARGS  )

Definition at line 909 of file rtpg_band_properties.c.

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().

Referenced by RASTER_setBandIsNoData().

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