PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_to_bytea()

Datum RASTER_to_bytea ( PG_FUNCTION_ARGS  )

Definition at line 127 of file rtpg_inout.c.

128 {
129  rt_pgraster *pgraster = NULL;
130  rt_raster raster = NULL;
131  uint8_t *wkb = NULL;
132  uint32_t wkb_size = 0;
133  bytea *result = NULL;
134  int result_size = 0;
135 
136  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
137  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
138 
139  /* Get raster object */
140  raster = rt_raster_deserialize(pgraster, FALSE);
141  if (!raster) {
142  PG_FREE_IF_COPY(pgraster, 0);
143  elog(ERROR, "RASTER_to_bytea: Cannot deserialize raster");
144  PG_RETURN_NULL();
145  }
146 
147  /* Parse raster to wkb object */
148  wkb = rt_raster_to_wkb(raster, FALSE, &wkb_size);
149  if (!wkb) {
151  PG_FREE_IF_COPY(pgraster, 0);
152  elog(ERROR, "RASTER_to_bytea: Cannot allocate and generate WKB data");
153  PG_RETURN_NULL();
154  }
155 
156  /* Create varlena object */
157  result_size = wkb_size + VARHDRSZ;
158  result = (bytea *)palloc(result_size);
159  SET_VARSIZE(result, result_size);
160  memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
161 
162  /* Free raster objects used */
164  pfree(wkb);
165  PG_FREE_IF_COPY(pgraster, 0);
166 
167  PG_RETURN_POINTER(result);
168 }
#define FALSE
Definition: dbfopen.c:168
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
uint8_t * rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize)
Return this raster in WKB form.
Definition: rt_wkb.c:494
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
Struct definitions.
Definition: librtcore.h:2250
unsigned int uint32_t
Definition: uthash.h:78
unsigned char uint8_t
Definition: uthash.h:79

References FALSE, rtrowdump::raster, rt_raster_deserialize(), rt_raster_destroy(), and rt_raster_to_wkb().

Here is the call graph for this function: