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

◆ RASTER_setBandPath()

Datum RASTER_setBandPath ( PG_FUNCTION_ARGS  )

Definition at line 912 of file rtpg_band_properties.c.

913{
914 rt_pgraster *pgraster = NULL;
915 rt_pgraster *pgrtn = NULL;
916 rt_raster raster = NULL;
917 rt_band band = NULL;
918 int32_t bandindex = 1;
919 const char *outdbpathchar = NULL;
920 int32_t outdbindex = 1;
921 bool forceset = FALSE;
922 rt_band newband = NULL;
923
924 int hasnodata;
925 double nodataval = 0.;
926
927 if (PG_ARGISNULL(0))
928 PG_RETURN_NULL();
929 pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
930
932 if (!raster) {
933 PG_FREE_IF_COPY(pgraster, 0);
934 elog(ERROR, "RASTER_setBandPath: Cannot deserialize raster");
935 PG_RETURN_NULL();
936 }
937
938 /* Check index is not NULL or smaller than 1 */
939 if (!PG_ARGISNULL(1))
940 bandindex = PG_GETARG_INT32(1);
941
942 if (bandindex < 1)
943 elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
944 else {
945 /* Fetch requested band */
946 band = rt_raster_get_band(raster, bandindex - 1);
947
948 if (!band)
949 elog(NOTICE, "Cannot find raster band of index %d. Returning original raster", bandindex);
950 else if (!rt_band_is_offline(band)) {
951 elog(NOTICE, "Band of index %d is not out-db. Returning original raster", bandindex);
952 }
953 else {
954 /* outdbpath */
955 if (!PG_ARGISNULL(2))
956 outdbpathchar = text_to_cstring(PG_GETARG_TEXT_P(2));
957 else
958 outdbpathchar = rt_band_get_ext_path(band);
959
960 /* outdbindex, is 1-based */
961 if (!PG_ARGISNULL(3))
962 outdbindex = PG_GETARG_INT32(3);
963
964 /* force */
965 if (!PG_ARGISNULL(4))
966 forceset = PG_GETARG_BOOL(4);
967
968 hasnodata = rt_band_get_hasnodata_flag(band);
969 if (hasnodata)
970 rt_band_get_nodata(band, &nodataval);
971
973 rt_raster_get_width(raster),
974 rt_raster_get_height(raster),
975 hasnodata,
976 nodataval,
977 outdbindex,
978 outdbpathchar,
979 forceset
980 );
981
982 if (rt_raster_replace_band(raster, newband, bandindex - 1) == NULL)
983 elog(NOTICE, "Cannot change path of band. Returning original raster");
984 else
985 /* old band is in the variable band */
986 rt_band_destroy(band);
987 }
988 }
989
990 /* Serialize raster again */
991 pgrtn = rt_raster_serialize(raster);
992 rt_raster_destroy(raster);
993 PG_FREE_IF_COPY(pgraster, 0);
994 if (!pgrtn) PG_RETURN_NULL();
995
996 SET_VARSIZE(pgrtn, pgrtn->size);
997 PG_RETURN_POINTER(pgrtn);
998}
#define FALSE
Definition dbfopen.c:168
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:1493
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
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
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
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:329
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:381
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:2251

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

Here is the call graph for this function: