# Create new column

**URL:** <https://community.thinkgeo.com/t/create-new-column/825>\
**Category:** WinForms\
**Created:** [November 10, 2009, 12:45am UTC](https://community.thinkgeo.com/t/create-new-column/825 "2009-11-10T00:45:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carol](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Carol](https://community.thinkgeo.com/u/Carol)\
**Post date:** [November 10, 2009, 12:45am UTC](https://community.thinkgeo.com/t/create-new-column/825/1 "2009-11-10T00:45:22Z")

</div>

Hello,

I'd&nbsp;like&nbsp;to&nbsp;create&nbsp;a&nbsp;new&nbsp;shp&nbsp;file&nbsp;and&nbsp;copy&nbsp;some&nbsp;data&nbsp;from&nbsp;other&nbsp;shp&nbsp;file.

How&nbsp;do&nbsp;I&nbsp;create&nbsp;some&nbsp;column&nbsp;I&nbsp;want?

If&nbsp;original&nbsp;shp&nbsp;have&nbsp;columns&nbsp;of&nbsp;ID,&nbsp;NAME,&nbsp;TYPE&nbsp;&nbsp;and&nbsp;I&nbsp;just&nbsp;want&nbsp;to&nbsp;have&nbsp;columns&nbsp;of&nbsp;ID&nbsp;and&nbsp;Name.

If&nbsp;I&nbsp;use&nbsp;CloneShapeFileStructure&nbsp;to&nbsp;copy&nbsp;structure&nbsp;of&nbsp;original&nbsp;shp&nbsp;file&nbsp;and&nbsp;how&nbsp;do&nbsp;I&nbsp;delete&nbsp;it&nbsp;which&nbsp;I&nbsp;don't&nbsp;want?

&nbsp;

&nbsp;

&nbsp;

---

<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:** [November 10, 2009, 1:03am UTC](https://community.thinkgeo.com/t/create-new-column/825/2 "2009-11-10T01:03:53Z")

</div>

Carol,

We&nbsp;have&nbsp;finished&nbsp;the&nbsp;remove&nbsp;column&nbsp;part,&nbsp;another&nbsp;part&nbsp;split&nbsp;column&nbsp;we&nbsp;are&nbsp;still&nbsp;working&nbsp;on&nbsp;it.  
  
The&nbsp;following&nbsp;code&nbsp;is&nbsp;how&nbsp;to&nbsp;implement&nbsp;function&nbsp;like&nbsp;you&nbsp;said:

`        private void ProcessNewShapeFile(string originalShapefilePath, string newShapefilePath)        {            ShapeFileFeatureLayer originalShapeFileFeatureLayer = new ShapeFileFeatureLayer(originalShapefilePath);            ShapeFileFeatureLayer.BuildIndexFile(originalShapefilePath, BuildIndexMode.DoNotRebuild);            ShapeFileFeatureLayer newShapeFileFeatureLayer = GenerateNewShapeFile(originalShapeFileFeatureLayer, newShapefilePath);            UpdateNewShapeFile(originalShapeFileFeatureLayer, newShapeFileFeatureLayer);            ShapeFileFeatureLayer.BuildRecordIdColumn(newShapefilePath, "RECID", BuildRecordIdMode.Rebuild);        }        private void UpdateNewShapeFile(ShapeFileFeatureLayer originalShapeFileFeatureLayer, ShapeFileFeatureLayer newShapeFileFeatureLayer)        {            newShapeFileFeatureLayer.Open();            newShapeFileFeatureLayer.EditTools.BeginTransaction();            originalShapeFileFeatureLayer.Open();            Collection<DbfColumn> dbfColumns = ((ShapeFileFeatureSource)originalShapeFileFeatureLayer.FeatureSource).GetDbfColumns();            Collection<string> columnNames = new Collection<string>();            foreach (DbfColumn dbfColumn in dbfColumns)            {                if (dbfColumn.ColumnName.Trim() != "OLDROADID1" && dbfColumn.ColumnName.Trim() != "DIR")                                {                    columnNames.Add(dbfColumn.ColumnName);                }            }            Collection<Feature> features = originalShapeFileFeatureLayer.FeatureSource.GetAllFeatures(columnNames);            foreach (Feature feature in features)            {                newShapeFileFeatureLayer.EditTools.Add(feature);            }            newShapeFileFeatureLayer.EditTools.CommitTransaction();            originalShapeFileFeatureLayer.Close();            newShapeFileFeatureLayer.Close();        }        private ShapeFileFeatureLayer GenerateNewShapeFile(ShapeFileFeatureLayer originalShapeFileFeatureLayer, string newShapefilePath)        {            originalShapeFileFeatureLayer.Open();            ShapeFileType shapeFileType = originalShapeFileFeatureLayer.GetShapeFileType();            Collection<DbfColumn> oringinalDbfColumns = ((ShapeFileFeatureSource)originalShapeFileFeatureLayer.FeatureSource).GetDbfColumns();            Collection<DbfColumn> DbfColumns = new Collection<DbfColumn>();            foreach (DbfColumn oringinalDbfColumn in oringinalDbfColumns)            {                if (oringinalDbfColumn.ColumnName.Trim() != "OLDROADID1" && oringinalDbfColumn.ColumnName.Trim() != "DIR")                {                    DbfColumns.Add(oringinalDbfColumn);                }            }            originalShapeFileFeatureLayer.Close();            ShapeFileFeatureSource.CreateShapeFile(shapeFileType, newShapefilePath, DbfColumns);            ShapeFileFeatureLayer newShapeFileFeatureLayer = new ShapeFileFeatureLayer(newShapefilePath, ShapeFileReadWriteMode.ReadWrite);            return newShapeFileFeatureLayer;        }`

Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;questions.  
  
Thanks

James

---

<div class="post-metadata">

**Author:** ![Carol](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Carol](https://community.thinkgeo.com/u/Carol)\
**Post date:** [November 10, 2009, 2:47am UTC](https://community.thinkgeo.com/t/create-new-column/825/3 "2009-11-10T02:47:28Z")

</div>

Thanks&nbsp;for&nbsp;your&nbsp;reply,&nbsp;James

I&nbsp;attach&nbsp;a&nbsp;file&nbsp;which&nbsp;is&nbsp;divided&nbsp;part&nbsp;by&nbsp;one&nbsp;shp&nbsp;file.

But,&nbsp;it&nbsp;can't&nbsp;show&nbsp;on&nbsp;the&nbsp;Map.&nbsp;I&nbsp;don't&nbsp;know&nbsp;what's&nbsp;wrong.

&nbsp;

[1423-road\_10019dbf.zip](https://community.thinkgeo.com/uploads/default/original/2X/4/466239e77d918f210170d4da92d53384b8df9f46.zip) (411 KB)

---

<div class="post-metadata">

**Author:** ![Carol](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Carol](https://community.thinkgeo.com/u/Carol)\
**Post date:** [November 10, 2009, 2:54am UTC](https://community.thinkgeo.com/t/create-new-column/825/4 "2009-11-10T02:54:25Z")

</div>

I&nbsp;can't&nbsp;upload&nbsp;sample&nbsp;to&nbsp;you.  
  
I&nbsp;send&nbsp;sample&nbsp;to&nbsp;your&nbsp;email.

The&nbsp;maximum&nbsp;file&nbsp;size&nbsp;allowed&nbsp;is&nbsp;500&nbsp;kb.

---

<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:** [November 10, 2009, 3:57am UTC](https://community.thinkgeo.com/t/create-new-column/825/5 "2009-11-10T03:57:14Z")

</div>

Carol,

I&nbsp;can&nbsp;display&nbsp;it,&nbsp;both&nbsp;map&nbsp;and&nbsp;data.

You&nbsp;said&nbsp;you&nbsp;send&nbsp;sample&nbsp;to&nbsp;my&nbsp;email,&nbsp;but&nbsp;I&nbsp;can&nbsp;not&nbsp;find&nbsp;it,&nbsp;it's&nbsp;just&nbsp;shp&nbsp;files.

Please&nbsp;send&nbsp;us&nbsp;your&nbsp;sample&nbsp;code,&nbsp;it&nbsp;may&nbsp;going&nbsp;to&nbsp;be&nbsp;help&nbsp;us.

 ![](https://community.thinkgeo.com/uploads/default/original/2X/0/0c54851ef07a87eaee1d7a031fe0a1446919fd8c.png)

Thanks

James

---

<div class="post-metadata">

**Author:** ![Carol](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Carol](https://community.thinkgeo.com/u/Carol)\
**Post date:** [November 10, 2009, 4:19am UTC](https://community.thinkgeo.com/t/create-new-column/825/6 "2009-11-10T04:19:56Z")

</div>

Thanks&nbsp;for&nbsp;your&nbsp;reply,&nbsp;James&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;it&nbsp;have&nbsp;to&nbsp;rebuild&nbsp;index&nbsp;file.&nbsp;  
&nbsp;&nbsp;  
&nbsp;When&nbsp;I&nbsp;rebuild&nbsp;index&nbsp;file,&nbsp;it&nbsp;can&nbsp;show.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;(But&nbsp;I&nbsp;don’t&nbsp;know&nbsp;why&nbsp;it&nbsp;have&nbsp;to&nbsp;rebuild&nbsp;index)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;:)

---

<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:** [November 10, 2009, 8:00pm UTC](https://community.thinkgeo.com/t/create-new-column/825/7 "2009-11-10T20:00:08Z")

</div>

Carol,&nbsp;  
&nbsp;&nbsp;  
&nbsp;It’s&nbsp;wonderful&nbsp;that&nbsp;you&nbsp;fix&nbsp;your&nbsp;problem.&nbsp;  
&nbsp;&nbsp;  
&nbsp;About&nbsp;Rebuild,&nbsp;when&nbsp;the&nbsp;data&nbsp;has&nbsp;some&nbsp;problem,&nbsp;rebuild&nbsp;will&nbsp;re-organize&nbsp;it&nbsp;and&nbsp;make&nbsp;our&nbsp;MapSuite&nbsp;can&nbsp;support&nbsp;it.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;James
