PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ RASTER_copyBand()

Datum RASTER_copyBand ( PG_FUNCTION_ARGS  )

Definition at line 857 of file rtpg_create.c.

References FALSE, PG_FUNCTION_INFO_V1(), RASTER_tile(), rt_raster_copy_band(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), rt_raster_serialize(), and rt_raster_serialized_t::size.

Referenced by RASTER_addBandOutDB().

858 {
859  rt_pgraster *pgto = NULL;
860  rt_pgraster *pgfrom = NULL;
861  rt_pgraster *pgrtn = NULL;
862  rt_raster torast = NULL;
863  rt_raster fromrast = NULL;
864  int toindex = 0;
865  int fromband = 0;
866  int oldtorastnumbands = 0;
867  int newtorastnumbands = 0;
868  int newbandindex = 0;
869 
870  /* Deserialize torast */
871  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
872  pgto = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
873 
874  torast = rt_raster_deserialize(pgto, FALSE);
875  if (!torast) {
876  PG_FREE_IF_COPY(pgto, 0);
877  elog(ERROR, "RASTER_copyBand: Could not deserialize first raster");
878  PG_RETURN_NULL();
879  }
880 
881  /* Deserialize fromrast */
882  if (!PG_ARGISNULL(1)) {
883  pgfrom = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
884 
885  fromrast = rt_raster_deserialize(pgfrom, FALSE);
886  if (!fromrast) {
887  rt_raster_destroy(torast);
888  PG_FREE_IF_COPY(pgfrom, 1);
889  PG_FREE_IF_COPY(pgto, 0);
890  elog(ERROR, "RASTER_copyBand: Could not deserialize second raster");
891  PG_RETURN_NULL();
892  }
893 
894  oldtorastnumbands = rt_raster_get_num_bands(torast);
895 
896  if (PG_ARGISNULL(2))
897  fromband = 1;
898  else
899  fromband = PG_GETARG_INT32(2);
900 
901  if (PG_ARGISNULL(3))
902  toindex = oldtorastnumbands + 1;
903  else
904  toindex = PG_GETARG_INT32(3);
905 
906  /* Copy band fromrast torast */
907  newbandindex = rt_raster_copy_band(
908  torast, fromrast,
909  fromband - 1, toindex - 1
910  );
911 
912  newtorastnumbands = rt_raster_get_num_bands(torast);
913  if (newtorastnumbands == oldtorastnumbands || newbandindex == -1) {
914  elog(NOTICE, "RASTER_copyBand: Could not add band to raster. "
915  "Returning original raster."
916  );
917  }
918 
919  rt_raster_destroy(fromrast);
920  PG_FREE_IF_COPY(pgfrom, 1);
921  }
922 
923  /* Serialize and return torast */
924  pgrtn = rt_raster_serialize(torast);
925  rt_raster_destroy(torast);
926  PG_FREE_IF_COPY(pgto, 0);
927  if (!pgrtn) PG_RETURN_NULL();
928 
929  SET_VARSIZE(pgrtn, pgrtn->size);
930  PG_RETURN_POINTER(pgrtn);
931 }
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
Definition: rt_raster.c:1370
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2250
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: