Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using TileCache from MetaCarta to create tiles for a WMS service. It creates a tile with an URL like http://example.com/tiles/Admin/06/000/000/357/000/000/158.png.

I am trying to understand how to start from Map Coordinates, and get the appropriate tile.

I am looking for some documentation which explains the Folder structure/hierarchy of the server cache directory

share|improve this question
    
D'you want to get tile from coordinate? –  Aragon Jun 12 '12 at 13:32
    
@Aragon: You are correct. I want to know which tile corresponds to a particular location and given zoom level –  Devdatta Tengshe Jun 12 '12 at 13:34
add comment

2 Answers

up vote 3 down vote accepted

answer to my comment(this code is for my tms scheme and you can adapt it to your need):

var originShift = 2 * Math.PI * 6378137 / 2.0;
var initialResolution = 2 * Math.PI * 6378137 / 256; //tilesize

var lon = 10;
var lat = 20;

var mx = lon * originShift / 180.0;
var my = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);

my = my * originShift / 180.0;

//MetersToPixel(mx, my, zooma)
var res = initialResolution / (Math.pow(2, zooma));
var px = (mx + originShift) / res;
var py = (my + originShift) / res;

//PixelsToTile(px, py)
var tx = Math.ceil(px / parseFloat(256)) - 1;
var ty = Math.ceil(py / parseFloat(256)) - 1;

tx and ty will give you to tms result as lanlot. if you want to know equivalent to google map, you can calculate the Y file name (Math.pow(2, zoom) - 1) - ty

Google Tile Mechanism: x/y/z.jpg

TMS Tile Mechanism: z/y/x.jpg

i hope it helps you...

share|improve this answer
1  
It looks like TileCache is not a TMS, because the url of the tile (example.com/tiles/Admin/06/000/000/357/000/000/158.png) has 7 components (after the name of the service) and not just 3, like in your answer –  Devdatta Tengshe Jun 12 '12 at 14:58
add comment

Not to be snarky, but just read the source.

share|improve this answer
1  
While I agree, that the getKey function from the linked page, technically answers this question, your link is not an answer. It supposes that the reader understands Python. It would have been better if you could have explained the formula, and shown how the x, y & z make up the long url. –  Devdatta Tengshe Jun 12 '12 at 14:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.