PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ WKBFromLWGEOM()

Datum WKBFromLWGEOM ( PG_FUNCTION_ARGS  )

Definition at line 423 of file lwgeom_inout.c.

424 {
425  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
426  LWGEOM *lwgeom;
427  uint8_t *wkb;
428  size_t wkb_size;
429  uint8_t variant = 0;
430  bytea *result;
431  text *type;
432  /* If user specified endianness, respect it */
433  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
434  {
435  type = PG_GETARG_TEXT_P(1);
436 
437  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
438  ! strncmp(VARDATA(type), "XDR", 3) )
439  {
440  variant = variant | WKB_XDR;
441  }
442  else
443  {
444  variant = variant | WKB_NDR;
445  }
446  }
447  wkb_size= VARSIZE(geom) - VARHDRSZ;
448  /* Create WKB hex string */
449  lwgeom = lwgeom_from_gserialized(geom);
450 
451  wkb = lwgeom_to_wkb(lwgeom, variant | WKB_EXTENDED , &wkb_size);
452  lwgeom_free(lwgeom);
453 
454  /* Prepare the PgSQL text return type */
455  result = palloc(wkb_size + VARHDRSZ);
456  memcpy(VARDATA(result), wkb, wkb_size);
457  SET_VARSIZE(result, wkb_size+VARHDRSZ);
458 
459  /* Clean up and return */
460  pfree(wkb);
461  PG_FREE_IF_COPY(geom, 0);
462  PG_RETURN_BYTEA_P(result);
463 }
static uint8_t variant
Definition: cu_in_twkb.c:26
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
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:764
#define WKB_EXTENDED
Definition: liblwgeom.h:2068
#define WKB_NDR
Definition: liblwgeom.h:2069
#define WKB_XDR
Definition: liblwgeom.h:2070
type
Definition: ovdump.py:41
unsigned char uint8_t
Definition: uthash.h:79

References lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_wkb(), ovdump::type, variant, WKB_EXTENDED, WKB_NDR, and WKB_XDR.

Referenced by LWGEOM_send(), and LWGEOM_to_bytea().

Here is the call graph for this function:
Here is the caller graph for this function: