430{
431 int i, is_empty, has_z = 0, has_m = 0, ndims;
432 size_t bbox_size = 0, optional_precision_byte = 0;
433 uint8_t flag = 0, type_prec = 0;
435
439 child_state.
geom_buf = &geom_bytebuffer;
441
444
445
448 if ( ndims > 2 )
449 {
452 }
453
454
455 optional_precision_byte = (has_z || has_m);
456
457
460
461
462 if ( has_z )
464 if ( has_m )
466
467
469 {
470
471 child_state.
bbox_max[i] = INT64_MIN;
472 child_state.
bbox_min[i] = INT64_MAX;
473
475 }
476
477
478 if ( abs(globals->
prec_xy) > 7 )
479 lwerror(
"%s: X/Z precision cannot be greater than 7 or less than -7", __func__);
480
481
483
485
487
488
489
491
493
495
497
499
501
502
503
504 if( optional_precision_byte )
505 {
506 uint8_t flag = 0;
507
508 if ( has_z && ( globals->
prec_z > 7 || globals->
prec_z < 0 ) )
509 lwerror(
"%s: Z precision cannot be negative or greater than 7", __func__);
510
511 if ( has_m && ( globals->
prec_m > 7 || globals->
prec_m < 0 ) )
512 lwerror(
"%s: M precision cannot be negative or greater than 7", __func__);
513
519 }
520
521
522 if ( is_empty )
523 {
524
525
526
529
533 return 0;
534 }
535
536
538
539
540
541
543 {
545 for ( i = 0; i < ndims; i++ )
546 {
551 }
552 }
553
554
555 bbox_size = 0;
557 {
558 LWDEBUG(4,
"We want boxes and will calculate required size");
560 }
561
562
564 {
565
566
568 size_to_register += bbox_size;
570 }
571
574
577
580 return 0;
581}
void bytebuffer_destroy_buffer(bytebuffer_t *s)
Free the bytebuffer_t and all memory managed within it.
void bytebuffer_append_bytebuffer(bytebuffer_t *write_to, bytebuffer_t *write_from)
Writes a uint8_t value to the buffer.
size_t bytebuffer_getlength(const bytebuffer_t *s)
Returns the length of the current buffer.
void bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val)
Writes a uint8_t value to the buffer.
void bytebuffer_append_uvarint(bytebuffer_t *b, const uint64_t val)
Writes a unsigned varInt to the buffer.
void bytebuffer_init_with_size(bytebuffer_t *s, size_t size)
Allocate just the internal buffer of an existing bytebuffer_t struct.
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
#define LWDEBUG(level, msg)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
static uint8_t lwgeom_twkb_type(const LWGEOM *geom)
static int lwgeom_to_twkb_buf(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *ts)
static void write_bbox(TWKB_STATE *ts, int ndims)
Writes the bbox in varints in the form: xmin, xdelta, ymin, ydelta.
static size_t sizeof_bbox(TWKB_STATE *ts, int ndims)
Calculates the size of the bbox in varints in the form: xmin, xdelta, ymin, ydelta.
#define FIRST_BYTE_SET_EXTENDED(flag, bool)
#define TYPE_PREC_SET_TYPE(flag, type)
Macros for manipulating the 'type_precision' int.
#define TYPE_PREC_SET_PREC(flag, prec)
#define HIGHER_DIM_SET_PRECM(flag, prec)
#define HIGHER_DIM_SET_HASM(flag, bool)
#define FIRST_BYTE_SET_EMPTY(flag, bool)
#define HIGHER_DIM_SET_PRECZ(flag, prec)
#define FIRST_BYTE_SET_IDLIST(flag, bool)
#define FIRST_BYTE_SET_BBOXES(flag, bool)
Header true/false flags.
#define HIGHER_DIM_SET_HASZ(flag, bool)
#define FIRST_BYTE_SET_SIZES(flag, bool)
int64_t bbox_min[MAX_N_DIMS]
bytebuffer_t * header_buf
int64_t accum_rels[MAX_N_DIMS]
int64_t bbox_max[MAX_N_DIMS]
uint8_t zigzag8(int8_t val)