python怎么来算面积_如何使用python来计算地球表面的多边形面积?

1586010002-jmsa.png

The title basically says it all. I need to calculate the area inside a polygon on the Earth's surface using Python. Calculating area enclosed by arbitrary polygon on Earth's surface says something about it, but remains vague on the technical details:

If you want to do this with a more

"GIS" flavor, then you need to select

an unit-of-measure for your area and

find an appropriate projection that

preserves area (not all do). Since you

are talking about calculating an

arbitrary polygon, I would use

something like a Lambert Azimuthal

Equal Area projection. Set the

origin/center of the projection to be

the center of your polygon, project

the polygon to the new coordinate

system, then calculate the area using

standard planar techniques.

So, how do I do this in Python?

解决方案

Let's say you have a representation of the state of Colorado in GeoJSON format

{"type": "Polygon",

"coordinates": [[

[-102.05, 41.0],

[-102.05, 37.0],

[-109.05, 37.0],

[-109.05, 41.0]

]]}

All coordinates are longitude, latitude. You can use pyproj to project the coordinates and Shapely to find the area of any projected polygon:

co = {"type": "Polygon", "coordinates": [

[(-102.05, 41.0),

(-102.05, 37.0),

(-109.05, 37.0),

(-109.05, 41.0)]]}

lon, lat = zip(*co['coordinates'][0])

from pyproj import Proj

pa = Proj("+proj=aea +lat_1=37.0 +lat_2=41.0 +lat_0=39.0 +lon_0=-106.55")

That's an equal area projection centered on and bracketing the area of interest. Now make new projected GeoJSON representation, turn into a Shapely geometric object, and take the area:

x, y = pa(lon, lat)

cop = {"type": "Polygon", "coordinates": [zip(x, y)]}

from shapely.geometry import shape

shape(cop).area # 268952044107.43506

It's a very close approximation to the surveyed area. For more complex features, you'll need to sample along the edges, between the vertices, to get accurate values. All caveats above about datelines, etc, apply. If you're only interested in area, you can translate your feature away from the dateline before projecting.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值