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

Definition at line 250 of file lwgeom_inout.c.

References lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_hexwkb(), result, WKB_EXTENDED, WKB_NDR, and WKB_XDR.

251 {
252  GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
253  LWGEOM *lwgeom;
254  char *hexwkb;
255  size_t hexwkb_size;
256  uint8_t variant = 0;
257  text *result;
258  text *type;
259  size_t text_size;
260 
261  /* If user specified endianness, respect it */
262  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
263  {
264  type = PG_GETARG_TEXT_P(1);
265 
266  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
267  ! strncmp(VARDATA(type), "XDR", 3) )
268  {
269  variant = variant | WKB_XDR;
270  }
271  else
272  {
273  variant = variant | WKB_NDR;
274  }
275  }
276 
277  /* Create WKB hex string */
278  lwgeom = lwgeom_from_gserialized(geom);
279  hexwkb = lwgeom_to_hexwkb(lwgeom, variant | WKB_EXTENDED, &hexwkb_size);
280  lwgeom_free(lwgeom);
281 
282  /* Prepare the PgSQL text return type */
283  text_size = hexwkb_size - 1 + VARHDRSZ;
284  result = palloc(text_size);
285  memcpy(VARDATA(result), hexwkb, hexwkb_size - 1);
286  SET_VARSIZE(result, text_size);
287 
288  /* Clean up and return */
289  pfree(hexwkb);
290  PG_FREE_IF_COPY(geom, 0);
291  PG_RETURN_TEXT_P(result);
292 }
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:776
#define WKB_NDR
Definition: liblwgeom.h:1770
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
char ** result
Definition: liblwgeom.h:218
LWGEOM * geom
#define WKB_EXTENDED
Definition: liblwgeom.h:1769
#define WKB_XDR
Definition: liblwgeom.h:1771

Here is the call graph for this function: