PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_to_binary()

Datum RASTER_to_binary ( PG_FUNCTION_ARGS  )

Definition at line 157 of file rtpg_inout.c.

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

Referenced by RASTER_to_bytea().

158 {
159  rt_pgraster *pgraster = NULL;
160  rt_raster raster = NULL;
161  uint8_t *wkb = NULL;
162  uint32_t wkb_size = 0;
163  char *result = NULL;
164  int result_size = 0;
165  int outasin = FALSE;
166 
167  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
168  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
169 
170  /* Get raster object */
171  raster = rt_raster_deserialize(pgraster, FALSE);
172  if (!raster) {
173  PG_FREE_IF_COPY(pgraster, 0);
174  elog(ERROR, "RASTER_to_binary: Could not deserialize raster");
175  PG_RETURN_NULL();
176  }
177 
178  if (!PG_ARGISNULL(1))
179  outasin = PG_GETARG_BOOL(1);
180 
181  /* Parse raster to wkb object */
182  wkb = rt_raster_to_wkb(raster, outasin, &wkb_size);
183  if (!wkb) {
184  rt_raster_destroy(raster);
185  PG_FREE_IF_COPY(pgraster, 0);
186  elog(ERROR, "RASTER_to_binary: Could not allocate and generate WKB data");
187  PG_RETURN_NULL();
188  }
189 
190  /* Create varlena object */
191  result_size = wkb_size + VARHDRSZ;
192  result = (char *)palloc(result_size);
193  SET_VARSIZE(result, result_size);
194  memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
195 
196  /* Free raster objects used */
197  rt_raster_destroy(raster);
198  pfree(wkb);
199  PG_FREE_IF_COPY(pgraster, 0);
200 
201  PG_RETURN_POINTER(result);
202 }
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: