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

Definition at line 1224 of file rt_pg.c.

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

1225 {
1226  rt_pgraster *pgraster = NULL;
1227  rt_raster raster = NULL;
1228  uint8_t *wkb = NULL;
1229  uint32_t wkb_size = 0;
1230  char *result = NULL;
1231  int result_size = 0;
1232  int outasin = FALSE;
1233 
1234  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
1235  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1236 
1237  /* Get raster object */
1238  raster = rt_raster_deserialize(pgraster, FALSE);
1239  if (!raster) {
1240  PG_FREE_IF_COPY(pgraster, 0);
1241  elog(ERROR, "RASTER_to_binary: Could not deserialize raster");
1242  PG_RETURN_NULL();
1243  }
1244 
1245  if (!PG_ARGISNULL(1))
1246  outasin = PG_GETARG_BOOL(1);
1247 
1248  /* Parse raster to wkb object */
1249  wkb = rt_raster_to_wkb(raster, outasin, &wkb_size);
1250  if (!wkb) {
1251  rt_raster_destroy(raster);
1252  PG_FREE_IF_COPY(pgraster, 0);
1253  elog(ERROR, "RASTER_to_binary: Could not allocate and generate WKB data");
1254  PG_RETURN_NULL();
1255  }
1256 
1257  /* Create varlena object */
1258  result_size = wkb_size + VARHDRSZ;
1259  result = (char *)palloc(result_size);
1260  SET_VARSIZE(result, result_size);
1261  memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
1262 
1263  /* Free raster objects used */
1264  rt_raster_destroy(raster);
1265  pfree(wkb);
1266  PG_FREE_IF_COPY(pgraster, 0);
1267 
1268  PG_RETURN_POINTER(result);
1269 }
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: