2014-02-19 101 views
0

我想在實現四叉樹的編碼方面得到一些幫助。我有作爲空間瓦片位置的輸入節點中的格式需要幫助添加節點來實現四叉樹java中

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

<12,3943,1813> 

我想創建四叉樹和添加節點(在Java)來實現以下內容:

輸入電平「12」被分割爲

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

進一步,每個'13'級別被分成級別'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> 
+0

請精確您的問題,我們沒有得到的代碼示例的點,你想用它去 –

+0

我有一個空間位置的瓷磚信息,格式爲<瓦變焦級別,瓷磚行,瓷磚umn> 首先,我給出的輸入爲<12,3943,1813> 我需要使用此信息創建四叉樹,即縮放級別13和縮放級別14 – user3138452

+0

您是否能夠根據提供的答案波紋管? –

回答

0

你能找到的MSDN一些有用的信息: http://msdn.microsoft.com/en-us/library/bb259689.aspx

我不能爲你提供了Java代碼來做到這一點,但這裏是C#中的專用方法,這樣你就可以輕鬆地移植它在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(); 
}