PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ WKBFromLWGEOM()

Datum WKBFromLWGEOM ( PG_FUNCTION_ARGS  )

Definition at line 398 of file lwgeom_inout.c.

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

Referenced by LWGEOM_send(), LWGEOM_to_bytea(), and LWGEOMFromTWKB().

399 {
400  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
401  LWGEOM *lwgeom;
402  uint8_t *wkb;
403  size_t wkb_size;
404  uint8_t variant = 0;
405  bytea *result;
406  text *type;
407  /* If user specified endianness, respect it */
408  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
409  {
410  type = PG_GETARG_TEXT_P(1);
411 
412  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
413  ! strncmp(VARDATA(type), "XDR", 3) )
414  {
415  variant = variant | WKB_XDR;
416  }
417  else
418  {
419  variant = variant | WKB_NDR;
420  }
421  }
422  wkb_size= VARSIZE(geom) - VARHDRSZ;
423  /* Create WKB hex string */
424  lwgeom = lwgeom_from_gserialized(geom);
425 
426  wkb = lwgeom_to_wkb(lwgeom, variant | WKB_EXTENDED , &wkb_size);
427  lwgeom_free(lwgeom);
428 
429  /* Prepare the PgSQL text return type */
430  result = palloc(wkb_size + VARHDRSZ);
431  memcpy(VARDATA(result), wkb, wkb_size);
432  SET_VARSIZE(result, wkb_size+VARHDRSZ);
433 
434  /* Clean up and return */
435  pfree(wkb);
436  PG_FREE_IF_COPY(geom, 0);
437  PG_RETURN_BYTEA_P(result);
438 }
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
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:750
#define WKB_EXTENDED
Definition: liblwgeom.h:1932
#define WKB_XDR
Definition: liblwgeom.h:1934
type
Definition: ovdump.py:41
Here is the call graph for this function:
Here is the caller graph for this function: