有没有可能在叶子上做一个椭圆?
Is it possible to make a elipse on folium?
我在网上看到folium在地图上生成一个椭圆形的图片,是否可以,我尝试手动创建但是每个点都是不可见的,有什么办法可以做到吗?
elipse on folium
是的,通过使用 folium 的多边形(和其他一些东西)
我为多边形构造复制了这个
import math
from shapely.geometry import Point
from shapely.affinity import scale, rotate
#input parameters
A = Point(-95.5, 41.25)
B = Point(-96.5, 41.25)
R = .25
d = A.distance(B)
#first, rotate B to B' around A so that |AB'| = |AB| and B'.y = A.y
#and then take S as midpoint of AB'
S = Point(A.x + d/2, A.y)
#alpha represents the angle of this rotation
alpha = math.atan2(B.y - A.y, B.x - A.x)
#create a circle with center at S passing through A and B'
C = S.buffer(d/2)
#rescale this circle in y-direction so that the corresponding
#axis is R units long
C = scale(C, 1, R/(d/2))
#rotate the ellipse obtained in previous step around A into the
#original position (positive angles represent counter-clockwise rotation)
C = rotate(C, alpha, origin = A, use_radians = True)
其中 C 是一个匀称的多边形
print(type(C))
<class 'shapely.geometry.polygon.Polygon'>
我将坐标从 X,Y 翻转到 Y,X 以使其对叶子友好
folium_poly = [[y,x] for x,y in C.exterior.coords]
剩下的就是叶
import folium
m = folium.Map([C.centroid.y, C.centroid.x])
folium.Polygon(folium_poly).add_to(m)
m
我在网上看到folium在地图上生成一个椭圆形的图片,是否可以,我尝试手动创建但是每个点都是不可见的,有什么办法可以做到吗? elipse on folium
是的,通过使用 folium 的多边形(和其他一些东西)
我为多边形构造复制了这个
import math
from shapely.geometry import Point
from shapely.affinity import scale, rotate
#input parameters
A = Point(-95.5, 41.25)
B = Point(-96.5, 41.25)
R = .25
d = A.distance(B)
#first, rotate B to B' around A so that |AB'| = |AB| and B'.y = A.y
#and then take S as midpoint of AB'
S = Point(A.x + d/2, A.y)
#alpha represents the angle of this rotation
alpha = math.atan2(B.y - A.y, B.x - A.x)
#create a circle with center at S passing through A and B'
C = S.buffer(d/2)
#rescale this circle in y-direction so that the corresponding
#axis is R units long
C = scale(C, 1, R/(d/2))
#rotate the ellipse obtained in previous step around A into the
#original position (positive angles represent counter-clockwise rotation)
C = rotate(C, alpha, origin = A, use_radians = True)
其中 C 是一个匀称的多边形
print(type(C))
<class 'shapely.geometry.polygon.Polygon'>
我将坐标从 X,Y 翻转到 Y,X 以使其对叶子友好
folium_poly = [[y,x] for x,y in C.exterior.coords]
剩下的就是叶
import folium
m = folium.Map([C.centroid.y, C.centroid.x])
folium.Polygon(folium_poly).add_to(m)
m