869{
875 int toindex = 0;
876 int fromband = 0;
877 int oldtorastnumbands = 0;
878 int newtorastnumbands = 0;
879 int newbandindex = 0;
880
881
882 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
883 pgto = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
884
886 if (!torast) {
887 PG_FREE_IF_COPY(pgto, 0);
888 elog(ERROR, "RASTER_copyBand: Could not deserialize first raster");
889 PG_RETURN_NULL();
890 }
891
892
893 if (!PG_ARGISNULL(1)) {
894 pgfrom = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
895
897 if (!fromrast) {
899 PG_FREE_IF_COPY(pgfrom, 1);
900 PG_FREE_IF_COPY(pgto, 0);
901 elog(ERROR, "RASTER_copyBand: Could not deserialize second raster");
902 PG_RETURN_NULL();
903 }
904
906
907 if (PG_ARGISNULL(2))
908 fromband = 1;
909 else
910 fromband = PG_GETARG_INT32(2);
911
912 if (PG_ARGISNULL(3))
913 toindex = oldtorastnumbands + 1;
914 else
915 toindex = PG_GETARG_INT32(3);
916
917
919 torast, fromrast,
920 fromband - 1, toindex - 1
921 );
922
924 if (newtorastnumbands == oldtorastnumbands || newbandindex == -1) {
925 elog(NOTICE, "RASTER_copyBand: Could not add band to raster. "
926 "Returning original raster."
927 );
928 }
929
931 PG_FREE_IF_COPY(pgfrom, 1);
932 }
933
934
937 PG_FREE_IF_COPY(pgto, 0);
938 if (!pgrtn) PG_RETURN_NULL();
939
940 SET_VARSIZE(pgrtn, pgrtn->
size);
941 PG_RETURN_POINTER(pgrtn);
942}
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
uint16_t rt_raster_get_num_bands(rt_raster raster)
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.