Google tile and TMS index algorithms

Source: Internet
Author: User

TMS, short for tile map service, is a tile map service, also known as wmts (Web Map tile Service). For specific standards, see the OGC website. The algorithm of TMS is simple, that is, to cut the projected world map into a four-tree hierarchy (to be verified, the number of cut tiles is pyramid-shaped with the hierarchy. The relationship between the number and hierarchy is shown in the following table:

& Lt; TD width = "193" & gt; 1 tile & lt;/TD & gt;
0 1 tile covers whole world
1 2 × 2 tiles 4 tiles
2 4 × 4 tiles 16 tiles
n 2n × 2n tiles 22n tiles
12 4096x4096 tiles 16.777.216
16 maximum zoom for opencyclemap (mostly) 232 = 4.294.967.296 tiles
17 maximum zoom for osmarender layer 17.179.869.184 tiles
18 maximum zoom for mapnik layer 68.719.476.736 tiles

Numbers these tiles. Due to the regularity of the tile numbers (Cartesian coordinate system of the plane), plus projection is also an algorithm (the sphere expands into a plane, an index relationship is established between numbers and coordinates. the longitude and latitude ranges can be obtained through numbers, and the number of tiles can be found through latitude and longitude. The formula is as follows:

N = 2 ^ zoomxtile = (lon_deg + 180)/360) * nytile = (1-(log (TAN (lat_rad) + Sec (lat_rad)/π )) /2 * n

From the formula, we can obtain the number index of the tile by determining the longitude and latitude and level. On the contrary, if we know the number, we can calculate the unknown longitude and latitude. The formula is as follows:

N = 2 ^ zoomlon_deg = xtile/N * 360.0-180.0lat _ rad = arctan (sinh (π * (1-2 * ytile/n) lat_deg = lat_rad * 180.0/π

Therefore: 1. When displaying a map, you can determine the map tiles to be loaded based on the central coordinates, level, and bound range. 2. When marking a point, based on the longitude and latitude of the point and the longitude and latitude range of the tile, you can determine the pixel Coordinate Position of the point in a certain tile, and the tile has a pixel relationship with bound, so point can be marked on the bound of map. 3. On the contrary, you can click the mouse on the bound to obtain the specific longitude and latitude information. This should be the foundation for the webmap engine to achieve a wide variety of map effects, including more functions such as line, surface, and map superposition.

I found an open-sourceCodeAfter you regroup it, you can obtain the inverse number between the number and latitude and longitude through the online method. Visit http://rovertang.com/labs/tileindex/. after you input the vertices and select the layers, you can get the Google tile and TMS tile index numbers:

It should be noted that Google tile is different from TMS because the Cartesian coordinate system origin of Google tile is in the upper left corner (that is, the intersection of the Arctic point and the central meridian ), the origin of TMS is in the lower left corner (the intersection of the South Pole and the central meridian ). Therefore, the X axis of the index is unchanged, and the Y axis is slightly changed. The result is that all the tile values in the column Minus Y and minus 1, and the formula is no longer listed. You can directly view the URL analysis provided by me.Source codeRight. Let's take a look at the index differences between Google tile and TMS at the Shanghai Expo Performing Arts Center (now the Mercedes Benz Performing Arts Center). After calculation, at 14 levels, google tile's X and Y are respectively 13721 and 6696, while TMS's X and Y are 13721 and 9687. the tile URLs of the two can access these two connections: refer (in the last Google Maps API V3 offline development package I have provided download, now added demo URL: http://rovertang.com/labs/GMAPIv3_Offline/), the comparison of the two is as follows:

BTW: If you need to change the TMS algorithm formula to executable code, refer to OSM wiki: slippy map tilenames. Python, Perl, PHP, and ,. net and other language code. If you are interested, refer.

 

 

Finally, although this article references more tilesArticleHowever, you may still have some one-sided understanding of tile maps.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.