How to calculate area for each feature in a Spatially Enabled Dataframe?

645
5
Jump to solution
06-10-2022 10:35 AM
Josh-R
by
New Contributor III

How does one calculate area for each feature in a Spatially Enabled Dataframe?  I read it in from a shapefile and need the acreage of each feature. I also would like to store the area as a new column.  This should be simple but I can't find a straight forward answer that works, I've referenced the two similar posts. Thank you!

 

sedf = pd.DataFrame.spatial.from_featureclass(myShapeFile)

 

 
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

You want to get a GeoSeriesAccessor and use its area property, maybe pipe that into a new field.

sedf = pd.DataFrame.spatial.from_featureclass(myShapeFile)

gsa = arcgis.features.GeoSeriesAccessor(sedf['SHAPE'])

# add column using insert
sedf.insert(0, 'the_area', gsa.area, True)

# alternatively, just add a new column at the end of the sedf
sedf['the_area'] = gsa.area

 

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
DanPatterson
MVP Esteemed Contributor

you could just calculate in the shapefile first


... sort of retired...
0 Kudos
Josh-R
by
New Contributor III

Please excuse the simplified example. I'm doing a bunch geoprocessing beforehand that I'm not showing, so I would like an updated calculation. I can do it in arcpy no problem but I am curious if the arcgis api has a way to do it.

0 Kudos
jcarlson
MVP Esteemed Contributor

You want to get a GeoSeriesAccessor and use its area property, maybe pipe that into a new field.

sedf = pd.DataFrame.spatial.from_featureclass(myShapeFile)

gsa = arcgis.features.GeoSeriesAccessor(sedf['SHAPE'])

# add column using insert
sedf.insert(0, 'the_area', gsa.area, True)

# alternatively, just add a new column at the end of the sedf
sedf['the_area'] = gsa.area

 

- Josh Carlson
Kendall County GIS
Josh-R
by
New Contributor III

Exactly what I was looking for! Thank you!

0 Kudos
DavidAnderson_1701
Occasional Contributor
0 Kudos