简体   繁体   English

计算 Python 中 GeoDataFrame 的总面积

[英]Calculating the total Area of a GeoDataFrame in Python

I have a GeoDataFrame with the geometry of South America.我有一个带有南美洲几何形状的 GeoDataFrame。 I wanted to calculate the area and did this the following way:我想计算面积并按照以下方式进行:

south_america.geometry.to_crs(epsg=3035)
south_america.loc[:, "AREA"] = south_america.geometry.area / 10**6
totalArea = south_america.AREA.sum()

The result should be 17759005.81506123, but is 0.001547957692761746.结果应为 17759005.81506123,但为 0.001547957692761746。

I know that the correct version is:我知道正确的版本是:

totalArea = sum(south_america.geometry.to_crs(epsg=3035).area) / 10**6

but I don't understand where the difference is.但我不明白区别在哪里。 Can you please explain it to me?你能给我解释一下吗?

  • to calculate areas in hectares it's necessary to use UTM CRS要以公顷为单位计算面积,必须使用 UTM CRS
  • there are multiple UTM CRS zones in South America.南美洲有多个 UTM CRS 区域。 Using one will reduce accuracy使用一个会降低准确性
  • have calculated country areas using a single UTM CRS and a UTM CRS by country.已使用单个 UTM CRS 和按国家/地区的 UTM CRS 计算国家区域。 Later gets closer to result you want后来更接近你想要的结果
  • I believe some countries will be covered by multiple UTM CRS zones, so even by country there is potential for some error.我相信某些国家/地区将被多个 UTM CRS 区域覆盖,因此即使按国家/地区,也可能会出现一些错误。 Also depends on accuracy of geometry, how used lowres so this will also have some impact on accuracy还取决于几何的精度,如何使用低分辨率,所以这也会对精度产生一些影响
  • results show both one UTM CRS zone for all countries and per country UTM CRS zone provide a result reasonably close to your expected answer结果显示所有国家/地区的一个 UTM CRS 区域和每个国家/地区 UTM CRS 区域提供的结果与您的预期答案相当接近

results comparison结果比较

1.0345126720577646 1.014198080585325
import geopandas as gpd

gdf = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))

# filter to south america and calculate area is hectares based on UTM geometry
south_america = gdf.loc[gdf["continent"].eq("South America")].assign(
    area=lambda d: d.to_crs(d.estimate_utm_crs()).area / 10**6,
    area_2=lambda d: [
        gpd.GeoDataFrame(geometry=[g], crs=gdf.crs).pipe(
            lambda d: d.to_crs(d.estimate_utm_crs()).area.sum() / 10**6
        )
        for g in d["geometry"]
    ],
)

# compare results to expected using global UTM approach and UTM by country
a = 17759005.81506123
print(south_america["area"].sum() / a, south_america["area_2"].sum() / a)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM