# Merge AreaShapes for creating a new ShapeFile from another ShapeFile

**URL:** <https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914>\
**Category:** WinForms\
**Created:** [February 25, 2012, 2:06pm UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914 "2012-02-25T14:06:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@Eric](https://community.thinkgeo.com/u/Eric)\
**Post date:** [February 25, 2012, 2:06pm UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914/1 "2012-02-25T14:06:53Z")

</div>

Hello,

&nbsp;I&nbsp;try&nbsp;to&nbsp;create&nbsp;a&nbsp;new&nbsp;shapefile&nbsp;AreaShape,&nbsp;from&nbsp;an&nbsp;existing&nbsp;shapefile,&nbsp;grouping&nbsp;the&nbsp;AreaShapes&nbsp;depending&nbsp;on&nbsp;Feature.ColumnValues.

&nbsp;Like&nbsp;this:

ORIGINAL&nbsp;SHAPEFILE&nbsp;  
  
------------------  
  
ID&nbsp;DEP&nbsp;&nbsp;&nbsp;&nbsp;SECTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NO  
  
1&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1  
  
2&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2  
  
3&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3  
  
  
  
4&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1  
  
5&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2

OUTPUT&nbsp;SHAPEFILE  
  
----------------  
  
ID&nbsp;DEP&nbsp;&nbsp;&nbsp;&nbsp;SECTION  
  
1&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AB  
  
2&nbsp;&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AC

&nbsp;I&nbsp;plan&nbsp;on&nbsp;creating&nbsp;an&nbsp;InMemoryLayer&nbsp;with:  
  
&nbsp;-&nbsp;New&nbsp;AreaShapes&nbsp;created&nbsp;using&nbsp;AreaBaseShape.Union  
  
&nbsp;-&nbsp;The&nbsp;ColumnValues&nbsp;copied&nbsp;from&nbsp;the&nbsp;base&nbsp;shapefile.

&nbsp;Then&nbsp;how&nbsp;to&nbsp;save&nbsp;the&nbsp;InMemoryLayer&nbsp;in&nbsp;a&nbsp;shapefile?  
  
&nbsp;or&nbsp;may&nbsp;be,&nbsp;there&nbsp;is&nbsp;a&nbsp;simpler&nbsp;way&nbsp;...

&nbsp;Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;help.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [February 27, 2012, 11:53am UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914/2 "2012-02-27T11:53:51Z")

</div>

Hi&nbsp;Eric,&nbsp;  
  
  
  
In&nbsp;this&nbsp;post&nbsp;Ben&nbsp;upload&nbsp;a&nbsp;sample&nbsp;shows&nbsp;how&nbsp;to&nbsp;save&nbsp;features&nbsp;into&nbsp;shape&nbsp;file,&nbsp;I&nbsp;think&nbsp;that&nbsp;should&nbsp;be&nbsp;helpful.&nbsp;  
  
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/5199/afv/topic/Default.aspx&nbsp;  
  
  
  
I&nbsp;copy&nbsp;the&nbsp;core&nbsp;code&nbsp;for&nbsp;that&nbsp;here:&nbsp;  
  
  
  
[code]

foreach&nbsp;(Feature&nbsp;feature&nbsp;in&nbsp;Map1.EditOverlay.Features)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shapeLayer.InternalFeatures.Add(feature.Id,&nbsp;feature);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Save&nbsp;shapes&nbsp;to&nbsp;ShapeFile  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShapeFileFeatureSource&nbsp;featureSource&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureSource("C:\\PolygonDrawn.shp",&nbsp;ShapeFileReadWriteMode.ReadWrite);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;featureSource.Open();  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;featureSource.BeginTransaction();  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;featureSource.AddFeature(feature);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;featureSource.CommitTransaction();  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;featureSource.Close();  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

And&nbsp;for&nbsp;your&nbsp;requirement&nbsp;I&nbsp;think&nbsp;we&nbsp;can&nbsp;just&nbsp;create&nbsp;two&nbsp;feature&nbsp;collection,&nbsp;then&nbsp;loop&nbsp;all&nbsp;features&nbsp;in&nbsp;original&nbsp;feature&nbsp;source,&nbsp;and&nbsp;add&nbsp;them&nbsp;to&nbsp;the&nbsp;two&nbsp;collections,&nbsp;after&nbsp;loop&nbsp;save&nbsp;them&nbsp;to&nbsp;feature&nbsp;layer.&nbsp;  
  
  
  
Regards,&nbsp;  
  
  
  
Don

---

<div class="post-metadata">

**Author:** ![Eric](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@Eric](https://community.thinkgeo.com/u/Eric)\
**Post date:** [February 27, 2012, 3:44pm UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914/3 "2012-02-27T15:44:05Z")

</div>

&nbsp;

---

<div class="post-metadata">

**Author:** ![Eric](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@Eric](https://community.thinkgeo.com/u/Eric)\
**Post date:** [February 27, 2012, 3:44pm UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914/4 "2012-02-27T15:44:58Z")

</div>

Thank&nbsp;you&nbsp;Don,&nbsp;this&nbsp;is&nbsp;what&nbsp;I&nbsp;was&nbsp;looking&nbsp;for&nbsp;…&nbsp;  
&nbsp;&nbsp;  
&nbsp;Eric

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [February 28, 2012, 7:51am UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914/5 "2012-02-28T07:51:17Z")

</div>

Thans&nbsp;Eric,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You’re&nbsp;welcome.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Don

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [February 28, 2012, 7:51am UTC](https://community.thinkgeo.com/t/merge-areashapes-for-creating-a-new-shapefile-from-another-shapefile/1914/6 "2012-02-28T07:51:22Z")

</div>

Thans&nbsp;Eric,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You’re&nbsp;welcome.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Don
