Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
```
# Compiled and build artifacts
*.pyc
__pycache__/
Expand Down Expand Up @@ -68,4 +67,6 @@ htmlcov/
*.tar.bz2
*.tar.xz
*.tar.zst
```

# Rust backup files
**/*.rs.bk
22 changes: 14 additions & 8 deletions src/elevation/providers/copernicus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ impl ElevationProvider for CopernicusDem30 {
grid_height: usize,
) -> Result<RawElevationGrid, Box<dyn std::error::Error>> {
use reqwest::blocking::Client;
use std::time::Duration;
use tiff::decoder::Decoder;
use std::io::Cursor;
use std::time::Duration;
use tiff::decoder::{Decoder, DecodingResult};

let client = Client::builder()
.timeout(Duration::from_secs(120))
Expand Down Expand Up @@ -145,12 +145,18 @@ impl ElevationProvider for CopernicusDem30 {
let height = decoder.dimensions()?.1 as usize;
tile_dims.insert((lat, lng), (width, height));

// Read the image data - Copernicus DEM uses 32-bit float
let mut buf = vec![0.0f32; width * height];
decoder.read_f32_into(&mut buf)?;

// Convert to f64 and store
let heights: Vec<f64> = buf.into_iter().map(|v| v as f64).collect();
// Read the image data - Copernicus DEM uses 32-bit float.
let heights: Vec<f64> = match decoder.read_image()? {
DecodingResult::F32(values) => values.into_iter().map(f64::from).collect(),
DecodingResult::F64(values) => values,
other => {
return Err(format!(
"Unsupported Copernicus DEM sample format: {:?}",
other
)
.into());
}
};
tile_data.insert((lat, lng), heights);
}

Expand Down
20 changes: 16 additions & 4 deletions src/overture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ fn overlaps_with_grid(
bboxes: &[(i32, i32, i32, i32)],
grid_min_x: i32,
grid_min_z: i32,
cell_size: i32,
) -> bool {
if way.nodes.is_empty() {
return false;
Expand Down Expand Up @@ -1122,6 +1123,13 @@ fn parse_row_group_by_collection<R: ChunkReader + 'static>(
) -> Result<Vec<ProcessedElement>, Box<dyn std::error::Error>> {
let row_group_reader = reader.get_row_group(rg_idx)?;
let row_iter = row_group_reader.get_row_iter(None)?;
let bbox = LLBBox::new(
target_min_lat,
target_min_lng,
target_max_lat,
target_max_lng,
)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))?;

match collection {
OvertureCollection::Building => {
Expand All @@ -1145,7 +1153,8 @@ fn parse_row_group_by_collection<R: ChunkReader + 'static>(
if b.is_osm_sourced {
return None;
}
building_to_processed_way(&b, coord_transformer, &LLBBox::new_unchecked(target_min_lat, target_min_lng, target_max_lat, target_max_lng))
building_to_processed_way(&b, coord_transformer, &bbox)
.map(ProcessedElement::Way)
})
.collect())
}
Expand All @@ -1170,7 +1179,8 @@ fn parse_row_group_by_collection<R: ChunkReader + 'static>(
if r.is_osm_sourced {
return None;
}
road_to_processed_way(&r, coord_transformer, &LLBBox::new_unchecked(target_min_lat, target_min_lng, target_max_lat, target_max_lng))
road_to_processed_way(&r, coord_transformer, &bbox)
.map(ProcessedElement::Way)
})
.collect())
}
Expand All @@ -1195,7 +1205,8 @@ fn parse_row_group_by_collection<R: ChunkReader + 'static>(
if w.is_osm_sourced {
return None;
}
water_to_processed_way(&w, coord_transformer, &LLBBox::new_unchecked(target_min_lat, target_min_lng, target_max_lat, target_max_lng))
water_to_processed_way(&w, coord_transformer, &bbox)
.map(ProcessedElement::Way)
})
.collect())
}
Expand All @@ -1220,7 +1231,8 @@ fn parse_row_group_by_collection<R: ChunkReader + 'static>(
if l.is_osm_sourced {
return None;
}
landuse_to_processed_way(&l, coord_transformer, &LLBBox::new_unchecked(target_min_lat, target_min_lng, target_max_lat, target_max_lng))
landuse_to_processed_way(&l, coord_transformer, &bbox)
.map(ProcessedElement::Way)
})
.collect())
}
Expand Down