0

How do I select point feature on mouse click?

I can select polygon feature but I cannot select apoint feature.

ESRI.ArcGIS.Carto.IIdentify identifyLayer = (IIdentify)iLayer;
IArray array = identifyLayer.Identify(identifyPoint);
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 23, 2018 at 8:16

2 Answers 2

2

The first step is to convert your clicked point into map coordinates, on your event the X and Y are screen coordinates which need to be converted with IDisplayTransformation:

In your OnMouseDown event:

IPoint pQueryPoint = new PointClass();
pQueryPoint = gDoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);

gDoc is of type IMxDocument. Then buffer the query point to a query geometry, this example is in pixels to map coordinates:

int PxTol = 6; // 6 pixels to select by
IPoint pNextPoint = gDoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X + PxTol, arg.Y);
double pSrchDist = pNextPoint.X - pQueryPoint.X; // measure the distance between points PxTol apart
ITopologicalOperator pTopOp = (ITopologicalOperator)pQueryPoint;
IGeometry pSrchGeom = pTopOp.Buffer(pSrchDist);

If your feature class has a spatial reference other than the FocusMap you will need to project the points first before creating the buffer. Then setup a spatial filter:

ISpatialFilter pSF = new SpatialFilterClass();
pSF.Geometry = pSrchGeom;
pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

Now search from the ILayer as IFeatureLayer to return a cursor:

IFeatureCursor pDestCur = (YourLayer as IFeatureLayer).FeatureClass.Search(pSF, true); 
// recycling cursor, use non-recycling if you're going to modify any part of the feature

which you can iterate through:

IFeature pFeat = pDestCur.NextFeature();
do
{
 // do something with pFeat
 pFeat = pDestCur.NextFeature();
} while (pFeat != null);

Or you can select to get an ISelectionSet:

ISelectionSet pSelSet = (YourLayer as IFeatureLayer).FeatureClass.Select(
pSF,
esriSelectionType.esriSelectionTypeHybrid,
esriSelectionOption.esriSelectionOptionNormal,
YourWorkspace);
answered Apr 23, 2018 at 23:23
1
  • I could select point feature.. thank you very much.. Commented Apr 24, 2018 at 4:19
0

You didn't post much code but I'm going to assume that identifyPoint is an IPoint in map coordinates.

IGeometry buffer = (identifyPoint as ITopologicalOperator).Buffer(1);
map.SelectByShape(buffer, null, true);

First you buffer the point you are using to search. The buffer will be in the units of the current geometry. So if I'm in UTM, the buffer would buffer 1 meter out. (doc)

Now I can take my current map and use select by shape. This will select anything within the buffer that is currently on the map. (doc)

answered Apr 23, 2018 at 21:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.