calculation precision during projection transformation

I am using wgs 84 base tiles, and the tile is not rendered as image but with geojson format.

I try to draw them in the tile according to the data. And the geometry of the returned feature is lng and lat format.

This is the formula I used:

``````double tileNumWidth = 1 << (zoom+1);
double tileNumHeight = 1 << zoom ;
float px = (float) ((tileNumWidth * fromLngToX(x) - tileX) * 256);
float py = (float) ((tileNumHeight * fromLatToY(y) - tileY) * 256);

public static double fromLngToX(double lng) {
return (lng + 180) / 360d;
}

public static double fromLatToY(double lat) {
return (90 - lat) / 180d;
}
``````

It worked as expected in a lower zoom level:

http://pbrd.co/1qBajKH

However once the map is zoomed to a higher level like 18+, then I will found that the lines cross two tile may be not conjugated:

http://pbrd.co/1qBaN3k

You may notice the obvious drift(not much, seems only 1 px).

So I wonder if this is caused by the precision of calculation?

• A similar phenomenon exists in ESRI when you zoom in to more than 1:1, this is a render problem and has nothing to do with the data. – Michael Stimson May 14 '14 at 0:44
• Thanks for your attention. While you mean ESRI encounter the same problem if scale to more than 1:1, but, in my case, when the zoom is 18, the scale is almost 1:2000, far away from the 1:1. – giser May 14 '14 at 0:54
• Is that in ArcMap, QGIS, MapInfo.. The problem occurs in ArcMap because the ends are so far proportionately away from the zoom, it could also be to do with the driver, project-on-the-fly and float rounding. – Michael Stimson May 14 '14 at 0:57