1

I was trying to create a Basetool which will collect points onMouseDown event. I was trying my tool to draw a line with the points collected. To collect points I used List. I am just putting the code here.

            IPoint screenPoint;
            screenPoint = new ESRI.ArcGIS.Geometry.Point();
            screenPoint.X = X;
            screenPoint.Y = Y;

            IScreenDisplay screenDisplay = (m_application.Document as IMxDocument).ActiveView.ScreenDisplay;
            IPoint mapPoint  = screenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            point.Add(mapPoint); // Point is List of IPoints

Using 2 MOuseDown, I want to collect 2 points and pass the putCoords method the points to create a Line. Can anyone please help me ?

  • You need to show the full code. We don't know if you are capturing into a graphic or edit sketch... – Hornbydd Aug 1 '18 at 11:52
2

Assuming you want a polyline geometry you can create one using an IPointCollection as a Path:

object gMissing = System.Type.Missing;

IPointCollection pOutPntColl = new PathClass(); // a new path
pOutPntColl.AddPoint(point[0], ref gMissing, ref gMissing); // add first point
pOutPntColl.AddPoint(point[1], ref gMissing, ref gMissing); // add 2nd point

IGeometryCollection pOutGeomColl = new PolylineClass(); // a new polyline
pOutGeomColl.AddGeometry((IGeometry)pOutPntColl, ref gMissing, ref gMissing); // add this path

IGeometry pOutGeom = (IGeometry)pOutGeomColl; // cast the geometry collection to a geometry
pOutGeom.SpatialReference = (m_application.Document as IMxDocument).FocusMap.SpatialReference; // set the spatial reference

A PolyLine is made from one (or more) paths so is constructed from an IGeometryCollection (supporting multi-part geometries) which is then cast to an IGeometry or IPolyline allowing you to set the SpatialReference.

A related (and helpful) object in this case would be an IRubberBand as new RubberLine, on TrackNew this will attach a stretchy line to your cursor from your first clicked point and then allow you to grab the last point when the tracking is finished.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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