Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a layer which has small rectangular gaps, I need to merge the gaps into the larger polygon that surrounds it, has anyone got any idea of how to do this, I know i can fill in the gaps with a new feature then go to Editor> Merge, but i have hundreds of these. If theres a way of doing this via vba or python, it would be great.

I'm using ArcGIS 9.3.1 (ArcEditor)

Heres what it looks like gaps is layer

share|improve this question
add comment

3 Answers 3

This can be done with a bunch of geoprocessing tools.

  1. Create a new large polygon layer that encompasses all features with holes
  2. Run the Symmetrical Difference tool
  3. Run the Multipart To Singlepart tool
  4. Delete the one very large feature from Multipart To Singlepart result layer
  5. Run Spatial Join, Target feature = result of Multipart To Singlepart layer
  6. Run Merge Tool
  7. Run Dissolve Tool, Dissolve Field option check the common ID field, and check the Unsplit lines check box

Once tested you could create a model within model builder and configure this process into a script. Sorry, links provided are for ArcGIS 10, same methodology though.

share|improve this answer
    
The symmetrical Difference tool is ArcInfo only, I've only got ArcEditor. –  Halil Siddique Feb 29 '12 at 21:12
add comment
up vote 2 down vote accepted

Thanks both, but I've found some vba code that did exactly what i wanted and was written by Kirk Kuykendall (so thanks Kirk).

Code is below

Option Explicit
Sub Test()
    ' loop through each selected feature
    ' and merge it with the adjacent feature
    ' that is largest.

    Dim pEditor As IEditor
    Set pEditor = _
      Application.FindExtensionByName("ESRI Object Editor")

    If pEditor.EditState <> esriStateEditing Then
        MsgBox "start editing first"
        Exit Sub
    End If

    Dim pEL As IEditLayers
    Set pEL = pEditor
    If pEL.CurrentLayer.FeatureClass.ShapeType _
       <> esriGeometryPolygon Then
        MsgBox "target layer not polygons"
        Exit Sub
    End If

    Dim pFSel As IFeatureSelection
    Set pFSel = pEL.CurrentLayer
    If pFSel.SelectionSet.Count = 0 Then
        MsgBox "nothing selected"
        Exit Sub
    End If

    Dim pFCur As IFeatureCursor
    pFSel.SelectionSet.Search Nothing, False, pFCur

    pEditor.StartOperation
    Dim pFeat As IFeature
    Set pFeat = pFCur.NextFeature
    Do Until pFeat Is Nothing
        Dim pLargestAdj As IFeature
        Set pLargestAdj = GetLargestAdjacent(pFeat)
        If Not pLargestAdj Is Nothing Then
            Dim pTopoOp As ITopologicalOperator
            Set pTopoOp = pLargestAdj.ShapeCopy
            Set pLargestAdj.Shape = pTopoOp.Union(pFeat.ShapeCopy)
            pLargestAdj.Store
            pFeat.Delete
        Else
            Debug.Print "nothing adjacent to: " & pFeat.OID
        End If
        Set pFeat = pFCur.NextFeature
    Loop
    pEditor.StopOperation "merge"
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    pMxDoc.ActiveView.Refresh
End Sub

Function GetLargestAdjacent(pFeat As IFeature) As IFeature
    Dim pSF As ISpatialFilter
    Set pSF = New SpatialFilter
    Set pSF.Geometry = pFeat.Shape
    pSF.SpatialRel = esriSpatialRelIntersects

    Dim pFC As IFeatureClass
    Set pFC = pFeat.Class
    Dim pFCur As IFeatureCursor
    Set pFCur = pFC.Search(pSF, False)

    Dim pFeat2 As IFeature, pLargestFeat As IFeature
    Dim dMaxArea As Double
    Set pFeat2 = pFCur.NextFeature
    Do Until pFeat2 Is Nothing
        If pFeat2.OID <> pFeat.OID Then
            If pLargestFeat Is Nothing Then
                Set pLargestFeat = pFeat2
                dMaxArea = GetArea(pFeat2.Shape)
            Else
                If GetArea(pFeat2.Shape) > dMaxArea Then
                    Set pLargestFeat = pFeat2
                    dMaxArea = GetArea(pFeat2.Shape)
                End If
            End If
        End If
        Set pFeat2 = pFCur.NextFeature
    Loop
    Set GetLargestAdjacent = pLargestFeat

End Function

Function GetArea(pArea As IArea) As Double
    GetArea = pArea.Area
End Function

Forum link is here http://forums.esri.com/Thread.asp?c=93&f=992&t=87064#238942

share|improve this answer
add comment

I think that there is a much easier answer to this one which I uncovered via a Discussion Forum posting a few years ago. That is to run the Union tool on the feature class in question (so it is the only feature class in the list) and uncheck the Gaps Allowed checkbox.

You will then need to Eliminate these small polygons which is easy using the tool of the same name in ArcInfo but should also be achievable with an ArcView or ArcEditor license using an ArcScript.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.