26 #include "../postgis_config.h" 62 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
63 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
64 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
66 0,1,2,3,4,5,6,7,8,9,20,20,20,20,20,20,
68 20,10,11,12,13,14,15,20,20,20,20,20,20,20,20,20,
70 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
72 20,10,11,12,13,14,15,20,20,20,20,20,20,20,20,20,
73 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
75 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
76 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
77 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
78 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
79 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
80 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
81 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
82 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20
93 lwerror(
"Invalid hex string, length (%d) has to be a multiple of two!", hexsize);
98 lwerror(
"Unable to allocate memory buffer.");
100 for( i = 0; i < hexsize/2; i++ )
105 lwerror(
"Invalid hex character (%c) encountered", hexbuf[2*i]);
107 lwerror(
"Invalid hex character (%c) encountered", hexbuf[2*i+1]);
109 buf[i] = ((h1 & 0x0F) << 4) | (h2 & 0x0F);
128 lwerror(
"WKB structure does not match expected size!");
140 LWDEBUG(4,
"Entered function");
147 if( wkb_type & 0xF0000000 )
156 wkb_type = wkb_type & 0x0FFFFFFF;
158 wkb_simple_type = wkb_type % 1000;
161 if( wkb_type >= 3000 && wkb_type < 4000 )
166 else if ( wkb_type >= 2000 && wkb_type < 3000 )
170 else if ( wkb_type >= 1000 && wkb_type < 2000 )
175 switch (wkb_simple_type)
235 lwerror(
"Unknown WKB type (%d)! Full WKB type number was (%d).", wkb_simple_type, wkb_type);
251 LWDEBUG(4,
"Entered function");
254 LWDEBUG(4,
"Passed state check");
256 char_value = s->
pos[0];
257 LWDEBUGF(4,
"Read byte value: %x", char_value);
339 if (npoints > maxpoints)
341 lwerror(
"point array length (%d) is too large");
344 LWDEBUGF(4,
"Pointarray has %d points", npoints);
346 if( s->
has_z ) ndims++;
347 if( s->
has_m ) ndims++;
370 for( i = 0; i < npoints * ndims; i++ )
397 if( s->
has_z ) ndims++;
398 if( s->
has_m ) ndims++;
417 for( i = 0; i < ndims; i++ )
425 if ( isnan(pt->
x) && isnan(pt->
y) )
448 if( pa == NULL || pa->
npoints == 0 )
476 if( pa == NULL || pa->
npoints == 0 )
508 LWDEBUGF(4,
"Polygon has %d rings", nrings);
514 for( i = 0; i < nrings; i++ )
539 LWDEBUG(2,
"Unable to add ring to polygon");
540 lwerror(
"Unable to add ring to polygon");
567 lwerror(
"Triangle has wrong number of rings: %d", nrings);
612 for ( i = 0; i < ngeoms; i++ )
619 lwerror(
"Unable to add geometry (%p) to curvepoly (%p)", geom, cp);
643 LWDEBUGF(4,
"Collection has %d components", ngeoms);
653 for ( i = 0; i < ngeoms; i++ )
660 lwerror(
"Unable to add geometry (%p) to collection (%p)", geom, col);
678 char wkb_little_endian;
685 if( wkb_little_endian != 1 && wkb_little_endian != 0 )
687 LWDEBUG(4,
"Leaving due to bad first byte!");
688 lwerror(
"Invalid endian flag value encountered.");
696 if ( ! wkb_little_endian )
701 if ( wkb_little_endian )
707 LWDEBUGF(4,
"Got WKB type number: 0x%X", wkb_type);
805 lwerror(
"lwgeom_from_hexwkb: null input");
809 hexwkb_len = strlen(hexwkb);
static POINTARRAY * ptarray_from_wkb_state(wkb_parse_state *s)
POINTARRAY Read a dynamically sized point array and advance the parse state forward.
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
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...
static void lwtype_from_wkb_state(wkb_parse_state *s, uint32_t wkb_type)
Take in an unknown kind of wkb type number and ensure it comes out as an extended WKB type number (wi...
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
static LWTRIANGLE * lwtriangle_from_wkb_state(wkb_parse_state *s)
TRIANGLE Read a WKB triangle, starting just after the endian byte, type number and optional srid numb...
uint8_t * serialized_pointlist
static LWCURVEPOLY * lwcurvepoly_from_wkb_state(wkb_parse_state *s)
CURVEPOLYTYPE.
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
static char byte_from_wkb_state(wkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
static LWCOLLECTION * lwcollection_from_wkb_state(wkb_parse_state *s)
POLYHEDRALSURFACETYPE.
static uint32_t integer_from_wkb_state(wkb_parse_state *s)
Int32 Read 4-byte integer and advance the parse state forward.
uint8_t * bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
#define WKB_COMPOUNDCURVE_TYPE
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
#define WKB_POLYHEDRALSURFACE_TYPE
#define WKB_TRIANGLE_TYPE
void lwgeom_free(LWGEOM *geom)
void ptarray_free(POINTARRAY *pa)
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
#define WKB_MULTISURFACE_TYPE
int ptarray_is_closed_z(const POINTARRAY *pa)
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUG(level, msg)
#define POLYHEDRALSURFACETYPE
static LWPOLY * lwpoly_from_wkb_state(wkb_parse_state *s)
POLYGON Read a WKB polygon, starting just after the endian byte, type number and optional srid number...
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
#define WKB_MULTICURVE_TYPE
int ptarray_is_closed_2d(const POINTARRAY *pa)
#define LW_PARSER_CHECK_NONE
#define LW_PARSER_CHECK_ZCLOSURE
#define LW_PARSER_CHECK_ODD
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
static LWCIRCSTRING * lwcircstring_from_wkb_state(wkb_parse_state *s)
CIRCULARSTRING Read a WKB circularstring, starting just after the endian byte, type number and option...
#define WKBZOFFSET
Flags applied in EWKB to indicate Z/M dimensions and presence/absence of SRID and bounding boxes...
LWCIRCSTRING * lwcircstring_construct_empty(int srid, char hasz, char hasm)
static uint8_t hex2char[256]
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
#define LW_TRUE
Return types for functions with status returns.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
POINTARRAY * ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist)
Construct a new POINTARRAY, copying in the data from ptlist.
LWCURVEPOLY * lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
static void wkb_parse_state_check(wkb_parse_state *s, size_t next)
Check that we are not about to read off the end of the WKB array.
#define WKB_POINT_TYPE
Well-Known Binary (WKB) Geometry Types.
#define WKB_LINESTRING_TYPE
char getMachineEndian(void)
#define WKB_CIRCULARSTRING_TYPE
#define WKB_MULTIPOLYGON_TYPE
#define WKB_CURVEPOLYGON_TYPE
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define WKB_MULTILINESTRING_TYPE
LWGEOM * lwgeom_from_wkb_state(wkb_parse_state *s)
Internal function declarations.
Used for passing the parse state between the parsing functions.
#define WKB_MULTIPOINT_TYPE
static LWLINE * lwline_from_wkb_state(wkb_parse_state *s)
LINESTRING Read a WKB linestring, starting just after the endian byte, type number and optional srid ...
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
#define LWDEBUGF(level, msg,...)
static LWPOINT * lwpoint_from_wkb_state(wkb_parse_state *s)
POINT Read a WKB point, starting just after the endian byte, type number and optional srid number...
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
static double double_from_wkb_state(wkb_parse_state *s)
Double Read an 8-byte double and advance the parse state forward.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
#define LW_PARSER_CHECK_CLOSURE
#define WKB_GEOMETRYCOLLECTION_TYPE