none
How to generate tile quadkeys between a set of latitude/longitude coordinates RRS feed

  • Question

  • Hello,

    I am trying to create an algorithm that could generate all the tile quadkeys at a certain zoom level (say, 13-20) between latitude and longitude coordinates. Let's say I have the top right coordinates, top left, bottom left, and bottom right. How can I generate the tile quadkeys in between?

    Any help would be appreciated! Thanks

    • Moved by Ricky_Brundritt Saturday, March 10, 2012 1:24 PM (From:Bing Maps: Map Control and Web services Development)
    Thursday, February 9, 2012 5:36 PM

Answers

  • All the calculations you need are given here: http://msdn.microsoft.com/en-us/library/bb259689.aspx

    Quadkeys are just an alternate way of referencing tiles as are defined under the x/y/z referencing system. I find it much easier to work in x/y/z because then, say, you know the distance covered by each tile at a given zoom level and calculate that you need 10 tiles across and 8 tiles down to fill the area - so iterate through the x and y identifiers by the required amount. You can then always convert from x/y/z to quadkey if needed.

    Why/what language are you writing this algorithm in? I've probably got some Python code lying around that does it.


    twitter: @alastaira blog: http://alastaira.wordpress.com/

    • Marked as answer by dybo Tuesday, February 14, 2012 2:12 PM
    Thursday, February 9, 2012 7:35 PM
    Moderator

All replies

  • From the sample code attached to the "Bing Map Tile System" http://msdn.microsoft.com/en-us/library/bb259689.aspx

    Use the following in this order:

    1. LatLongToPixelXY()
    2. PixelXYToTileXY()
    3. TileXYToQuadKey()


    Thursday, February 9, 2012 7:15 PM
  • All the calculations you need are given here: http://msdn.microsoft.com/en-us/library/bb259689.aspx

    Quadkeys are just an alternate way of referencing tiles as are defined under the x/y/z referencing system. I find it much easier to work in x/y/z because then, say, you know the distance covered by each tile at a given zoom level and calculate that you need 10 tiles across and 8 tiles down to fill the area - so iterate through the x and y identifiers by the required amount. You can then always convert from x/y/z to quadkey if needed.

    Why/what language are you writing this algorithm in? I've probably got some Python code lying around that does it.


    twitter: @alastaira blog: http://alastaira.wordpress.com/

    • Marked as answer by dybo Tuesday, February 14, 2012 2:12 PM
    Thursday, February 9, 2012 7:35 PM
    Moderator
  • Thanks for the replies!

    I am writing it in C# (for wp7). I know python though.

    So if I understand correctly, I can convert the lat/longs into PixelX/Ys, convert those into TileX/Ys. Then i just do 2 foreach loops to interate through the X and Ys and increment them by one during each interation? I can then convert them back to quadkeys if necessary.

    Friday, February 10, 2012 3:44 PM
  • So if I understand correctly, I can convert the lat/longs into PixelX/Ys, convert those into TileX/Ys. Then i just do 2 foreach loops to interate through the X and Ys and increment them by one during each interation? I can then convert them back to quadkeys if necessary.

    Bingo.

    Why would you want to do that on a WP7 device though? I assumed that you were trying to generate some sort of tilecache on a server..


    twitter: @alastaira blog: http://alastaira.wordpress.com/

    Friday, February 10, 2012 4:20 PM
    Moderator
  • Oh, I meant I am making an wp7 application, but this function would be server-side
    Tuesday, February 14, 2012 2:12 PM