PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ RASTER_setBandPath()

Datum RASTER_setBandPath ( PG_FUNCTION_ARGS  )

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

Referenced by RASTER_setBandIsNoData().

760 {
761  rt_pgraster *pgraster = NULL;
762  rt_pgraster *pgrtn = NULL;
763  rt_raster raster = NULL;
764  rt_band band = NULL;
765  int32_t bandindex = 1;
766  const char *outdbpathchar = NULL;
767  int32_t outdbindex = 1;
768  bool forceset = FALSE;
769  rt_band newband = NULL;
770 
771  int hasnodata;
772  double nodataval = 0.;
773 
774  if (PG_ARGISNULL(0))
775  PG_RETURN_NULL();
776  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
777 
778  raster = rt_raster_deserialize(pgraster, FALSE);
779  if (!raster) {
780  PG_FREE_IF_COPY(pgraster, 0);
781  elog(ERROR, "RASTER_setBandPath: Cannot deserialize raster");
782  PG_RETURN_NULL();
783  }
784 
785  /* Check index is not NULL or smaller than 1 */
786  if (!PG_ARGISNULL(1))
787  bandindex = PG_GETARG_INT32(1);
788 
789  if (bandindex < 1)
790  elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
791  else {
792  /* Fetch requested band */
793  band = rt_raster_get_band(raster, bandindex - 1);
794 
795  if (!band)
796  elog(NOTICE, "Cannot find raster band of index %d. Returning original raster", bandindex);
797  else if (!rt_band_is_offline(band)) {
798  elog(NOTICE, "Band of index %d is not out-db. Returning original raster", bandindex);
799  }
800  else {
801  /* outdbpath */
802  if (!PG_ARGISNULL(2))
803  outdbpathchar = text_to_cstring(PG_GETARG_TEXT_P(2));
804  else
805  outdbpathchar = rt_band_get_ext_path(band);
806 
807  /* outdbindex, is 1-based */
808  if (!PG_ARGISNULL(3))
809  outdbindex = PG_GETARG_INT32(3);
810 
811  /* force */
812  if (!PG_ARGISNULL(4))
813  forceset = PG_GETARG_BOOL(4);
814 
815  hasnodata = rt_band_get_hasnodata_flag(band);
816  if (hasnodata)
817  rt_band_get_nodata(band, &nodataval);
818 
820  rt_raster_get_width(raster),
821  rt_raster_get_height(raster),
822  hasnodata,
823  nodataval,
824  outdbindex,
825  outdbpathchar,
826  forceset
827  );
828 
829  if (rt_raster_replace_band(raster, newband, bandindex - 1) == NULL)
830  elog(NOTICE, "Cannot change path of band. Returning original raster");
831  else
832  /* old band is in the variable band */
833  rt_band_destroy(band);
834  }
835  }
836 
837  /* Serialize raster again */
838  pgrtn = rt_raster_serialize(raster);
839  rt_raster_destroy(raster);
840  PG_FREE_IF_COPY(pgraster, 0);
841  if (!pgrtn) PG_RETURN_NULL();
842 
843  SET_VARSIZE(pgrtn, pgrtn->size);
844  PG_RETURN_POINTER(pgrtn);
845 }
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:325
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:195
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:336
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1682
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:359
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:626
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:1502
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:2230
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:717
Here is the call graph for this function:
Here is the caller graph for this function: