PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ lwgeom_to_twkb_with_idlist()

uint8_t* lwgeom_to_twkb_with_idlist ( const LWGEOM geom,
int64_t *  idlist,
uint8_t  variant,
int8_t  precision_xy,
int8_t  precision_z,
int8_t  precision_m,
size_t *  twkb_size 
)

Convert LWGEOM to a char* in TWKB format.

Caller is responsible for freeing the returned array.

Definition at line 567 of file lwout_twkb.c.

References bytebuffer_destroy_buffer(), bytebuffer_get_buffer_copy(), bytebuffer_init_with_size(), TWKB_STATE::geom_buf, TWKB_STATE::header_buf, TWKB_STATE::idlist, LWDEBUG, LWDEBUGF, lwerror(), lwgeom_is_collection(), lwgeom_write_to_buffer(), TWKB_GLOBALS::prec_m, TWKB_GLOBALS::prec_xy, TWKB_GLOBALS::prec_z, variant, and TWKB_GLOBALS::variant.

Referenced by cu_twkb_idlist(), lwgeom_to_twkb(), and TWKBFromLWGEOMArray().

570 {
571  LWDEBUGF(2, "Entered %s", __func__);
572  LWDEBUGF(2, "variant value %x", variant);
573 
574  TWKB_GLOBALS tg;
575  TWKB_STATE ts;
576  bytebuffer_t geom_bytebuffer;
577 
578  uint8_t *twkb;
579 
580  memset(&ts, 0, sizeof(TWKB_STATE));
581  memset(&tg, 0, sizeof(TWKB_GLOBALS));
582 
583  tg.variant = variant;
584  tg.prec_xy = precision_xy;
585  tg.prec_z = precision_z;
586  tg.prec_m = precision_m;
587 
588  if ( idlist && ! lwgeom_is_collection(geom) )
589  {
590  lwerror("Only collections can support ID lists");
591  return NULL;
592  }
593 
594  if ( ! geom )
595  {
596  LWDEBUG(4,"Cannot convert NULL into TWKB.");
597  lwerror("Cannot convert NULL into TWKB");
598  return NULL;
599  }
600 
601  ts.idlist = idlist;
602  ts.header_buf = NULL;
603  ts.geom_buf = &geom_bytebuffer;
605  lwgeom_write_to_buffer(geom, &tg, &ts);
606 
607  twkb = bytebuffer_get_buffer_copy(ts.geom_buf, twkb_size);
609  return twkb;
610 }
uint8_t variant
Definition: cu_in_twkb.c:26
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1085
uint8_t variant
Definition: lwout_twkb.h:78
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int8_t prec_z
Definition: lwout_twkb.h:80
bytebuffer_t * header_buf
Definition: lwout_twkb.h:88
const int64_t * idlist
Definition: lwout_twkb.h:92
int8_t prec_xy
Definition: lwout_twkb.h:79
int8_t prec_m
Definition: lwout_twkb.h:81
void bytebuffer_init_with_size(bytebuffer_t *s, size_t size)
Allocate just the internal buffer of an existing bytebuffer_t struct.
Definition: bytebuffer.c:71
uint8_t * bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length)
Returns a copy of the internal buffer.
Definition: bytebuffer.c:173
static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *parent_state)
Definition: lwout_twkb.c:407
bytebuffer_t * geom_buf
Definition: lwout_twkb.h:89
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
unsigned char uint8_t
Definition: uthash.h:79
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
void bytebuffer_destroy_buffer(bytebuffer_t *s)
Free the bytebuffer_t and all memory managed within it.
Definition: bytebuffer.c:104
Here is the call graph for this function:
Here is the caller graph for this function: