PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_asHEXEWKB()

Datum LWGEOM_asHEXEWKB ( PG_FUNCTION_ARGS  )

Definition at line 287 of file lwgeom_inout.c.

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

References 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: