AnsweredAssumed Answered


Question asked by bulla_b on Nov 20, 2017
Latest reply on Nov 21, 2017 by bulla_b



I'm trying to do a spatial query on a layer in my map.  In my code, I first check to see if the layer is there:


IEnumerable<Layer> gridLayer = map.GetLayersAsFlattenedList().Where(l => l.Name.IndexOf("GISWRKS1.WORKS.LAND_Grid", StringComparison.CurrentCultureIgnoreCase) >= 0);


if (gridLayer.Count() == 0)
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Please add the GRID layer before proceeding.", "Missing Layer");


Later in the code I want to use a point to intersect the gridLayer using this code:


SpatialQueryFilter spatialFilter = new SpatialQueryFilter();
spatialFilter.FilterGeometry = intersectPoint;
spatialFilter.SpatialRelationship = SpatialRelationship.Intersects;
spatialFilter.SubFields = "GRIDNO";


FeatureLayer grid = (FeatureLayer)gridLayer;        //This does not work.   Null Reference Exception or sometimes an InvalidCast, depending on what I am doing.  How do I turn my gridLayer from above into something I can use to query??  I've tried many different things...FeatureLayer, BasicFeatureLayer, FeatureClass.....nothing works.


RowCursor gridCursor = grid.Search(spatialFilter);
while (gridCursor.MoveNext())
using (Feature feature = (Feature)gridCursor.Current)