38 static char *
hexchr =
"0123456789ABCDEF";
44 if ( ! bytes || ! size )
46 lwerror(
"hexbutes_from_bytes: invalid input");
51 for( i = 0; i < size; i++ )
54 hex[2*i] =
hexchr[bytes[i] >> 4];
56 hex[2*i+1] =
hexchr[bytes[i] & 0x0F];
85 uint32_t wkb_type = 0;
199 uint8_t *iptr = (uint8_t *)(&ival);
206 LWDEBUGF(4,
"Writing value '%u'", ival);
216 buf[2*i] =
hexchr[b >> 4];
218 buf[2*i+1] =
hexchr[b & 0x0F];
244 const uint8_t ndr_nan[
NAN_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f};
245 const uint8_t xdr_nan[
NAN_SIZE] = {0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
253 buf[2*i] =
hexchr[b >> 4];
255 buf[2*i + 1] =
hexchr[b & 0x0F];
274 uint8_t *dptr = (uint8_t *)(&d);
291 buf[2*i] =
hexchr[b >> 4];
293 buf[2*i+1] =
hexchr[b & 0x0F];
424 for ( i = 0; i < pa->
npoints; i++ )
426 LWDEBUGF(4,
"Writing point #%d", i);
428 for ( j = 0; j < dims; j++ )
430 LWDEBUGF(4,
"Writing dimension #%d (buf = %p)", j, buf);
435 LWDEBUGF(4,
"Done (buf = %p)", buf);
467 LWDEBUGF(4,
"Entering function, buf = %p", buf);
469 LWDEBUGF(4,
"Endian set, buf = %p", buf);
472 LWDEBUGF(4,
"Type set, buf = %p", buf);
477 LWDEBUGF(4,
"SRID set, buf = %p", buf);
481 LWDEBUGF(4,
"Pointarray set, buf = %p", buf);
588 for ( i = 0; i < poly->
nrings; i++ )
615 for ( i = 0; i < poly->
nrings; i++ )
639 for ( i = 0; i < col->
ngeoms; i++ )
664 for ( i = 0; i < col->
ngeoms; i++ )
682 LWDEBUG(4,
"Cannot convert NULL into WKB.");
683 lwerror(
"Cannot convert NULL into WKB.");
693 switch ( geom->
type )
746 switch ( geom->
type )
811 return written_bytes;
821 b_size = 2 * b_size + 1;
828 buffer[written_size] =
'\0';
832 if (written_size != (ptrdiff_t)b_size)
835 lwerror(
"Output WKB is not the same size as the allocated buffer. Variant: %u, Geom: %s",
variant, wkt);
862 if (written_size != (ptrdiff_t)b_size)
865 lwerror(
"Output WKB is not the same size as the allocated buffer. Variant: %u, Geom: %s",
variant, wkt);
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)
#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)
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
#define LWSIZE_SET(varsize, len)
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
#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 uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
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 uint8_t * double_nan_to_wkb_buf(uint8_t *buf, uint8_t variant)
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)
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
uint8_t * lwgeom_to_wkb_buffer(const LWGEOM *geom, uint8_t variant)
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)
static size_t empty_to_wkb_size(const LWGEOM *geom, uint8_t variant)
static uint8_t * integer_to_wkb_buf(const uint32_t ival, uint8_t *buf, uint8_t variant)
static size_t lwpoly_to_wkb_size(const LWPOLY *poly, uint8_t variant)
lwvarlena_t * lwgeom_to_hexwkb_varlena(const LWGEOM *geom, 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 ptrdiff_t lwgeom_to_wkb_write_buf(const LWGEOM *geom, uint8_t variant, uint8_t *buffer)
Convert LWGEOM to a char* in WKB format.
lwvarlena_t * lwgeom_to_wkb_varlena(const LWGEOM *geom, 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)
Datum buffer(PG_FUNCTION_ARGS)