Skip to content Skip to sidebar Skip to footer

How Can I Convert Geopandas Crs Units To Meters^2?

I'm using geopandas, and I'm trying to get the areas of the shapefile I uploaded, but I'm unsure of what the unit of measurement is for the result of the .area attribute. Here is m

Solution 1:

The most important part of area computation by geopandas is that you must use the CRS that corresponds to an equal-area projection. In this case, the simple cylindrical equal-area projection (epsg=6933) is good to use.

The data files can be obtained from:- data_source

The relevant code should becomes:

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))

Output:

           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

Solution 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)

Gives the output:

[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)]

I think unit_name is what you are looking for


Post a Comment for "How Can I Convert Geopandas Crs Units To Meters^2?"