Skip to content

Commit

Permalink
Add HTTP reader based example
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Aug 31, 2023
1 parent d9877a6 commit dca2d8b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ tiff = { git = "https://github.com/image-rs/image-tiff" }

[dev-dependencies]
image = "0.24.5"
http-range-client = "0.7.0"
env_logger = "0.10.0"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ cargo run --example pixel data/tiff/N265E425.tif 2550 3050
cargo run --example crop data/tiff/N265E425.tif 100x100+2500+3000 dtm.png
cargo run --example img2ascii data/tiff/sat.tif
cargo run --example http_dtm
```
61 changes: 61 additions & 0 deletions examples/http_dtm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use georaster::geotiff::{GeoTiffReader, RasterValue};
use http_range_client::HttpReader;

fn main() {
env_logger::init();
let mut img_reader = HttpReader::new("https://data.sourcepole.com/srtm_1km_3857.tif");
// File size: 244M
// gdalinfo:
// Driver: GTiff/GeoTIFF
// Files: srtm_1km_3857.tif
// Size is 41999, 17610
// Coordinate System is:
// ID["EPSG",3857]]
// Data axis to CRS axis mapping: 1,2
// Origin = (-20037506.487966008484364,8401593.447238374501467)
// Pixel Size = (954.174162299386694,-954.196881813704067)
// Metadata:
// AREA_OR_POINT=Area
// Image Structure Metadata:
// COMPRESSION=DEFLATE
// INTERLEAVE=BAND
// Corner Coordinates:
// Upper Left (-20037506.488, 8401593.447) (179d59'59.94"W, 60d 0'30.00"N)
// Lower Left (-20037506.488,-8401813.642) (179d59'59.94"W, 60d 0'33.56"S)
// Upper Right (20036854.154, 8401593.447) (179d59'38.84"E, 60d 0'30.00"N)
// Lower Right (20036854.154,-8401813.642) (179d59'38.84"E, 60d 0'33.56"S)
// Center ( -326.167, -110.097) ( 0d 0'10.55"W, 0d 0' 3.56"S)
// Band 1 Block=256x256 Type=Int32, ColorInterp=Gray
// NoData Value=-9999
// Overviews: 5250x2202, 657x276, 83x35

// img_reader.set_min_req_size(1_048_576); // 1MB 6 requests, 6'291'456 B
// img_reader.set_min_req_size(524288); // 512KB 7 requests, 3'670'016 B
img_reader.set_min_req_size(262144); // 256KB 7 requests, 1'835'008 B

let mut tiff = GeoTiffReader::open(img_reader).expect("Cannot create decoder");

let img = tiff.images().get(0).expect("Image info");
assert_eq!(img.dimensions, Some((41999, 17610)));
assert_eq!(img.colortype, Some(tiff::ColorType::Gray(32)));
assert_eq!(tiff.origin(), Some([-20037506.48796601, 8401593.447238375]));
assert_eq!(
tiff.pixel_size(),
Some([954.1741622993867, -954.1968818137041])
);
assert_eq!(
tiff.geo_params,
Some("WGS 84 / Pseudo-Mercator|WGS 84|".to_string())
);

tiff.seek_to_image(0).unwrap();
assert_eq!(tiff.read_pixel(20000, 8000), RasterValue::I32(372));

// Read medium overview
tiff.seek_to_image(1).unwrap();
let max_height = tiff
.pixels(0, 0, 657, 276)
.map(|(_x, _y, h)| if let RasterValue::I32(v) = h { v } else { 0 })
.max();
assert_eq!(max_height, Some(3405));
}

0 comments on commit dca2d8b

Please sign in to comment.