# Editing Shape Files

**URL:** <https://community.thinkgeo.com/t/editing-shape-files/441>\
**Category:** WinForms\
**Created:** [May 27, 2009, 5:00pm UTC](https://community.thinkgeo.com/t/editing-shape-files/441 "2009-05-27T17:00:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@Jake](https://community.thinkgeo.com/u/Jake)\
**Post date:** [May 27, 2009, 5:00pm UTC](https://community.thinkgeo.com/t/editing-shape-files/441/1 "2009-05-27T17:00:38Z")

</div>

When&nbsp;working&nbsp;with&nbsp;shape&nbsp;files&nbsp;at&nbsp;street&nbsp;level&nbsp;I&nbsp;would&nbsp;like&nbsp;to&nbsp;make&nbsp;modifications&nbsp;to&nbsp;the&nbsp;shape&nbsp;file&nbsp;dynamically.&nbsp;&nbsp;Say&nbsp;I&nbsp;see&nbsp;a&nbsp;street&nbsp;is&nbsp;missing&nbsp;on&nbsp;one&nbsp;of&nbsp;my&nbsp;maps&nbsp;and&nbsp;want&nbsp;to&nbsp;include&nbsp;that.&nbsp;&nbsp;Are&nbsp;there&nbsp;methods&nbsp;that&nbsp;allow&nbsp;you&nbsp;to&nbsp;draw&nbsp;a&nbsp;line&nbsp;on&nbsp;the&nbsp;screen&nbsp;and&nbsp;have&nbsp;it&nbsp;update&nbsp;the&nbsp;shape&nbsp;file&nbsp;accordingly?&nbsp;

I&nbsp;would&nbsp;also&nbsp;like&nbsp;to&nbsp;add&nbsp;other&nbsp;shapes&nbsp;to&nbsp;the&nbsp;maps,&nbsp;these&nbsp;would&nbsp;be&nbsp;stored&nbsp;in&nbsp;a&nbsp;database&nbsp;with&nbsp;GPS&nbsp;reference&nbsp;points.&nbsp;&nbsp;If&nbsp;I&nbsp;move&nbsp;one&nbsp;of&nbsp;the&nbsp;houses,&nbsp;how&nbsp;simple&nbsp;is&nbsp;it&nbsp;to&nbsp;gather&nbsp;the&nbsp;new&nbsp;GPS&nbsp;coordinates&nbsp;to&nbsp;update&nbsp;the&nbsp;database&nbsp;with?&nbsp;

&nbsp;

Jake

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [June 1, 2009, 3:37am UTC](https://community.thinkgeo.com/t/editing-shape-files/441/2 "2009-06-01T03:37:23Z")

</div>

Jake,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;it’s&nbsp;difficult&nbsp;to&nbsp;include&nbsp;a&nbsp;missing&nbsp;street&nbsp;as&nbsp;it’s&nbsp;almost&nbsp;impossible&nbsp;to&nbsp;locate&nbsp;with&nbsp;mouse&nbsp;exactly&nbsp;the&nbsp;position&nbsp;you&nbsp;want.&nbsp;If&nbsp;you&nbsp;you&nbsp;can&nbsp;get&nbsp;the&nbsp;2&nbsp;points,&nbsp;you&nbsp;can&nbsp;easily&nbsp;add&nbsp;that&nbsp;missing&nbsp;street&nbsp;programally&nbsp;though.&nbsp;We&nbsp;might&nbsp;add&nbsp;Snapping&nbsp;in&nbsp;Desktop&nbsp;and&nbsp;it&nbsp;will&nbsp;be&nbsp;much&nbsp;easier&nbsp;even&nbsp;with&nbsp;mouse&nbsp;then.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Here&nbsp;is&nbsp;the&nbsp;code&nbsp;how&nbsp;to&nbsp;get&nbsp;features&nbsp;from&nbsp;the&nbsp;TrackOverlay&nbsp;and&nbsp;add&nbsp;them&nbsp;to&nbsp;a&nbsp;shape&nbsp;file.&nbsp;  
&nbsp;&nbsp;  
&nbsp;`ShapeFileFeatureLayer targetEditLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer(“WorldLayer”);winformsMap1.Overlays[“Overlay1”].Lock.EnterWriteLock();targetEditLayer.Open();try{                targetEditLayer.EditTools.BeginTransaction();                foreach (Feature feature in winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)                {                    targetEditLayer.EditTools.Add(feature);                }                TransactionResult result = targetEditLayer.EditTools.CommitTransaction();                if (result.TotalFailureCount > 0)                {                    MessageBox.Show(“Edit error”);                }            }            finally            {                targetEditLayer.Close();                winformsMap1.Overlays[“Overlay1”].Lock.ExitWriteLock();            }            winformsMap1.Refresh();`&nbsp;  
&nbsp;&nbsp;  
&nbsp;It’s&nbsp;very&nbsp;easy&nbsp;to&nbsp;update&nbsp;your&nbsp;shape&nbsp;in&nbsp;a&nbsp;database.&nbsp;The&nbsp;code&nbsp;is&nbsp;almost&nbsp;the&nbsp;same&nbsp;as&nbsp;above,&nbsp;get&nbsp;the&nbsp;updated&nbsp;feature&nbsp;from&nbsp;TrackOverlay&nbsp;and&nbsp;then&nbsp;update&nbsp;the&nbsp;corresponding&nbsp;shape&nbsp;in&nbsp;the&nbsp;database.&nbsp;You&nbsp;need&nbsp;to&nbsp;replace&nbsp;ShapeFileFeatureLayer&nbsp;with&nbsp;MsSql2008FeatureLayer&nbsp;for&nbsp;example&nbsp;and&nbsp;use&nbsp;the&nbsp;method&nbsp;Update&nbsp;instead&nbsp;of&nbsp;Add,&nbsp;will&nbsp;be&nbsp;fine.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Hope&nbsp;it&nbsp;helps.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Ben
