问题描述
我正在使用https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_land.geojson中的geojson数据,并尝试在陆地上用h3十六进制网格填充这些多边形。陆地轮廓正确,但h3网格已拉伸。我假设我需要变换一些投影,但是我不确定在哪里。坦白地说,我不确定为什么还要打这个电话poly=geometry.polygon(area['geometry']['coordinates'][0])
,谢谢。
import folium import json from shapely import geometry import h3
gjfile=open('ne_50m_land.geojson','r') gjland = json.loads(gjfile.read())
m = folium.Map([51,-102],tiles='stamentoner',zoom_start=5,control_scale=True,max_zoom=20)
style = {'fillColor': '#f5f5f5','lineColor': '#ffffbf'}
for area in gjland['features']:
try:
poly=geometry.polygon(area['geometry']['coordinates'][0])
folium.GeoJson(poly,style_function=lambda x: style).add_to(m)
except: #ignore this multipolygon for Now. one island in northern russia
continue
poly =area
hexagons = list(h3.polyfill(poly['geometry'],3))
polylines = []
lat = []
lng = []
for hex in hexagons:
p2=h3.h3_to_geo(hex)
polygons = h3.h3_set_to_multi_polygon([hex],geo_json=False)
# flatten polygons into loops.
outlines = [loop for polygon in polygons for loop in polygon]
polyline = [outline + [outline[0]] for outline in outlines][0]
lat.extend(map(lambda v:v[0],polyline))
lng.extend(map(lambda v:v[1],polyline))
polylines.append(polyline)
for polyline in polylines:
my_polyLine=folium.polyLine(locations=polyline,weight=1,color='blue')
m.add_child(my_polyLine)
m.save('map.html')
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)