1

I have a geopandas GeoDataFrame with Polygon geometry and I am calculating the area of the polygon, however, I am not sure what the unit is for the area.

import geopandas as gpd
from shapely.geometry import Polygon

create two dummy polygons

poly1 = Polygon([(35.8,-98.666), (35.81,-98.656), (35.822,-98.662), (35.824,-98.678)]) poly2 = Polygon([(35.527,-98.709), (35.537,-98.699), (35.55,-98.706), (35.552,-98.722)])

create a geopandas DataFrame with two rows

data = {'name': ['Polygon 1', 'Polygon 2'], 'geometry': [poly1, poly2]} df = gpd.GeoDataFrame(data, crs='EPSG:4326')

I'd like to reproject the geometry and calculate the area in square meters or another linear unit, however, I have been having issues with re-projection and transforming geometries:

 `df['geometry'][0].area`

when I attempt to convert the crs to a projected coordinate reference system, I get Polygon (Inf Inf....).

df.to_crs('EPSG:32610', inplace=True)
df.crs

Expected output is to calculate the area() in square meters units.

kms
  • 473
  • 10
  • 24

1 Answers1

1

Have you reversed lat and long? If you swap them it works:

import geopandas as gpd
from shapely.geometry import Polygon

coords1 = [(35.8,-98.666), (35.81,-98.656), (35.822,-98.662), (35.824,-98.678)] coords1 = [x[::-1] for x in coords1] #Reverse lat lon #[(-98.666, 35.8), (-98.656, 35.81), (-98.662, 35.822), (-98.678, 35.824)]

coords2 = [(35.527,-98.709), (35.537,-98.699), (35.55,-98.706), (35.552,-98.722)] coords2 = [x[::-1] for x in coords2]

poly1 = Polygon(coords1) poly2= Polygon(coords2)

data = {'name': ['Polygon 1', 'Polygon 2'], 'geometry': [poly1, poly2]} df = gpd.GeoDataFrame(data, crs='EPSG:4326') df.apply(lambda x: x.geometry.is_valid, axis=1) #0 True #1 True

df = df.to_crs(epsg=26915) df.apply(lambda x: x.geometry.is_valid, axis=1)

0 True #Both were invalid with your original coordinates

1 True

df["area_m2"] = df.geometry.area

0 2.722672e+06

1 2.904215e+06

enter image description here

BERA
  • 72,339
  • 13
  • 72
  • 161
  • I swapped the axes to long, lat ...POLYGON ((-97.489 28.834, -97.479 28.844, -97.... and then gdf.geometry.area, I am still not seeing the values in square meters. The crs of the geoDataFrame is Projected CRS: EPSG:26915 – kms May 04 '23 at 18:45
  • I get approximately 0.000570 when running .area() method on geometry column. – kms May 04 '23 at 21:26