Why esriSpatialRelTouches relation does not work?

1645
3
01-29-2012 10:14 PM
New Contributor
I have two feature layers. The first one is just a polygon and the other one consists of a series of polygons which are enclosed by the first one. Thus, some polygons of the second feature layer touch on the boundaries of the first feauture layer. I wrotre a code (the basic part shown below to identify which polygons of the second layer touches the boundary of the polygon in the first layer but while the code runs without a problem it does not identify (e.g. by giving FID with Msgbox) any such polygon whilsty it should.
Any help please?

    Dim pBlockBoundaryFC  As IFeatureClass
    Set pBlockBoundaryFC = pBlockBoundary.FeatureClass


    Dim pBlockBoundaryFields  As IFields
    Set pBlockBoundaryFields = pBlockBoundaryFC.Fields

    Dim pGeom As IGeometry


    Dim pSpatialFilter As ISpatialFilter
    Set pSpatialFilter = New SpatialFilter

    Dim pBlockBoundaryCursor As IFeatureCursor
    Set pBlockBoundaryCursor = pBlockBoundaryFC.Search(pSpatialFilter, False)
      

    Set pBlockBoundaryFeature = pBlockBoundaryCursor.NextFeature
    Do Until pBlockBoundaryFeature Is Nothing

    Set pGeom = pBlockBoundaryFeature.Shape
    With pSpatialFilter
 
    Set .Geometry = pGeom
        .GeometryField = "Shape"
        .SpatialRel = esriSpatialRelTouches
    End With

    Dim pRelOp As IRelationalOperator
    Set pRelOp = pGeom

      Set pNewParcelsFeature = pNewParcelsCursor.NextFeature
      Do Until pNewParcelsFeature Is Nothing

        FID = pNewParcelsFeature.Value(intposFID)
        If pRelOp.Touches(pNewParcelsFeature.Shape) Then

        ''Report the FID of each parcel that 'touches' the exetrnal boundary
        MsgBox FID
        End If
   
    Set pNewParcelsFeature = pNewParcelsCursor.NextFeature

    Loop

  
    Set pBlockBoundaryFeature = pBlockBoundaryCursor.NextFeature
   
    Loop
Reply
0 Kudos
3 Replies
MVP Frequent Contributor
Demetris,

I've restructured your code. Have a look. You should really get into the habit of documenting your code with comments, this is good programing as it allows others to follow the code easier.


Duncan

Dim pBlockBoundaryFC As IFeatureClass
Set pBlockBoundaryFC = pBlockBoundary.FeatureClass
Dim pBlockBoundaryFields As IFields
Set pBlockBoundaryFields = pBlockBoundaryFC.Fields

' Create Spatialfilter
Dim pGeom As IGeometry
Dim pSpatialFilter As ISpatialFilter
Set pSpatialFilter = New SpatialFilter

' Create a cursor over all BlockBoundary
Dim pBlockBoundaryCursor As IFeatureCursor
Set pBlockBoundaryCursor = pBlockBoundaryFC.Search(Nothing, False)

' Main BlockBoundary loop
Set pBlockBoundaryFeature = pBlockBoundaryCursor.NextFeature
Do Until pBlockBoundaryFeature Is Nothing
' Get block boundary polygon and update spatialfilter
Set pGeom = pBlockBoundaryFeature.Shape
With pSpatialFilter
  Set .Geometry = pGeom
  .GeometryField = "Shape"
  .SpatialRel = esriSpatialRelTouches
End With

' I am assuming you have a NewParcelFC layer
set  pNewParcelsCursor = pNewParcelFC.Search(pspatialfilter,False)
Set pNewParcelsFeature = pNewParcelsCursor.NextFeature
Do Until pNewParcelsFeature Is Nothing
  FID = pNewParcelsFeature.Value(intposFID)
  MsgBox FID
  Set pNewParcelsFeature = pNewParcelsCursor.NextFeature
loop

' Get next Block boundary
Set pBlockBoundaryFeature = pBlockBoundaryCursor.NextFeature
Loop
Reply
0 Kudos
Regular Contributor III
I have two feature layers. The first one is just a polygon and the other one consists of a series of polygons which are enclosed by the first one. Thus, some polygons of the second feature layer touch on the boundaries of the first feauture layer.


So you're saying you have features in one layer that are inside of a feature on another layer?  The definition of "touch" is that the geometries only share a boundary.  If one geometry is inside another then they cannot touch because their interiors intersect.
Reply
0 Kudos
New Contributor
Thank you both for the answers. Although I eventually did it with a different way you helped me very much. I eventually used one loop passing the pFeature from another procedures and using the Boundary property of  ITopologicalOperator Inteface.

Many thanks again.
I have given points to both of you.
Reply
0 Kudos