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]",
198 char *iptr = (
char*)(&ival);
205 LWDEBUGF(4,
"Writing value '%u'", ival);
215 buf[2*i] =
hexchr[b >> 4];
217 buf[2*i+1] =
hexchr[b & 0x0F];
245 char *dptr = (
char*)(&d);
262 buf[2*i] =
hexchr[b >> 4];
264 buf[2*i+1] =
hexchr[b & 0x0F];
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);
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);
831 LWDEBUGF(4,
"buf (%p) - wkb_out (%p) = %d", buf, wkb_out, buf - wkb_out);
834 if ( buf_size != (
size_t) (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;
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
#define FLAGS_NDIMS(flags)
#define POLYHEDRALSURFACETYPE
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
void * lwalloc(size_t size)
#define LW_TRUE
Return types for functions with status returns.
#define WKBZOFFSET
Flags applied in EWKB to indicate Z/M dimensions and presence/absence of SRID and bounding boxes.
#define WKB_COMPOUNDCURVE_TYPE
#define WKB_POLYHEDRALSURFACE_TYPE
#define WKB_GEOMETRYCOLLECTION_TYPE
#define WKB_TRIANGLE_TYPE
char getMachineEndian(void)
#define WKB_MULTIPOLYGON_TYPE
#define WKB_MULTIPOINT_TYPE
#define WKB_MULTISURFACE_TYPE
#define WKB_CURVEPOLYGON_TYPE
#define WKB_POINT_TYPE
Well-Known Binary (WKB) Geometry Types.
#define WKB_MULTICURVE_TYPE
#define WKB_MULTILINESTRING_TYPE
#define WKB_LINESTRING_TYPE
#define WKB_CIRCULARSTRING_TYPE
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static size_t lwcollection_to_wkb_size(const LWCOLLECTION *col, uint8_t variant)
static size_t lwgeom_to_wkb_size(const LWGEOM *geom, uint8_t variant)
static uint8_t * ptarray_to_wkb_buf(const POINTARRAY *pa, uint8_t *buf, uint8_t variant)
static uint8_t * lwpoint_to_wkb_buf(const LWPOINT *pt, uint8_t *buf, uint8_t variant)
char * hexbytes_from_bytes(const uint8_t *bytes, size_t size)
static int lwgeom_wkb_needs_srid(const LWGEOM *geom, uint8_t variant)
static uint8_t * endian_to_wkb_buf(uint8_t *buf, uint8_t variant)
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
static uint8_t * lwtriangle_to_wkb_buf(const LWTRIANGLE *tri, uint8_t *buf, uint8_t variant)
static uint32_t lwgeom_wkb_type(const LWGEOM *geom, uint8_t variant)
static size_t ptarray_to_wkb_size(const POINTARRAY *pa, uint8_t variant)
static size_t lwtriangle_to_wkb_size(const LWTRIANGLE *tri, uint8_t variant)
static uint8_t * empty_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant)
static uint8_t * lwgeom_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant)
static uint8_t * double_to_wkb_buf(const double d, uint8_t *buf, uint8_t variant)
static size_t lwpoint_to_wkb_size(const LWPOINT *pt, uint8_t variant)
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
static size_t empty_to_wkb_size(const LWGEOM *geom, uint8_t variant)
static uint8_t * integer_to_wkb_buf(const int ival, uint8_t *buf, uint8_t variant)
static size_t lwpoly_to_wkb_size(const LWPOLY *poly, uint8_t variant)
static size_t lwline_to_wkb_size(const LWLINE *line, uint8_t variant)
static int wkb_swap_bytes(uint8_t variant)
static uint8_t * lwpoly_to_wkb_buf(const LWPOLY *poly, uint8_t *buf, uint8_t variant)
static uint8_t * lwline_to_wkb_buf(const LWLINE *line, uint8_t *buf, uint8_t variant)
static uint8_t * lwcollection_to_wkb_buf(const LWCOLLECTION *col, uint8_t *buf, uint8_t variant)