AnsweredAssumed Answered

Query a Feature Layer to find polygons from a single point

Question asked by flyinb on Apr 13, 2016
Latest reply on Apr 14, 2016 by akajanus-esristaff

I am using the .net SDK. The queries are actually being performed by a service bus, so there is no "user" viewing a map, only code to query a FeatureLayer.

 

What I am trying to do is take a geometry point from a particular FeatureLayer ( a single point), then Query another FeatureLayer that uses Polygons, and find all the polygons that overlap that particular geometry point.

 

I have found plenty of places to do the opposite (see if a point is within a ploygon), but what i need is to find all polygons that touch a point.

 

The code I am using:

var treeFeatureUrl = "<myurl for a feature layer with single points>";

                var uri = new Uri(treeFeatureUrl);

                var queryTask = new QueryTask(uri);

                var queryParams = new Query("OBJECTID,AssetId")

                {

                    OutFields = OutFields.All,

                    ReturnGeometry = true,

                    Where = $"AssetID=140156"

                };

                var queryResult = await queryTask.ExecuteAsync(queryParams);

                var firstTree = queryResult.FeatureSet.Features.FirstOrDefault();

                textBox1.Text += JsonConvert.SerializeObject(firstTree, Formatting.Indented) + Environment.NewLine;              

                textBox1.Text += Environment.NewLine + Environment.NewLine;

 

                var url = "<myurl for a feature layer with polygon areas>";

                var mapUri = new Uri(url);

                var qTask = new QueryTask(mapUri);

                var qparams = new Query("OBJECTID")

                {

                    Geometry = firstTree.Geometry,

                    OutFields = OutFields.All,

                    ReturnGeometry = false,

                    SpatialRelationship = SpatialRelationship.Within,

                };

                var findREsult = await qTask.ExecuteAsync(qparams);              

                var foundFeatures = findREsult.FeatureSet.Features;

                textBox1.Text += JsonConvert.SerializeObject(foundFeatures, Formatting.Indented) + Environment.NewLine;              

                textBox1.Text += Environment.NewLine + Environment.NewLine;

 

The above code never returns any results, probably because it's using the geometry from the firstTree as the search area.

 

I am not sure how to accomplish what it is I am trying to achieve:  find all polygons that touch a certain single point.

Outcomes