簡體   English   中英

計算 Python 中 GeoDataFrame 的總面積

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

我有一個帶有南美洲幾何形狀的 GeoDataFrame。 我想計算面積並按照以下方式進行:

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

結果應為 17759005.81506123,但為 0.001547957692761746。

我知道正確的版本是:

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

但我不明白區別在哪里。 你能給我解釋一下嗎?

  • 要以公頃為單位計算面積,必須使用 UTM CRS
  • 南美洲有多個 UTM CRS 區域。 使用一個會降低准確性
  • 已使用單個 UTM CRS 和按國家/地區的 UTM CRS 計算國家區域。 后來更接近你想要的結果
  • 我相信某些國家/地區將被多個 UTM CRS 區域覆蓋,因此即使按國家/地區,也可能會出現一些錯誤。 還取決於幾何的精度,如何使用低分辨率,所以這也會對精度產生一些影響
  • 結果顯示所有國家/地區的一個 UTM CRS 區域和每個國家/地區 UTM CRS 區域提供的結果與您的預期答案相當接近

結果比較

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