2012-07-06 41 views
0

我目前正在嘗試使用heatmap.py生成熱圖覆蓋圖到Google地圖。描述heatmap.py的站點(http://jjguy.com/heatmap/)顯示華盛頓特區上的一張美麗熱圖的圖片以及用於生成它的代碼。運行代碼後,但是,我得到以下KML輸出:使用heatmap.py生成kml文件

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
    <Folder> 
    <GroundOverlay> 
     <Icon> 
     <href>classic.png</href> 
     </Icon> 
     <LatLonBox> 
     <north>38.9096822126249293</north> 
     <south>38.8880342183292171</south> 
     <east>-77.0127326291108432</east> 
     <west>-77.0498038539626435</west> 
     <rotation>0</rotation> 
     </LatLonBox> 
    </GroundOverlay> 
    </Folder> 
</kml> 

這僅僅是一個長方形的盒子。此外,我調查了源代碼,發現以下內容:

KML = """<?xml version="1.0" encoding="UTF-8"?>                               
<kml xmlns="http://www.opengis.net/kml/2.2">                               
    <Folder>                                        
    <GroundOverlay>                                      
     <Icon>                                       
     <href>%s</href>                                     
     </Icon>                                       
     <LatLonBox>                                      
     <north>%2.16f</north>                                   
     <south>%2.16f</south>                                   
     <east>%2.16f</east>                                    
     <west>%2.16f</west>                                    
     <rotation>0</rotation> 
    <GroundOverlay>                                      
     <Icon>                                       
     <href>%s</href>                                     
     </Icon>                                       
     <LatLonBox>                                      
     <north>%2.16f</north>                                   
     <south>%2.16f</south>                                   
     <east>%2.16f</east>                                    
     <west>%2.16f</west>                                    
     <rotation>0</rotation>                                   
     </LatLonBox>                                      
    </GroundOverlay>                                     
    </Folder>                                        
</kml>""" 

def saveKML(self, kmlFile): 
    """                                        
    Saves a KML template to use with google earth. Assumes x/y coordinates                       
    are lat/long, and creates an overlay to display the heatmap within Google                      
    Earth.                                       

    kmlFile -> output filename for the KML.                              
    """ 

    tilePath = os.path.basename(self.imageFile) 
    north = self.maxXY[1] 
    south = self.minXY[1] 
    east = self.maxXY[0] 
    west = self.minXY[0] 

    bytes = KML % (tilePath, north, south, east, west) 
    file(kmlFile, "w").write(bytes) 

這看起來確實如此,輸出建議。有沒有人能夠使用heatmap.py生成類似於圖片的熱圖。如果沒有,您是否能夠使用其他方法生成類似的熱圖?謝謝。

回答

1

這不是「只是一個矩形框」。這正是如何在KML中定義覆蓋。 Google文檔報告此示例:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
<GroundOverlay> 
    <name>GroundOverlay.kml</name> 
    <color>7fffffff</color> 
    <drawOrder>1</drawOrder> 
    <Icon> 
     <href>http://www.google.com/intl/en/images/logo.gif</href> 
     <refreshMode>onInterval</refreshMode> 
     <refreshInterval>86400</refreshInterval> 
     <viewBoundScale>0.75</viewBoundScale> 
    </Icon> 
    <LatLonBox> 
     <north>37.83234</north> 
     <south>37.832122</south> 
     <east>-122.373033</east> 
     <west>-122.373724</west> 
     <rotation>45</rotation> 
    </LatLonBox> 
</GroundOverlay> 
</kml> 

您可以將其另存爲kml文件並檢查其是否有效。與您的問題中的代碼相比,主要區別在於<color>標記:此示例使用Alpha通道來減少圖像的不透明度。 <Icon>部分包含要顯示的圖像的引用,<LatLonBox>包含圖像的座標。

Check the google documentation about GroundOverlay for more details