PostGIS  2.3.8dev-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 560 of file lwout_twkb.c.

References bytebuffer_t::buf_start, bytebuffer_create(), bytebuffer_getlength(), TWKB_STATE::geom_buf, TWKB_STATE::header_buf, TWKB_STATE::idlist, LWDEBUG, LWDEBUGF, lwerror(), lwfree(), 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().

563 {
564  LWDEBUGF(2, "Entered %s", __func__);
565  LWDEBUGF(2, "variant value %x", variant);
566 
567  TWKB_GLOBALS tg;
568  TWKB_STATE ts;
569 
570  uint8_t *twkb;
571 
572  memset(&ts, 0, sizeof(TWKB_STATE));
573  memset(&tg, 0, sizeof(TWKB_GLOBALS));
574 
575  tg.variant = variant;
576  tg.prec_xy = precision_xy;
577  tg.prec_z = precision_z;
578  tg.prec_m = precision_m;
579 
580  if ( idlist && ! lwgeom_is_collection(geom) )
581  {
582  lwerror("Only collections can support ID lists");
583  return NULL;
584  }
585 
586  if ( ! geom )
587  {
588  LWDEBUG(4,"Cannot convert NULL into TWKB.");
589  lwerror("Cannot convert NULL into TWKB");
590  return NULL;
591  }
592 
593  ts.idlist = idlist;
594  ts.header_buf = NULL;
596  lwgeom_write_to_buffer(geom, &tg, &ts);
597 
598  if ( twkb_size )
599  *twkb_size = bytebuffer_getlength(ts.geom_buf);
600 
601  twkb = ts.geom_buf->buf_start;
602  lwfree(ts.geom_buf);
603  return twkb;
604 }
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:1004
bytebuffer_t * bytebuffer_create(void)
Allocate a new bytebuffer_t.
Definition: bytebuffer.c:34
void lwfree(void *mem)
Definition: lwutil.c:242
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
static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *parent_state)
Definition: lwout_twkb.c:407
uint8_t * buf_start
Definition: bytebuffer.h:40
bytebuffer_t * geom_buf
Definition: lwout_twkb.h:89
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
size_t bytebuffer_getlength(bytebuffer_t *s)
Returns the length of the current buffer.
Definition: bytebuffer.c:325
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: