31 #define TWKB_IN_MAXCOORDS 4
84 if( (
s->pos + next) >
s->twkb_end)
86 lwerror(
"%s: TWKB structure does not match expected size!", __func__);
122 lwerror(
"%s: no varint to skip", __func__);
179 LWDEBUG(2,
"Entering ptarray_from_twkb_state");
180 LWDEBUGF(4,
"Pointarray has %d points", npoints);
188 for( i = 0; i < npoints; i++ )
193 dlist[ndims*i + j] =
s->coords[j] /
s->factor;
197 dlist[ndims*i + j] =
s->coords[j] /
s->factor;
203 dlist[ndims*i + j] =
s->coords[j] /
s->factor_z;
210 dlist[ndims*i + j] =
s->coords[j] /
s->factor_m;
226 LWDEBUG(2,
"Entering lwpoint_from_twkb_state");
243 LWDEBUG(2,
"Entering lwline_from_twkb_state");
278 LWDEBUG(2,
"Entering lwpoly_from_twkb_state");
289 LWDEBUGF(4,
"Polygon has %d rings", nrings);
295 for( i = 0; i < nrings; i++ )
324 LWDEBUG(2,
"Unable to add ring to polygon");
325 lwerror(
"Unable to add ring to polygon");
342 LWDEBUG(2,
"Entering lwmultipoint_from_twkb_state");
349 LWDEBUGF(4,
"Number of geometries %d", ngeoms);
354 for ( i = 0; i < ngeoms; i++ )
358 for ( i = 0; i < ngeoms; i++ )
363 lwerror(
"Unable to add geometry (%p) to collection (%p)", geom, col);
380 LWDEBUG(2,
"Entering lwmultilinestring_from_twkb_state");
388 LWDEBUGF(4,
"Number of geometries %d",ngeoms);
393 for ( i = 0; i < ngeoms; i++ )
397 for ( i = 0; i < ngeoms; i++ )
402 lwerror(
"Unable to add geometry (%p) to collection (%p)", geom, col);
419 LWDEBUG(2,
"Entering lwmultipolygon_from_twkb_state");
426 LWDEBUGF(4,
"Number of geometries %d",ngeoms);
431 for ( i = 0; i < ngeoms; i++ )
435 for ( i = 0; i < ngeoms; i++ )
440 lwerror(
"Unable to add geometry (%p) to collection (%p)", geom, col);
458 LWDEBUG(2,
"Entering lwcollection_from_twkb_state");
466 LWDEBUGF(4,
"Number of geometries %d",ngeoms);
471 for ( i = 0; i < ngeoms; i++ )
475 for ( i = 0; i < ngeoms; i++ )
480 lwerror(
"Unable to add geometry (%p) to collection (%p)", geom, col);
492 LWDEBUG(2,
"Entering magicbyte_from_twkb_state");
511 s->has_bbox = metadata & 0x01;
512 s->has_size = (metadata & 0x02) >> 1;
513 s->has_idlist = (metadata & 0x04) >> 2;
514 extended_dims = (metadata & 0x08) >> 3;
515 s->is_empty = (metadata & 0x10) >> 4;
520 int8_t precision_z, precision_m;
525 s->has_z = (extended_dims & 0x01);
526 s->has_m = (extended_dims & 0x02) >> 1;
527 precision_z = (extended_dims & 0x1C) >> 2;
528 precision_m = (extended_dims & 0xE0) >> 5;
531 s->factor_z = pow(10, (
double)precision_z);
532 s->factor_m = pow(10, (
double)precision_m);
549 s->ndims = 2 +
s->has_z +
s->has_m;
584 has_bbox =
s->has_bbox;
585 memset(&bbox, 0,
sizeof(
GBOX));
661 LWDEBUG(2,
"Entering lwgeom_from_twkb");
662 LWDEBUGF(4,
"twkb_size: %d",(
int) twkb_size);
668 s.twkb =
s.pos = twkb;
669 s.twkb_end = twkb + twkb_size;
GBOX * gbox_clone(const GBOX *gbox)
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
int ptarray_is_closed_2d(const POINTARRAY *pa)
#define SRID_UNKNOWN
Unknown SRID value.
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static LWCOLLECTION * lwmultipoly_from_twkb_state(twkb_parse_state *s)
MULTIPOLYGON.
#define TWKB_IN_MAXCOORDS
LWGEOM * lwgeom_from_twkb(const uint8_t *twkb, size_t twkb_size, char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
static double twkb_parse_state_double(twkb_parse_state *s, double factor)
static void twkb_parse_state_varint_skip(twkb_parse_state *s)
static POINTARRAY * ptarray_from_twkb_state(twkb_parse_state *s, uint32_t npoints)
POINTARRAY Read a dynamically sized point array and advance the parse state forward.
static void header_from_twkb_state(twkb_parse_state *s)
LWGEOM * lwgeom_from_twkb_state(twkb_parse_state *s)
Internal function declarations.
static int64_t twkb_parse_state_varint(twkb_parse_state *s)
static uint8_t byte_from_twkb_state(twkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
static LWPOLY * lwpoly_from_twkb_state(twkb_parse_state *s)
POLYGON.
static LWCOLLECTION * lwmultiline_from_twkb_state(twkb_parse_state *s)
MULTILINESTRING.
static uint32_t lwtype_from_twkb_type(uint8_t twkb_type)
static LWCOLLECTION * lwmultipoint_from_twkb_state(twkb_parse_state *s)
MULTIPOINT.
static LWCOLLECTION * lwcollection_from_twkb_state(twkb_parse_state *s)
COLLECTION, MULTIPOINTTYPE, MULTILINETYPE, MULTIPOLYGONTYPE.
static LWPOINT * lwpoint_from_twkb_state(twkb_parse_state *s)
POINT.
static uint64_t twkb_parse_state_uvarint(twkb_parse_state *s)
static void twkb_parse_state_advance(twkb_parse_state *s, size_t next)
Check that we are not about to read off the end of the WKB array.
static LWLINE * lwline_from_twkb_state(twkb_parse_state *s)
LINESTRING.
uint8_t * serialized_pointlist
Used for passing the parse state between the parsing functions.
size_t varint_size(const uint8_t *the_start, const uint8_t *the_end)
int8_t unzigzag8(uint8_t val)
int64_t varint_s64_decode(const uint8_t *the_start, const uint8_t *the_end, size_t *size)
uint64_t varint_u64_decode(const uint8_t *the_start, const uint8_t *the_end, size_t *size)