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

Definition at line 363 of file lwgeom_inout.c.

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

Referenced by LWGEOM_send(), and LWGEOM_to_bytea().

364 {
365  GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
366  LWGEOM *lwgeom;
367  uint8_t *wkb;
368  size_t wkb_size;
369  uint8_t variant = 0;
370  bytea *result;
371  text *type;
372 
373  /* If user specified endianness, respect it */
374  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
375  {
376  type = PG_GETARG_TEXT_P(1);
377 
378  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
379  ! strncmp(VARDATA(type), "XDR", 3) )
380  {
381  variant = variant | WKB_XDR;
382  }
383  else
384  {
385  variant = variant | WKB_NDR;
386  }
387  }
388 
389  /* Create WKB hex string */
390  lwgeom = lwgeom_from_gserialized(geom);
391  wkb = lwgeom_to_wkb(lwgeom, variant | WKB_EXTENDED , &wkb_size);
392  lwgeom_free(lwgeom);
393 
394  /* Prepare the PgSQL text return type */
395  result = palloc(wkb_size + VARHDRSZ);
396  memcpy(VARDATA(result), wkb, wkb_size);
397  SET_VARSIZE(result, wkb_size+VARHDRSZ);
398 
399  /* Clean up and return */
400  pfree(wkb);
401  PG_FREE_IF_COPY(geom, 0);
402  PG_RETURN_BYTEA_P(result);
403 }
#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
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
Definition: lwout_wkb.c:692
#define WKB_EXTENDED
Definition: liblwgeom.h:1769
#define WKB_XDR
Definition: liblwgeom.h:1771

Here is the call graph for this function:

Here is the caller graph for this function: