为什么在投影和瓦片的尺度值的差异? [英] Why the difference in scale values in projection vs. tile?

查看:205
本文介绍了为什么在投影和瓦片的尺度值的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用




此投影使用单位圆的半径 R = 1 以格林威治子午线为中心。到目前为止,没有缩放或应用任何翻译。该投影将生成以下间隔的输出值:





在D3 v4中,这是




这个投影的核心是使用相同的计算标准墨卡托投影。这可以从在上述等式右侧用黑色着色的术语容易地看出,这些术语与墨卡托投影使用的那些完全相同。通过应用一些缩放和翻译,只需调整输出间隔以更好地适应屏幕显示的需要。



首先,投影被截断,南方超过



从而将整个地图投影到正方形上。之后,有三个调整(在上述等式中与颜色匹配):


  1. 将原点移动到左上角 0,0)

  2. 将区间标准化为 [0,1] —以绿色
  3. 分隔
  4. 向上缩放以适应 256& 256

  5. $ b

    这将从间隔中产生输出值








    这是投影比例的差异,这就是你需要乘以/除以的原因。如果要同时使用 d3.geo.mercator()以及同一个地图中的切片,您需要修改比例以相互匹配。



    对标准墨卡托投影施加相同的纬度限制,就像Web Mercator投影的情况一样,以下面的间隔结束:



    标准墨卡托投影



    区隔项目



    长度= 2π



    网络墨卡托投影









    <

      var projection = d3.geoMercator()
    .scale((1< 12)/ 2 / Math.PI);

    使用简单的指数运算,比例因子可以重写为

     (1 <4)*(1 <8)/ 2 / Math.PI 
    pre>

    并进一步

     (1 < * 256 /(2 * Math.PI)

    第一项 << 4)等于 2 4 ,这是要使用的实际缩放系数: 16 。这将获得


    是调整包括的问题的标度的校正因子。


    Using the d3.geo.tile plugin, examples all have a difference between the scale of the map projection and the scale passed to the tile() function. In particular, tile_scale = projection_scale * 2 * Math.PI. See examples here and here.

    What's the meaning of this 2 * PI multiplication?

    解决方案

    To understand why there is an additional factor of applied to the scales when it comes to using the d3.geo.tile plugin, it is important to know the difference between the projection used by d3.geoMercator() and the one used when plotting the raster tiles.

    D3

    D3 implements the standard Mercator projection using the formulae:

    This projection is using the unit circle's radius of R = 1 centering on the Greenwich meridian. Up to this point there is no scaling nor any translation applied. The projection will produce output values from the following intervals:

    In D3 v4 this is implemented as

    export function mercatorRaw(lambda, phi) {
      return [lambda, log(tan((halfPi + phi) / 2))];
    }
    

    D3 v3 used a slightly different notation which more closely resembles the above mentioned formulae while, of course, being equivalent to the newer implementation:

    function d3_geo_mercator(λ, φ) {
      return [λ, Math.log(Math.tan(π / 4 + φ / 2))];
    }
    

    The intervals' values are often obscured by the fact that d3.geo.mercator() uses default values for translation and scaling. You have to explicitely set those to .translate([0,0]).scale(1) to get the above mentioned intervals.

    Tiles

    Tiles on the other hand use a slightly modified version of the Mercator projection known as Web Mercator. The relevant formulae are

    This projection, at its core, uses the same calculations as the standard Mercator projection. This can easily be seen from the terms colored in black on the right sides of the above equations, which are exactly the same as those used by the Mercator projection. Just the output intervals are adjusted to better suit the needs of screen display by applying some scaling and translation.

    First of all, the projection is cut off for latitudes both north and south exceeding

    Thereby projecting the entire map onto a square. Afterwards, there are three adjustments (matched by color in the above equations):

    1. Move the origin to the upper left corner (0, 0) — adjustment by π in blue.
    2. Normalize the intervals to [0, 1] — divide by in green
    3. Scale up to fit an area of 256 × 256 — multiply by 256 in red.

    This will yield output values from the intervals


    It's this difference in scales of the projections involved, which is the reason why you need to multiply / divide by . If you want to use both d3.geo.mercator() as well as the tiles in the same map, you need to modify the scales to match each other.

    Imposing the same restrictions for latitude on the standard Mercator projection as is the case for the Web Mercator projection you end up with the following intervals:

    Standard Mercator Projection

    Projects to the intervals

    having length = 2π.

    Web Mercator Projection

    Projects to the intervals

    having length = 256.

    This is corrected when setting the projection's scale like

    var projection = d3.geoMercator()
        .scale((1 << 12) / 2 / Math.PI );
    

    Using simple exponentiation math the scaling factor can be rewritten as

    (1 << 4) * (1 << 8) / 2 / Math.PI
    

    and further

    (1 << 4) * 256 / ( 2 * Math.PI )
    

    The first term (1 << 4) equals 24 which is the actual zoom factor to use: 16. This will get tiles of zoom level 4. The next term

    is the correction factor to adjust the scales which includes the your question was all about.

    这篇关于为什么在投影和瓦片的尺度值的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆