0

我目前正在尝试使用 heatmap.py 为 Google Maps 生成热图覆盖。描述 heatmap.py 的网站 (http://jjguy.com/heatmap/) 展示了一张华盛顿特区上空的美丽热图以及用于生成它的代码。然而,运行代码后,我得到以下 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 生成类似于图中所示的热图。如果没有,您是否能够使用另一种方法生成类似的热图?谢谢。

4

1 回答 1

1

那不是“只是一个矩形框”。这正是 KML 中定义叠加层的方式。谷歌文档报告了这个例子:

<?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>

You can save it as kml file and check that it works. The main difference compared to the code in your question is the <color> tag: this example uses the alpha channel to reduce the opacity of the image. The <Icon> section contains a reference to the image to show, the <LatLonBox> contains the coordinates of the image.

Check the google documentation about GroundOverlay for more details.

于 2012-07-06T19:00:16.427 回答