static void test_point_xyzm() { PCPOINT *pt; double x = 1; double y = 40; double z = 160; double m = 640; double d; pt = pc_point_make(schema_xyz); CU_ASSERT_PTR_NOT_NULL( pt ); CU_ASSERT_SUCCESS(pc_point_set_x(pt, x)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "X", &d)); CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_x(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001); CU_ASSERT_SUCCESS(pc_point_set_y(pt, y)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Y", &d)); CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_y(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001); CU_ASSERT_SUCCESS(pc_point_set_z(pt, z)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Z", &d)); CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_z(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001); CU_ASSERT_FAILURE(pc_point_set_m(pt, m)); CU_ASSERT_FAILURE(pc_point_get_double_by_name(pt, "M", &d)); CU_ASSERT_FAILURE(pc_point_get_m(pt, &d)); pc_point_free(pt); pt = pc_point_make(schema_xyzm); CU_ASSERT_PTR_NOT_NULL( pt ); CU_ASSERT_SUCCESS(pc_point_set_x(pt, x)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "X", &d)); CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_x(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001); CU_ASSERT_SUCCESS(pc_point_set_y(pt, y)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Y", &d)); CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_y(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001); CU_ASSERT_SUCCESS(pc_point_set_z(pt, z)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Z", &d)); CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_z(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001); CU_ASSERT_SUCCESS(pc_point_set_m(pt, m)); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "M", &d)); CU_ASSERT_DOUBLE_EQUAL(d, m, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_m(pt, &d)); CU_ASSERT_DOUBLE_EQUAL(d, m, 0.000001); pc_point_free(pt); }
uint8_t * pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize) { static uint32_t srid_mask = 0x20000000; static uint32_t m_mask = 0x40000000; static uint32_t z_mask = 0x80000000; uint32_t wkbtype = 1; /* WKB POINT */ size_t size = 1 + 4 + 8 + 8; /* endian + type + dblX, + dblY */ uint8_t *wkb, *ptr; uint32_t srid = pt->schema->srid; double x, y, z, m; int has_x = pc_point_get_x(pt, &x) == PC_SUCCESS; int has_y = pc_point_get_y(pt, &y) == PC_SUCCESS; int has_z = pc_point_get_z(pt, &z) == PC_SUCCESS; int has_m = pc_point_get_m(pt, &m) == PC_SUCCESS; if ( ! ( has_x && has_y ) ) return NULL; if ( srid ) { wkbtype |= srid_mask; size += 4; } if ( has_z ) { wkbtype |= z_mask; size += 8; } if ( has_m ) { wkbtype |= m_mask; size += 8; } wkb = pcalloc(size); ptr = wkb; ptr[0] = machine_endian(); /* Endian flag */ ptr += 1; memcpy(ptr, &wkbtype, 4); /* WKB type */ ptr += 4; if ( srid != 0 ) { memcpy(ptr, &srid, 4); /* SRID */ ptr += 4; } memcpy(ptr, &x, 8); /* X */ ptr += 8; memcpy(ptr, &y, 8); /* Y */ ptr += 8; if ( has_z ) { memcpy(ptr, &z, 8); /* Z */ ptr += 8; } if ( has_m ) { memcpy(ptr, &m, 8); /* M */ ptr += 8; } if ( wkbsize ) *wkbsize = size; return wkb; }