Open Table of Contents

ET GeoWizards Scripting

Batch Processing - How to do it?

Performing batch operations is very important to many GIS users. ET GeoWizards has a couple of batch functions included in the interface - Batch Clip and Batch Erase, but there are many user request for more batch processing functions. The introduction of Scripting in ET GeoWizards 9.0 allows many functions of the software to be used in a batch mode with very easy VBA scripts.

Here is an example that will clip all the layers in the data frame with a specified polygon layer.

Sub BatchClip()
    Dim ET As New ETGW_Core
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim sLayerName As String
    Dim pFeatureLayer As IFeatureLayer
    Dim pInFeatureClass As IFeatureClass
    Dim pOutFeatureClass As IFeatureClass
    Dim sOutFileName As String
    Dim sOutDir As String
    Dim pClipLayer As IFeatureLayer
    Dim pClipFeatureClass As IFeatureClass
    Dim dFuzzyTol As Double
    Dim lCol As New Collection
    Dim j As Integer
    On Error GoTo EH
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Set pClipLayer = ET.GetLayer("clip_layer")
    If pClipLayer Is Nothing Then
        Exit Sub
    End If
    Set pClipFeatureClass = pClipLayer.FeatureClass
    dFuzzyTol = 0.002
   ' Get names of all the feature layers in the data frame
    Set lCol = ET.GetFeatureLayers("All")
    If (lCol.Count = 0) Then
        MsgBox "No suitable layers in the map"
        Exit Sub
    End If
    ' Assign the output folder
    sOutDir = "c:\00"
    ' Loop through the feature layers
    For j = 1 To lCol.Count
        sLayerName = lCol.Item(j)
        ' Skip the clip layer
        If (sLayerName <> "clip_layer") Then
            'Get a unique file name for each layer
            sOutFileName = ET.GetUniquefeature className(sOutDir, sLayerName, "_clipped")
           ' Get the feature layer using it's name
            Set pFeatureLayer = ET.GetLayer(sLayerName)
            Set pInFeatureClass = pFeatureLayer.FeatureClass
            Set pOutFeatureClass = ET.ClipIt(pInFeatureClass, pClipFeatureClass, _
                                                sOutFileName, dFuzzyTol)
            ' Check if the process completed successfully
            If Not pOutFeatureClass Is Nothing Then
                Set pFeatureLayer = New FeatureLayer
                Set pFeatureLayer.FeatureClass = pOutFeatureClass
                pFeatureLayer.Name = pOutFeatureClass.AliasName
                pMap.AddLayer pFeatureLayer
            End If
        End If
    Next j
    Set pMxDoc = Nothing
    Exit Sub
EH:
    Set pMxDoc = Nothing
    MsgBox Err.Description
End Sub

Copy friendly version of the script above