SpatialFilter Intersect distance

216
3
03-11-2020 07:54 AM
BrianBulla
Regular Contributor

Hi,

How close do two object have to be in order for a SpatialFilter Intersect considers them to be intersecting?  I'm doing some testing at a very small scale and getting some 'not expected' results.

In the screenshot below, I am running the following code to find the intersecting Watermain ID to place onto the Watermain Break point.  So basically I pass the point of the selected Watermain Break and the Watermain Layer to this procedure (GetIntersectingFeature), and then update the Watermain Break:

public string GetIntersectingFeature(MapPoint point, FeatureLayer intersectLayer, string fieldName)
        {
            try
            {
                //ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(point.X.ToString() + " : " + point.Y.ToString());

                //Create a Spatial Query using the supplied point, layer and fieldname
                SpatialQueryFilter spatialFilter = new SpatialQueryFilter();
                spatialFilter.FilterGeometry = point;
                spatialFilter.SpatialRelationship = SpatialRelationship.Intersects;
                spatialFilter.SubFields = fieldName;

                //Gets the intersecting feature
                string fieldValue = null;
                RowCursor featureCursor = intersectLayer.Search(spatialFilter);
                Feature feature;

                //Gets the value using the fieldName
                while (featureCursor.MoveNext())
                {
                    using (feature = (Feature)featureCursor.Current)
                    {
                        int fieldPosition = feature.FindField(fieldName);
                        if (feature[fieldPosition] != null)
                            fieldValue = feature[fieldPosition].ToString();
                        else
                            fieldValue = null;
                    }
                }

                return fieldValue;
            }

            catch (Exception ex)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("An error occured while finding the intersecting feature." + "\n" + "\n" + ex.ToString(), "GetIntersecingFeature", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return null;
            }
        }

From the screenshot below, all of the selected points have a value returned.  I really only should be getting a value returned for the Watermain Breaks that are exactly intersecting the Watermain.  Is there a setting I am missing in either ArcGIS Pro, or in my code to tighten up the tolerance of what is considered 'intersecting'??

Thanks,

0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi Brian

Can you try another SpatialRelationship such as "Crosses" ? SpatialRelationships

Thanks

Uma

0 Kudos
BrianBulla
Regular Contributor

Hi Uma Harano‌,

When I change .Intersects to .Crosses I get some better results.  The points that are not intersecting are fine, but now the points that ARE intersecting are not getting any value transferred over.

From reading the description on that link you sent me, it sounds like .Crosses will not work in my case.  I am using a point/line combination...

"Crosses - Returns a feature if the intersection of the interiors of the two shapes is not empty and has a lower dimension that the maximum dimension of the two shapes. Two lines that share an endpoint do not cross. Valid for polyline/polyline, polyline/Area, multipoint/Area, and multipoint/polyline shape type combinations."

Do you have any other suggestions??  Is there another reason why the .Intersects will not work when the point/line are very close, but not intersecting??

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Brian,

I used Interest in my sample code and I don't see this problem. 

What projection are you using? Also, would it be possible if you can zip up a small set of your data and share it?  That would really help us narrow down this issue.

Thanks

Uma

0 Kudos