PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_copyBand()

Datum RASTER_copyBand ( PG_FUNCTION_ARGS  )

Definition at line 868 of file rtpg_create.c.

869 {
870  rt_pgraster *pgto = NULL;
871  rt_pgraster *pgfrom = NULL;
872  rt_pgraster *pgrtn = NULL;
873  rt_raster torast = NULL;
874  rt_raster fromrast = NULL;
875  int toindex = 0;
876  int fromband = 0;
877  int oldtorastnumbands = 0;
878  int newtorastnumbands = 0;
879  int newbandindex = 0;
880 
881  /* Deserialize torast */
882  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
883  pgto = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
884 
885  torast = rt_raster_deserialize(pgto, FALSE);
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  /* Deserialize fromrast */
893  if (!PG_ARGISNULL(1)) {
894  pgfrom = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
895 
896  fromrast = rt_raster_deserialize(pgfrom, FALSE);
897  if (!fromrast) {
898  rt_raster_destroy(torast);
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 
905  oldtorastnumbands = rt_raster_get_num_bands(torast);
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  /* Copy band fromrast torast */
918  newbandindex = rt_raster_copy_band(
919  torast, fromrast,
920  fromband - 1, toindex - 1
921  );
922 
923  newtorastnumbands = rt_raster_get_num_bands(torast);
924  if (newtorastnumbands == oldtorastnumbands || newbandindex == -1) {
925  elog(NOTICE, "RASTER_copyBand: Could not add band to raster. "
926  "Returning original raster."
927  );
928  }
929 
930  rt_raster_destroy(fromrast);
931  PG_FREE_IF_COPY(pgfrom, 1);
932  }
933 
934  /* Serialize and return torast */
935  pgrtn = rt_raster_serialize(torast);
936  rt_raster_destroy(torast);
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 }
#define FALSE
Definition: dbfopen.c:168
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
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
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
Struct definitions.
Definition: librtcore.h:2250

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

Here is the call graph for this function: