![](/img/trans.png)
[英]How can we parse a JSON file for specific records of county borders and overlay that on a Folium HeatMap?
[英]How can we plot City borders, or County borders, on a Folium Map?
我有一些代碼可以為我生成一個不錯的 Heat Map。 這是我的代碼。
import folium
from folium.plugins import HeatMap
max_amount = float(df_top20['Total_Minutes'].max())
hmap = folium.Map(location=[35.5, -82.5], zoom_start=7, )
hm_wide = HeatMap(list(zip(df_top20.Latitude.values, df_top20.Longitude.values, df_top20.Total_Minutes.values)),
min_opacity=0.2,
max_val=max_amount,
radius=25,
blur=20,
max_zoom=1,
)
hmap.add_child(hm_wide)
如何在這個 map 上疊加特定的北卡羅來納州城市或縣? 我在 dataframe 中有城市/縣。
如果要疊加衛星圖像:
coordinates = [35.5, -82.5]
start_and_end_dates = ee.DateRange('2015-06-30', '2023-07-01')
ee_image_col = ee.ImageCollection('LANDSAT/LC08/C02/T1').filterBounds(ee.Geometry.Point(coordinates[1], coordinates[0])).filterDate(start_and_end_dates).first()
def add_ee_layer(self, ee_image_col, params, name):
map_dict = ee.Image(ee_image_col).getMapId(params)
folium.raster_layers.TileLayer(
tiles=map_dict['tile_fetcher'].url_format,
attr='Map Data © <a href="https://earthengine.google.com/">Google Earth Engine</a>',#"Map Data © Google Earth Engine"
name=name,
overlay=True,
control=True
).add_to(self)
hmap.add_tile_layer(ee_image_col, params={'bands': ['B4', 'B3', 'B2'], 'min': 5000, 'max': 12000}, name=sat_id)
hmap.add_child(folium.LayerControl())
folium.LayerControl(collapsed=False).add_to(hmap)
您可以使用.clip()
裁剪區域以指定城市或縣,或裁剪給定zoom_deg
:
def get_geoJSON_data(coordinates, zoom_deg):
return {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
coordinates[1] - zoom_deg,
coordinates[0] - zoom_deg
],
[
coordinates[1] + zoom_deg,
coordinates[0] - zoom_deg
],
[
coordinates[1] + zoom_deg,
coordinates[0] + zoom_deg
],
[
coordinates[1] - zoom_deg,
coordinates[0] + zoom_deg
],
[
coordinates[1] - zoom_deg,
coordinates[0] - zoom_deg
]
]
]
}
}
]
}
zoom_deg = 10.0
像...first().clip(ee.Geometry.Polygon(get_geoJSON_data(coordinates, zoom_deg)['features'][0]['geometry']['coordinates']))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.