[英]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?
你能给我解释一下吗?
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.