@Test @Category(UnitTest.class) public void testPixelToLatLonUL() { zoom = 1; int tileSize = MrGeoConstants.MRGEO_MRS_TILESIZE_DEFAULT_INT; long height = tileSize * (long) Math.pow(2.0, zoom - 1); long width = 2 * height; double resolution = TMSUtils.resolution(zoom, tileSize); LatLon result = TMSUtils.pixelToLatLonUL(0, 0, zoom, tileSize); Assert.assertEquals(-180.0, result.lon, 1e-8); Assert.assertEquals(90.0 - resolution, result.lat, 1e-8); result = TMSUtils.pixelToLatLonUL(width / 2 - 1, 0, zoom, tileSize); Assert.assertEquals(0.0 - resolution, result.lon, 1e-8); Assert.assertEquals(90.0 - resolution, result.lat, 1e-8); result = TMSUtils.pixelToLatLonUL(width / 2, 0, zoom, tileSize); Assert.assertEquals(0.0, result.lon, 1e-8); Assert.assertEquals(90.0 - resolution, result.lat, 1e-8); result = TMSUtils.pixelToLatLonUL(width - 1, 0, zoom, tileSize); Assert.assertEquals(180.0 - resolution, result.lon, 1e-8); Assert.assertEquals(90.0 - resolution, result.lat, 1e-8); result = TMSUtils.pixelToLatLonUL(width - 1, height - 1, zoom, tileSize); Assert.assertEquals(180.0 - resolution, result.lon, 1e-8); Assert.assertEquals(-90.0, result.lat, 1e-8); }
public static LatLon pixelToLatLonUL(long px, long py, int zoom, int tilesize) { Tile tile = pixelsULToTile(px, py, zoom, tilesize); Bounds bounds = tileBounds(tile.tx, tile.ty, zoom, tilesize); Pixel tilepx = latLonToPixelsUL(bounds.n, bounds.w, zoom, tilesize); double resolution = resolution(zoom, tilesize); long pixelsFromTileLeft = px - tilepx.px; long pixelsFromTileTop = py - tilepx.py; return new LatLon(bounds.n - (pixelsFromTileTop * resolution), bounds.w + (pixelsFromTileLeft * resolution)); }
TMSUtils { public static LatLon pixelToLatLonUL(long px, long py, int zoom, int tilesize) { Tile tile = pixelsULToTile(px, py, zoom, tilesize); Bounds bounds = tileBounds(tile.tx, tile.ty, zoom, tilesize); Pixel tilepx = latLonToPixelsUL(bounds.n, bounds.w, zoom, tilesize); double resolution = resolution(zoom, tilesize); long pixelsFromTileLeft = px - tilepx.px; long pixelsFromTileTop = py - tilepx.py; return new LatLon(bounds.n - (pixelsFromTileTop * resolution), bounds.w + (pixelsFromTileLeft * resolution)); } }
TMSUtils { public static LatLon pixelToLatLonUL(long px, long py, int zoom, int tilesize) { Tile tile = pixelsULToTile(px, py, zoom, tilesize); Bounds bounds = tileBounds(tile.tx, tile.ty, zoom, tilesize); Pixel tilepx = latLonToPixelsUL(bounds.n, bounds.w, zoom, tilesize); double resolution = resolution(zoom, tilesize); long pixelsFromTileLeft = px - tilepx.px; long pixelsFromTileTop = py - tilepx.py; return new LatLon(bounds.n - (pixelsFromTileTop * resolution), bounds.w + (pixelsFromTileLeft * resolution)); }  }
TMSUtils { public static LatLon pixelToLatLonUL(long px, long py, int zoom, int tilesize) { Tile tile = pixelsULToTile(px, py, zoom, tilesize); Bounds bounds = tileBounds(tile.tx, tile.ty, zoom, tilesize); Pixel tilepx = latLonToPixelsUL(bounds.n, bounds.w, zoom, tilesize); double resolution = resolution(zoom, tilesize); long pixelsFromTileLeft = px - tilepx.px; long pixelsFromTileTop = py - tilepx.py; return new LatLon(bounds.n - (pixelsFromTileTop * resolution), bounds.w + (pixelsFromTileLeft * resolution)); }  static Bounds limit(Bounds bounds); static TileBounds boundsToTile(Bounds bounds, int zoom,
    int tilesize); static TileBounds boundsToTileExact(Bounds bounds, int zoom,
    int tilesize); static Tile calculateTile(Tile tile, int srcZoom, int dstZoom,
    int tilesize); static boolean isValidTile(long tx, long ty, int zoomlevel); static Pixel latLonToPixels(double lat, double lon, int zoom,
    int tilesize); static Pixel latLonToPixelsUL(double lat, double lon, int zoom,
    int tilesize); static Tile latLonToTile(double lat, double lon, int zoom,
    int tilesize); static Pixel latLonToTilePixel(double lat, double lon, long tx,
    long ty, int zoom, int tilesize); static Pixel latLonToTilePixelUL(double lat, double lon, long tx,
    long ty, int zoom, int tilesize); static long numXTiles(int zoomlevel); static long numYTiles(int zoomlevel); static Tile pixelsToTile(double px, double py, int tilesize); static Tile pixelsULToTile(double px, double py, int zoom,
    int tilesize); static LatLon pixelToLatLon(long px, long py, int zoom,
    int tilesize); static LatLon pixelToLatLonUL(long px, long py, int zoom,
    int tilesize); static LatLon tilePixelToLatLon(long px, long py, Tile tile, int zoom,
    int tilesize); static LatLon tilePixelULToLatLon(long px, long py, Tile tile, int zoom,
    int tilesize); static double resolution(int zoom, int tilesize); static Bounds tileBounds(long tx, long ty, int zoom, int tilesize); static Bounds tileBounds(Tile tile, int zoom, int tilesize); static Bounds tileBounds(Bounds bounds, int zoom, int tilesize); static double[] tileBoundsArray(long tx, long ty, int zoom,
    int tilesize); static Tile tileid(long tileid, int zoomlevel); static long tileid(long tx, long ty, int zoomlevel); static long maxTileId(int zoomlevel); static double[] tileSWNEBoundsArray(long tx, long ty, int zoom,
    int tilesize); static Bounds tileToBounds(TileBounds bounds, int zoom,
    int tilesize); static int zoomForPixelSize(double pixelSize, int tilesize); }
TMSUtils { public static LatLon pixelToLatLonUL(long px, long py, int zoom, int tilesize) { Tile tile = pixelsULToTile(px, py, zoom, tilesize); Bounds bounds = tileBounds(tile.tx, tile.ty, zoom, tilesize); Pixel tilepx = latLonToPixelsUL(bounds.n, bounds.w, zoom, tilesize); double resolution = resolution(zoom, tilesize); long pixelsFromTileLeft = px - tilepx.px; long pixelsFromTileTop = py - tilepx.py; return new LatLon(bounds.n - (pixelsFromTileTop * resolution), bounds.w + (pixelsFromTileLeft * resolution)); }  static Bounds limit(Bounds bounds); static TileBounds boundsToTile(Bounds bounds, int zoom,
    int tilesize); static TileBounds boundsToTileExact(Bounds bounds, int zoom,
    int tilesize); static Tile calculateTile(Tile tile, int srcZoom, int dstZoom,
    int tilesize); static boolean isValidTile(long tx, long ty, int zoomlevel); static Pixel latLonToPixels(double lat, double lon, int zoom,
    int tilesize); static Pixel latLonToPixelsUL(double lat, double lon, int zoom,
    int tilesize); static Tile latLonToTile(double lat, double lon, int zoom,
    int tilesize); static Pixel latLonToTilePixel(double lat, double lon, long tx,
    long ty, int zoom, int tilesize); static Pixel latLonToTilePixelUL(double lat, double lon, long tx,
    long ty, int zoom, int tilesize); static long numXTiles(int zoomlevel); static long numYTiles(int zoomlevel); static Tile pixelsToTile(double px, double py, int tilesize); static Tile pixelsULToTile(double px, double py, int zoom,
    int tilesize); static LatLon pixelToLatLon(long px, long py, int zoom,
    int tilesize); static LatLon pixelToLatLonUL(long px, long py, int zoom,
    int tilesize); static LatLon tilePixelToLatLon(long px, long py, Tile tile, int zoom,
    int tilesize); static LatLon tilePixelULToLatLon(long px, long py, Tile tile, int zoom,
    int tilesize); static double resolution(int zoom, int tilesize); static Bounds tileBounds(long tx, long ty, int zoom, int tilesize); static Bounds tileBounds(Tile tile, int zoom, int tilesize); static Bounds tileBounds(Bounds bounds, int zoom, int tilesize); static double[] tileBoundsArray(long tx, long ty, int zoom,
    int tilesize); static Tile tileid(long tileid, int zoomlevel); static long tileid(long tx, long ty, int zoomlevel); static long maxTileId(int zoomlevel); static double[] tileSWNEBoundsArray(long tx, long ty, int zoom,
    int tilesize); static Bounds tileToBounds(TileBounds bounds, int zoom,
    int tilesize); static int zoomForPixelSize(double pixelSize, int tilesize); final static int MAXZOOMLEVEL; }