I work with a map of Paris in ETRS89 / UTM zone 31N projection (EPSG:25831) and need to write slippy map tiles in filenames like /z/x/y.png
.
I made a custom python script to read the QGIS project file and write the tiles but I can't get the tile names right.
The extent of my map [minX, minY, maxX, maxY] is something like [230000, 6270000, 295000, 6225000]. So for example in zoom 10 they should be named something like:
/10/518/351.png
/10/519/351.png
/10/518/352.png
/10/519/352.png
How could I calculate the x and y tile names correctly? For now I try to calculate them starting with the transformation of the upper left corner from degrees to meters. The meter coordinates origin of slippy maps (85W 180N) in meters are:
originX = 471118.87
originY = 9446194.39
Now I calculate the tile size in meters using the resolution in meters (for example 76.43702828517624 for z=10) and tile size in pixels (for example 256):
tileSize = resolutionsInMeters[z] * tileSizeInPixels
With that numbers in mind I calculate the x and y tile names:
x = int( math.floor( ( minX-originX ) / tileSize ) )
y = int( math.floor( ( originY-maxY ) / tileSize ) )
The result definitely is wrong, any hints to get valid tile names?