35 LWDEBUGF(2,
"Entered lwgeom_twkb_type",0);
61 lwerror(
"Unsupported geometry type: %s [%d]",
78 for ( i = 0; i < ndims; i++ )
93 for ( i = 0; i < ndims; i++ )
114 size_t npoints_offset = 0;
117 LWDEBUGF(2,
"Entered %s", __func__);
120 if ( pa->
npoints == 0 && register_npoints )
143 if ( register_npoints )
157 for ( i = 0; i < pa->
npoints; i++ )
163 for ( j = 0; j < ndims; j++ )
169 nextdelta[j] = (int64_t) llround(globals->
factor[j] * dbl_ptr[j]) - ts->
accum_rels[j];
170 LWDEBUGF(4,
"deltavalue: %d, ", nextdelta[j]);
171 diff += llabs(nextdelta[j]);
177 if ( i > 0 && diff == 0 && max_points_left > minpoints )
187 for ( j = 0; j < ndims; j++ )
196 for ( j = 0; j < ndims; j++ )
212 if ( register_npoints )
224 if ( register_npoints )
237 LWDEBUGF(2,
"Entered %s", __func__);
250 LWDEBUGF(2,
"Entered %s", __func__);
268 for ( i = 0; i < poly->
nrings; i++ )
288 LWDEBUGF(2,
"Entered %s", __func__);
294 for ( i = 0; i < col->
ngeoms; i++ )
305 for ( i = 0; i < col->
ngeoms; i++ )
318 for ( i = 0; i < col->
ngeoms; i++ )
337 LWDEBUGF(2,
"Entered %s", __func__);
338 LWDEBUGF(4,
"Number of geometries in collection is %d", col->
ngeoms);
346 for ( i = 0; i < col->
ngeoms; i++ )
354 for ( i = 0; i < col->
ngeoms; i++ )
368 LWDEBUGF(2,
"Entered %s", __func__);
370 switch ( geom->
type )
413 int i, is_empty, has_z, has_m, ndims;
414 size_t bbox_size = 0, optional_precision_byte = 0;
415 uint8_t flag = 0, type_prec = 0;
421 child_state.
geom_buf = &geom_bytebuffer;
434 optional_precision_byte = (has_z || has_m);
450 child_state.
bbox_max[i] = INT64_MIN;
451 child_state.
bbox_min[i] = INT64_MAX;
457 if ( abs(globals->
prec_xy) > 7 )
458 lwerror(
"%s: X/Z precision cannot be greater than 7 or less than -7", __func__);
483 if( optional_precision_byte )
487 if ( has_z && ( globals->
prec_z > 7 || globals->
prec_z < 0 ) )
488 lwerror(
"%s: Z precision cannot be negative or greater than 7", __func__);
490 if ( has_m && ( globals->
prec_m > 7 || globals->
prec_m < 0 ) )
491 lwerror(
"%s: M precision cannot be negative or greater than 7", __func__);
524 for ( i = 0; i < ndims; i++ )
537 LWDEBUG(4,
"We want boxes and will calculate required size");
547 size_to_register += bbox_size;
569 int8_t precision_xy, int8_t precision_z, int8_t precision_m,
572 LWDEBUGF(2,
"Entered %s", __func__);
573 LWDEBUGF(2,
"variant value %x", variant);
591 lwerror(
"Only collections can support ID lists");
597 LWDEBUG(4,
"Cannot convert NULL into TWKB.");
598 lwerror(
"Cannot convert NULL into TWKB");
616 int8_t precision_xy, int8_t precision_z, int8_t precision_m,
static int lwmulti_to_twkb_buf(const LWCOLLECTION *col, TWKB_GLOBALS *globals, TWKB_STATE *ts)
#define FIRST_BYTE_SET_EMPTY(flag, bool)
#define HIGHER_DIM_SET_PRECM(flag, prec)
#define TYPE_PREC_SET_TYPE(flag, type)
Macros for manipulating the 'type_precision' int.
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
void bytebuffer_append_bytebuffer(bytebuffer_t *write_to, bytebuffer_t *write_from)
Writes a uint8_t value to the buffer.
static int lwgeom_to_twkb_buf(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *ts)
void bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val)
Writes a uint8_t value to the buffer.
static uint8_t lwgeom_twkb_type(const LWGEOM *geom)
#define LWDEBUG(level, msg)
static void write_bbox(TWKB_STATE *ts, int ndims)
Writes the bbox in varints in the form: xmin, xdelta, ymin, ydelta.
static int lwpoly_to_twkb_buf(const LWPOLY *poly, TWKB_GLOBALS *globals, TWKB_STATE *ts)
#define HIGHER_DIM_SET_HASZ(flag, bool)
static int lwline_to_twkb_buf(const LWLINE *line, TWKB_GLOBALS *globals, TWKB_STATE *ts)
size_t bytebuffer_getlength(const bytebuffer_t *s)
Returns the length of the current buffer.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
uint8_t zigzag8(int8_t val)
bytebuffer_t * header_buf
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.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
int64_t accum_rels[MAX_N_DIMS]
#define FIRST_BYTE_SET_SIZES(flag, bool)
void bytebuffer_append_uvarint(bytebuffer_t *b, const uint64_t val)
Writes a unsigned varInt to the buffer.
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.
static int ptarray_to_twkb_buf(const POINTARRAY *pa, TWKB_GLOBALS *globals, TWKB_STATE *ts, int register_npoints, int minpoints)
Stores a pointarray as varints in the buffer , controls whether an npoints entry is added to the buff...
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
#define WKB_POINT_TYPE
Well-Known Binary (WKB) Geometry Types.
#define FIRST_BYTE_SET_BBOXES(flag, bool)
Header true/false flags.
#define WKB_LINESTRING_TYPE
#define TYPE_PREC_SET_PREC(flag, prec)
#define WKB_MULTIPOLYGON_TYPE
#define HIGHER_DIM_SET_PRECZ(flag, prec)
#define WKB_MULTILINESTRING_TYPE
void bytebuffer_init_with_size(bytebuffer_t *s, size_t size)
Allocate just the internal buffer of an existing bytebuffer_t struct.
#define FIRST_BYTE_SET_EXTENDED(flag, bool)
uint8_t * bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length)
Returns a copy of the internal buffer.
#define WKB_MULTIPOINT_TYPE
static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *parent_state)
int64_t bbox_max[MAX_N_DIMS]
size_t varint_u64_encode_buf(uint64_t val, uint8_t *buf)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
static int lwpoint_to_twkb_buf(const LWPOINT *pt, TWKB_GLOBALS *globals, TWKB_STATE *ts)
size_t varint_s64_encode_buf(int64_t val, uint8_t *buf)
#define HIGHER_DIM_SET_HASM(flag, bool)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
#define LWDEBUGF(level, msg,...)
#define FLAGS_NDIMS(flags)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
#define FIRST_BYTE_SET_IDLIST(flag, bool)
void bytebuffer_append_varint(bytebuffer_t *b, const int64_t val)
Writes a signed varInt to the buffer.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
void bytebuffer_destroy_buffer(bytebuffer_t *s)
Free the bytebuffer_t and all memory managed within it.
static int lwcollection_to_twkb_buf(const LWCOLLECTION *col, TWKB_GLOBALS *globals, TWKB_STATE *ts)
#define WKB_GEOMETRYCOLLECTION_TYPE
int64_t bbox_min[MAX_N_DIMS]
uint8_t * lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size)