PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_asWKB()

Datum RASTER_asWKB ( PG_FUNCTION_ARGS  )

Definition at line 47 of file rtpg_wkb.c.

48 {
49  rt_pgraster *pgraster = NULL;
50  rt_raster raster = NULL;
51  uint8_t *wkb = NULL;
52  uint32_t wkb_size = 0;
53  char *result = NULL;
54  int result_size = 0;
55  int outasin = FALSE;
56 
57  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
58  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
59 
60  /* Get raster object */
61  raster = rt_raster_deserialize(pgraster, FALSE);
62  if (!raster) {
63  PG_FREE_IF_COPY(pgraster, 0);
64  elog(ERROR, "RASTER_asWKB: Cannot deserialize raster");
65  PG_RETURN_NULL();
66  }
67 
68  if (!PG_ARGISNULL(1))
69  outasin = PG_GETARG_BOOL(1);
70 
71  /* Parse raster to wkb object */
72  wkb = rt_raster_to_wkb(raster, outasin, &wkb_size);
73  if (!wkb) {
75  PG_FREE_IF_COPY(pgraster, 0);
76  elog(ERROR, "RASTER_asWKB: Cannot allocate and generate WKB data");
77  PG_RETURN_NULL();
78  }
79 
80  /* Create varlena object */
81  result_size = wkb_size + VARHDRSZ;
82  result = (char *)palloc(result_size);
83  SET_VARSIZE(result, result_size);
84  memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
85 
86  /* Free raster objects used */
88  pfree(wkb);
89  PG_FREE_IF_COPY(pgraster, 0);
90 
91  PG_RETURN_POINTER(result);
92 }
#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: