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

Definition at line 262 of file lwgeom_inout.c.

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

263 {
264  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
265  LWGEOM *lwgeom;
266  char *hexwkb;
267  size_t hexwkb_size;
268  uint8_t variant = 0;
269  text *result;
270  text *type;
271  size_t text_size;
272 
273  /* If user specified endianness, respect it */
274  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
275  {
276  type = PG_GETARG_TEXT_P(1);
277 
278  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
279  ! strncmp(VARDATA(type), "XDR", 3) )
280  {
281  variant = variant | WKB_XDR;
282  }
283  else
284  {
285  variant = variant | WKB_NDR;
286  }
287  }
288 
289  /* Create WKB hex string */
290  lwgeom = lwgeom_from_gserialized(geom);
291  hexwkb = lwgeom_to_hexwkb(lwgeom, variant | WKB_EXTENDED, &hexwkb_size);
292  lwgeom_free(lwgeom);
293 
294  /* Prepare the PgSQL text return type */
295  text_size = hexwkb_size - 1 + VARHDRSZ;
296  result = palloc(text_size);
297  memcpy(VARDATA(result), hexwkb, hexwkb_size - 1);
298  SET_VARSIZE(result, text_size);
299 
300  /* Clean up and return */
301  pfree(hexwkb);
302  PG_FREE_IF_COPY(geom, 0);
303  PG_RETURN_TEXT_P(result);
304 }
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:834
uint8_t variant
Definition: cu_in_twkb.c:26
#define WKB_NDR
Definition: liblwgeom.h:1933
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define WKB_EXTENDED
Definition: liblwgeom.h:1932
#define WKB_XDR
Definition: liblwgeom.h:1934

Here is the call graph for this function: