<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Trend Plane in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702943#M18829</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may not be what you're looking for and its certainly not what I would call concise however the attached code generates a trend plane through all the points within each drainage area.&amp;nbsp; It then calculates the slope and aspect of the trend plane and enters them into the drainage area feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used point geometry as the input to the IInterpolationOp.Trend method but I believe you may be able to use a grid instead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Public Sub CreateTrendPlane()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pSF As ISpatialFilter
Dim pLiDARPointsLayer&amp;nbsp; As IFeatureLayer
Dim pDALayer As IFeatureLayer
Dim pDAFeatCur As IFeatureCursor
Dim pDAFeat As IFeature
Dim pSelectionSet As ISelectionSet
Dim pArea As IArea
Dim pPoint As IPoint
Dim pArray As IArray
Dim pRasterIdentify As IRasterIdentifyObj
Dim pSurfaceOp As ISurfaceOp
Dim pRasterLayer As IRasterLayer
Dim pOutputRaster As IRaster
Dim pAspectRaster As IRaster
Dim pSlopeRaster As IRaster
Dim pIdentify As IIdentify
Dim lAspectFieldIndex As Long
Dim lSlopeFieldIndex As Long

Const ElevationFieldName = "GRID_CODE"

Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

Set pDALayer = pMap.Layer(0) ' put DA layer at top of TOC
Set pLiDARPointsLayer = pMap.Layer(1) ' put LidarPoints layer next

lAspectFieldIndex = pDALayer.FeatureClass.FindField("MyAspect")
lSlopeFieldIndex = pDALayer.FeatureClass.FindField("MySlope")

Dim iCount As Integer
Dim iNumber As Integer
iCount = 1
iNumber = pDALayer.FeatureClass.FeatureCount(Nothing)

Set pDAFeatCur = pDALayer.FeatureClass.Search(Nothing, False)
Set pDAFeat = pDAFeatCur.NextFeature

While Not pDAFeat Is Nothing

&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSF = New SpatialFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSF.Geometry = pDAFeat.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; pSF.GeometryField = pLiDARPointsLayer.FeatureClass.ShapeFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; pSF.SpatialRel = esriSpatialRelContains
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSelectionSet = pLiDARPointsLayer.FeatureClass.Select(pSF, esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFDescr As IFeatureClassDescriptor
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFDescr = New FeatureClassDescriptor
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFDescr.CreateFromSelectionSet pSelectionSet, Nothing, ElevationFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pInterpolationOp As IInterpolationOp
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pInterpolationOp = New RasterInterpolationOp
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pRasterAnalysisEnv As IRasterAnalysisEnvironment
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterAnalysisEnv = pInterpolationOp
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterAnalysisEnv.SetCellSize esriRasterEnvValue, CVar(15)
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterAnalysisEnv.SetExtent esriRasterEnvMaxOf
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pInputPoints As IGeoDataset
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pInputPoints = pFDescr
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pOutputRaster = pInterpolationOp.Trend(pInputPoints, esriGeoAnalysisLinearTrend, 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSurfaceOp = New RasterSurfaceOp
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pAspectRaster = pSurfaceOp.Aspect(pOutputRaster)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSlopeRaster = pSurfaceOp.Slope(pOutputRaster, esriGeoAnalysisSlopePercentrise)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterLayer = New rasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterLayer.CreateFromRaster pAspectRaster
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pIdentify = pRasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArea = pDAFeat.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoint = pArea.Centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArray = pIdentify.Identify(pPoint)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterIdentify = pArray.Element(0)
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Value(lAspectFieldIndex) = pRasterIdentify.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Store
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterLayer = New rasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterLayer.CreateFromRaster pSlopeRaster
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pIdentify = pRasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArray = pIdentify.Identify(pPoint)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterIdentify = pArray.Element(0)
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Value(lSlopeFieldIndex) = pRasterIdentify.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Store
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pDAFeat = pDAFeatCur.NextFeature
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ThisDocument.Parent.StatusBar.Message(0) = "Calculated " &amp;amp; CStr(iCount) &amp;amp; " of " &amp;amp; CStr(iNumber)
&amp;nbsp;&amp;nbsp;&amp;nbsp; iCount = iCount + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Wend

MsgBox "Done"

End Sub
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:33:53 GMT</pubDate>
    <dc:creator>JeremySury</dc:creator>
    <dc:date>2021-12-12T05:33:53Z</dc:date>
    <item>
      <title>Mean slope calculation code for VBScript or Python</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702942#M18828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've been working tirelessly on trying to develop a code that will return an average slope for a selected area.&amp;nbsp; I can build a model to give me the answer, but not as concise as I want it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The ideal code would be VBScript in which the user select an existing shapfile, runs the code, then a message box appears stating "Average Slope = XX.XX%".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an elevation database on C:\geodata\elevation\ containing a 10m DEM and a slope file derived using spatial analyst of that DEM.&amp;nbsp; The problem I see is using the extent/mask of a selected shapefile to calculate the mean pixel value of the slope raster.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We use a code for finding shape acres (code listed below) and I've been trying to piggyback off of it with no avail.&amp;nbsp; I've also tried using python but am having trouble making a scipt that will list a message box stating "Average Slope =".&amp;nbsp; When I use this method I use zonal statistics and it provides a nice large table, but I only want the Mean value to be printed out as a message box.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for any advice anyone may have,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Tyson&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Public Sub ShapeAcres()

Dim pMxDoc As IMxDocument
Dim pArea As IArea
Dim pAcres As Double, pFeet As Double, pMeters As Double
Dim i As Integer, Looper As Integer
Dim pPoly As IFeature
Dim pMap As IMap
Dim pFSelection As IEnumFeature
Dim pActiveView As IActiveView
Dim pContentsView As IContentsView

Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pActiveView = pMap
Set pContentsView = pMxDoc.CurrentContentsView
Set pFSelection = pMap.FeatureSelection
i = pMap.SelectionCount

'-- Make sure element is selected
If i = 0 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Please select one or more shapes"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
End If

Do Until Looper = i
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoly = pFSelection.Next
&amp;nbsp;&amp;nbsp;&amp;nbsp; Looper = Looper + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArea = pPoly.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; pMeters = (pMeters + pArea.Area)
Loop

pFeet = pMeters * 10.76391042
pAcres = pFeet / 43560
MsgBox "Percent Slope = " &amp;amp; Format(pAcres, "##,###.0")

End Sub&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 18:17:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702942#M18828</guid>
      <dc:creator>TysonHart</dc:creator>
      <dc:date>2010-04-21T18:17:12Z</dc:date>
    </item>
    <item>
      <title>Trend Plane</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702943#M18829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may not be what you're looking for and its certainly not what I would call concise however the attached code generates a trend plane through all the points within each drainage area.&amp;nbsp; It then calculates the slope and aspect of the trend plane and enters them into the drainage area feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used point geometry as the input to the IInterpolationOp.Trend method but I believe you may be able to use a grid instead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Public Sub CreateTrendPlane()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pSF As ISpatialFilter
Dim pLiDARPointsLayer&amp;nbsp; As IFeatureLayer
Dim pDALayer As IFeatureLayer
Dim pDAFeatCur As IFeatureCursor
Dim pDAFeat As IFeature
Dim pSelectionSet As ISelectionSet
Dim pArea As IArea
Dim pPoint As IPoint
Dim pArray As IArray
Dim pRasterIdentify As IRasterIdentifyObj
Dim pSurfaceOp As ISurfaceOp
Dim pRasterLayer As IRasterLayer
Dim pOutputRaster As IRaster
Dim pAspectRaster As IRaster
Dim pSlopeRaster As IRaster
Dim pIdentify As IIdentify
Dim lAspectFieldIndex As Long
Dim lSlopeFieldIndex As Long

Const ElevationFieldName = "GRID_CODE"

Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

Set pDALayer = pMap.Layer(0) ' put DA layer at top of TOC
Set pLiDARPointsLayer = pMap.Layer(1) ' put LidarPoints layer next

lAspectFieldIndex = pDALayer.FeatureClass.FindField("MyAspect")
lSlopeFieldIndex = pDALayer.FeatureClass.FindField("MySlope")

Dim iCount As Integer
Dim iNumber As Integer
iCount = 1
iNumber = pDALayer.FeatureClass.FeatureCount(Nothing)

Set pDAFeatCur = pDALayer.FeatureClass.Search(Nothing, False)
Set pDAFeat = pDAFeatCur.NextFeature

While Not pDAFeat Is Nothing

&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSF = New SpatialFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSF.Geometry = pDAFeat.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; pSF.GeometryField = pLiDARPointsLayer.FeatureClass.ShapeFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; pSF.SpatialRel = esriSpatialRelContains
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSelectionSet = pLiDARPointsLayer.FeatureClass.Select(pSF, esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFDescr As IFeatureClassDescriptor
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFDescr = New FeatureClassDescriptor
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFDescr.CreateFromSelectionSet pSelectionSet, Nothing, ElevationFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pInterpolationOp As IInterpolationOp
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pInterpolationOp = New RasterInterpolationOp
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pRasterAnalysisEnv As IRasterAnalysisEnvironment
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterAnalysisEnv = pInterpolationOp
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterAnalysisEnv.SetCellSize esriRasterEnvValue, CVar(15)
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterAnalysisEnv.SetExtent esriRasterEnvMaxOf
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pInputPoints As IGeoDataset
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pInputPoints = pFDescr
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pOutputRaster = pInterpolationOp.Trend(pInputPoints, esriGeoAnalysisLinearTrend, 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSurfaceOp = New RasterSurfaceOp
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pAspectRaster = pSurfaceOp.Aspect(pOutputRaster)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSlopeRaster = pSurfaceOp.Slope(pOutputRaster, esriGeoAnalysisSlopePercentrise)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterLayer = New rasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterLayer.CreateFromRaster pAspectRaster
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pIdentify = pRasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArea = pDAFeat.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPoint = pArea.Centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArray = pIdentify.Identify(pPoint)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterIdentify = pArray.Element(0)
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Value(lAspectFieldIndex) = pRasterIdentify.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Store
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterLayer = New rasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pRasterLayer.CreateFromRaster pSlopeRaster
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pIdentify = pRasterLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArray = pIdentify.Identify(pPoint)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRasterIdentify = pArray.Element(0)
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Value(lSlopeFieldIndex) = pRasterIdentify.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDAFeat.Store
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pDAFeat = pDAFeatCur.NextFeature
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ThisDocument.Parent.StatusBar.Message(0) = "Calculated " &amp;amp; CStr(iCount) &amp;amp; " of " &amp;amp; CStr(iNumber)
&amp;nbsp;&amp;nbsp;&amp;nbsp; iCount = iCount + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Wend

MsgBox "Done"

End Sub
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:33:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702943#M18829</guid>
      <dc:creator>JeremySury</dc:creator>
      <dc:date>2021-12-12T05:33:53Z</dc:date>
    </item>
    <item>
      <title>Mean slope calculation code for VBScript or Python</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702944#M18830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess with my limited scripting knowledge I couldn't get the code to run.&amp;nbsp; There were several arguments that i wasn't able to debug.&amp;nbsp; But, in looking around I think I've found the code I want but I can't figure out how to get it to run.&amp;nbsp; Its probably very basic but I'm really struggling with making it run.&amp;nbsp; Here's the code, I just need to figure out how to implement it and adjust the resulting min/max to mean from the dbf table:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Public Sub GetLayerZonalMinMax(pRasLayer As IRasterLayer, ByRef min As Double, ByRef max As Double)
&amp;nbsp;&amp;nbsp;&amp;nbsp; If pRasLayer.Raster Is Nothing Then Exit Sub
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pMxDoc As IMxDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pMap As IMap
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pCompositeLayer As ICompositeLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pLayer As ILayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMxDoc = ThisDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMap = pMxDoc.FocusMap
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pCompositeLayer = pMap.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pLayer = pCompositeLayer.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFeaturelayer As IFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeaturelayer = pLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pDataset As IDataset
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pDataset = pFeaturelayer.FeatureClass
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim sPath As String
&amp;nbsp;&amp;nbsp;&amp;nbsp; sPath = pDataset.Workspace.pathname &amp;amp; "\" &amp;amp; pDataset.Name &amp;amp; ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim outputTable As String
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim tablePath As String
&amp;nbsp;&amp;nbsp;&amp;nbsp; tablePath = "C:\gis\temp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim tableName As String
&amp;nbsp;&amp;nbsp;&amp;nbsp; tableName = "output.dbf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'tableName = pRasLayer.Name + ".dbf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; outputTable = tablePath + "\" + tableName
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim rasPath As String
&amp;nbsp;&amp;nbsp;&amp;nbsp; rasPath = pRasLayer.FilePath
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim gp As Object
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set gp = CreateObject("esriGeoprocessing.GPDispatch.1")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CheckOutExtension "spatial"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Load required toolboxes...
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddToolbox "C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx"
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.ZonalStatisticsAsTable_sa sPath, "ZONE", rasPath, outputTable, "DATA"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pWSF As IWorkspaceFactory
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFeatureWS As IFeatureWorkspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pTable As ITable
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pWSF = New ShapefileWorkspaceFactory
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureWS = pWSF.OpenFromFile(tablePath, 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pTable = pFeatureWS.OpenTable(tableName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myMin As Double
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myMax As Double
&amp;nbsp;&amp;nbsp;&amp;nbsp; myMin = pTable.GetRow(0).Value(4)
&amp;nbsp;&amp;nbsp;&amp;nbsp; myMax = pTable.GetRow(0).Value(5)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pDataset = pTable
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDataset.Delete
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
End Sub&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/mean-slope-calculation-code-for-vbscript-or-python/m-p/702944#M18830</guid>
      <dc:creator>TysonHart</dc:creator>
      <dc:date>2021-12-12T05:33:56Z</dc:date>
    </item>
  </channel>
</rss>

