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

In VectorTile.cpp the wrong latitudes are calculated. #1

Closed
Serinox opened this issue Jun 3, 2017 · 2 comments
Closed

In VectorTile.cpp the wrong latitudes are calculated. #1

Serinox opened this issue Jun 3, 2017 · 2 comments

Comments

@Serinox
Copy link
Contributor

Serinox commented Jun 3, 2017

Currently Cairo Egypt (specifically tile 9613,9626,14) is being calculated at roughly latitude -30 in the example project. I think this is due to a difference between the mbtile specification and the slippy tile spec that the tiley2lat and lat2tiley are expecting.

The mbtile format uses the "Tile Map Service Specification" which has incompatible tile indexing with slippy map tiles. The latitude functions seem to work when modified to be as follows:

double tiley2lat(int y, int z) 
{
	double n = pow(2.0,z);
	int ymax  = 1 << z;
	y = ymax - y - 1;
	double latRad = atan(sinh(M_PI*(1-(2*y/n))));
	return 180.0 / M_PI * latRad;
}

int lat2tiley(double lat, int z)
{
	int y = (int)(floor((1.0 - log( tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, z)));
	int ymax  = 1 << z;
	y = ymax - y - 1;
	return y;
}

these modifications were found here https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/

With the above changes Cairo is back at roughly latitude 30 comfortably above the equator.

@TimSC
Copy link
Owner

TimSC commented Jun 3, 2017

There is something weird going on... in openmaptiles.org tiles, Cairo is in 14/9613/9626 but in mapbox.com, it is 14/9613/6757... I need to have a think.

Update: As far as I can tell, the origin of tiles for mbtiles format is in the bottom left or south west (from a TileMill generated PBF, following the Tile Map Service Specification). However, for tile URLs the origin is in the top left/north west (following the google tiles convention). More info on the OSM wiki. Looks like I am worrying over nothing!

TimSC added a commit that referenced this issue Jun 4, 2017
@TimSC
Copy link
Owner

TimSC commented Jun 4, 2017

Fix committed to master. Thx @Serinox!

@TimSC TimSC closed this as completed Jun 4, 2017
TimSC added a commit that referenced this issue Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants