PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ WKBFromLWGEOM()

Datum WKBFromLWGEOM ( PG_FUNCTION_ARGS  )

Definition at line 422 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().

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