ARTLEBEDEV
  • Graphic design
  • Studio projects
  • About the spherical Mercator math

    We have a map of 512×512 tiles where each pixel has a unique hex code. Dividing the map into 512 lines, each with 512 tiles. The line is 131 072×256 pixels in size, 33 554 432 pixels overall.

    All that’s left is to calculate how many square kilometers are made up by pixels in those lines.

    First, understanding where the Mercator projection put our lines on the sphere. Learning that on Google Maps data is shown in a spherical coordinate system (Spherical Mercator EPSG:900913 (EPSG:3857) and WGS84 Datum). The sphere radius is 6 378 137 meters. The map does not show the entire sphere, the maximum polar parallel is 85,051 128 78°.

    In the Mercator projection, the parallels are shifted the further they are from the central meridian.

    This parallel shift (y) is represented by formula 1:

    R=1; θ is the parallel angle in radians.

    The resultant parallel shift value (scale coefficient) is converted back into radians using formula 2:

    On a Mercator sphere the scale of map segments (tiles) is decreased gradually with distance from equator.

    If we were to imagine the Mercator projection as a gradient scale, it would be absolutely linear.

    All lines on the scale are exactly the same, yet the closer the line to a pole on the map, the smaller its scale on the sphere. To determine the scale range, we convert the angle of the maximum polar parallel into radians 85,051 128 78° · π / 180° = 1,484 422 229 748 71 and calculate its scale coefficient using formula 1.

    1 · ln (tan(1,484 422 229 748 71 / 2 + π / 4)) = 3,141 592 653 628 9

    Since the sphere is symmetrical, it is sufficient to determine the scale coefficient for each parallel for only half of the sphere, meaning to calculate angles for 256 lines that have the same size on the map and become smaller the further they are from the equator on the sphere. The scale gradient can be divided into any number of segments, but given the scale of the map we need exactly 256, from the equator (y255) to the polar parallel (y0).

    Dividing the scale gradient into 256 segments.

    y255 = y0 / 256 = 0,012 271 846 3
    y254 = y255 + y255 = 0,024 543 692 6
    y253 = y254 + y255 = 0,036 815 538 9
    y252 = y253 + y255 = ...
    y251 = y252 + y255
    And so on all the way to the polar parallel.

    Using formula 2, we can convert the scale coefficient for each parallel into radians and degrees.

    θ255 = 2 atan (exp (y255 / 1)) – ½ π = 0,012 271 538 3 rad = 0,703 107 352 4°
    θ254 = 2 atan (exp (y254 / 1)) – ½ π = 0,024 541 228 8 rad = 1,406 108 835 5°
    θ253 = 0,036 807 225 2 rad = 2,108 898 659 3°
    etc.

    Calculating the area of the polar segment that didn’t fit on the map.

    Polar angle (φ0) = (90°θ0) · 2 = 9,897 742 44° = 0,172 748 194 1 rad
    Polar segment height = Sphere radius · (1 – cos(φ0 / 2)) = 23,777 208 59 km
    Polar chord = 2 · Sphere radius · sin(φ0 / 2) = 1 100,442 151 23 km
    Polar area = π · ((Polar chord / 2) ^ 2 + Polar segment height ^ 2) = 952 872,030 890 85 km2

    All that’s left is to calculate the area of each line.

    Finding the angle (φ) of intersection of the parallel with the sphere radius in radians for each parallel from θ255 to θ0.

    φ255 = (90°θ255) · 2 π / 180° = 3,117 049 577 rad
    φ254 = (90°θ254) · 2 π / 180° = 3,092 510 195 9 rad
    φ253 = 3,067 978 203 2 rad
    etc.

    We already know the polar segment height, now we need to calculate the height (h) of the lines:

    h0 = Sphere radius · (1 – cos(φ0 / 2)) – Polar segment height = 0,589 672 519 79 km
    h1 = Sphere radius · (1 – cos(φ1 / 2)) – Sum of previous segments' heights = 0,604 267 661 96 km
    h2 = Sphere radius · (1 – cos(φ2 / 2)) – Sum of previous segments' heights = 0,619 222 612 38 km
    h3 = 0,634 546 168 98 km
    etc.
    h255 = Sphere radiusSum of previous segments' heights = 78,267 588 018 18 km

    Finally, we get the area (S) of each line.

    S0 = 2 π · Sphere radius · h0 = 23 631,136 069 7 km2
    S1 = 2 π · Sphere radius · h1 = 24 216,036 635 6 km2
    S2 = 24 815,356 523 4 km2
    S3 = 25 429,448 309 54 km2
    etc.

    S255 = 3 136 574,895 768 57 km2
    S256 = S255
    S257 = S254
    S258 = S253
    etc.
    S511 = S0

    To get the area of a pixel in the line, we simply divide the line area by the number of pixels it has.

    Tiles in the Mercator projection in scale 10 on the sphere have a shape that looks oddly like a square.

    Using some magic to calculate the number of pixels.

    Looking at how many square kilometers are made by pixels in each line.

    Rounding the numbers and comparing with the data from Wikipedia.

      Color Name Area, km2   Wikipedia Difference
    1#BC2657Russia16 523 293>16 364 387 158 906
    2#00A66DAntarctica12 982 769<14 000 0001 017 231
    3#639F5AChina9 279 960>9 232 276 47 684
    4#D23127Canada8 951 513<9 093 507 141 994
    5#717070Brazil8 402 706<8 460 415 57 709
    6#C6382FUnited States of America7 675 122>7 664 012 11 110
    7#F9DD14Australia7 602 329<7 633 565 31 236
    8#E4A41BIndia3 107 011>2 864 021 242 990
    9#1BAA64Argentina2 718 051<2 736 690 18 639
    10#8D9C46Kazakhstan2 663 315<2 699 700 36 385
    11#02A3D3Algeria2 311 284<2 381 741 70 457
    12#EE9617Democratic Republic of the Congo2 298 093>2 267 048 31 045
    13#BA4939Greenland (Denmark)2 148 362<2 166 086 17 724
    14#C73A2DMexico1 945 932>1 943 945 1 987
    15#05A39DSaudi Arabia1 933 260<2 149 690 216 430
    16#B7A42FIndonesia1 884 107>1 811 569 72 538
    17#C58B2DSudan1 848 010<1 886 068 38 058
    18#D17B26Libya1 619 483<1 759 540 140 057
    19#3A987EIran1 614 889>1 531 595 83 294
    20#789D50Mongolia1 544 445>1 481 307 63 138
    21#D92D1EState of Alaska (USA)1 445 171<1 553 556 108 385
    22#7CB341Peru1 283 667>1 279 996 3 671
    23#E78619Chad1 261 656>1 259 200 2 456
    24#039FCCMali1 253 642>1 220 190 33 452
    25#92BC35Angola1 253 229>1 246 700 6 529
    26#05A865South Africa1 207 747<1 214 470 6 723
    27#EC8618Niger1 181 112<1 266 700 85 588
    28#856862Colombia1 126 802>1 038 700 88 102
    29#3A9D76Ethiopia1 125 202>1 000 000 125 202
    30#52AF50Bolivia1 076 932<1 083 301 6 369
    31#0B9AC5Mauritania1 041 661>1 025 520 16 141
    32#C37E2FEgypt 995 966> 995 450 516
    33#986052Venezuela 904 531> 882 050 22 481
    34#D38824Nigeria 904 112< 910 768 6 656
    35#BBC226Tanzania 886 158> 885 800 358
    36#1BA575Pakistan 846 859< 881 912 35 053
    37#7DB93CNamibia 819 591< 823 290 3 699
    Show all
    38#2CAE59Mozambique 777 243< 786 380 9 137
    39#0DA0A1Turkey 766 879< 769 632 2 753
    40#66B249Chile 743 189< 743 812 623
    41#A7BF2EZambia 740 579< 743 398 2 819
    42#D7A520Myanmar 663 594> 653 508 10 086
    43#4E9A6CSouth Sudan 645 839> 619 745 26 094
    44#3BA26EAfghanistan 638 342< 652 230 13 888
    45#D69722Somalia 637 081> 627 337 9 744
    46#DF871ECentral African Republic 623 043> 622 984 59
    47#F3D313Madagascar 590 710> 581 540 9 170
    48#E2951CKenya 577 330> 569 140 8 190
    49#67B644Botswana 561 420< 566 730 5 310
    50#E5761AUkraine 558 031> 553 544 4 487
    51#AC6143France 545 040< 551 695 6 655
    52#ECA416Thailand 510 625< 510 890 265
    53#866F5ESpain 495 397< 498 980 3 583
    54#779556Cameroon 464 083< 472 710 8 627
    55#19A188Turkmenistan 463 674< 469 930 6 256
    56#F4DA13Papua New Guinea 461 724> 452 860 8 864
    57#00736FYemen 454 707< 527 968 73 261
    58#299F80Uzbekistan 435 604> 425 400 10 204
    59#0DA199Iraq 429 297< 437 367 8 070
    60#0E9CC9Morocco 412 458< 446 300 33 842
    61#E5581ASweden 412 314> 410 335 1 979
    62#3DAD57Paraguay 397 335> 397 302 33
    63#52B34BZimbabwe 388 113> 386 847 1 266
    64#0FA484Japan 368 605> 364 485 4 120
    65#887859Germany 352 555> 348 672 3 883
    66#00A596Republic of the Congo 342 139> 341 500 639
    67#05A589Vietnam 324 000> 318 003 5 997
    68#2793A1Cote d'Ivoire 320 564> 310 070 10 494
    69#D9B11FOman 309 362< 311 888 2 526
    70#4C8A81Poland 307 097< 309 500 2 403
    71#00A3BDNorway 305 211> 304 282 929
    72#E0591CFinland 302 498< 303 815 1 317
    73#747D67Italy 297 320> 294 140 3 180
    74#C8A426Philippines 293 519< 298 170 4 651
    75#1898ABBurkina Faso 273 799< 273 800 1
    76#06A1D0Western Sahara 270 371> 266 000 4 371
    77#CCBB22New Zealand 264 276> 262 443 1 833
    78#05A493Gabon 261 946> 257 667 4 279
    79#BABA29Ecuador 247 882< 256 369 8 487
    80#00A3CCGuinea 245 958> 245 717 241
    81#CB552CUnited Kingdom (UK) 241 571< 241 930 359
    82#898054Romania 234 966> 229 891 5 075
    83#0D9DB4Ghana 233 184> 227 533 5 651
    84#00A58BLaos 228 584< 230 800 2 216
    85#37899BGuyana 210 929> 196 849 14 080
    86#C17132Belarus 204 905> 202 900 2 005
    87#E99517Uganda 204 166> 197 100 7 066
    88#7AA54BEast Malaysia 197 022< 198 161 1 139
    89#0C9BC1Senegal 196 113> 192 530 3 583
    90#A19A3CKyrgyzstan 190 095< 191 801 1 706
    91#619067Syria 185 250> 183 630 1 620
    92#F1A616Cambodia 177 905> 176 515 1 390
    93#2BAC5EUruguay 174 208< 175 015 807
    94#DD781FTunisia 148 430< 155 360 6 930
    95#0EA57ANepal 147 126< 156 000 8 874
    96#2791A7Suriname 144 772> 141 510 3 262
    97#4FA064Tajikistan 139 171> 130 168 9 003
    98#2AA66EBangladesh 134 038> 130 598 3 440
    99#8EA541West Malaysia 130 553< 130 647 94
    100#199C9AGreece 130 398< 143 351 12 953
    101#B38D36Eritrea 121 106> 101 000 20 106
    102#2AA276North Korea 120 588> 120 408 180
    103#CA4B2DNicaragua 119 227< 119 990 763
    104#A08F40Benin 115 716> 110 622 5 094
    105#D54525Honduras 111 724> 88 802 22 922
    106#975358Cuba 110 261< 111 890 1 629
    107#289991Bulgaria 110 122> 109 820 302
    108#C8422EGuatemala 108 315< 108 489 174
    109#E24B1BIceland 100 555< 107 159 6 604
    110#1AA37ESouth Korea 99 147< 100 250 1 103
    111#00A3C5Liberia 96 081< 99 909 3 828
    112#3EB152Malawi 94 115< 96 320 2 205
    113#9D7B48Hungary 91 506< 94 080 2 574
    114#4D9474Jordan 89 086< 89 608 522
    115#996850Portugal 87 941< 91 470 3 529
    116#199F91Azerbaijan 84 423< 86 100 1 677
    117#0C9CBBFrench Guiana (France) 83 680> 83 534 146
    118#28969AAustria 83 118> 82 445 673
    119#38908ECzech Republic 78 219> 77 247 972
    120#758561Serbia 76 724< 88 246 11 522
    121#AB5845Panama 74 528> 74 340 188
    122#05A0C1Sierra Leone 72 229> 71 620 609
    123#E6B21AUnited Arab Emirates 71 477< 83 600 12 123
    124#BD5B36Ireland 68 490< 68 883 393
    125#05A57ESri Lanka 64 708> 62 732 1 976
    126#CF6E28Lithuania 63 577> 62 680 897
    127#DA6A21Latvia 63 207> 62 249 958
    128#DE4C1CSvalbard and Jan Mayen (Norway) 61 745< 62 045 300
    129#E97619Georgia 56 782< 69 700 12 918
    130#8B924BTogo 56 600> 54 385 2 215
    131#0D9EABCroatia 55 814< 55 974 160
    132#BB5138Costa Rica 51 138> 51 060 78
    133#05A1B1Bosnia and Herzegovina 50 916< 51 187 271
    134#B0763CSlovakia 48 622> 48 105 517
    135#706777Dominican Republic 47 802< 48 320 518
    136#E3671AEstonia 43 107> 42 388 719
    137#D95E23Denmark 42 384< 42 434 50
    138#3CA666Bhutan 39 996> 38 394 1 602
    139#5F8375Switzerland 39 778< 39 997 219
    140#3EB44ATaiwan 35 560> 32 260 3 300
    141#CE612BNetherlands 34 130> 33 893 237
    142#05A0C8Guinea-Bissau 33 431> 28 120 5 311
    143#0EAA61Lesotho 30 598> 30 355 243
    144#BF6634Belgium 30 411> 30 278 133
    145#53B944Moldova 30 244< 32 891 2 647
    146#289C88Armenia 28 394< 29 843 1 449
    147#ECD917Solomon Islands 28 307> 27 986 321
    148#4C8E7BAlbania 28 027> 27 398 629
    149#0DA38EEquatorial Guinea 26 968< 28 051 1 083
    150#845C67Haiti 26 829< 27 560 731
    151#CDC420Burundi 25 043< 25 680 637
    152#399486Republic of Macedonia 24 891< 25 433 542
    153#DDC61BRwanda 23 922< 24 668 746
    154#E1401BBelize 21 820< 22 806 986
    155#B18139Israel 21 562> 20 330 1 232
    156#629761Djibouti 21 520< 23 180 1 660
    157#DC401DEl Salvador 20 406< 20 721 315
    158#199AA3Slovenia 20 184> 20 151 33
    159#DCBD1DFiji 18 734> 18 274 460
    160#CFD21FNew Caledonia (France) 18 532> 18 275 257
    161#00A580Kuwait 17 380< 17 818 438
    162#1BAB5ESwaziland 17 349> 17 204 145
    163#DD2D1AHawaii (USA) 16 680> 16 647 33
    164#0EAA5CEast Timor 14 698< 14 874 176
    165#00A4B4Montenegro 13 596> 13 452 144
    166#E76619Kaliningrad Oblast (Russia) 13 326< 13 355 29
    167#A84A46Bahamas 12 286> 10 010 2 276
    168#E0D61AVanuatu 12 083< 12 173 90
    169#0FA969Falkland Islands (UK) 11 834> 11 586 248
    170#F4B416Qatar 11 606< 12 189 583
    171#975A55Jamaica 10 978> 10 831 147
    172#608A6ERepublic of Kosovo 10 880< 10 887 7
    173#00A2D0Gambia 10 450> 10 000 450
    174#768D5BLebanon 10 239> 10 230 9
    175#835D65Puerto Rico (USA) 8 886< 9 104 218
    176#05A2A7Abkhazia 8 665> 8 660 5
    177#B9403BGalapagos Islands (Ecuador) 8 019> 8 010 9
    178#4A8587Canary Islands (Spain) 7 414< 7 493 79
    179#3EB34EKerguelen Islands (France) 7 005< 7 215 210
    180#0EAA57Palestine 6 036> 5 265 771
    181#A3A539Brunei Darussalam 5 863> 5 269 594
    182#3EB548Republic of Cyprus 5 511< 5 550 39
    183#4A818CTrinidad and Tobago 5 137> 5 128 9
    184#388C95Cape Verde 4 031< 4 033 2
    185#00A4AASouth Ossetia 3 860< 3 900 40
    186#EAC917South Georgia and the South Sandwich Islands (UK) 3 644< 3 903 259
    187#3CAA5FFrench Polynesia (France) 3 518< 3 667 149
    188#8A884FNorthern Cyprus 3 461> 3 355 106
    189#05A85ATransnistria 3 209< 4 163 954
    190#05A774Samoa 2 835> 2 821 14
    191#AE6B3FLuxembourg 2 586= 2 586
    192#68BA40Reunion (France) 2 499< 2 511 12
    193#73766CAzores (Portugal) 2 293< 2 333 40
    194#93C233Mauritius 1 991< 2 030 39
    195#F8D514Comoros 1 657< 1 862 205
    196#3886A6Guadeloupe (France) 1 626< 1 628 2
    197#D75024Faroe Islands (Denmark) 1 378< 1 392 14
    198#3887A0Martinique (France) 1 111< 1 128 17
    199#0EAA55Hong Kong 1 067> 1 053 14
    200#C6982ASao Tome and Principe 998> 964 34
    201#AA5046Turks and Caicos Islands (UK) 886> 430 456
    202#5E7D7AMadeira (Portugal) 790< 801 11
    203#EFB316Bahrain 758< 765 7
    204#3685A3Dominica 748< 751 3
    205#2CB14CSingapore 678< 687 9
    206#F5C214Tonga 659< 717 58
    207#8FAD3CFederated States of Micronesia 655< 702 47
    208#278FB3Saint Lucia 603< 606 3
    209#10FDFFIsle of Man (UK) 568< 572 4
    210#A5AF34Guam (USA) 539< 544 5
    211#DA2E1BLine Islands (Kiribati) 489< 503 14
    212#9B714DAndorra 465< 468 3
    213#B9B02CNorthern Mariana Islands (USA) 462< 464 2
    214#64a554Palau 442< 459 17
    215#CECB1FSeychelles 440< 455 15
    216#1997C0Barbados 434> 431 3
    217#477C94Antigua and Barbuda 422< 443 21
    218#1896B8Curacao (Netherlands) 419< 444 25
    219#248DB0Saint Vincent and the Grenadines 382< 389 7
    220#A8C62CMayotte (France) 382> 374 8
    221#278EADGrenada 352> 344 8
    222#2CB054Heard Island and McDonald Islands (Australia) 345< 412 67
    223#1BAD58Crozet Islands (France) 339< 352 13
    224#846364US Virgin Islands (USA) 336< 346 10
    225#EBD216Prince Edward Islands (South Africa ) 330< 335 5
    226#B59933Malta 309< 316 7
    227#68BE3CGilbert Islands (Kiribati) 284> 281 3
    228#F1C014Cook Islands (New Zealand) 284> 236 48
    229#1897B2Bonaire (Netherlands) 269< 294 25
    230#E8BF19Niue (New Zealand) 261> 260 1
    231#955455Cayman Islands (UK) 259< 264 5
    232#4A7C97Saint Kitts and Nevis 258< 261 3
    233#05A0B9Akrotiri and Dhekelia (UK) 248< 254 6
    234#00A65ASaint Pierre and Miquelon (France) 218< 242 24
    235#7BAD45Marshall Islands 210> 181 29
    236#0EA872American Samoa (USA) 197< 199 2
    237#91B538Easter Island (Chile) 183> 164 19
    238#F3CB14Tristan da Cunha (UK) 176< 207 31
    239#1695BCAruba (Netherlands) 175< 178 3
    240#FAE114Liechtenstein 158< 160 2
    241#F5DF13British Virgin Islands (UK) 139< 151 12
    242#00A676Wallis and Futuna (France) 139< 142 3
    243#05A85EChristmas Island (Australia) 133< 135 2
    244#F7CC14Saint Helena (UK) 122> 121 1
    245#66AC4EMacquarie Island (Australia) 122< 128 6
    246#178FB7Jersey (UK) 120> 118 2
    247#4A7E91Montserrat (UK) 100< 102 2
    248#05A86CAscension Island (UK) 96> 88 8
    249#CAB024Maldives 87< 298 211
    250#16B793Guernsey (UK) 78= 78
    251#6F6774Anguilla (UK) 77< 91 14
    252#DFCF1ABouvet Island (Norway) 73> 49 24
    253#2CB14FSan Marino 61= 61
    254#EDDC16Amsterdam Island (France) 54< 55 1
    255#A94949Bermuda (UK) 50< 54 4
    256#A6B730Pitcairn Islands (UK) 49> 47 2
    257#716C73Saint Martin (French) 46< 54 8
    258#5E797ESan Andres, Providencia and Santa Catalina (Colombia) 46< 53 7
    259#53B647British Indian Ocean Territory (UK) 45< 60 15
    260#1BA86DTokelau (New Zealand) 41> 12 29
    261#BDCE24Norfolk Island (Australia) 36= 36
    262#7FC336Phoenix Islands (Kiribati) 33> 28 5
    263#1BAD51Sint Maarten (Netherlands) 31< 34 3
    264#05A857Macau 30> 28 2
    265#7EC136Nauru 21= 21
    266#00A666Europa Island (France) 21< 28 7
    267#5D7582Sint Eustatius (Netherlands) 20< 21 1
    268#1BAD53Ceuta (Spain) 20> 19 1
    269#93C630Tuvalu 20< 26 6
    270#5D7187Saint Barthelemy (France) 18< 21 3
    271#5B7183Saba (Netherlands) 12< 13 1
    272#00A65FCocos Islands (Australia) 12< 14 2
    273#D0D61FMelilla (Spain) 12= 12
    274#E0DA1ASaint-Paul Island (France) 10> 6 4
    275#50AB56Wake Island (USA) 9> 7 2
    276#BED224Gibraltar (UK) 6< 7 1
    277#FFFFFFSpratly Islands (Brunei, China, Malaysia, Philippines, Taiwan and Vietnam) 6< 7 1
    278#52B942Banaba Island (Kiribati) 6= 6
    279#DF361CMidway Atoll (USA) 5< 6 1
    280#A9CD29Juan de Nova Island (France) 5< 6 1
    281#2AAA66Jarvis Island (USA) 4= 4
    282#8A37A3Paracel Islands (China, Taiwan, Vietnan) 4< 8 4
    283#BCC925Glorioso Islands (France) 4< 12 8
    284#9E8544Navassa Island (USA) 4< 5 1
    285#B94138Clipperton Island (France) 3< 6 3
    286#D23324Palmyra Atoll (USA) 3< 5 2
    287#94C82FMonaco 2= 2
    288#A9CB29Howland Island (USA) 2= 2
    289#68BD3DBaker Island (USA) 1< 2 1
    290#D33C25Johnston Atoll (USA) 1< 3 2
    291#7EBE38Tromelin Island (France) 1= 1
    292#DB371DKure Atoll (USA)0,9=0,9
    293#00A658Vatican City0,5>0,440,06
      Kingman Reef (USA)0,002<0,0120,01
      Sealand0,001<0,0040,003
                 
        Water 366 495 583 > 361 132 000 5 363 583
        Land 144 712 310 < 148 940 000 4 227 690
        Total 511 207 893 > 510 072 000 1 135 893

    Recalling our story about Yemen and the housewife.

    Some territories didn’t make it on our list, including the Somali Republic, Jubaland, Galmudug, Puntland, Maakhir, Khatumo, Somaliland, Awdalland, Nagorno-Karabakh Republic, Lugansk and Donetsk People’s Republics.