PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_asHEXEWKB()

Datum LWGEOM_asHEXEWKB ( PG_FUNCTION_ARGS  )

Definition at line 291 of file lwgeom_inout.c.

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

Here is the call graph for this function: