Modifying many_points.rs
example to render elevation points
#84
-
I'm trying to render some elevation points, but I'm pretty sure I'm using the wrong coordinate system(s). The code below replaces the original fn generate_points() -> Vec<ColoredPoint> {
let fpath = Path::new("galileo/examples/data/N45E024.hgt");
// Hardcoded lat/lon to match the data in the file
let lat = 45.0;
let lon = 24.0;
// Distance in degrees between each elevation point
let res_inc = 1.0 / 3600.0;
// File contains 3601*3601 elevation values, 2 bytes each (i16)
const GRID_COUNT: usize = 3601;
const ELEVATION_VALUE_BYTE_COUNT: usize = 2;
let file = File::open(fpath).expect("Cannot read file.");
let mut data = Vec::new();
let byte_count = BufReader::new(file).read_to_end(&mut data).unwrap();
// GRID_COUNT columns, GRID_COUNT lines, and each elevation value is 2 bytes (big endian)
assert_eq!(
byte_count,
GRID_COUNT * GRID_COUNT * ELEVATION_VALUE_BYTE_COUNT
);
let points: Vec<ColoredPoint> = data
.iter()
.step_by(ELEVATION_VALUE_BYTE_COUNT)
.enumerate()
.zip(data[1..].iter().step_by(ELEVATION_VALUE_BYTE_COUNT))
.map(|((i, b0), b1)| {
let ei: i16 = (((*b0 as u16) << 8usize) | (*b1 as u16)) as i16;
let xi = i % GRID_COUNT;
let yi = i / GRID_COUNT;
let x = lat + (res_inc * (xi as f64));
let y = lon - (res_inc * (yi as f64));
let z = ei as f64;
// FIXME: this is definitely wrong
// let x = x * 20_000.0;
// let y = y * 20_000.0;
let red = z * (255 as f64) / 2600.0;
let red = red as u8;
let color = Color::rgba(red, 0, 0, 200);
ColoredPoint {
point: Point3d::new(x, y, z),
color,
}
})
.step_by(10)
.collect();
let highest_point = points
.iter()
.max_by(|p0, p1| p0.point.z().total_cmp(&p1.point.z()))
.unwrap();
log::info!("Generated {} points", points.len());
log::info!("First point: {}", &points[0].point);
log::info!("Highest point: {}", highest_point.point);
// [2024-09-01T16:54:31Z INFO elevation_points] Generated 1296721 points
// [2024-09-01T16:54:31Z INFO elevation_points] First point: {45, 24, 330}
// [2024-09-01T16:54:31Z INFO elevation_points] Highest point: {45.736111111111114, 24.4, 2516}
points
} When uncommenting the Do I need to create Not even sure this question makes sense, so any advice is much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hey, @BogdanOlar . At least you can see the mountains, that is already cool! :-) To project your points into correct coordinate system:
This will give you points in the right position of the world, but a couple things I would also check in your code:
Let me know if this helps. |
Beta Was this translation helpful? Give feedback.
-
Looks super cool! |
Beta Was this translation helpful? Give feedback.
Hey, @BogdanOlar . At least you can see the mountains, that is already cool! :-)
To project your points into correct coordinate system:
This will give you points in the right position of the …