Help with finding intersecting layer

1309
12
Jump to solution
08-21-2020 08:10 AM
BrianBulla
Occasional Contributor III

Hi.  I'm creating a series of MapTools to sketch a line on the map that will represent a new feature.  A criteria of the sketch is that the first node of the sketch must intersect a line feature.  So for example, to create a hydrant lateral the first click must intersect a watermain....the second click will represent the hydrant valve and the last the hydrant.

I have created a routine for checking for the intersection of the first click to a given layer, but I am getting mixed results.  With certain layers it works (ie.  my sewer layer for my sewer connection tool), but other layers (ie. my watermain layer for my hydrant tool).  Here is the code:

public static bool IntersectsLayer(MapPoint point, FeatureLayer layer)
        {
            try
            {
                SpatialQueryFilter spatialFilter = new SpatialQueryFilter();
                spatialFilter.FilterGeometry = point;
                spatialFilter.SpatialRelationship = SpatialRelationship.Intersects;

                RowCursor theCursor = layer.Search(spatialFilter);
                Feature feature;
                while (theCursor.MoveNext())
                {
                    using (feature = (Feature)theCursor.Current)
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString());
            }

            return false;
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And here is the code that calls it:

protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            //use the sketch geometry to create the connectionPoint, valve and hydrant
            var pointCollection = ((Multipart)geometry).Points;
            MapPoint connectionPoint = pointCollection[0];
            MapPoint hydrantPoint = pointCollection[pointCollection.Count - 1];
            MapPoint valvePoint = pointCollection[1];

            //start creating the features
            QueuedTask.Run(() =>
            {
                if (Global.IntersectsLayer(connectionPoint, waterMainLayer) == false)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(connectionPoint.X.ToString() + ", " + connectionPoint.Y.ToString(), "Error");
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("The starting point must intersect the WaterMain or Water Service layer.", "Error");
                    return;
                }

         .......‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Can anyone see anything wrong in the code?  For some reason it always returns false when using the watermain layer.  I have snapping turned on, and it always works when using my similarly coded sewer connection tool.

Any ideas are appreciated.

0 Kudos
12 Replies
BrianBulla
Occasional Contributor III

OK.  Thanks for all your help!  

0 Kudos
YassineKha
New Contributor II

Hi sir,

I really want a help from you if it is possible.

currently Im working on Asp.Net MVC web Application and it consume some Arcgis services such as tileLayer ..

and my object is to draw Line on the map and get the intersect with the TileLayer with the geometry engine if possible?

Could you please share with me a link or some sample code that I can start from?

Many thanks

0 Kudos
BrianBulla
Occasional Contributor III

Hi Wolfgang,

Just to follow up on this, I did work with esri Canada on this and the end result is that the TEST environment I was using must have some flaw in it.  esri Canada also could not reproduce the issue, and after trying the exact same code in our PRODUCTION environment there were no issues.

So I guess a rebuild of our TEST environment is in order, which should happen soon.

Thanks for all your help with this.

0 Kudos