OruxMaps
Visit the new forum: <a href="http://www.oruxmaps.com/foro">OruxMaps</a>

Join the forum, it's quick and easy

OruxMaps
Visit the new forum: <a href="http://www.oruxmaps.com/foro">OruxMaps</a>
OruxMaps
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How to create tiles?

2 posters

Go down

How to create tiles? Empty How to create tiles?

Post  pedja Mon Apr 09, 2012 10:45 am

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?

Question

pedja

Cantidad de envíos : 111
Fecha de inscripción : 2010-12-06

Back to top Go down

How to create tiles? Empty Re: How to create tiles?

Post  orux Mon Apr 09, 2012 7:21 pm

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?

Question

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
orux

Cantidad de envíos : 3946
Fecha de inscripción : 2009-07-06

Back to top Go down

How to create tiles? Empty Re: How to create tiles?

Post  pedja Tue Apr 10, 2012 10:21 am

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.

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

Back to top Go down

How to create tiles? Empty Re: How to create tiles?

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum