I am looking for a way to scale a selected polygon to a specific area. For an example, i have a selected polygon that is 8 acres in size and i want to scale it down to 5 acres without changing the shape of the polygon. So basically expanding or contracting the shape of the polygon. I had done this back in desktop v10.8, but i am having trouble making the conversion to Pro. Any help is appreciated.
Solved! Go to Solution.
This is how I handles it in Desktop and it worked really well
Public Class ScalePoly
Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Public m_pApp As IApplication = My.ArcMap.Application
Private pDoc As IMxDocument
Private pMap As IMap
Private pSelected As IEnumFeature
Public Sub New()
End Sub
Sub ScaleIt(ByVal pTrans2D As ITransform2D, ByVal dAreaFactor As Double)
Dim dFactor As Double
dFactor = dAreaFactor ^ 0.5
With pTrans2D
.Scale(GetCentroid(pTrans2D), dFactor, dFactor)
End With
End Sub
Function GetCentroid(ByVal pArea As IArea) As IPoint
GetCentroid = pArea.Centroid
End Function
Protected Overrides Sub OnClick()
Try
pDoc = m_pApp.Document
pMap = pDoc.FocusMap
Dim pActiveView As IActiveView
pActiveView = pDoc.FocusMap
pSelected = pDoc.FocusMap.FeatureSelection
'Get the selected layer and make sure it's a polygon feature class
Dim pFClass As IFeatureClass
Dim featTest As IFeature
featTest = pSelected.Next
If featTest Is Nothing Then
MsgBox("You must select at least one polygon", vbCritical)
Exit Sub
Else
pFClass = featTest.Class
If Not pFClass.ShapeType = esriGeometryType.esriGeometryPolygon Then
MsgBox("A Polygon feature must be selected -- please retry")
Exit Sub
End If
End If
'Move the pointer in the set to the top
pSelected.Reset()
Dim thePoly As IFeature
Dim pGeo As IGeometry
Dim theArea As IArea
Dim dDesiredArea As Double
Dim dCurrentArea As Double
Dim pArea As IArea
Dim pOrigin As IPoint
Dim pTransform As ITransform2D
Dim scaleValue As String = Nothing
thePoly = pSelected.Next
Do Until thePoly Is Nothing
pGeo = thePoly.Shape
theArea = thePoly.Shape
dCurrentArea = theArea.Area
Dim cbx2 = ESRI.ArcGIS.Desktop.AddIns.AddIn.FromID(Of ScalePolyCombo)(My.ThisAddIn.IDs.ScalePolyCombo)
cbx2.GetACValue(scaleValue)
If Not scaleValue = "" Then
dDesiredArea = Convert.ToDouble(scaleValue) * 43560
Else
MsgBox("Please enter a valid acreage value to scale polygon to")
Exit Sub
End If
If dDesiredArea < 1 Then
MsgBox("dDesiredArea is < 1")
Exit Sub
End If
ScaleIt(thePoly.Shape, dDesiredArea / dCurrentArea)
pArea = thePoly.Shape
pOrigin = pArea.Centroid
pTransform = thePoly.Shape
pTransform.Move(1, 1)
pGeo = pTransform
pGeo.SpatialReference = pMap.SpatialReference
thePoly.Shape = pGeo
thePoly.Store()
thePoly = pSelected.Next
Loop
'refresh the map display
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing)
pActiveView.Refresh()
'release obj's
scaleValue = Nothing
theArea = Nothing
thePoly = Nothing
dCurrentArea = 0
dDesiredArea = 0
Catch ex As Exception
MsgBox(ex.ToString)
Exit Sub
End Try
End Sub
Protected Overrides Sub OnUpdate()
End Sub
End Class
But i can't seem to make the conversion to Pro because a cannot find the equivalent for the ITransform2D in Pro.