diff --git a/.gitignore b/.gitignore index d73015725..6eb303fc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -``` # Compiled and build artifacts *.pyc __pycache__/ @@ -68,4 +67,6 @@ htmlcov/ *.tar.bz2 *.tar.xz *.tar.zst -``` \ No newline at end of file + +# Rust backup files +**/*.rs.bk diff --git a/src/elevation/providers/copernicus.rs b/src/elevation/providers/copernicus.rs index edb35fffb..1de210ea9 100644 --- a/src/elevation/providers/copernicus.rs +++ b/src/elevation/providers/copernicus.rs @@ -42,9 +42,9 @@ impl ElevationProvider for CopernicusDem30 { grid_height: usize, ) -> Result> { 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)) @@ -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 = buf.into_iter().map(|v| v as f64).collect(); + // Read the image data - Copernicus DEM uses 32-bit float. + let heights: Vec = 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); } diff --git a/src/overture.rs b/src/overture.rs index 6e5ddbb2a..7ac73e56a 100644 --- a/src/overture.rs +++ b/src/overture.rs @@ -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; @@ -1122,6 +1123,13 @@ fn parse_row_group_by_collection( ) -> Result, Box> { 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 => { @@ -1145,7 +1153,8 @@ fn parse_row_group_by_collection( 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()) } @@ -1170,7 +1179,8 @@ fn parse_row_group_by_collection( 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()) } @@ -1195,7 +1205,8 @@ fn parse_row_group_by_collection( 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()) } @@ -1220,7 +1231,8 @@ fn parse_row_group_by_collection( 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()) }