Select to view content in your preferred language

Selecting Features Within a Polygon [solved]

6169
6
08-28-2017 11:51 AM
DrewD
by
Regular Contributor

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.

0 Kudos
6 Replies
KenBuja
MVP Esteemed 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

0 Kudos
DrewD
by
Regular Contributor

Result

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

0 Kudos
KenBuja
MVP Esteemed Contributor

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

0 Kudos
DrewD
by
Regular Contributor

No change.

0 Kudos
DeepinderDeol
Occasional Contributor

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.

0 Kudos
DrewD
by
Regular Contributor

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

0 Kudos