# How to simply Draw and Select vertices?

**URL:** <https://community.thinkgeo.com/t/how-to-simply-draw-and-select-vertices/1055>\
**Category:** WinForms\
**Created:** [February 18, 2010, 2:35pm UTC](https://community.thinkgeo.com/t/how-to-simply-draw-and-select-vertices/1055 "2010-02-18T14:35:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_S](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/aca169/32.png) [@Eric\_S](https://community.thinkgeo.com/u/Eric_S)\
**Post date:** [February 18, 2010, 2:35pm UTC](https://community.thinkgeo.com/t/how-to-simply-draw-and-select-vertices/1055/1 "2010-02-18T14:35:29Z")

</div>

Can&nbsp;anyone&nbsp;point&nbsp;me&nbsp;to&nbsp;an&nbsp;approqach&nbsp;where&nbsp;I&nbsp;can&nbsp;simply&nbsp;draw&nbsp;vertices&nbsp;on&nbsp;a&nbsp;line&nbsp;and&nbsp;have&nbsp;the&nbsp;ability&nbsp;to&nbsp;select&nbsp;a&nbsp;vertex&nbsp;and&nbsp;return&nbsp;its&nbsp;position?&nbsp;I&nbsp;have&nbsp;been&nbsp;looking&nbsp;at&nbsp;some&nbsp;of&nbsp;the&nbsp;editInteractiveOverlay&nbsp;samples&nbsp;and&nbsp;maybe&nbsp;I&nbsp;am&nbsp;missing&nbsp;something,&nbsp;as&nbsp;I&nbsp;don't&nbsp;want&nbsp;to&nbsp;actually&nbsp;edit&nbsp;the&nbsp;vertices.&nbsp;Just&nbsp;draw&nbsp;and&nbsp;select.&nbsp;Any&nbsp;pointers&nbsp;are&nbsp;greatly&nbsp;apreciated.Thanks.

Eric

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [February 18, 2010, 4:45pm UTC](https://community.thinkgeo.com/t/how-to-simply-draw-and-select-vertices/1055/2 "2010-02-18T16:45:41Z")

</div>

&nbsp;One&nbsp;way&nbsp;to&nbsp;do&nbsp;that&nbsp;is&nbsp;to&nbsp;use&nbsp;an&nbsp;InMemoryFeatureLayer&nbsp;with&nbsp;two&nbsp;features.&nbsp;Because,&nbsp;if&nbsp;you&nbsp;are&nbsp;just&nbsp;selecting&nbsp;a&nbsp;vertex&nbsp;and&nbsp;displaying,&nbsp;you&nbsp;don't&nbsp;need&nbsp;an&nbsp;EditInterectiveOverlay.&nbsp;Of&nbsp;the&nbsp;two&nbsp;features,&nbsp;one&nbsp;for&nbsp;the&nbsp;line&nbsp;itself&nbsp;and&nbsp;another&nbsp;one&nbsp;for&nbsp;the&nbsp;vertex.&nbsp;In&nbsp;the&nbsp;code&nbsp;below,&nbsp;I&nbsp;use&nbsp;the&nbsp;MapClick&nbsp;event&nbsp;to&nbsp;select&nbsp;a&nbsp;vertex&nbsp;and&nbsp;display&nbsp;its&nbsp;X&nbsp;and&nbsp;Y&nbsp;values&nbsp;in&nbsp;a&nbsp;message&nbsp;box.&nbsp;I&nbsp;hope&nbsp;this&nbsp;will&nbsp;help.

 ![](https://community.thinkgeo.com/uploads/default/original/2X/2/2ec264a893a538b9f9a67e93097dd1b3e0b750ab.jpg)

&nbsp;

&nbsp;

` private void Post7115()        {            winformsMap1.MapClick += new EventHandler<MapClickWinformsMapEventArgs>(winformsMap1_MapClick);            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;            winformsMap1.CurrentExtent = new RectangleShape(-97.7487, 30.274, -97.7343, 30.2658);            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.LightGoldenrodYellow);            ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer(@"..\..\Data\austinstreets.shp");            streetLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad2;            streetLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;            LayerOverlay staticOverlay = new LayerOverlay();            staticOverlay.Layers.Add("StreetLayer", streetLayer);            winformsMap1.Overlays.Add(staticOverlay);            LineShape lineShape = new LineShape();            lineShape.Vertices.Add(new Vertex(-97.744, 30.2732));            lineShape.Vertices.Add(new Vertex(-97.747, 30.2693));            lineShape.Vertices.Add(new Vertex(-97.7382, 30.2698));            lineShape.Vertices.Add(new Vertex(-97.7358,30.2669));            MultipointShape multipointShape = new MultipointShape();            foreach (Vertex vertex in lineShape.Vertices)            {                multipointShape.Points.Add(new PointShape(vertex));            }                       InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Red, 12);            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 3, true);            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;            inMemoryFeatureLayer.Open();            inMemoryFeatureLayer.EditTools.BeginTransaction();            inMemoryFeatureLayer.EditTools.Add(new Feature(multipointShape));            inMemoryFeatureLayer.EditTools.Add(new Feature(lineShape));            inMemoryFeatureLayer.EditTools.CommitTransaction();            inMemoryFeatureLayer.Close();            LayerOverlay lineOverlay = new LayerOverlay();            lineOverlay.Layers.Add("Line", inMemoryFeatureLayer);            winformsMap1.Overlays.Add(lineOverlay);            winformsMap1.Refresh(lineOverlay);        }        void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)        {            FeatureLayer Layer = winformsMap1.FindFeatureLayer("Line");            Layer.Open();            Collection<Feature> selectedFeatures = Layer.QueryTools.GetFeaturesNearestTo(e.WorldLocation, GeographyUnit.DecimalDegree, 2,ReturningColumnsType.NoColumns);  // GetFeaturesContaining(e.WorldLocation, new string[1] { "CNTRY_NAME" });            Layer.Close();            if (selectedFeatures.Count > 0)            {                foreach (Feature feature in selectedFeatures)                {                    if (feature.GetWellKnownType().ToString() == "Multipoint")                    {                        MultipointShape multipointShape = (MultipointShape)feature.GetShape();                        PointShape pointShape = multipointShape.GetClosestPointTo(e.WorldLocation, GeographyUnit.DecimalDegree);                        MessageBox.Show("X: " + Math.Round(pointShape.X,4) + " Y: " + Math.Round(pointShape.Y,4), "Vertex", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);                    }                }            }        }`

---

<div class="post-metadata">

**Author:** ![Eric\_S](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/aca169/32.png) [@Eric\_S](https://community.thinkgeo.com/u/Eric_S)\
**Post date:** [February 19, 2010, 7:56am UTC](https://community.thinkgeo.com/t/how-to-simply-draw-and-select-vertices/1055/3 "2010-02-19T07:56:50Z")

</div>

Thanks&nbsp;Val,&nbsp;this&nbsp;works&nbsp;beatifully.&nbsp;Exactly&nbsp;the&nbsp;pointer&nbsp;I&nbsp;needed&nbsp;without&nbsp;having&nbsp;to&nbsp;work&nbsp;with&nbsp;an&nbsp;editOverlay’s&nbsp;control&nbsp;points.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Eric&nbsp;

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [February 19, 2010, 9:30am UTC](https://community.thinkgeo.com/t/how-to-simply-draw-and-select-vertices/1055/4 "2010-02-19T09:30:01Z")

</div>

&nbsp;You&nbsp;are&nbsp;welcome&nbsp;and&nbsp;don't&nbsp;forget&nbsp;to&nbsp;check&nbsp;the&nbsp;Code&nbsp;Community&nbsp;for&nbsp;new&nbsp;projects.

[code.thinkgeo.com/](http://code.thinkgeo.com/)
