用到了两个库:shapely、pyproj,直接pip安装即可。
from pyproj import Geod
from shapely.geometry import Point, LineString, Polygon
# 计算距离
line_string = LineString([Point(123.429056, 41.833526), Point(123.435235, 41.773191)])
geod = Geod(ellps="WGS84")
geod.geometry_length(line_string)
# 计算封闭区域面积、周长
geod = Geod(ellps="WGS84")
geod.geometry_area_perimeter(Polygon([
(123.432746, 41.792136), (123.435922, 41.784584),
(123.450857, 41.784392), (123.447681, 41.79252),
]))