PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 546 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().

549 {
550  LWDEBUGF(2, "Entered %s", __func__);
551  LWDEBUGF(2, "variant value %x", variant);
552 
553  TWKB_GLOBALS tg;
554  TWKB_STATE ts;
555 
556  uint8_t *twkb;
557 
558  memset(&ts, 0, sizeof(TWKB_STATE));
559  memset(&tg, 0, sizeof(TWKB_GLOBALS));
560 
561  tg.variant = variant;
562  tg.prec_xy = precision_xy;
563  tg.prec_z = precision_z;
564  tg.prec_m = precision_m;
565 
566  if ( idlist && ! lwgeom_is_collection(geom) )
567  {
568  lwerror("Only collections can support ID lists");
569  return NULL;
570  }
571 
572  if ( ! geom )
573  {
574  LWDEBUG(4,"Cannot convert NULL into TWKB.");
575  lwerror("Cannot convert NULL into TWKB");
576  return NULL;
577  }
578 
579  ts.idlist = idlist;
580  ts.header_buf = NULL;
582  lwgeom_write_to_buffer(geom, &tg, &ts);
583 
584  if ( twkb_size )
585  *twkb_size = bytebuffer_getlength(ts.geom_buf);
586 
587  twkb = ts.geom_buf->buf_start;
588  lwfree(ts.geom_buf);
589  return twkb;
590 }
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:991
bytebuffer_t * bytebuffer_create(void)
Allocate a new bytebuffer_t.
Definition: bytebuffer.c:46
void lwfree(void *mem)
Definition: lwutil.c:214
uint8_t variant
Definition: lwout_twkb.h:54
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
int8_t prec_z
Definition: lwout_twkb.h:56
bytebuffer_t * header_buf
Definition: lwout_twkb.h:64
const int64_t * idlist
Definition: lwout_twkb.h:68
int8_t prec_xy
Definition: lwout_twkb.h:55
int8_t prec_m
Definition: lwout_twkb.h:57
static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *parent_state)
Definition: lwout_twkb.c:393
uint8_t * buf_start
Definition: bytebuffer.h:52
bytebuffer_t * geom_buf
Definition: lwout_twkb.h:65
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
size_t bytebuffer_getlength(bytebuffer_t *s)
Returns the length of the current buffer.
Definition: bytebuffer.c:337
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: