0

現在、heatmap.py を使用して Google マップにヒートマップ オーバーレイを生成しようとしています。heatmap.py を説明しているサイト (http://jjguy.com/heatmap/) には、ワシントン DC の美しいヒートマップの写真と、それを生成するために使用されたコードが示されています。ただし、コードを実行すると、次の 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 でオーバーレイが定義されている方法です。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>タグです。この例では、アルファ チャネルを使用して画像の不透明度を減らしています。<Icon>セクションには、表示する画像への参照が含まれており、<LatLonBox>画像の座標が含まれています。

詳細については、GroundOverlay に関する Google ドキュメントを確認してください

于 2012-07-06T19:00:16.427 に答える