I want to know whether there is a function provided by ArcObjects (vb.net) to realize the "Select Features by Polygon" on ArcMap (shown below).

I am using VS 2012 (vb.net) and ArcObjects 10.2.2.

enter image description here


If you want to select features by polygon using ArcObjects, you would typically use a spatial filter, which is very simple to implement. Here's an example in VB.NET, where pPolygon is your polygon object, and pLayer is the layer you wish to select features from:

' create the spatial filter
Dim pSpatialFilter As ISpatialFilter = New SpatialFilterClass()
pSpatialFilter.Geometry = pPolygon
pSpatialFilter.GeometryField = pLayer.FeatureClass.ShapeFieldName
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains

' select features
Dim pFeatureSelection As IFeatureSelection
pFeatureSelection = pLayer
pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, False)

If you want to draw the polygon yourself using ArcObjects, then that's a bit of extra work. There are sample functions available to draw a polygon with mouse clicks (just google it), and then use that polygon object as your spatial filter input.

  • Hi lcoursey, I have followed the sample code to draw a polygon on map, but the start point always on the top of the map, is there is a way to allow user start drawings at any point as required ( the same as "Select Features by Polygon" tool? thanks. – littleleaf Jul 30 '14 at 3:45
  • @littleleaf What sample code are you using? Can you send me a link? – pvdev Jul 30 '14 at 8:21
  • Hi lcoursey , thanks for the concern, the sample code I use from the following link: help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/… – littleleaf Jul 30 '14 at 8:56
  • I posted some code for how to do something similar to what you're attempting here. Scroll to the last answer for the complete code. gis.stackexchange.com/questions/26067/… – Rich Wawrzonek Jul 30 '14 at 22:53
  • Thank you Rich, but unfortunately I failed to make it work after I convert your code to vb.net. even don't know how to call the code on OnMouseDown, Move and Up. I can't put Overrides on them. – littleleaf Jul 31 '14 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.