Selecting Features Within a Polygon [solved]

2866
6
08-28-2017 11:51 AM
Highlighted
by
New Contributor III

Hello, I was wondering if I could get some help with this problem.

Currently I'm using this line of code to select point features inside of a polygon. 

MapView.Active.SelectFeatures(polygon, SelectionCombinationMethod.Add, true, false);

However I noticed it is not very.. accurate? the description for this method is that it selects features that intersect a geometry, however clearly that's not whats happening as the points are outside of the polygon. What would be a functioning equivalent to the geoprocessing tool Select by Location? As the SelectFeatures method is unclear as to what it actually does.

Any help would be appreciated.

------------------------------------------------------------------------------------------------------------------------------------------------------------

The solution I found was to use a SpatialQueryFilter (below)

SpatialQueryFilter sqf = new SpatialQueryFilter { FilterGeometry = polygon, SpatialRelationship = SpatialRelationship.Contains };

[pointlayer].Select(sqf);

Instead of MapView.Active.SelectFeatures(polygon), which doesn't work properly.

Reply
0 Kudos
6 Replies
Highlighted
MVP Honored Contributor

Are you using 2-D or 3-D? The third parameter (isVisualIntersect) is for 3-D while the fourth parameter (isWhollyWithin) is for 2-D. What happens when you use

MapView.Active.SelectFeatures(polygon, SelectionCombinationMethod.Add, false, true);

You should make this a Question rather than a Discussion

Reply
0 Kudos
Highlighted
by
New Contributor III

Result

I'm using 2D only. This is with MapView.Active.SelectFeatures(polygon, SelectionCombinationMethod.Add, false, true);

Reply
0 Kudos
Highlighted
MVP Honored Contributor

Yeah, that is strange. What happens if you set both booleans to true?

Reply
0 Kudos
Highlighted
by
New Contributor III

No change.

Reply
0 Kudos
Highlighted
New Contributor III

Hi Drew,

MapView.Active.SelectFeatures(...) does a visual select so you get the results for what you are viewing currently. With isWhollyWithin set to TRUE, a point feature would only get selected if the symbol for the point feature is completely within the selected polygon feature. You might also get different results if you zoom-in/out of the view as the point symbol that was initially just inside the polygon geometry might now fall completely or partially outside the polygon boundary when you zoom out.

The results shown in the screenshots you shared seem correct to me. Also your solution of using SpatialQueryFilter and layer select is good and will get you the results you were expecting.

Thanks.

Reply
0 Kudos
Highlighted
by
New Contributor III

Zooming in and out had no effect, which is why I perceived it as a broken function. Thanks for the confirmation though!

Reply
0 Kudos