SpatialFilter failing when used with feature service added to TOC

494
0
10-31-2017 09:20 AM
DianaVettori
New Contributor

Hi Experts,

I am facing an issue with Feature service which is added to TOC. And now i need to do a spatial query on the feature service but it is throwing an error.Although it works for Iqueryfilter but fails for Ispatialfilter. Below is code snippet.

IPoint pPoint = new PointClass();
pPoint.X = esriPoint.X;
pPoint.Y = esriPoint.Y;
pPoint.SpatialReference = cartoMap.SpatialReference;
var env = pPoint.Envelope.Envelope;
var mapLayers = gettingalllayersfromTOC(cartoMap); //getting all layer 
var pLayer = mapLayers[14]; // index of feature service added to tOC

List<IFeature> features = new List<IFeature>();

ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = env;
spatialFilter.GeometryField = ((IFeatureLayer)pLayer).FeatureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; 


IFeatureCursor cursor = ((IFeatureLayer)pLayer).FeatureClass.Search(spatialFilter, false);
IFeature feature = cursor.NextFeature();
while (feature != null)
{
features.Add(feature);
feature = cursor.NextFeature();
}

Error is thrown at "IFeatureCursor cursor = ((IFeatureLayer)pLayer).FeatureClass.Search(spatialFilter, false);"

{"ERROR: code:400, Cannot perform query. Invalid query parameters., 24305: The Polygon input is not valid because the ring does not have enough distinct points. Each ring of a polygon must contain at least three distinct points., Unable to perform query. Please check your parameters., Bad syntax in request."}

0 Kudos
0 Replies