PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_asHEXEWKB()

Datum LWGEOM_asHEXEWKB ( PG_FUNCTION_ARGS  )

Definition at line 286 of file lwgeom_inout.c.

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

Referenced by LWGEOM_out().

287 {
288  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
289  LWGEOM *lwgeom;
290  char *hexwkb;
291  size_t hexwkb_size;
292  uint8_t variant = 0;
293  text *result;
294  text *type;
295  size_t text_size;
296 
297  /* If user specified endianness, respect it */
298  if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
299  {
300  type = PG_GETARG_TEXT_P(1);
301 
302  if ( ! strncmp(VARDATA(type), "xdr", 3) ||
303  ! strncmp(VARDATA(type), "XDR", 3) )
304  {
305  variant = variant | WKB_XDR;
306  }
307  else
308  {
309  variant = variant | WKB_NDR;
310  }
311  }
312 
313  /* Create WKB hex string */
314  lwgeom = lwgeom_from_gserialized(geom);
315  hexwkb = lwgeom_to_hexwkb(lwgeom, variant | WKB_EXTENDED, &hexwkb_size);
316  lwgeom_free(lwgeom);
317 
318  /* Prepare the PgSQL text return type */
319  text_size = hexwkb_size - 1 + VARHDRSZ;
320  result = palloc(text_size);
321  memcpy(VARDATA(result), hexwkb, hexwkb_size - 1);
322  SET_VARSIZE(result, text_size);
323 
324  /* Clean up and return */
325  pfree(hexwkb);
326  PG_FREE_IF_COPY(geom, 0);
327  PG_RETURN_TEXT_P(result);
328 }
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
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
#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: