[英]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
但我不明白區別在哪里。 你能給我解釋一下嗎?
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.