Generalize a Polygon or Polycurve

Created:3/8/2000
Description:

The code below shows how you can generalize a line or polygon using the Douglas-Poiker algorithm.

For an example of how to generalize feaures within a FeatureClass, see the Simplify Tool Control sample.


How to use:
  1. Open ArcMap, open the VBA editor and paste the code below into the code window.
  2. Select a line or polygon graphic in ArcMap, and then run the Generalize macro.
Option Explicit

Public Sub Generalize()
  '
  ' Generalize works on a Path or Polycurve, so first we need to find out the
  ' Geometry we'll be acting on.
  '
  Dim pMxDoc As IMxDocument, pGraphicsSelect As IGraphicsContainerSelect
  Set pMxDoc = ThisDocument
  Set pGraphicsSelect = pMxDoc.ActiveView
  If pGraphicsSelect.ElementSelectionCount = 1 Then
    '
    ' Get the currently selected item.
    '
    Dim pElement As IElement
    Set pElement = pGraphicsSelect.SelectedElement(0)
    Dim pGeom As IGeometry
    Set pGeom = pElement.Geometry
    '
    ' We can call Generalize on Geometries with a CoClass of Polygon, Polyline or Ring.
    '
    If (pGeom.GeometryType = esriGeometryPolygon) Or (pGeom.GeometryType = esriGeometryPolyline) Then
      Dim pPolycurve As IPolycurve2
      Set pPolycurve = pGeom
      pPolycurve.Generalize pPolycurve.Length / 50
      pElement.Geometry = pGeom
    End If
    pMxDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
  End If
End Sub