Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client-side terrain: scale slope calculations by latitude #4807

Closed
ajashton opened this issue Jun 8, 2017 · 4 comments
Closed

client-side terrain: scale slope calculations by latitude #4807

ajashton opened this issue Jun 8, 2017 · 4 comments

Comments

@ajashton
Copy link
Member

ajashton commented Jun 8, 2017

@mollymerp @kkaefer I brought this up recently in chat but figured I should capture details in a ticket.

Slope calculations for terrain visualization from mercator-projected tiles should ideally to take into account the varying scale along latitude. The ground distance covered by 1 pixel in mercator shrinks as you move away from the equator, so hills at extreme latitudes will appear more flat than they really are if this is not accounted for.

This StackExchange answer explains the situation well and includes some math that can be used to adjust the terrain visualization to be more accurate.

…assuming scale is correct at the Equator, its distortion equals the secant of the latitude. That is, distances on the map appear to be multiplied by the secant.

Horizontal scale factor approx. latitude
1.25× ±37°
1.5× ±48°
±60°
±70°
±75°
±78.5°

Options:

  • Compensate for latitude on a per-pixel basis. Most accurate but probably difficult or expensive.
  • Compensate for latitude on a per-tile basis (eg adjust all pixels in a tile based on the lat of the tile center). This would require Some gradual falloff at the most zoomed out levels to avoid obvious seams between tiles. A mostly-acceptable tradeoff, but unfortunate for places like Svalbard.
    • This is the option we went with for vector terrain
  • Do nothing. A hillshade style designed with 20-40° of latitude in mind would slightly over-exaggerate slopes in equatorial regions and under-exaggerate them at more extreme latitudes, but the error would not be very noticeable at most populated latitudes. Northern North America & northern Europe would lose out on accuracy in the most noticeable way, with perhaps also southern South America and New Zealand.
@mollymerp
Copy link
Contributor

Thanks @ajashton for capturing in a ticket. Very interesting stack exchange article! I think per-pixel basis might be more trouble than its worth but I don't think per-tile scaling would be too difficult.

@kkaefer let me know if you have thoughts on this or if you have explored any of these options previously.

@kkaefer
Copy link
Contributor

kkaefer commented Jun 12, 2017

I haven't explored any of this. It might be preferable to do per-pixel, since we could use varying interpolation, and enable this effect for z0 tiles as well by having 4 triangles, 2 for the northern hemisphere and two for the southern hemisphere that'd allow us to compute the latitude for every pixel. If we do it per tile, we might end up with seams at the tile boundaries, in particular for low zoom level tiles.

@mourner
Copy link
Member

mourner commented Jun 12, 2017

An option in the middle would be to calculate adjustment at the top and the bottom of a tile and then interpolate (e.g. linearly) in each pixel. This should be cheaper than per-pixel cos calculation. Although the per-pixel shouldn't necessarily be expensive, since cos should be calculated with simple lookup tables on many GPUs — we should try it out first.

@mollymerp
Copy link
Contributor

mollymerp commented Sep 21, 2017

I implemented a per-pixel scaling in d000949. not sure how best to profile this, but let's move the discussion over to the PR #5286 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants