PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_to_bytea ( PG_FUNCTION_ARGS  )

Definition at line 1177 of file rt_pg.c.

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

1178 {
1179  rt_pgraster *pgraster = NULL;
1180  rt_raster raster = NULL;
1181  uint8_t *wkb = NULL;
1182  uint32_t wkb_size = 0;
1183  bytea *result = NULL;
1184  int result_size = 0;
1185 
1186  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
1187  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1188 
1189  /* Get raster object */
1190  raster = rt_raster_deserialize(pgraster, FALSE);
1191  if (!raster) {
1192  PG_FREE_IF_COPY(pgraster, 0);
1193  elog(ERROR, "RASTER_to_bytea: Could not deserialize raster");
1194  PG_RETURN_NULL();
1195  }
1196 
1197  /* Parse raster to wkb object */
1198  wkb = rt_raster_to_wkb(raster, FALSE, &wkb_size);
1199  if (!wkb) {
1200  rt_raster_destroy(raster);
1201  PG_FREE_IF_COPY(pgraster, 0);
1202  elog(ERROR, "RASTER_to_bytea: Could not allocate and generate WKB data");
1203  PG_RETURN_NULL();
1204  }
1205 
1206  /* Create varlena object */
1207  result_size = wkb_size + VARHDRSZ;
1208  result = (bytea *)palloc(result_size);
1209  SET_VARSIZE(result, result_size);
1210  memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
1211 
1212  /* Free raster objects used */
1213  rt_raster_destroy(raster);
1214  pfree(wkb);
1215  PG_FREE_IF_COPY(pgraster, 0);
1216 
1217  PG_RETURN_POINTER(result);
1218 }
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
char ** result
Definition: liblwgeom.h:218
uint8_t * rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize)
Return this raster in WKB form.
Definition: rt_api.c:7887
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350

Here is the call graph for this function: