PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ RASTER_copyBand()

Datum RASTER_copyBand ( PG_FUNCTION_ARGS  )

Definition at line 904 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().

905 {
906  rt_pgraster *pgto = NULL;
907  rt_pgraster *pgfrom = NULL;
908  rt_pgraster *pgrtn = NULL;
909  rt_raster torast = NULL;
910  rt_raster fromrast = NULL;
911  int toindex = 0;
912  int fromband = 0;
913  int oldtorastnumbands = 0;
914  int newtorastnumbands = 0;
915  int newbandindex = 0;
916 
917  /* Deserialize torast */
918  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
919  pgto = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
920 
921  torast = rt_raster_deserialize(pgto, FALSE);
922  if (!torast) {
923  PG_FREE_IF_COPY(pgto, 0);
924  elog(ERROR, "RASTER_copyBand: Could not deserialize first raster");
925  PG_RETURN_NULL();
926  }
927 
928  /* Deserialize fromrast */
929  if (!PG_ARGISNULL(1)) {
930  pgfrom = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
931 
932  fromrast = rt_raster_deserialize(pgfrom, FALSE);
933  if (!fromrast) {
934  rt_raster_destroy(torast);
935  PG_FREE_IF_COPY(pgfrom, 1);
936  PG_FREE_IF_COPY(pgto, 0);
937  elog(ERROR, "RASTER_copyBand: Could not deserialize second raster");
938  PG_RETURN_NULL();
939  }
940 
941  oldtorastnumbands = rt_raster_get_num_bands(torast);
942 
943  if (PG_ARGISNULL(2))
944  fromband = 1;
945  else
946  fromband = PG_GETARG_INT32(2);
947 
948  if (PG_ARGISNULL(3))
949  toindex = oldtorastnumbands + 1;
950  else
951  toindex = PG_GETARG_INT32(3);
952 
953  /* Copy band fromrast torast */
954  newbandindex = rt_raster_copy_band(
955  torast, fromrast,
956  fromband - 1, toindex - 1
957  );
958 
959  newtorastnumbands = rt_raster_get_num_bands(torast);
960  if (newtorastnumbands == oldtorastnumbands || newbandindex == -1) {
961  elog(NOTICE, "RASTER_copyBand: Could not add band to raster. "
962  "Returning original raster."
963  );
964  }
965 
966  rt_raster_destroy(fromrast);
967  PG_FREE_IF_COPY(pgfrom, 1);
968  }
969 
970  /* Serialize and return torast */
971  pgrtn = rt_raster_serialize(torast);
972  rt_raster_destroy(torast);
973  PG_FREE_IF_COPY(pgto, 0);
974  if (!pgrtn) PG_RETURN_NULL();
975 
976  SET_VARSIZE(pgrtn, pgrtn->size);
977  PG_RETURN_POINTER(pgrtn);
978 }
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
int 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:1374
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:2213
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
Here is the call graph for this function:
Here is the caller graph for this function: