[Visual Basic 6.0]The example shows how to get the Geometry properties for a selected polygon in an ArcMap edit session.
Public Sub t_IGeometry_polygon() Dim pID As New UID pID = "esriEditor.editor" Dim pEditor As IEditor Dim pApp As IApplication Set pApp = Application Set pEditor = pApp.FindExtensionByCLSID(pID) If pEditor.SelectionCount <> 1 Then MsgBox "select one polygon" Exit Sub End If Dim pEnumFeat As IEnumFeature Dim pFeature As IFeature Set pEnumFeat = pEditor.EditSelection Dim pGeometry As IGeometry Set pFeature = pEnumFeat.Next While Not pFeature Is Nothing If pFeature.Shape.GeometryType = esriGeometryPolygon Then Set pGeometry = pFeature.Shape MsgBox "+++Polygon::IGeometry properties..." & vbCrLf _ & "Dimension = " & pGeometry.Dimension & vbCrLf _ & "Geometry type = " & pGeometry.GeometryType & vbCrLf _ & "Envelope = " & pGeometry.Envelope.XMin & "," & pGeometry.Envelope.YMin & "," _ & pGeometry.Envelope.XMax & "," & pGeometry.Envelope.YMin & vbCrLf _ & "IsEmpty = " & pGeometry.IsEmpty & vbCrLf _ & "SpatialReference = " & pGeometry.SpatialReference.Name End If Set pFeature = pEnumFeat.Next Wend End Sub
[C#]// The example shows how to get the properties for a selected polygon in // an ArcMap edit session. public void ShowPolygonProperties() { //get editor extension UID editorUID = new UIDClass(); editorUID.Value = "esriEditor.Editor"; IEditor editor = m_application.FindExtensionByCLSID(editorUID) as IEditor;if (editor.SelectionCount != 1) { System.Windows.Forms.MessageBox.Show("Start Editor and select one polygon"); return; }IEnumFeature selectedFeatures = editor.EditSelection; IPoint centerPoint = new PointClass(); IPoint labelPoint = new PointClass(); IFeature feature = selectedFeatures.Next();while (feature != null) { if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { IArea area = feature.Shape as IArea; String message = "+++Polygon.IArea properties...\n" + "Area = " + area.Area + "\n" + "Center.X = " + area.Centroid.X + "\n" + "Center.Y = " + area.Centroid.Y + "\n" + "LabelPoint.X = " + area.LabelPoint.X + "\n" + "LabelPoint.Y = " + area.LabelPoint.Y; area.QueryCentroid(centerPoint); area.QueryLabelPoint(labelPoint); message = message + "\n" + "+++Polygon.IArea Queries..." + "\n" + "Center = " + centerPoint.X + "," + centerPoint.Y + "\n" + "Label = " + labelPoint.X + "," + labelPoint.Y;System.Windows.Forms.MessageBox.Show(message); }feature = selectedFeatures.Next(); } }
[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button
in the upper-left corner of the page.