return geodesic area from spatial dataframe area property

863
2
Jump to solution
04-29-2022 07:29 AM
DavidAnderson_1701
Occasional Contributor

Now that the calculate geomemtry tool in Pro gives the option to calculate either planar area or geodesic area, I was wondering if spatial data frames would have that option.

Currently data_frame.spatial.area returns planar area.  The documentation (arcgis.features module — arcgis 2.0.0 documentation) does not show a option to flip between planar and geodesic.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
HamishMorton
Esri Contributor

Hi @DavidAnderson_1701,

Have you thought about using the areas_and_lengths function of the geometry.functions class? It isnt as easy as accessing the area property by doesnt add too much additional overhead!

I have put together an example below:

from arcgis.gis import GIS
from arcgis.geometry.functions import areas_and_lengths
from arcgis.features import GeoAccessor
from arcgis.geometry import LengthUnits, AreaUnits

# Sign in
gis = GIS("home")
print(f"Signed in to {gis.url} as {gis.users.me.username}.\n\nCreating SEDF:")


# Get Polygon layer and query to return SEDF
polygon_flc = gis.content.get("<item_id>")
print(f"Obtained item: {polygon_flc.title}")

# Get layer
polygon_fl = polygon_flc.layers[0]
print(f"Obtained layer: {polygon_fl.properties.name}")

# Query and return SEDF
polygon_sdf = GeoAccessor.from_layer(polygon_fl)
print(f"SEDF has {polygon_sdf.shape[0]} rows")

# Get the area of the entire dataframe (planar)
area_property_planar = polygon_sdf.spatial.area
print(f"Area property (planar) is: {area_property_planar}")

# Get the area of the entire dataframe (planar)
areas_lengths_planar = areas_and_lengths(
    polygons=list(polygon_sdf["SHAPE"]), 
    length_unit = LengthUnits.METER, 
    area_unit = AreaUnits.SQUAREMETERS, 
    calculation_type = "planar")
print(f"Areas and lengths (planar) is: {sum(areas_lengths_planar['areas'])}")

# Get the area of the entire dataframe (geodesic)
areas_lengths_geodesic = areas_and_lengths(
    polygons=list(polygon_sdf["SHAPE"]), 
    length_unit = LengthUnits.METER, 
    area_unit = AreaUnits.SQUAREMETERS, 
    calculation_type = "geodesic")
print(f"Areas and lengths (geodesic) is: {sum(areas_lengths_geodesic['areas'])}")

 

Hamish

View solution in original post

2 Replies
HamishMorton
Esri Contributor

Hi @DavidAnderson_1701,

Have you thought about using the areas_and_lengths function of the geometry.functions class? It isnt as easy as accessing the area property by doesnt add too much additional overhead!

I have put together an example below:

from arcgis.gis import GIS
from arcgis.geometry.functions import areas_and_lengths
from arcgis.features import GeoAccessor
from arcgis.geometry import LengthUnits, AreaUnits

# Sign in
gis = GIS("home")
print(f"Signed in to {gis.url} as {gis.users.me.username}.\n\nCreating SEDF:")


# Get Polygon layer and query to return SEDF
polygon_flc = gis.content.get("<item_id>")
print(f"Obtained item: {polygon_flc.title}")

# Get layer
polygon_fl = polygon_flc.layers[0]
print(f"Obtained layer: {polygon_fl.properties.name}")

# Query and return SEDF
polygon_sdf = GeoAccessor.from_layer(polygon_fl)
print(f"SEDF has {polygon_sdf.shape[0]} rows")

# Get the area of the entire dataframe (planar)
area_property_planar = polygon_sdf.spatial.area
print(f"Area property (planar) is: {area_property_planar}")

# Get the area of the entire dataframe (planar)
areas_lengths_planar = areas_and_lengths(
    polygons=list(polygon_sdf["SHAPE"]), 
    length_unit = LengthUnits.METER, 
    area_unit = AreaUnits.SQUAREMETERS, 
    calculation_type = "planar")
print(f"Areas and lengths (planar) is: {sum(areas_lengths_planar['areas'])}")

# Get the area of the entire dataframe (geodesic)
areas_lengths_geodesic = areas_and_lengths(
    polygons=list(polygon_sdf["SHAPE"]), 
    length_unit = LengthUnits.METER, 
    area_unit = AreaUnits.SQUAREMETERS, 
    calculation_type = "geodesic")
print(f"Areas and lengths (geodesic) is: {sum(areas_lengths_geodesic['areas'])}")

 

Hamish
DavidAnderson_1701
Occasional Contributor

That worked like a champ.  I hadn't dug into the geometry module much before now.  It is good to learn about the area_and_length functionality.

0 Kudos