PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_to_bytea()

Datum RASTER_to_bytea ( PG_FUNCTION_ARGS  )

Definition at line 110 of file rtpg_inout.c.

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

Referenced by RASTER_out().

111 {
112  rt_pgraster *pgraster = NULL;
113  rt_raster raster = NULL;
114  uint8_t *wkb = NULL;
115  uint32_t wkb_size = 0;
116  bytea *result = NULL;
117  int result_size = 0;
118 
119  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
120  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
121 
122  /* Get raster object */
123  raster = rt_raster_deserialize(pgraster, FALSE);
124  if (!raster) {
125  PG_FREE_IF_COPY(pgraster, 0);
126  elog(ERROR, "RASTER_to_bytea: Could not deserialize raster");
127  PG_RETURN_NULL();
128  }
129 
130  /* Parse raster to wkb object */
131  wkb = rt_raster_to_wkb(raster, FALSE, &wkb_size);
132  if (!wkb) {
133  rt_raster_destroy(raster);
134  PG_FREE_IF_COPY(pgraster, 0);
135  elog(ERROR, "RASTER_to_bytea: Could not allocate and generate WKB data");
136  PG_RETURN_NULL();
137  }
138 
139  /* Create varlena object */
140  result_size = wkb_size + VARHDRSZ;
141  result = (bytea *)palloc(result_size);
142  SET_VARSIZE(result, result_size);
143  memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
144 
145  /* Free raster objects used */
146  rt_raster_destroy(raster);
147  pfree(wkb);
148  PG_FREE_IF_COPY(pgraster, 0);
149 
150  PG_RETURN_POINTER(result);
151 }
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
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
unsigned int uint32_t
Definition: uthash.h:78
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:2201
unsigned char uint8_t
Definition: uthash.h:79
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: