/* * Can we read this example point value? */ static void test_schema_xy() { /* "Intensity", "ReturnNumber", "NumberOfReturns", "ScanDirectionFlag", "EdgeOfFlightLine", "Classification", "ScanAngleRank", "UserData", "PointSourceId", "Time", "Red", "Green", "Blue", "PointID", "BlockID", "X", "Y", "Z" 25, 1, 1, 1, 0, 1, 6, 124, 7327, 246093, 39, 57, 56, 20, 0, -125.0417204, 49.2540081, 128.85 */ static char *hexpt = "01010000000AE9C90307A1100522A5000019000101010001067C9F1C4953C474650A0E412700390038001400000000000000876B6601962F750155320000"; uint8_t *bytes = bytes_from_hexbytes(hexpt, strlen(hexpt)); PCPOINT *pt; double val; pt = pc_point_from_wkb(lasschema, bytes, strlen(hexpt)/2); pc_point_get_double_by_name(pt, "x", &val); CU_ASSERT_DOUBLE_EQUAL(val, -125.0417204, 0.00001); pc_point_free(pt); pt = pc_point_from_wkb(lasschema, bytes, strlen(hexpt)/2); pc_point_get_double_by_name(pt, "y", &val); CU_ASSERT_DOUBLE_EQUAL(val, 49.2540081, 0.00001); pc_point_free(pt); pcfree(bytes); }
void test_point_geometry_bytes(const PCSCHEMA *s, size_t expectedgeomwkbsize, const char *pthexbytes, const char *expectedgeomhexbytes) { /* point byte: endianness (1 = NDR, 0 = XDR) uint32: pcid (key to POINTCLOUD_SCHEMAS) uchar[]: data (interpret relative to pcid) */ /* geometry byte: endianness (1 = NDR, 0 = XDR) uint32: point type (XYZ=01000080, XYM=01000040, XY=01000000, XYZM=010000C0) double[]: XY(Z?)(M?) coordinates */ PCPOINT *pt; uint8_t *ptwkb, *geomwkb; char *geomhexbytes; size_t pthexsize, geomwkbsize; pthexsize = strlen(pthexbytes); ptwkb = pc_bytes_from_hexbytes(pthexbytes, pthexsize); pt = pc_point_from_wkb(s, ptwkb, pthexsize/2); CU_ASSERT_PTR_NOT_NULL(pt); geomwkb = pc_point_to_geometry_wkb(pt, &geomwkbsize); CU_ASSERT_EQUAL(geomwkbsize,expectedgeomwkbsize); geomhexbytes = pc_hexbytes_from_bytes(geomwkb,geomwkbsize); CU_ASSERT_STRING_EQUAL(geomhexbytes, expectedgeomhexbytes); pcfree(geomhexbytes); pcfree(geomwkb); pc_point_free(pt); pcfree(ptwkb); }
static void test_point_hex_inout() { // byte: endianness (1 = NDR, 0 = XDR) // uint32: pcid (key to POINTCLOUD_SCHEMAS) // uchar[]: pointdata (interpret relative to pcid) double d; char *hexbuf = "00000000010000000100000002000000030004"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = pc_bytes_from_hexbytes(hexbuf, hexsize); PCPOINT *pt = pc_point_from_wkb(schema, wkb, hexsize/2); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "X", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 0.01, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Y", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 0.02, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Z", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 0.03, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Intensity", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 4, 0.0001); CU_ASSERT_FAILURE(pc_point_get_double_by_name(pt, "M", &d)); pc_point_free(pt); pcfree(wkb); hexbuf = "01010000000100000002000000030000000500"; hexsize = strlen(hexbuf); wkb = pc_bytes_from_hexbytes(hexbuf, hexsize); pt = pc_point_from_wkb(schema, wkb, hexsize/2); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "X", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 0.01, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Y", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 0.02, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Z", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 0.03, 0.000001); CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Intensity", &d)); CU_ASSERT_DOUBLE_EQUAL(d, 5, 0.0001); CU_ASSERT_FAILURE(pc_point_get_double_by_name(pt, "M", &d)); pc_point_free(pt); pcfree(wkb); }
PCPOINT * pc_point_from_hexwkb(const char *hexwkb, size_t hexlen, FunctionCallInfoData *fcinfo) { PCPOINT *pt; PCSCHEMA *schema; uint32 pcid; uint8 *wkb = bytes_from_hexbytes(hexwkb, hexlen); size_t wkblen = hexlen/2; pcid = wkb_get_pcid(wkb); schema = pc_schema_from_pcid(pcid, fcinfo); pt = pc_point_from_wkb(schema, wkb, wkblen); pfree(wkb); return pt; }