# Drawing and saving shapes

**URL:** <https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451>\
**Category:** WinForms\
**Created:** [October 6, 2010, 4:55pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451 "2010-10-06T16:55:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [October 6, 2010, 4:55pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/1 "2010-10-06T16:55:45Z")

</div>

Hi

I'm&nbsp;porting&nbsp;an&nbsp;app&nbsp;from&nbsp;V2&nbsp;to&nbsp;V4&nbsp;and&nbsp;am&nbsp;a&nbsp;bit&nbsp;confused&nbsp;about&nbsp;how&nbsp;drawing&nbsp;and&nbsp;saving&nbsp;shapes&nbsp;now&nbsp;works.

Let's&nbsp;say&nbsp;I&nbsp;have&nbsp;3&nbsp;drop&nbsp;down&nbsp;menus.&nbsp;The&nbsp;first&nbsp;one&nbsp;allows&nbsp;me&nbsp;to&nbsp;draw&nbsp;a&nbsp;point,&nbsp;the&nbsp;second&nbsp;a&nbsp;line&nbsp;and&nbsp;the&nbsp;third&nbsp;a&nbsp;polygon.

In&nbsp;V2&nbsp;I&nbsp;would&nbsp;create&nbsp;3&nbsp;shape&nbsp;files&nbsp;and&nbsp;corresponding&nbsp;layers,&nbsp;do&nbsp;a&nbsp;BeginEdit&nbsp;on&nbsp;the&nbsp;correct&nbsp;layer&nbsp;then&nbsp;CommitEdit&nbsp;when&nbsp;finished&nbsp;drawing.

On&nbsp;V4&nbsp;I&nbsp;have&nbsp;to&nbsp;use&nbsp;TrackInteractiveOverlay.&nbsp;I&nbsp;have&nbsp;it&nbsp;quite&nbsp;happily&nbsp;drawing&nbsp;all&nbsp;3&nbsp;shape&nbsp;types&nbsp;on&nbsp;one&nbsp;layer&nbsp;but&nbsp;now&nbsp;want&nbsp;to&nbsp;save.

Do&nbsp;I&nbsp;have&nbsp;to&nbsp;have&nbsp;3&nbsp;overlays&nbsp;if&nbsp;I&nbsp;want&nbsp;to&nbsp;save&nbsp;to&nbsp;3&nbsp;different&nbsp;shape&nbsp;files?&nbsp;I&nbsp;can't&nbsp;see&nbsp;how&nbsp;this&nbsp;would&nbsp;work&nbsp;as&nbsp;to&nbsp;start&nbsp;drawing&nbsp;I&nbsp;simply&nbsp;say&nbsp;map.TrackOverlay.TrackMode&nbsp;=&nbsp;xx.

Also,&nbsp;how&nbsp;do&nbsp;I&nbsp;then&nbsp;load&nbsp;the&nbsp;shape&nbsp;files&nbsp;in&nbsp;the&nbsp;future&nbsp;and&nbsp;allow&nbsp;them&nbsp;to&nbsp;be&nbsp;edited?

Cheers

Steve

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 7, 2010, 10:26pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/2 "2010-10-07T22:26:23Z")

</div>

Steve,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;questions.  
I&nbsp;think&nbsp;it&nbsp;depends&nbsp;on&nbsp;where&nbsp;you&nbsp;want&nbsp;to&nbsp;save.&nbsp;It&nbsp;is&nbsp;possible&nbsp;to&nbsp;save&nbsp;point,&nbsp;line&nbsp;and&nbsp;polygon&nbsp;into&nbsp;one&nbsp;InmemoryFeatureLayer&nbsp;while&nbsp;it&nbsp;is&nbsp;impossible&nbsp;to&nbsp;save&nbsp;them&nbsp;into&nbsp;one&nbsp;specified&nbsp;shape&nbsp;file&nbsp;because&nbsp;they&nbsp;are&nbsp;belonging&nbsp;to&nbsp;different&nbsp;types&nbsp;of&nbsp;shapes.&nbsp;According&nbsp;to&nbsp;the&nbsp;shape&nbsp;file&nbsp;specification,&nbsp;one&nbsp;shape&nbsp;file&nbsp;can&nbsp;only&nbsp;store&nbsp;one&nbsp;type&nbsp;of&nbsp;shapes,&nbsp;either&nbsp;in&nbsp;point&nbsp;or&nbsp;line&nbsp;or&nbsp;area.  
When&nbsp;you&nbsp;want&nbsp;to&nbsp;edit&nbsp;the&nbsp;shapes&nbsp;no&nbsp;matter&nbsp;they&nbsp;are&nbsp;stored&nbsp;in&nbsp;shape&nbsp;file&nbsp;or&nbsp;inmemory,&nbsp;just&nbsp;load&nbsp;it&nbsp;into&nbsp;EditIntertativeOverlay.  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
Thanks.  
Yang

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [October 7, 2010, 10:41pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/3 "2010-10-07T22:41:09Z")

</div>

Hi&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;the&nbsp;reply.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Let’s&nbsp;say&nbsp;I&nbsp;have&nbsp;4&nbsp;drop&nbsp;down&nbsp;menu’s.&nbsp;The&nbsp;first&nbsp;is&nbsp;bus&nbsp;stops&nbsp;and&nbsp;allows&nbsp;point&nbsp;to&nbsp;be&nbsp;drawn,&nbsp;the&nbsp;second&nbsp;is&nbsp;park&nbsp;benches&nbsp;and&nbsp;is&nbsp;points,&nbsp;the&nbsp;third&nbsp;is&nbsp;bridges&nbsp;and&nbsp;is&nbsp;lines&nbsp;and&nbsp;the&nbsp;last&nbsp;id&nbsp;bandstands&nbsp;and&nbsp;is&nbsp;polygons.&nbsp;Each&nbsp;of&nbsp;the&nbsp;4&nbsp;types&nbsp;needs&nbsp;to&nbsp;be&nbsp;saved&nbsp;into&nbsp;a&nbsp;different&nbsp;shape&nbsp;file&nbsp;on&nbsp;the&nbsp;hard&nbsp;disk.&nbsp;  
&nbsp;&nbsp;  
&nbsp;In&nbsp;V2&nbsp;it&nbsp;was&nbsp;easy.&nbsp;Each&nbsp;shape&nbsp;file&nbsp;was&nbsp;a&nbsp;separate&nbsp;layer.&nbsp;I&nbsp;just&nbsp;saved&nbsp;the&nbsp;layer&nbsp;and&nbsp;the&nbsp;shape&nbsp;file&nbsp;was&nbsp;updated.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I’m&nbsp;not&nbsp;sure&nbsp;what&nbsp;to&nbsp;do&nbsp;in&nbsp;v4.&nbsp;All&nbsp;4&nbsp;shapes&nbsp;will&nbsp;be&nbsp;drawn&nbsp;on&nbsp;the&nbsp;one&nbsp;layer.&nbsp;How&nbsp;do&nbsp;I&nbsp;save&nbsp;the&nbsp;shapes?&nbsp;I&nbsp;can&nbsp;iterate&nbsp;through&nbsp;all&nbsp;the&nbsp;shapes&nbsp;on&nbsp;the&nbsp;layer&nbsp;but&nbsp;how&nbsp;do&nbsp;I&nbsp;match&nbsp;them&nbsp;with&nbsp;the&nbsp;files&nbsp;they&nbsp;need&nbsp;to&nbsp;be&nbsp;stored&nbsp;in?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 9, 2010, 8:04am UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/4 "2010-10-09T08:04:27Z")

</div>

Steve,

Thanks&nbsp;for&nbsp;your&nbsp;feedback.  
Why&nbsp;not&nbsp;use&nbsp;the&nbsp;WellKnownType&nbsp;to&nbsp;identify&nbsp;the&nbsp;feature&nbsp;type?&nbsp;Hope&nbsp;it&nbsp;helps.  
`WellKnownType wellKnownType = basShape.GetWellKnownType();`  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;ask.  
Thanks.  
Yale

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [October 11, 2010, 5:31pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/5 "2010-10-11T17:31:05Z")

</div>

Hi&nbsp;Yale&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;problem&nbsp;isn’t&nbsp;how&nbsp;to&nbsp;identify&nbsp;the&nbsp;type&nbsp;of&nbsp;each&nbsp;feature,&nbsp;its&nbsp;how&nbsp;to&nbsp;write&nbsp;the&nbsp;shape&nbsp;to&nbsp;one&nbsp;of&nbsp;a&nbsp;number&nbsp;of&nbsp;shape&nbsp;files&nbsp;on&nbsp;the&nbsp;hard&nbsp;drive.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 12, 2010, 8:26am UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/6 "2010-10-12T08:26:58Z")

</div>

Steve,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;feedback.  
I&nbsp;am&nbsp;sorry&nbsp;if&nbsp;I&nbsp;misunderstand&nbsp;anything.&nbsp;Let&nbsp;me&nbsp;make&nbsp;sure&nbsp;what&nbsp;we&nbsp;are&nbsp;going&nbsp;to&nbsp;achieve.&nbsp;Let&nbsp;us&nbsp;say&nbsp;we&nbsp;have&nbsp;4&nbsp;features&nbsp;in&nbsp;the&nbsp;InmemoryFetureLayer:  
Feture1----&nbsp;AreaType.  
Feture2---&nbsp;LineType  
Feture3---&nbsp;PointType  
Feture4----LineType  
When&nbsp;we&nbsp;want&nbsp;to&nbsp;save&nbsp;those&nbsp;features&nbsp;into&nbsp;disk-based&nbsp;shape&nbsp;files,&nbsp;we&nbsp;have&nbsp;to&nbsp;save&nbsp;them&nbsp;into&nbsp;three&nbsp;files:  
a.shp&nbsp;----&nbsp;Polygon&nbsp;type  
b.shp----&nbsp;Polyline&nbsp;type  
c.shp&nbsp;----&nbsp;point&nbsp;type  
&nbsp;  
Then&nbsp;when&nbsp;a&nbsp;feature&nbsp;come&nbsp;in&nbsp;for&nbsp;save,&nbsp;we&nbsp;use&nbsp;the&nbsp;API&nbsp;GetWellKnownType&nbsp;to&nbsp;determine&nbsp;which&nbsp;file&nbsp;we&nbsp;will&nbsp;save&nbsp;it&nbsp;to.  
Anything&nbsp;unclear&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
Thanks.  
Yale

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [October 12, 2010, 5:52pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/7 "2010-10-12T17:52:05Z")

</div>

Hi&nbsp;Yale&nbsp;  
&nbsp;&nbsp;  
&nbsp;What&nbsp;you&nbsp;have&nbsp;outlined&nbsp;is&nbsp;the&nbsp;procedure&nbsp;&nbsp;Iwant&nbsp;to&nbsp;follow,&nbsp;but&nbsp;what&nbsp;I&nbsp;don’t&nbsp;know&nbsp;is&nbsp;how&nbsp;to&nbsp;save&nbsp;to&nbsp;the&nbsp;shape&nbsp;files.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;What&nbsp;if&nbsp;feature1&nbsp;already&nbsp;exists&nbsp;in&nbsp;a.shp?&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;What&nbsp;is&nbsp;the&nbsp;actual&nbsp;mechanism&nbsp;I&nbsp;should&nbsp;use&nbsp;to&nbsp;save&nbsp;each&nbsp;feature&nbsp;to&nbsp;the&nbsp;shape&nbsp;files?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 13, 2010, 6:49am UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/8 "2010-10-13T06:49:14Z")

</div>

Steve,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;feedback.  
I&nbsp;do&nbsp;not&nbsp;think&nbsp;there&nbsp;is&nbsp;an&nbsp;existing&nbsp;API&nbsp;to&nbsp;determine&nbsp;a&nbsp;feature&nbsp;is&nbsp;already&nbsp;exists&nbsp;in&nbsp;a&nbsp;shape&nbsp;or&nbsp;not,&nbsp;the&nbsp;simplest&nbsp;way&nbsp;is&nbsp;to&nbsp;loop&nbsp;each&nbsp;feature&nbsp;in&nbsp;the&nbsp;shape&nbsp;to&nbsp;compare&nbsp;with&nbsp;the&nbsp;target&nbsp;feature&nbsp;,while&nbsp;this&nbsp;will&nbsp;cause&nbsp;some&nbsp;performance&nbsp;issue&nbsp;if&nbsp;the&nbsp;shape&nbsp;contains&nbsp;too&nbsp;many&nbsp;features.&nbsp;This&nbsp;performance&nbsp;problem&nbsp;can&nbsp;be&nbsp;avoided&nbsp;by&nbsp;using&nbsp;some&nbsp;spatial&nbsp;query&nbsp;APIs&nbsp;like&nbsp;GetFeaturesInsideBoundingBox&nbsp;to&nbsp;get&nbsp;some&nbsp;candidate&nbsp;features&nbsp;first.  
Following&nbsp;code&nbsp;snippet&nbsp;shows&nbsp;you&nbsp;how&nbsp;to&nbsp;save&nbsp;a&nbsp;feature&nbsp;into&nbsp;an&nbsp;existing&nbsp;shape&nbsp;file,&nbsp;hope&nbsp;it&nbsp;helps.  
  
&nbsp;  
`ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(@"a.shp", ShapeFileReadWriteMode.ReadWrite);shapeFileLayer.Open();try{    shapeFileLayer.EditTools.BeginTransaction();    shapeFileLayer.EditTools.Add(feature);    TransactionResult result = shapeFileLayer.EditTools.CommitTransaction();}finally{    shapeFileLayer.Close();}`  
  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
Thanks.  
Yang

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [April 11, 2011, 6:15pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/9 "2011-04-11T18:15:32Z")

</div>

I’m&nbsp;getting&nbsp;an&nbsp;error&nbsp;on&nbsp;Open&nbsp;as&nbsp;the&nbsp;file&nbsp;does&nbsp;not&nbsp;exist.&nbsp;I’ll&nbsp;be&nbsp;creating&nbsp;the&nbsp;file&nbsp;each&nbsp;time.&nbsp;  
&nbsp;&nbsp;  
&nbsp;How&nbsp;do&nbsp;I&nbsp;create&nbsp;a&nbsp;new&nbsp;shape&nbsp;file?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [April 11, 2011, 6:39pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/10 "2011-04-11T18:39:46Z")

</div>

&nbsp;Figured&nbsp;it&nbsp;out:

`  ShapeFileFeatureLayer.CreateShapeFile(shapeFileType, shapePath, cols);`  
  
&nbsp;  
Cheers  
&nbsp;  
Steve

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [April 11, 2011, 10:10pm UTC](https://community.thinkgeo.com/t/drawing-and-saving-shapes/1451/11 "2011-04-11T22:10:27Z")

</div>

Steve,&nbsp;  
&nbsp;&nbsp;  
&nbsp;That’s&nbsp;great!&nbsp;Hope&nbsp;everything&nbsp;is&nbsp;ok&nbsp;for&nbsp;your&nbsp;application,&nbsp;if&nbsp;you&nbsp;encounter&nbsp;any&nbsp;more&nbsp;questions&nbsp;or&nbsp;problems&nbsp;please&nbsp;let&nbsp;us&nbsp;know&nbsp;again,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Scott,
