我目前正在尝试使用 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 生成类似于图中所示的热图。如果没有,您是否能够使用另一种方法生成类似的热图?谢谢。