37 static char *
hexchr =
"0123456789ABCDEF";
43 if ( ! bytes || ! size )
45 lwerror(
"hexbutes_from_bytes: invalid input");
50 for( i = 0; i < size; i++ )
53 hex[2*i] =
hexchr[bytes[i] >> 4];
55 hex[2*i+1] =
hexchr[bytes[i] & 0x0F];
134 lwerror(
"Unsupported geometry type: %s [%d]",
169 buf[1] = ((variant &
WKB_NDR) ?
'1' :
'0');
174 buf[0] = ((variant &
WKB_NDR) ? 1 : 0);
198 char *iptr = (
char*)(&ival);
205 LWDEBUGF(4,
"Writing value '%u'", ival);
212 int j = (swap ? WKB_INT_SIZE - 1 - i : i);
215 buf[2*i] =
hexchr[b >> 4];
217 buf[2*i+1] =
hexchr[b & 0x0F];
228 buf[i] = iptr[WKB_INT_SIZE - 1 - i];
245 char *dptr = (
char*)(&d);
259 int j = (swap ? WKB_DOUBLE_SIZE - 1 - i : i);
262 buf[2*i] =
hexchr[b >> 4];
264 buf[2*i+1] =
hexchr[b & 0x0F];
275 buf[i] = dptr[WKB_DOUBLE_SIZE - 1 - i];
333 static double nn =
NAN;
397 for ( i = 0; i < pa->
npoints; i++ )
399 LWDEBUGF(4,
"Writing point #%d", i);
401 for ( j = 0; j < dims; j++ )
403 LWDEBUGF(4,
"Writing dimension #%d (buf = %p)", j, buf);
408 LWDEBUGF(4,
"Done (buf = %p)", buf);
440 LWDEBUGF(4,
"Entering function, buf = %p", buf);
442 LWDEBUGF(4,
"Endian set, buf = %p", buf);
445 LWDEBUGF(4,
"Type set, buf = %p", buf);
450 LWDEBUGF(4,
"SRID set, buf = %p", buf);
454 LWDEBUGF(4,
"Pointarray set, buf = %p", buf);
561 for ( i = 0; i < poly->nrings; i++ )
588 for ( i = 0; i < poly->nrings; i++ )
612 for ( i = 0; i < col->ngeoms; i++ )
637 for ( i = 0; i < col->ngeoms; i++ )
661 switch ( geom->
type )
714 switch ( geom->
type )
771 if ( size_out ) *size_out = 0;
775 LWDEBUG(4,
"Cannot convert NULL into WKB.");
776 lwerror(
"Cannot convert NULL into WKB.");
782 LWDEBUGF(4,
"WKB output size: %d", buf_size);
786 LWDEBUG(4,
"Error calculating output WKB buffer size.");
787 lwerror(
"Error calculating output WKB buffer size.");
794 buf_size = 2 * buf_size + 1;
795 LWDEBUGF(4,
"Hex WKB output size: %d", buf_size);
800 (variant &
WKB_NDR && variant & WKB_XDR) )
813 LWDEBUGF(4,
"Unable to allocate %d bytes for WKB output buffer.", buf_size);
814 lwerror(
"Unable to allocate %d bytes for WKB output buffer.", buf_size);
825 if ( variant & WKB_HEX )
831 LWDEBUGF(4,
"buf (%p) - wkb_out (%p) = %d", buf, wkb_out, buf - wkb_out);
834 if ( buf_size != (buf - wkb_out) )
836 LWDEBUG(4,
"Output WKB is not the same size as the allocated buffer.");
837 lwerror(
"Output WKB is not the same size as the allocated buffer.");
843 if ( size_out ) *size_out = buf_size;
static uint8_t * empty_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant)
static int lwgeom_wkb_needs_srid(const LWGEOM *geom, uint8_t variant)
static size_t ptarray_to_wkb_size(const POINTARRAY *pa, uint8_t variant)
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
static uint8_t * lwline_to_wkb_buf(const LWLINE *line, uint8_t *buf, uint8_t variant)
static uint32_t lwgeom_wkb_type(const LWGEOM *geom, uint8_t variant)
static uint8_t * lwpoly_to_wkb_buf(const LWPOLY *poly, uint8_t *buf, uint8_t variant)
#define WKB_COMPOUNDCURVE_TYPE
#define WKB_POLYHEDRALSURFACE_TYPE
#define WKB_TRIANGLE_TYPE
#define WKB_MULTISURFACE_TYPE
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUG(level, msg)
static uint8_t * lwpoint_to_wkb_buf(const LWPOINT *pt, uint8_t *buf, uint8_t variant)
#define POLYHEDRALSURFACETYPE
#define WKB_MULTICURVE_TYPE
static uint8_t * integer_to_wkb_buf(const int ival, uint8_t *buf, uint8_t variant)
static size_t lwgeom_to_wkb_size(const LWGEOM *geom, uint8_t variant)
char * hexbytes_from_bytes(uint8_t *bytes, size_t size)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
static uint8_t * lwgeom_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant)
#define WKBZOFFSET
Flags applied in EWKB to indicate Z/M dimensions and presence/absence of SRID and bounding boxes...
#define LW_TRUE
Return types for functions with status returns.
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
#define WKB_POINT_TYPE
Well-Known Binary (WKB) Geometry Types.
static size_t lwpoly_to_wkb_size(const LWPOLY *poly, uint8_t variant)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
#define WKB_LINESTRING_TYPE
char getMachineEndian(void)
#define WKB_CIRCULARSTRING_TYPE
#define WKB_MULTIPOLYGON_TYPE
#define WKB_CURVEPOLYGON_TYPE
#define WKB_MULTILINESTRING_TYPE
static size_t empty_to_wkb_size(const LWGEOM *geom, uint8_t variant)
static int wkb_swap_bytes(uint8_t variant)
static size_t lwpoint_to_wkb_size(const LWPOINT *pt, uint8_t variant)
static uint8_t * lwcollection_to_wkb_buf(const LWCOLLECTION *col, uint8_t *buf, uint8_t variant)
static uint8_t * double_to_wkb_buf(const double d, uint8_t *buf, uint8_t variant)
static uint8_t * ptarray_to_wkb_buf(const POINTARRAY *pa, uint8_t *buf, uint8_t variant)
#define WKB_MULTIPOINT_TYPE
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_M(flags)
static uint8_t * endian_to_wkb_buf(uint8_t *buf, uint8_t variant)
void * lwalloc(size_t size)
static size_t lwcollection_to_wkb_size(const LWCOLLECTION *col, uint8_t variant)
static size_t lwtriangle_to_wkb_size(const LWTRIANGLE *tri, uint8_t variant)
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)
static size_t lwline_to_wkb_size(const LWLINE *line, uint8_t variant)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
#define WKB_GEOMETRYCOLLECTION_TYPE
static uint8_t * lwtriangle_to_wkb_buf(const LWTRIANGLE *tri, uint8_t *buf, uint8_t variant)