# How to promote to EditOverlay

**URL:** <https://community.thinkgeo.com/t/how-to-promote-to-editoverlay/1493>\
**Category:** WinForms\
**Created:** [November 11, 2010, 12:12pm UTC](https://community.thinkgeo.com/t/how-to-promote-to-editoverlay/1493 "2010-11-11T12:12:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David9](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/david9/32/24954_2.png) [@David9](https://community.thinkgeo.com/u/David9)\
**Post date:** [November 11, 2010, 12:12pm UTC](https://community.thinkgeo.com/t/how-to-promote-to-editoverlay/1493/1 "2010-11-11T12:12:55Z")

</div>

&nbsp;Greetings....&nbsp;&nbsp;I&nbsp;am&nbsp;still&nbsp;in&nbsp;my&nbsp;first&nbsp;few&nbsp;hours&nbsp;with&nbsp;MapSuite&nbsp;4.5&nbsp;and&nbsp;am&nbsp;very&nbsp;impressed&nbsp;so&nbsp;far.&nbsp;&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;scratch&nbsp;together&nbsp;a&nbsp;prototype&nbsp;application&nbsp;for&nbsp;my&nbsp;boss&nbsp;by&nbsp;Monday&nbsp;(no,&nbsp;I&nbsp;did&nbsp;not&nbsp;procrastinate&nbsp;on&nbsp;some&nbsp;task&nbsp;,&nbsp;I&nbsp;am&nbsp;just&nbsp;presenting&nbsp;options&nbsp;for&nbsp;a&nbsp;project&nbsp;that&nbsp;is&nbsp;going&nbsp;slowly).

Let's&nbsp;say&nbsp;I&nbsp;pull&nbsp;in&nbsp;some&nbsp;shapes&nbsp;from&nbsp;a&nbsp;shp&nbsp;file&nbsp;or&nbsp;use&nbsp;inMemoryLayer.InternalFeatures.Add&nbsp;to&nbsp;get&nbsp;features&nbsp;into&nbsp;an&nbsp;overlay&nbsp;and&nbsp;then&nbsp;add&nbsp;the&nbsp;overlay&nbsp;to&nbsp;the&nbsp;map.&nbsp;How&nbsp;do&nbsp;I&nbsp;promote&nbsp;those&nbsp;features&nbsp;to&nbsp;the&nbsp;EditOverlay?&nbsp;&nbsp;I&nbsp;saw&nbsp;how&nbsp;to&nbsp;promote&nbsp;from&nbsp;the&nbsp;TrackOverlay&nbsp;to&nbsp;the&nbsp;EditOverlay&nbsp;in&nbsp;the&nbsp;samples&nbsp;but&nbsp;when&nbsp;I&nbsp;try&nbsp;something&nbsp;like&nbsp;this:

InMemoryFeatureLayer&nbsp;inMemoryLayer&nbsp;=&nbsp;(InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("worldLayer")

I&nbsp;get&nbsp;an&nbsp;exception:

Unable&nbsp;to&nbsp;cast&nbsp;object&nbsp;of&nbsp;type&nbsp;'ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer'&nbsp;to&nbsp;type&nbsp;'ThinkGeo.MapSuite.Core.InMemoryFeatureLayer'

Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;time,

Dave

---

<div class="post-metadata">

**Author:** ![David9](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/david9/32/24954_2.png) [@David9](https://community.thinkgeo.com/u/David9)\
**Post date:** [November 11, 2010, 1:46pm UTC](https://community.thinkgeo.com/t/how-to-promote-to-editoverlay/1493/2 "2010-11-11T13:46:21Z")

</div>

Please&nbsp;delete&nbsp;this&nbsp;topic,&nbsp;I&nbsp;just&nbsp;figured&nbsp;it&nbsp;out&nbsp;for&nbsp;InMemoryFeatureLayers,&nbsp;which&nbsp;is&nbsp;all&nbsp;I&nbsp;really&nbsp;needed&nbsp;anyway…&nbsp;  
&nbsp;&nbsp;  
&nbsp;Dave

---

<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:** [November 11, 2010, 2:32pm UTC](https://community.thinkgeo.com/t/how-to-promote-to-editoverlay/1493/3 "2010-11-11T14:32:42Z")

</div>

&nbsp;I&nbsp;am&nbsp;not&nbsp;sure&nbsp;what&nbsp;you&nbsp;want&nbsp;to&nbsp;accomplish&nbsp;exactely&nbsp;but&nbsp;to&nbsp;make&nbsp;you&nbsp;understand&nbsp;how&nbsp;to&nbsp;get&nbsp;some&nbsp;features&nbsp;from&nbsp;a&nbsp;shapefile&nbsp;and&nbsp;add&nbsp;them&nbsp;to&nbsp;the&nbsp;EditOverlay,&nbsp;let's&nbsp;take&nbsp;an&nbsp;example.&nbsp;Let's&nbsp;say&nbsp;that&nbsp;you&nbsp;have&nbsp;a&nbsp;shapefile&nbsp;for&nbsp;countries&nbsp;(countries02.shp)&nbsp;made&nbsp;of&nbsp;polygon&nbsp;and&nbsp;you&nbsp;want&nbsp;to&nbsp;add&nbsp;the&nbsp;features&nbsp;(countries)&nbsp;that&nbsp;are&nbsp;landlocked&nbsp;to&nbsp;the&nbsp;EditOverlay&nbsp;to&nbsp;edit&nbsp;them&nbsp;by&nbsp;dragging&nbsp;them.&nbsp;You&nbsp;need&nbsp;to&nbsp;get&nbsp;the&nbsp;features&nbsp;from&nbsp;the&nbsp;shapefile&nbsp;and&nbsp;then&nbsp;add&nbsp;them&nbsp;one&nbsp;by&nbsp;one&nbsp;to&nbsp;the&nbsp;EditOverlay.&nbsp;Look&nbsp;at&nbsp;the&nbsp;code&nbsp;below&nbsp;with&nbsp;the&nbsp;comments.&nbsp;See&nbsp;the&nbsp;screenshot&nbsp;of&nbsp;the&nbsp;features&nbsp;in&nbsp;the&nbsp;EditOverlay&nbsp;ready&nbsp;to&nbsp;be&nbsp;dragged.

&nbsp;

`    winformsMap1.MapUnit = GeographyUnit.DecimalDegree;    winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);    ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"../../data/countries02.shp");    worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;    worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;    LayerOverlay layerOverlay = new LayerOverlay();    layerOverlay.Layers.Add("worldLayer",worldLayer);    winformsMap1.Overlays.Add("LayerOverlay", layerOverlay);        ShapeFileFeatureLayer featureLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer("worldLayer");    featureLayer.Open();    Collection<Feature> features = featureLayer.QueryTools.GetFeaturesByColumnValue("LANDLOCKED", "Y");    featureLayer.Close();    //Loops thru all the features of the feature collection from the column query and add a new feature with the MultiPolygonShape    //to the EditShapesLayer of the EditOverlay.    winformsMap1.EditOverlay.EditShapesLayer.Open();    winformsMap1.EditOverlay.EditShapesLayer.EditTools.BeginTransaction();    foreach (Feature feature in features)    {        //Gets the MultiPolygonShape of each feature because countries02.shp is polygon based shapefile.        MultipolygonShape multipolygonShape = (MultipolygonShape)feature.GetShape();        winformsMap1.EditOverlay.EditShapesLayer.EditTools.Add(new Feature(multipolygonShape));    }    winformsMap1.EditOverlay.EditShapesLayer.EditTools.CommitTransaction();       //Sets the properties so that the features are only draggable.    winformsMap1.EditOverlay.CanAddVertex = false;    winformsMap1.EditOverlay.CanRemoveVertex = false;    winformsMap1.EditOverlay.CanReshape = false;    winformsMap1.EditOverlay.CanResize = false;    winformsMap1.EditOverlay.CanRotate = false;    //Sets the edit overlay so that its features are editable.    winformsMap1.EditOverlay.CalculateAllControlPoints();    //Sets the extent of the map to the bounding box of the features of the EditOverlay.    winformsMap1.CurrentExtent = winformsMap1.EditOverlay.EditShapesLayer.GetBoundingBox();    winformsMap1.EditOverlay.EditShapesLayer.Close();    winformsMap1.Refresh();`

&nbsp;

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

&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:** [November 11, 2010, 2:38pm UTC](https://community.thinkgeo.com/t/how-to-promote-to-editoverlay/1493/4 "2010-11-11T14:38:31Z")

</div>

I&nbsp;saw&nbsp;your&nbsp;last&nbsp;request&nbsp;after&nbsp;publishing&nbsp;my&nbsp;answer.&nbsp;I&nbsp;will&nbsp;keep&nbsp;this&nbsp;post&nbsp;for&nbsp;everybody&nbsp;to&nbsp;take&nbsp;advantage.&nbsp;Above,&nbsp;I&nbsp;show&nbsp;how&nbsp;to&nbsp;add&nbsp;the&nbsp;features&nbsp;from&nbsp;shapefile&nbsp;to&nbsp;EditOverlay,&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;add&nbsp;them&nbsp;to&nbsp;your&nbsp;own&nbsp;InMemoryFeatureLayer,&nbsp;it&nbsp;is&nbsp;basically&nbsp;the&nbsp;same&nbsp;principle,&nbsp;EditOverlay.EditShapesLayer&nbsp;being&nbsp;itself&nbsp;an&nbsp;InMemoryFeatureLayer&nbsp;type.&nbsp;Thank&nbsp;you.
