Reputation: 4023
In order to convert the coordinates of the geometries in a vector tile from TomTom, you need to know how many pixels are there in a tile. The documentation states that:
The extent is equal to 4096, so the value range for X and Y coordinates is from 0 to 4095.
But, another part of the documentation shows that meters/tile side is 40075017 and meters/pixel is 156543 at the zoom level 0. If you do the division, it comes to be about 256, which seems to indicate that each tile is 256 x 256.
So, which is it?
Tried to create a conversion method like following, but unsure if it's correct:
public static double[] convertFromLocalToGlobal(int x, int y, int tileX, int tileY, int zoom) {
double earthCircumference = 40075017.0;
int numTiles = 1 << zoom; // 2^zoom
double tileSize = earthCircumference / numTiles;
double originX = tileX * tileSize;
double originY = tileY * tileSize;
// I'm assuming 256 pixels per tile side because the documentation shows
// 40075017 metres for a tile side and 156543 metres for a pixel at zoom level 0
double posX = originX + x * (tileSize / 256);
double posY = originY + y * (tileSize / 256);
// Convert meters to global coordinates
double lon = (posX / earthCircumference) * 360.0 - 180.0;
double normalizedY = posY / earthCircumference;
double mercatorY = Math.PI * (1 - 2 * normalizedY);
double lat = Math.toDegrees(Math.atan(Math.sinh(mercatorY)));
return new double[]{lat, lon};
}
Upvotes: 0
Views: 25