PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ WKBFromLWGEOM()

Datum WKBFromLWGEOM ( PG_FUNCTION_ARGS  )

Definition at line 430 of file lwgeom_inout.c.

431 {
432  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
433  LWGEOM *lwgeom;
434  uint8_t *wkb;
435  size_t wkb_size;
436  uint8_t variant = 0;
437  bytea *result;
438  text *type;
439  /* If user specified endianness, respect it */
440  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
441  {
442  type = PG_GETARG_TEXT_P(1);
443 
444  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
445  ! strncmp(VARDATA(type), "XDR", 3) )
446  {
447  variant = variant | WKB_XDR;
448  }
449  else
450  {
451  variant = variant | WKB_NDR;
452  }
453  }
454  wkb_size= VARSIZE_ANY_EXHDR(geom);
455  /* Create WKB hex string */
456  lwgeom = lwgeom_from_gserialized(geom);
457 
458  wkb = lwgeom_to_wkb(lwgeom, variant | WKB_EXTENDED , &wkb_size);
459  lwgeom_free(lwgeom);
460 
461  /* Prepare the PgSQL text return type */
462  result = palloc(wkb_size + VARHDRSZ);
463  memcpy(VARDATA(result), wkb, wkb_size);
464  SET_VARSIZE(result, wkb_size+VARHDRSZ);
465 
466  /* Clean up and return */
467  lwfree(wkb);
468  PG_FREE_IF_COPY(geom, 0);
469  PG_RETURN_BYTEA_P(result);
470 }
static uint8_t variant
Definition: cu_in_twkb.c:26
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
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:790
void lwfree(void *mem)
Definition: lwutil.c:242
#define WKB_EXTENDED
Definition: liblwgeom.h:2123
#define WKB_NDR
Definition: liblwgeom.h:2124
#define WKB_XDR
Definition: liblwgeom.h:2125
type
Definition: ovdump.py:42

References lwfree(), 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: