PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_setBandPath()

Datum RASTER_setBandPath ( PG_FUNCTION_ARGS  )

Definition at line 933 of file rtpg_band_properties.c.

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

References FALSE, 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: