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 = 0, has_m = 0, 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;
437 optional_precision_byte = (has_z || has_m);
453 child_state.
bbox_max[i] = INT64_MIN;
454 child_state.
bbox_min[i] = INT64_MAX;
460 if ( abs(globals->
prec_xy) > 7 )
461 lwerror(
"%s: X/Z precision cannot be greater than 7 or less than -7", __func__);
486 if( optional_precision_byte )
490 if ( has_z && ( globals->
prec_z > 7 || globals->
prec_z < 0 ) )
491 lwerror(
"%s: Z precision cannot be negative or greater than 7", __func__);
493 if ( has_m && ( globals->
prec_m > 7 || globals->
prec_m < 0 ) )
494 lwerror(
"%s: M precision cannot be negative or greater than 7", __func__);
527 for ( i = 0; i < ndims; i++ )
540 LWDEBUG(4,
"We want boxes and will calculate required size");
550 size_to_register += bbox_size;
572 int8_t precision_xy, int8_t precision_z, int8_t precision_m,
575 LWDEBUGF(2,
"Entered %s", __func__);
594 lwerror(
"Only collections can support ID lists");
600 LWDEBUG(4,
"Cannot convert NULL into TWKB.");
601 lwerror(
"Cannot convert NULL into TWKB");
619 int8_t precision_xy, int8_t precision_z, int8_t precision_m,
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_append_varint(bytebuffer_t *b, const int64_t val)
Writes a signed varInt to the buffer.
uint8_t * bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length)
Returns a copy of the internal 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.
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_NDIMS(flags)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
#define WKB_GEOMETRYCOLLECTION_TYPE
#define WKB_MULTIPOLYGON_TYPE
#define WKB_MULTIPOINT_TYPE
#define WKB_POINT_TYPE
Well-Known Binary (WKB) Geometry Types.
#define WKB_MULTILINESTRING_TYPE
#define WKB_LINESTRING_TYPE
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static int lwpoint_to_twkb_buf(const LWPOINT *pt, TWKB_GLOBALS *globals, TWKB_STATE *ts)
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 uint8_t lwgeom_twkb_type(const LWGEOM *geom)
static int lwgeom_to_twkb_buf(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *ts)
static int ptarray_to_twkb_buf(const POINTARRAY *pa, TWKB_GLOBALS *globals, TWKB_STATE *ts, int register_npoints, uint32_t minpoints)
Stores a pointarray as varints in the buffer @register_npoints, controls whether an npoints entry is ...
static int lwline_to_twkb_buf(const LWLINE *line, TWKB_GLOBALS *globals, TWKB_STATE *ts)
static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWKB_STATE *parent_state)
static int lwpoly_to_twkb_buf(const LWPOLY *poly, TWKB_GLOBALS *globals, TWKB_STATE *ts)
static int lwmulti_to_twkb_buf(const LWCOLLECTION *col, 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.
static int lwcollection_to_twkb_buf(const LWCOLLECTION *col, TWKB_GLOBALS *globals, TWKB_STATE *ts)
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)
#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]
size_t varint_s64_encode_buf(int64_t val, uint8_t *buf)
size_t varint_u64_encode_buf(uint64_t val, uint8_t *buf)
uint8_t zigzag8(int8_t val)