如何将 geopandas crs 单位转换为米^2?
How can I convert geopandas crs units to meters^2?
我正在使用 geopandas,我正在尝试获取我上传的 shapefile 的面积,但我不确定 .area 属性结果的测量单位是什么。这是我的代码:
water = gp.read_file("/Users/user/Downloads/tlgdb_2020_a_us_areawater.gdb")
lakeSup = water.loc[water['FULLNAME'].str.contains('Lk Superior', na=False)]
lakeSup = lakeSup.to_crs(epsg=4269)
lakeSup['area'] = lakeSup.area
print(lakeSup.head(10))
输出
ANSICODE ... area
233938 None ... 0.000821
629973 None ... 0.215539
629974 None ... 0.043184
629975 None ... 0.358674
629976 None ... 0.533665
629977 None ... 0.035854
629978 None ... 0.054233
629979 None ... 0.737469
629980 None ... 0.101494
629981 None ... 0.035499
根据 geopandas' docs,.area 属性“Returns 包含以 CRS 单位表示的 GeoSeries 中每个几何体面积的系列。”我很困惑这意味着什么,以及我如何使用这些信息来简单地为我的 shapefile 的几何图形(例如米^2)获得一个定义的区域。谢谢!
# Create a generic geoseries object
lakeSup = gpd.GeoSeries(
[Point(1, 1), Point(2, 2), Point(3, 3)], crs="EPSG:3857"
)
print(lakeSup.crs.axis_info)
给出输出:
[Axis(name=Easting, abbrev=X, direction=east, unit_auth_code=EPSG, unit_code=9001, unit_name=metre),
Axis(name=Northing, abbrev=Y, direction=north, unit_auth_code=EPSG, unit_code=9001, unit_name=metre)]
我想 unit_name 就是您要找的东西
geopandas 面积计算最重要的部分是您必须使用对应于 equal-area
投影的 CRS。在这种情况下,简单的 cylindrical equal-area projection
(epsg=6933) 很好用。
数据文件可以从:- data_source
相关代码应该变成:
water = gp.read_file("/Users/user/Downloads/tlgdb_2020_a_us_areawater.gdb")
# check the CRS
water.crs
# you should find that it is already `epsg=4269`
# select some rows of data
lakeSup = water.loc[water['FULLNAME'].str.contains('Lk Superior', na=False)]
# lakeSup = lakeSup.to_crs(epsg=4269) # already is
# convert CRS to equal-area projection
# the length unit is now `meter`
eqArea_lakeSup = lakeSup.to_crs(epsg=6933)
# compute areas in sq meters
areas = eqArea_lakeSup.area
# set the area units to sq Km.
# and add it as a new column to geodataframe
eqArea_lakeSup["area_sqKm"] = areas.values/10e6
# print some result
print(eqArea_lakeSup[["FULLNAME","area_sqKm"]].head(10))
输出:
FULLNAME area_sqKm
233938 Lk Superior 0.695790
629973 Lk Superior 181.784389
629974 Lk Superior 36.563379
629975 Lk Superior 303.028792
629976 Lk Superior 446.529784
629977 Lk Superior 30.418959
629978 Lk Superior 45.785750
629979 Lk Superior 621.004141
629980 Lk Superior 86.142490
629981 Lk Superior 30.186412
我正在使用 geopandas,我正在尝试获取我上传的 shapefile 的面积,但我不确定 .area 属性结果的测量单位是什么。这是我的代码:
water = gp.read_file("/Users/user/Downloads/tlgdb_2020_a_us_areawater.gdb")
lakeSup = water.loc[water['FULLNAME'].str.contains('Lk Superior', na=False)]
lakeSup = lakeSup.to_crs(epsg=4269)
lakeSup['area'] = lakeSup.area
print(lakeSup.head(10))
输出
ANSICODE ... area
233938 None ... 0.000821
629973 None ... 0.215539
629974 None ... 0.043184
629975 None ... 0.358674
629976 None ... 0.533665
629977 None ... 0.035854
629978 None ... 0.054233
629979 None ... 0.737469
629980 None ... 0.101494
629981 None ... 0.035499
根据 geopandas' docs,.area 属性“Returns 包含以 CRS 单位表示的 GeoSeries 中每个几何体面积的系列。”我很困惑这意味着什么,以及我如何使用这些信息来简单地为我的 shapefile 的几何图形(例如米^2)获得一个定义的区域。谢谢!
# Create a generic geoseries object
lakeSup = gpd.GeoSeries(
[Point(1, 1), Point(2, 2), Point(3, 3)], crs="EPSG:3857"
)
print(lakeSup.crs.axis_info)
给出输出:
[Axis(name=Easting, abbrev=X, direction=east, unit_auth_code=EPSG, unit_code=9001, unit_name=metre),
Axis(name=Northing, abbrev=Y, direction=north, unit_auth_code=EPSG, unit_code=9001, unit_name=metre)]
我想 unit_name 就是您要找的东西
geopandas 面积计算最重要的部分是您必须使用对应于 equal-area
投影的 CRS。在这种情况下,简单的 cylindrical equal-area projection
(epsg=6933) 很好用。
数据文件可以从:- data_source
相关代码应该变成:
water = gp.read_file("/Users/user/Downloads/tlgdb_2020_a_us_areawater.gdb")
# check the CRS
water.crs
# you should find that it is already `epsg=4269`
# select some rows of data
lakeSup = water.loc[water['FULLNAME'].str.contains('Lk Superior', na=False)]
# lakeSup = lakeSup.to_crs(epsg=4269) # already is
# convert CRS to equal-area projection
# the length unit is now `meter`
eqArea_lakeSup = lakeSup.to_crs(epsg=6933)
# compute areas in sq meters
areas = eqArea_lakeSup.area
# set the area units to sq Km.
# and add it as a new column to geodataframe
eqArea_lakeSup["area_sqKm"] = areas.values/10e6
# print some result
print(eqArea_lakeSup[["FULLNAME","area_sqKm"]].head(10))
输出:
FULLNAME area_sqKm
233938 Lk Superior 0.695790
629973 Lk Superior 181.784389
629974 Lk Superior 36.563379
629975 Lk Superior 303.028792
629976 Lk Superior 446.529784
629977 Lk Superior 30.418959
629978 Lk Superior 45.785750
629979 Lk Superior 621.004141
629980 Lk Superior 86.142490
629981 Lk Superior 30.186412