PCPATCH_UNCOMPRESSED * pc_patch_uncompressed_from_ght(const PCPATCH_GHT *paght) { #ifndef HAVE_LIBGHT pcerror("%s: libght support is not enabled", __func__); return NULL; #else int i, npoints; PCPATCH_UNCOMPRESSED *patch; PCPOINT point; const PCSCHEMA *schema; GhtNodeListPtr nodelist; GhtCoordinate coord; GhtNodePtr node; GhtTreePtr tree; GhtAttributePtr attr; /* Build a structured tree from the tree serialization */ if ( ! paght || ! paght->ght ) return NULL; tree = ght_tree_from_pc_patch(paght); if ( ! tree ) return NULL; /* Convert tree to nodelist */ ght_nodelist_new(paght->npoints, &nodelist); ght_tree_to_nodelist(tree, nodelist); /* Allocate uncompressed patch */ ght_nodelist_get_num_nodes(nodelist, &npoints); schema = paght->schema; patch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED)); patch->type = PC_NONE; patch->readonly = PC_FALSE; patch->schema = schema; patch->npoints = npoints; patch->bounds = paght->bounds; patch->stats = pc_stats_clone(paght->stats); patch->maxpoints = npoints; patch->datasize = schema->size * npoints; patch->data = pcalloc(patch->datasize); /* Set up utility point */ point.schema = schema; point.readonly = PC_FALSE; point.data = patch->data; /* Process each point... */ for ( i = 0; i < npoints; i++ ) { double val; /* Read and set X and Y */ ght_nodelist_get_node(nodelist, i, &node); ght_node_get_coordinate(node, &coord); pc_point_set_x(&point, coord.x); pc_point_set_y(&point, coord.y); /* Read and set all the attributes */ ght_node_get_attributes(node, &attr); while ( attr ) { GhtDimensionPtr dim; const char *name; ght_attribute_get_value(attr, &val); ght_attribute_get_dimension(attr, &dim); ght_dimension_get_name(dim, &name); pc_point_set_double_by_name(&point, name, val); ght_attribute_get_next(attr, &attr); } point.data += schema->size; } /* Done w/ nodelist and tree */ ght_nodelist_free_deep(nodelist); // ght_tree_free(tree); /* Done */ return patch; #endif }
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); }