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.
Solved! Go to Solution.
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'])}")
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'])}")
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.