CU_ASSERT_STRING_EQUAL(s,"00A000000400000004000000050080000001000000000000000000000000000000000000000000000000008000000100000000000000003FF0000000000000000000000000000000800000013FF00000000000003FF0000000000000000000000000000000800000013FF0000000000000000000000000000000000000000000000080000001000000000000000000000000000000000000000000000000");
cu_wkb("MULTIPOINT(0 0 0, 0.26794919243112270647255365849413 1 3)");
- //printf("WKB: %s",s);
CU_ASSERT_STRING_EQUAL(s,"008000000400000002008000000100000000000000000000000000000000000000000000000000800000013FD126145E9ECD563FF00000000000004008000000000000");
+
+ cu_wkb("MULTIPOINT EMPTY");
+ CU_ASSERT_STRING_EQUAL(s,"000000000400000000");
}
static void test_wkb_out_multilinestring(void) {}
{
cu_wkb("SRID=14;MULTIPOLYGON(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((-1 -1 0,-1 2 0,2 2 0,2 -1 0,-1 -1 0),(0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))");
CU_ASSERT_STRING_EQUAL(s,"00A00000060000000E000000020080000003000000010000000500000000000000000000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF00000000000003FF000000000000000000000000000003FF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000030000000200000005BFF0000000000000BFF00000000000000000000000000000BFF0000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000BFF00000000000000000000000000000BFF0000000000000BFF000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF00000000000003FF000000000000000000000000000003FF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
+
+ cu_wkb("MULTIPOLYGON EMPTY");
+ CU_ASSERT_STRING_EQUAL(s,"000000000600000000");
}
static void test_wkb_out_collection(void)
cu_wkb("GEOMETRYCOLLECTION EMPTY");
CU_ASSERT_STRING_EQUAL(s,"000000000700000000");
+
+ cu_wkb("GEOMETRYCOLLECTION(LINESTRING EMPTY)");
+ CU_ASSERT_STRING_EQUAL(s,"000000000700000001000000000200000000");
+
+ cu_wkb("GEOMETRYCOLLECTION(LINESTRING EMPTY, MULTILINESTRING(EMPTY,EMPTY))");
+ // printf("%s\n",s );
+ CU_ASSERT_STRING_EQUAL(s,"000000000700000002000000000200000000000000000500000002000000000200000000000000000200000000");
}
static void test_wkb_out_circularstring(void)
/* Bulk copy the coordinates when: dimensionality matches, output format */
/* is not hex, and output endian matches internal endian. */
- if ( (dims == pa_dims) && ! wkb_swap_bytes(variant) && ! (variant & WKB_HEX) )
+ if ( pa->npoints && (dims == pa_dims) && ! wkb_swap_bytes(variant) && ! (variant & WKB_HEX) )
{
size_t size = pa->npoints * dims * WKB_DOUBLE_SIZE;
memcpy(buf, getPoint_internal(pa, 0), size);
/* Endian flag + type number */
size_t size = WKB_BYTE_SIZE + WKB_INT_SIZE;
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)pt) )
+ return empty_to_wkb_size((LWGEOM*)pt, variant);
+
/* Extended WKB needs space for optional SRID integer */
if ( lwgeom_wkb_needs_srid((LWGEOM*)pt, variant) )
size += WKB_INT_SIZE;
static uint8_t* lwpoint_to_wkb_buf(const LWPOINT *pt, uint8_t *buf, uint8_t variant)
{
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)pt) )
+ return empty_to_wkb_buf((LWGEOM*)pt, buf, variant);
+
/* Set the endian flag */
LWDEBUGF(4, "Entering function, buf = %p", buf);
buf = endian_to_wkb_buf(buf, variant);
/* Endian flag + type number */
size_t size = WKB_BYTE_SIZE + WKB_INT_SIZE;
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)line) )
+ return empty_to_wkb_size((LWGEOM*)line, variant);
+
/* Extended WKB needs space for optional SRID integer */
if ( lwgeom_wkb_needs_srid((LWGEOM*)line, variant) )
size += WKB_INT_SIZE;
static uint8_t* lwline_to_wkb_buf(const LWLINE *line, uint8_t *buf, uint8_t variant)
{
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)line) )
+ return empty_to_wkb_buf((LWGEOM*)line, buf, variant);
+
/* Set the endian flag */
buf = endian_to_wkb_buf(buf, variant);
/* Set the geometry type */
/* endian flag + type number + number of rings */
size_t size = WKB_BYTE_SIZE + WKB_INT_SIZE + WKB_INT_SIZE;
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)tri) )
+ return empty_to_wkb_size((LWGEOM*)tri, variant);
+
/* Extended WKB needs space for optional SRID integer */
if ( lwgeom_wkb_needs_srid((LWGEOM*)tri, variant) )
size += WKB_INT_SIZE;
static uint8_t* lwtriangle_to_wkb_buf(const LWTRIANGLE *tri, uint8_t *buf, uint8_t variant)
{
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)tri) )
+ return empty_to_wkb_buf((LWGEOM*)tri, buf, variant);
+
/* Set the endian flag */
buf = endian_to_wkb_buf(buf, variant);
/* endian flag + type number + number of rings */
size_t size = WKB_BYTE_SIZE + WKB_INT_SIZE + WKB_INT_SIZE;
int i = 0;
+
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)poly) )
+ return empty_to_wkb_size((LWGEOM*)poly, variant);
/* Extended WKB needs space for optional SRID integer */
if ( lwgeom_wkb_needs_srid((LWGEOM*)poly, variant) )
{
int i;
+ /* Only process empty at this level in the EXTENDED case */
+ if ( (variant & WKB_EXTENDED) && lwgeom_is_empty((LWGEOM*)poly) )
+ return empty_to_wkb_buf((LWGEOM*)poly, buf, variant);
+
/* Set the endian flag */
buf = endian_to_wkb_buf(buf, variant);
/* Set the geometry type */
return 0;
/* Short circuit out empty geometries */
- if ( lwgeom_is_empty(geom) )
+ if ( (!(variant & WKB_EXTENDED)) && lwgeom_is_empty(geom) )
{
return empty_to_wkb_size(geom, variant);
}
static uint8_t* lwgeom_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant)
{
- if ( lwgeom_is_empty(geom) )
+ /* Do not simplify empties when outputting to canonical form */
+ if ( lwgeom_is_empty(geom) & ! (variant & WKB_EXTENDED) )
return empty_to_wkb_buf(geom, buf, variant);
switch ( geom->type )