Create a Map Tile Downloader

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Create a Map Tile Downloader

Nakadale
Hello! Can anyone help me with my problem? I'm trying to do a map tile downloader for my map app. problem is when I try to implement the formula from this site Slippy Map Tilenames the tiles X and Y number that i get are off. Upon further trying to make it work is for me to get the Zoom Level with decimal numbers. I wonder if there maybe other way to get the correct tiles aside from using Slippy Map Tilenames or if there can be a way to calculate the Zoom level with decimals?
Reply | Threaded
Open this post in threaded view
|

Re: Create a Map Tile Downloader

Dev3
Hi Nakadale,
Based on your question on GIS.SE, and this one, I feel that you are misunderstanding the Slippy map tile structure. The structure of the Tile sets is fixed.
  • For a particular zoom level, the x & y of the tiles goes from 0 to (2^zoom)-1.
  • There are only integer zoomlevels (from 0 to 19...), and you can't get zoomlevles in decimal values.

It is important to note that the formulas given on the linked page give the coordinates for the NW-corner of the square.


If you want to download tiles, have a look at this gist which I've successfully used in the past: https://gist.github.com/devdattaT/dd218d1ecdf6100bcf15

To successfully download tiles, you need to find which tiles intersect your study area, and only download those. To find which tiles which intersect your study area, you can use the bounding box of your polygon as the first check. Find out which tiles contain your geometry by  checking for tiles that contain the top-left & Bottom-right of your bounding box. Your Geometry will be guaranteed to be within these. After this, as a secondary filter, you can check if your geometry intersects each tile before downloading it, if required.

If this doesn't answer your question, you need to explain why you are interested with partial zoom-levels and resolution.

Regards,
Devdatta Tengshe


On Mon, Jul 14, 2014 at 12:48 PM, Nakadale <[hidden email]> wrote:
Hello! Can anyone help me with my problem? I'm trying to do a map tile
downloader for my map app. problem is when I try to implement the formula
from this site  Slippy Map Tilenames
<http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Zoom_levels>   the
tiles X and Y number that i get are off. Upon further trying to make it work
is for me to get the Zoom Level with decimal numbers. I wonder if there
maybe other way to get the correct tiles aside from using Slippy Map
Tilenames or if there can be a way to calculate the Zoom level with
decimals?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Create-a-Map-Tile-Downloader-tp5150857.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev


_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Create a Map Tile Downloader

slippyr4
here are some bits of c# code which will help the OP out. 

// you won't be able to use BoundingBox<T> - that's my class - but these are the "world extents" for a OSM map
_worldExtents = new BoundingBox<Coord>(left: -20037508.34, right: 20037508.34, top: 20037508.34, bottom: -20037508.34);

// compute resolutions for each zoom level
double[] resolutions = new double[_numZoomLevels];
            for (int z = 0; z < _numZoomLevels; z++)
            {
                resolutions[z] = (_worldExtents.Width / _tileSize) / Math.Pow(2.0, z);
            }


then you need to know how big a tile is in your chosen zoom level
private const int _tileSize = 256;
double _tileSizeMetres = _resolutions[_zoomLevel] * _tileSize;

// then you can work out the range of tiles you need
// e.MapExtents  is the region of interest (a rectangle in EPSG 3857)
            var tile_min_x = (int)Math.Floor((e.MapExtents.Left - _worldExtents.Left) / _tileSizeMetres);
            var tile_max_x = (int)Math.Floor((e.MapExtents.Right - _worldExtents.Left) / _tileSizeMetres);
            var tile_min_y = (int)Math.Floor((_worldExtents.Top - e.MapExtents.Top) / _tileSizeMetres);
            var tile_max_y = (int)Math.Floor((_worldExtents.Top - e.MapExtents.Bottom) / _tileSizeMetres);

// logically you can now do the following:-

for (int x = tile_min_x; x <= tile_max_x; x++)
            {
                for (int y = tile_min_y; y <= tile_max_y; y++)
                {
             // download tile x,y, _zoomLevel here

}
}


hope that helps. it's not finished code and won't compile, but if you regard it as pseudo-code it works correctly.


On 15 July 2014 12:29, Devdatta Tengshe <[hidden email]> wrote:
Hi Nakadale,
Based on your question on GIS.SE, and this one, I feel that you are misunderstanding the Slippy map tile structure. The structure of the Tile sets is fixed.
  • For a particular zoom level, the x & y of the tiles goes from 0 to (2^zoom)-1.
  • There are only integer zoomlevels (from 0 to 19...), and you can't get zoomlevles in decimal values.

It is important to note that the formulas given on the linked page give the coordinates for the NW-corner of the square.


If you want to download tiles, have a look at this gist which I've successfully used in the past: https://gist.github.com/devdattaT/dd218d1ecdf6100bcf15

To successfully download tiles, you need to find which tiles intersect your study area, and only download those. To find which tiles which intersect your study area, you can use the bounding box of your polygon as the first check. Find out which tiles contain your geometry by  checking for tiles that contain the top-left & Bottom-right of your bounding box. Your Geometry will be guaranteed to be within these. After this, as a secondary filter, you can check if your geometry intersects each tile before downloading it, if required.

If this doesn't answer your question, you need to explain why you are interested with partial zoom-levels and resolution.

Regards,
Devdatta Tengshe


On Mon, Jul 14, 2014 at 12:48 PM, Nakadale <[hidden email]> wrote:
Hello! Can anyone help me with my problem? I'm trying to do a map tile
downloader for my map app. problem is when I try to implement the formula
from this site  Slippy Map Tilenames
<http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Zoom_levels>   the
tiles X and Y number that i get are off. Upon further trying to make it work
is for me to get the Zoom Level with decimal numbers. I wonder if there
maybe other way to get the correct tiles aside from using Slippy Map
Tilenames or if there can be a way to calculate the Zoom level with
decimals?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Create-a-Map-Tile-Downloader-tp5150857.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev


_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev


_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Create a Map Tile Downloader

Nakadale
This post was updated on .
Hi Slippyr4,

I have to ask since my base map isn't really the whole world map but just a portion of it. let's say i can only zoom in and zoom out on the island of Australia. would the "World Extents" be the same as the one on your code?

Thank you for the help! :)
Reply | Threaded
Open this post in threaded view
|

Re: Create a Map Tile Downloader

slippyr4
Yes, the world extents stay the same, because they are used to work out the proper x,y,z tiles based on the EPSG3857 projection which DOES cover the whole planet. 

That you are only interested in australia is neither here nor there.

mapExtents, in my code, is the area of map that my app is displaying. consider it your region of interest. If your intention is to calculate the tileset that corresponds to australia, then that forms your mapExtent.


On 18 July 2014 02:39, Nakadale <[hidden email]> wrote:
Hi Slippyr4,

I have to ask since my base map isn't really the whole world map but just a
portion of it. let's say i can only zoom in and zoom out on the island of
Australia. would the "World Extents" be the same as the one on your code?
and when you are referring to MapExtends that would mean the size of the map
container?

Thank you for the help! :)



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Create-a-Map-Tile-Downloader-tp5150857p5151635.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev


_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev