PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ WKBFromLWGEOM()

Datum WKBFromLWGEOM ( PG_FUNCTION_ARGS  )

Definition at line 428 of file lwgeom_inout.c.

429 {
430  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
431  LWGEOM *lwgeom;
432  uint8_t *wkb;
433  size_t wkb_size;
434  uint8_t variant = 0;
435  bytea *result;
436  text *type;
437  /* If user specified endianness, respect it */
438  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
439  {
440  type = PG_GETARG_TEXT_P(1);
441 
442  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
443  ! strncmp(VARDATA(type), "XDR", 3) )
444  {
445  variant = variant | WKB_XDR;
446  }
447  else
448  {
449  variant = variant | WKB_NDR;
450  }
451  }
452  wkb_size= VARSIZE_ANY_EXHDR(geom);
453  /* Create WKB hex string */
454  lwgeom = lwgeom_from_gserialized(geom);
455 
456  wkb = lwgeom_to_wkb(lwgeom, variant | WKB_EXTENDED , &wkb_size);
457  lwgeom_free(lwgeom);
458 
459  /* Prepare the PgSQL text return type */
460  result = palloc(wkb_size + VARHDRSZ);
461  memcpy(VARDATA(result), wkb, wkb_size);
462  SET_VARSIZE(result, wkb_size+VARHDRSZ);
463 
464  /* Clean up and return */
465  lwfree(wkb);
466  PG_FREE_IF_COPY(geom, 0);
467  PG_RETURN_BYTEA_P(result);
468 }
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: