0

I would like to get some help in coding for implementing quadtree. I have a input node as spatial tile location in the format

<tile zoom level,tile row,tile column> given as 

<12,3943,1813>

I want to create a quadtree and add nodes(in java) to implement the following:

Input Level '12' is split as

<13,7886,3626> <13,7887,3626> <13,7886,3627> <13,7887,3627> . 

Futher each '13' level is split into level '14'.

<13,7886,3626> is split as

<14,15772,7252> <14,15773,7252> <14,15772,7253> <14,15773,7253>

<13,7887,3626> is split as

<14,15774,7252> <14,15775,7252> <14,15774,7253> <14,15775,7253>

<13,7886,3627> is split as

<14,15772,7254> <14,15773,7254> <14,15772,7255> <14,15773,7255>

<13,7887,3627> is split as

<14,15774,7254> <14,15775,7254> <14,15774,7255> <14,15775,7255>
user3138452
  • 85
  • 1
  • 5

1 Answers1

0

You could find some useful information on the MSDN: http://msdn.microsoft.com/en-us/library/bb259689.aspx

I can't provide you with the Java code to do that, but here is the dedicated method in C# so you can easily port it in Java:

/// <summary>
/// Converts tile XY coordinates into a QuadKey at a specified level of detail.
/// </summary>
/// <param name="tileX">Tile X coordinate.</param>
/// <param name="tileY">Tile Y coordinate.</param>
/// <param name="levelOfDetail">Level of detail, from 1 (lowest detail)
/// to 23 (highest detail).</param>
/// <returns>A string containing the QuadKey.</returns>
public static string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail)
{
    StringBuilder quadKey = new StringBuilder();
    for (int i = levelOfDetail; i > 0; i--)
    {
        char digit = '0';
        int mask = 1 << (i - 1);
        if ((tileX & mask) != 0)
        {
            digit++;
        }
        if ((tileY & mask) != 0)
        {
            digit++;
            digit++;
        }
        quadKey.Append(digit);
    }
    return quadKey.ToString();
}
Nicolas Boonaert
  • 2,954
  • 1
  • 20
  • 28