gpt4 book ai didi

django - GeoDjango:确定多边形的面积

转载 作者:行者123 更新时间:2023-12-04 11:22:13 27 4
gpt4 key购买 nike

在我的模型中,我通过以下方式定义了一个多边形字段

polygon = models.PolygonField(srid=4326, geography=True, null=True, blank=True)

当我想确定多边形的面积时,我调用
area_square_degrees = object.polygon.area

但是如何将结果转换为 square degrees使用 GeoDjango 进入 m2?
This answer不起作用,因为 area没有方法 sq_m .是否有任何内置转换?

最佳答案

您需要将数据转换为正确的空间引用系统。

area_square_local_units = object.polygon.transform(srid, clone=False).area

在英国,您可能会使用使用米的英国国家电网 SRID 27700。
area_square_meters = object.polygon.transform(27700, clone=False).area

您可能想要也可能不想克隆几何体,这取决于您是否需要在其未变换状态下对其进行任何其他操作。

文档在这里 https://docs.djangoproject.com/en/1.8/ref/contrib/gis/geos/

关于django - GeoDjango:确定多边形的面积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19892943/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com