Skip to content

Commit

Permalink
Use calculated Mercator grid resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Apr 27, 2019
1 parent 5573769 commit 111f350
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 44 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 27 additions & 22 deletions t-rex-core/src/core/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,35 @@ impl Grid {
srid: 3857,
units: Unit::Meters,
// Formula: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Resolution_and_Scale
// const PIXEL_WIDTH_Z0: f64 = 156543.0339280410; // from mapcache
// calculated: const PIXEL_WIDTH_Z0: f64 = 2.0 * 6378137.0 * consts::PI / 256.0; // = 40075016.68557849 / 256
// let resolutions: Vec<f64> = (0..23).map(|z| {
// PIXEL_WIDTH_Z0 / (z as f64).exp2()
// }).collect();
resolutions: vec![
156543.0339280410,
78271.51696402048,
39135.75848201023,
19567.87924100512,
9783.939620502561,
4891.969810251280,
2445.984905125640,
1222.992452562820,
611.4962262814100,
305.7481131407048,
152.8740565703525,
76.43702828517624,
38.21851414258813,
19.10925707129406,
9.554628535647032,
4.777314267823516,
2.388657133911758,
1.194328566955879,
0.5971642834779395,
0.2985821417389700,
0.1492910708694850,
0.0746455354347424,
0.0373227677173712,
78271.5169640205,
39135.75848201025,
19567.879241005125,
9783.939620502562,
4891.969810251281,
2445.9849051256406,
1222.9924525628203,
611.4962262814101,
305.7481131407051,
152.87405657035254,
76.43702828517627,
38.218514142588134,
19.109257071294067,
9.554628535647034,
4.777314267823517,
2.3886571339117584,
1.1943285669558792,
0.5971642834779396,
0.2985821417389698,
0.1492910708694849,
0.07464553543474245,
0.037322767717371225,
],
level_max: Vec::new(),
origin: Origin::BottomLeft,
Expand Down
74 changes: 53 additions & 21 deletions t-rex-core/src/core/grid_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,31 @@ fn test_bbox() {
extent,
Extent {
minx: -1017529.7205322683,
miny: 7005300.768279828,
maxx: -978393.9620502591,
maxy: 7044436.526761841,
miny: 7005300.768279836,
maxx: -978393.9620502554,
maxy: 7044436.526761845
}
);

let extent = grid.tile_extent(486, 691, 10);
assert_eq!(
extent,
Extent {
minx: -1017529.7205322683,
miny: 7005300.768279828,
maxx: -978393.9620502591,
maxy: 7044436.526761841,
miny: 7005300.768279836,
maxx: -978393.9620502554,
maxy: 7044436.526761845
}
);

let extent = grid.tile_extent(32, 42, 6);
assert_eq!(
extent,
Extent {
minx: 0.0,
miny: 6261721.357121639,
maxx: 626172.1357121654,
maxy: 6887893.492833804
}
);

Expand All @@ -83,19 +95,19 @@ fn test_bbox() {
Extent {
minx: -1017529.7205322683,
miny: -20037508.342789248,
maxx: -978393.9620502591,
maxy: -19998372.58430724,
maxx: -978393.9620502554,
maxy: -19998372.58430724
}
);

let extent_ch = grid.tile_extent_xyz(1073, 717, 11);
assert_eq!(
extent_ch,
Extent {
minx: 958826.0828092434,
miny: 5987771.04774756,
maxx: 978393.9620502479,
maxy: 6007338.926988564,
minx: 958826.0828092508,
miny: 5987771.047747567,
maxx: 978393.9620502554,
maxy: 6007338.926988572
}
);

Expand All @@ -115,8 +127,8 @@ fn test_bbox() {
fn test_grid_calculations() {
let grid = Grid::web_mercator();

assert_eq!(grid.pixel_width(10), 152.8740565703525);
assert_eq!(grid.scale_denominator(10), 545978.7734655447);
assert_eq!(grid.pixel_width(10), 152.87405657035254);
assert_eq!(grid.scale_denominator(10), 545978.7734655448);

assert_eq!(grid.level_limit(0), (1, 1));
assert_eq!(grid.level_limit(10), (1024, 1024));
Expand Down Expand Up @@ -174,10 +186,10 @@ fn test_grid_calculations() {
assert_eq!(
extent,
Extent {
minx: 782715.1696402021,
miny: 5792092.25533751,
maxx: 939258.2035682425,
maxy: 5948635.289265554,
minx: 782715.1696402058,
miny: 5792092.255337518,
maxx: 939258.2035682462,
maxy: 5948635.289265558
}
);
let limits = grid.tile_limits(extent, 0);
Expand Down Expand Up @@ -362,14 +374,25 @@ mod web_mercator {
lat: 53.33087298301705,
}
);
assert_eq!(
ul(32, 42, 6),
LngLat {
lon: 0.0,
lat: -48.92249926375824,
}
);
}

#[test]
fn test_xy() {
let ul = ul(486, 332, 10);
let xy_ = xy(ul.lon, ul.lat);
assert_eq!(xy_, (-1017529.7205322663, 7044436.526761846));
assert_eq!(xy(0.0, 0.0), (0.0, -0.0000000007081154551613622));
let lnglat = ul(486, 332, 10);
assert_eq!(
xy(lnglat.lon, lnglat.lat),
(-1017529.7205322663, 7044436.526761846)
);
let lnglat = ul(32, 42, 6);
assert_eq!(xy(lnglat.lon, lnglat.lat), (0.0, -6261721.357121639));
}

#[test]
Expand All @@ -384,6 +407,15 @@ mod web_mercator {
maxy: 7044436.526761846,
}
);
assert_eq!(
tile_extent(32, 42, 6),
Extent {
minx: 0.0,
miny: -6887893.492833804,
maxx: 626172.1357121639,
maxy: -6261721.357121639
}
);
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion t-rex-core/src/mvt/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl ScreenGeom<geom::LineString> for screen::LineString {
}
}


impl ScreenGeom<geom::MultiLineString> for screen::MultiLineString {
fn from_geom(
extent: &Extent,
Expand Down

0 comments on commit 111f350

Please sign in to comment.