PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_asHEXEWKB()

Datum LWGEOM_asHEXEWKB ( PG_FUNCTION_ARGS  )

Definition at line 293 of file lwgeom_inout.c.

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

References lwfree(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_hexwkb(), variant, WKB_EXTENDED, WKB_NDR, and WKB_XDR.

Here is the call graph for this function: