How to create tiles?
2 posters
How to create tiles?
I have map database in a custom format so I cannot use any tool to convert map to format that can be used for OruxMaps. So, I have to do it on my own.
I see two ways to do it: to create simple online map server that receives x, y and z as parameters and create appropriate tile, or to create OruxMaps map database on my own. I prefer the first method as it would allow more general usability.
Well, there is just one issue: I do not know how to treat zoom levels. Database I deal with uses geo resolution (meters per pixel) to distinguish map quality. That means I can generate tile by specifying coordinates of one corner, width and height of a tile and geo resolution. Map I have uses Merkator projection so tiling is pretty much straightforward.
Tool I am going to create should accept coordinates, tile width and height (I recon 256 pixels is usual), and zoom level. I do not know how to match zoom level with map resolution.
Any hint on this?
I see two ways to do it: to create simple online map server that receives x, y and z as parameters and create appropriate tile, or to create OruxMaps map database on my own. I prefer the first method as it would allow more general usability.
Well, there is just one issue: I do not know how to treat zoom levels. Database I deal with uses geo resolution (meters per pixel) to distinguish map quality. That means I can generate tile by specifying coordinates of one corner, width and height of a tile and geo resolution. Map I have uses Merkator projection so tiling is pretty much straightforward.
Tool I am going to create should accept coordinates, tile width and height (I recon 256 pixels is usual), and zoom level. I do not know how to match zoom level with map resolution.
Any hint on this?
pedja- Cantidad de envíos : 111
Fecha de inscripción : 2010-12-06
Re: How to create tiles?
pedja wrote:I have map database in a custom format so I cannot use any tool to convert map to format that can be used for OruxMaps. So, I have to do it on my own.
I see two ways to do it: to create simple online map server that receives x, y and z as parameters and create appropriate tile, or to create OruxMaps map database on my own. I prefer the first method as it would allow more general usability.
Well, there is just one issue: I do not know how to treat zoom levels. Database I deal with uses geo resolution (meters per pixel) to distinguish map quality. That means I can generate tile by specifying coordinates of one corner, width and height of a tile and geo resolution. Map I have uses Merkator projection so tiling is pretty much straightforward.
Tool I am going to create should accept coordinates, tile width and height (I recon 256 pixels is usual), and zoom level. I do not know how to match zoom level with map resolution.
Any hint on this?
Hi, pedja;
It is easy;
zoom level 0 --> the world is one tile, 256 px ~ 40.000.000 mts.
zoom level 1 --> 2x2 tiles 512 px ~ 40.000.000 mts.
zoom level 2 --> 4x4 tiles 1024 px ~ 40.000.000 mts.
zoom level n --> 2^(2*n) tiles 256x(2^n) px ~ 40.000.000 mts.
orux
orux- Cantidad de envíos : 3946
Fecha de inscripción : 2009-07-06
Re: How to create tiles?
I am afraid it is not that simple. I guess this would not tolerate approximation in Earth size, and it math you suggested works only on Equator. As you go north or south, longitude circle shrinks so all math has to consider it.
I found example of an function that should do necessary calculation. I am yet to test it.
I found example of an function that should do necessary calculation. I am yet to test it.
- Code:
public static Bounds2 CalculateTileBounds (int tileX, int tileY, int zoomLevel)
{
Bounds2 bounds = new Bounds2 ();
double unit = 1.0 / (1 << zoomLevel);
double relY1 = tileY * unit;
double relY2 = relY1 + unit;
double yy1 = Math.Atan (Math.Sinh (Math.PI));
double limitY = Math.Log (Math.Tan (yy1) + 1.0 / Math.Cos(yy1));
double rangeY = 2 * limitY;
relY1 = limitY - rangeY * relY1;
relY2 = limitY - rangeY * relY2;
double lat1 = 180.0 / Math.PI * Math.Atan (Math.Sinh (relY1));
double lat2 = 180.0 / Math.PI * Math.Atan (Math.Sinh (relY2));
unit = 360.0 / (1 << zoomLevel);
double lon1 = -180 + tileX * unit;
bounds.MinY = lat1;
bounds.MaxY = lat2;
bounds.MinX = lon1;
bounds.MaxX = lon1 + unit;
bounds.Normalize ();
return bounds;
}
pedja- Cantidad de envíos : 111
Fecha de inscripción : 2010-12-06
Similar topics
» Is it possible to create offline map tiles from WMS map service?
» convert raw OSM instead of d/l tiles?
» Oruxmaps maps in the cloud
» Import multiple files, Swiss grid
» is it possible to refresh tiles in an offline map?
» convert raw OSM instead of d/l tiles?
» Oruxmaps maps in the cloud
» Import multiple files, Swiss grid
» is it possible to refresh tiles in an offline map?
Permissions in this forum:
You cannot reply to topics in this forum