Select to view content in your preferred language

How to program "share a line segment with" functionality of Select by Location

1589
10
Jump to solution
04-23-2012 11:31 AM
USFS_AGOLAdministrator
Deactivated User
Hello all,

I have created a tool which finds the second largest polygon in a selectionset, and eliminates a polygon to the second largest polygon, instead of the largest polygon, as the native eliminate tool does in ArcMap.  In the Select By Location form, it gives you the option of selecting between several different Spatial selection methods, of which "Target layer features share a line segment with the source layer feature" is one of them.  I have written the following code:

Dim pSF As ISpatialFilter             pSF.Geometry = pFeat.Shape             pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects


It seems the ISpatialFilter interface does not give the ability to select features that share a line segment.  It gives the ability to do a bunch of other things, but selecting features that share a line segment is not one of them.  Is there another interface I'm missing somewhere that does give that functionality?
0 Kudos
10 Replies
USFS_AGOLAdministrator
Deactivated User
Lance, 

The following code does exactly what I need it to do, but only goes for bout 1500 records, then bombs out.  Can you see anything I can do to make it handle more records?  Really all this is doing is finding out how many neighboring polygons each polygon in the layer has.  Is there a better way to determine this?

pFeat = pFeatCur.NextFeature

While Not pFeat Is Nothing
   'Select each feature in the layer.  This feature will be used later to select other features that share a border with it.

  pQF.WhereClause = "OBJECTID = " & pFeat.OID
  Dim pSel As ISelectionSet = m_pFLay.FeatureClass.Select(pQF, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, pWorkspace)
  strParam.Add(m_pFLay.Name)
  strParam.Add("NEW_SELECTION")
  strParam.Add(pQF.WhereClause)

  'execute the select layer by attribute tool
  Dim results2 As IGeoProcessorResult = CType(gp.Execute("SelectLayerByAttribute_Management", strParam, Nothing), IGeoProcessorResult)

  If results2.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then
     MsgBox("Failed to execute select by attribute!",    MsgBoxStyle.Information, "frmSelectLayer_btnRun_click")
      results2 = Nothing
      gp = Nothing
      Exit Sub
  End If

  'now execute the select layer by location tool so we can select all features that share a border with each polygon in the layer
  strParam.RemoveAll()

  gp.OverwriteOutput = True

  strParam.Add(m_pFLay.Name)
  strParam.Add("SHARE_A_LINE_SEGMENT_WITH")
  strParam.Add("")
  strParam.Add("")
  strParam.Add("NEW_SELECTION")

  'execute the select layer by location tool
  Dim results As IGeoProcessorResult = CType(gp.Execute("SelectLayerByLocation_Management", strParam, Nothing), IGeoProcessorResult)

  If results.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then
      MsgBox("Failed to execute select by layer!", MsgBoxStyle.Information, "frmSelectLayer_btnRun_click")
      results = Nothing
      gp = Nothing
      Exit Sub
  End If

  strParam.RemoveAll()
  
  'now return the number of features that share a border, and populate the attribute table
  Dim pFSel As IFeatureSelection = CType(m_pFLay, IFeatureSelection)

  comReleaser.ManageLifetime(pFeat)
  nCurRecNo = nCurRecNo + 1
              
  Dim intFeatCount As Integer = pFSel.SelectionSet.Count
  pFeat.Value(lFld) = intFeatCount
  pFeatCur.UpdateFeature(pFeat)
              
  My.ArcMap.Application.StatusBar.Message(0) = nCurRecNo.ToString & "/" & n.ToString & " records complete."
  Me.ProgressBar1.Value = nCurRecNo

  GC.Collect()
  GC.WaitForPendingFinalizers()

  Marshal.ReleaseComObject(pFeat)

  pFeat = pFeatCur.NextFeature

  Application.DoEvents()
End While

0 Kudos