Calculate mean aspect for polygons

9720
5
03-20-2012 11:43 PM
JohannesRein
New Contributor II
Hello

I have a dem and a polygon featureclass for which i want to calculate the mean aspect for every single polygon.

I found a topic about this problem in the old esri forum , but unfortunaly i do not get a correct result.

1) Generate the ASPECT for the dem
2) Calculate COS and SIN for the Aspect-raster (COS = ([ASPECT] * 0.01745329)) (SIN([ASPECT] * 0.01745329))
3) Zonal Statistics to SUM the SIN and COS raster for every Polygon.
4) RASTER = 360 + ATAN2([SUM_COS], [SUM_SIN]) * 180 / pi
5) RESULT = MOD([RASTER], 360)

The result i get from the calculations seems to be correct for a few areas, but in others it is shifted of 90 or 180 degrees.

I don't know what i am doing wrong.

Thank you.
0 Kudos
5 Replies
Luke_Pinner
MVP Regular Contributor
Do you actually need "mean" aspect? Another option is to generate a trend surface and calculate aspect from that to get the overall aspect of a polygon - eg:
[ATTACH=CONFIG]12944[/ATTACH]

To do this...

  • Clip and mask your DEM to the polygon

  • Convert the masked DEM to points, or...

  • Create Random Points constrained by your landslide polygon which you can use to sample the elevation values.
Then

  • Generate the elevation trend surface from those points and then calculate aspect (and slope if required) from that.

0 Kudos
CarlBeyerhelm
Occasional Contributor
The attached zip file contains a Python script tool that calculates zonal mean aspect azimuth, and mean aspect class.

The syntax for the fundamental calculation is:

math.fmod(360 + (math.atan2(!MeanSin!, !MeanCos!)) * (180 / math.pi), 360)
RyanDeBruyn1
New Contributor III

Great sample.   Thought to add for reference if one wanted to calculate the output as Raster in Map Algebra

from arcpy.sa import *
import math
asp = Aspect(inElevation)
aspNull = SetNull(asp, asp, "VALUE = -1")
aspCos = Cos(aspNull * math.pi / 180.0)
aspSin = Sin(aspNull * math.pi / 180.0)
xxSumSin = ZonalStatistics(inZones,"OBJECTID", "aspSin", "MEAN", "DATA")
xxSumCos = ZonalStatistics(inZones,"OBJECTID", aspCos, "MEAN", "DATA")
asp_azm = (360+(ATan2(xxSumSin,xxSumCos)) * (180 / math.pi)) % 360.0
0 Kudos
Laura_G
New Contributor

I have roughly ~700 polygons that I would like to derive the mean aspect for each. I've downloaded the zip file and input the polygon featureclass. I've also specified the zoneID field but the tool won't accept any of my elevation rasters. 
I've tried exporting my rasters to ESRI grid, I've tried changing the source type properties from generic to elevation. I've tried shortening the file names and the tool always returns  ERROR -1 Input must be an ESRI grid...

I'm not sure where I've gone wrong. Any help/advice would be greatly appreciated 

0 Kudos
CarlBeyerhelm
Occasional Contributor

I've revised the code to be compatible with ArcGIS Pro, and to accept either a TIFF or ESRI grid as the elevation raster.

The revised toolbox and user guidance are attached as a ZIP file.