# Layer with mutiple shape files

**URL:** <https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355>\
**Category:** WinForms\
**Created:** [July 18, 2010, 2:19pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355 "2010-07-18T14:19:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lenny](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@Lenny](https://community.thinkgeo.com/u/Lenny)\
**Post date:** [July 18, 2010, 2:19pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355/1 "2010-07-18T14:19:49Z")

</div>

Hello,

I'm&nbsp;trying&nbsp;to&nbsp;use&nbsp;MultipleShapeFileFeatureLayer&nbsp;and&nbsp;getting&nbsp;followng&nbsp;exception&nbsp;when&nbsp;WinForm&nbsp;map&nbsp;control&nbsp;tries&nbsp;to&nbsp;draw&nbsp;the&nbsp;layer.

`System.InvalidOperationException: Your input index is out of bound`

Here&nbsp;is&nbsp;the&nbsp;piece&nbsp;of&nbsp;code&nbsp;I'm&nbsp;using&nbsp;to&nbsp;create&nbsp;MutipleShapeFileFeatureLayer:

`string[] shapeFiles = new string[] { @"c:\data\Folder1\1.shp", @"c:\data\Folder2\1.shp" };string[] indexFiles = new string[] { @"c:\data\Folder3\1.midx", @"c:\data\Folder3\1.midx" };MultipleShapeFileFeatureLayer.BuildIndex(shapeFiles, indexFiles, BuildIndexMode.DoNotRebuild);MultipleShapeFileFeatureLayer shapeLayer = new MultipleShapeFileFeatureLayer(shapeFiles, indexFiles);ValueStyle valueStyle = new ValueStyle();valueStyle.ColumnName = "Column1";valueStyle.ValueItems.Add(new ValueItem("value1", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));valueStyle.ValueItems.Add(new ValueItem("value2", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));shapeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;LayerOverlay groupLayer = new LayerOverlay();groupLayer.Name = "test1";groupLayer.Layers.Add(shapeLayer);winformsMap1.Overlays.Add(layerKey, groupLayer);winformsMaps1.Refresh(); // The exception is being thrown here.`

---

<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:** [July 18, 2010, 7:08pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355/2 "2010-07-18T19:08:53Z")

</div>

Lenny,

Welcome&nbsp;you&nbsp;to&nbsp;ThinkGeo&nbsp;discussion&nbsp;forum&nbsp;and&nbsp;thanks&nbsp;for&nbsp;your&nbsp;post.  
&nbsp;  
I&nbsp;do&nbsp;not&nbsp;see&nbsp;any&nbsp;obvious&nbsp;problem&nbsp;in&nbsp;the&nbsp;code&nbsp;pasted,&nbsp;could&nbsp;you&nbsp;upload&nbsp;the&nbsp;data&nbsp;or&nbsp;send&nbsp;it&nbsp;via&nbsp;email&nbsp;[forumsupport@thinkgeo.com](mailto:forumsupport@thinkgeo.com)&nbsp;and&nbsp;asked&nbsp;to&nbsp;forward&nbsp;to&nbsp;Yale,&nbsp;I&nbsp;think&nbsp;that&nbsp;would&nbsp;definitely&nbsp;be&nbsp;helpful&nbsp;to&nbsp;identify&nbsp;the&nbsp;problem.  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale

---

<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:** [July 18, 2010, 9:38pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355/3 "2010-07-18T21:38:24Z")

</div>

Lenny,

Thanks&nbsp;for&nbsp;your&nbsp;data&nbsp;and&nbsp;now&nbsp;I&nbsp;think&nbsp;I&nbsp;figured&nbsp;out&nbsp;where&nbsp;is&nbsp;the&nbsp;problem&nbsp;with&nbsp;the&nbsp;help&nbsp;of&nbsp;the&nbsp;code&nbsp;and&nbsp;data.  
&nbsp;  
The&nbsp;problem&nbsp;is&nbsp;in&nbsp;our&nbsp;.mids&nbsp;file,&nbsp;we&nbsp;store&nbsp;the&nbsp;id&nbsp;in&nbsp;the&nbsp;format&nbsp;of&nbsp;“shapeFileNameWithoutFolder:&nbsp;recordId”,&nbsp;while&nbsp;in&nbsp;the&nbsp;case,&nbsp;the&nbsp;shapeFileNameWithoutFolder&nbsp;is&nbsp;the&nbsp;same&nbsp;for&nbsp;both&nbsp;shape&nbsp;file,&nbsp;so&nbsp;it&nbsp;is&nbsp;impossible&nbsp;to&nbsp;make&nbsp;a&nbsp;difference&nbsp;between&nbsp;which&nbsp;shape&nbsp;file&nbsp;it&nbsp;is&nbsp;from.&nbsp;One&nbsp;solution&nbsp;for&nbsp;it&nbsp;is&nbsp;to&nbsp;change&nbsp;the&nbsp;shape&nbsp;file&nbsp;name.&nbsp;Following&nbsp;code&nbsp;is&nbsp;a&nbsp;updated&nbsp;version&nbsp;for&nbsp;it,&nbsp;I&nbsp;could&nbsp;not&nbsp;find&nbsp;the&nbsp;“column1”&nbsp;column&nbsp;in&nbsp;the&nbsp;data&nbsp;attached,&nbsp;so,&nbsp;I&nbsp;changed&nbsp;to&nbsp;one&nbsp;reasonable&nbsp;column&nbsp;value.  
&nbsp;  
`string[] shapeFiles = new string[] { @"c:\data\Folder1\1.shp", @"c:\data\Folder2\2.shp" };string[] indexFiles = new string[] { @"c:\data\Folder3\1.midx", @"c:\data\Folder3\1.midx" };MultipleShapeFileFeatureLayer.BuildIndex(shapeFiles, indexFiles, BuildIndexMode.DoNotRebuild);MultipleShapeFileFeatureLayer shapeLayer = new MultipleShapeFileFeatureLayer(shapeFiles, indexFiles);ValueStyle valueStyle = new ValueStyle();//valueStyle.ColumnName = "Column1";//valueStyle.ValueItems.Add(new ValueItem("value1", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));//valueStyle.ValueItems.Add(new ValueItem("value2", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2))); valueStyle.ColumnName = "LoadId";valueStyle.ValueItems.Add(new ValueItem("2752", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));valueStyle.ValueItems.Add(new ValueItem("A", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));valueStyle.ValueItems.Add(new ValueItem("DK2752", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));valueStyle.ValueItems.Add(new ValueItem("", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2))); shapeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;LayerOverlay groupLayer = new LayerOverlay();groupLayer.Name = "test1";groupLayer.Layers.Add(shapeLayer);winformsMap1.Overlays.Add("groupLayer", groupLayer); winformsMap1.MapUnit = GeographyUnit.DecimalDegree;shapeLayer.Open();winformsMap1.CurrentExtent = shapeLayer.GetBoundingBox();shapeLayer.Close(); winformsMap1.Refresh();`  
&nbsp;

 ![](https://community.thinkgeo.com/uploads/default/original/2X/7/74ede78a663cfb8205791c2140938e74f48677a2.png)  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale  

&nbsp;

---

<div class="post-metadata">

**Author:** ![Lenny](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@Lenny](https://community.thinkgeo.com/u/Lenny)\
**Post date:** [July 19, 2010, 1:47pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355/4 "2010-07-19T13:47:51Z")

</div>

Yale,&nbsp;thank&nbsp;you&nbsp;for&nbsp;the&nbsp;explanation.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Unfortunately,&nbsp;changing&nbsp;the&nbsp;filenames&nbsp;will&nbsp;not&nbsp;work&nbsp;in&nbsp;my&nbsp;case.&nbsp;I&nbsp;tried&nbsp;to&nbsp;use&nbsp;separate&nbsp;index&nbsp;files&nbsp;for&nbsp;each&nbsp;shape&nbsp;file&nbsp;but&nbsp;the&nbsp;map&nbsp;control&nbsp;only&nbsp;displayed&nbsp;data&nbsp;from&nbsp;the&nbsp;first&nbsp;file&nbsp;(no&nbsp;exception&nbsp;was&nbsp;thrown)&nbsp;.&nbsp;Is&nbsp;there&nbsp;another&nbsp;way&nbsp;how&nbsp;to&nbsp;solve&nbsp;this&nbsp;issue?&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards.

---

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [July 19, 2010, 2:03pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355/5 "2010-07-19T14:03:59Z")

</div>

Yale,&nbsp;this&nbsp;seems&nbsp;like&nbsp;a&nbsp;pretty&nbsp;common&nbsp;scenario.&nbsp;&nbsp;&nbsp;Are&nbsp;you&nbsp;considering&nbsp;doing&nbsp;something&nbsp;to&nbsp;support&nbsp;having&nbsp;common&nbsp;file&nbsp;names&nbsp;in&nbsp;different&nbsp;folders?

---

<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:** [July 19, 2010, 9:55pm UTC](https://community.thinkgeo.com/t/layer-with-mutiple-shape-files/1355/6 "2010-07-19T21:55:43Z")

</div>

Lenny&nbsp;&&nbsp;Ted,

Thanks&nbsp;for&nbsp;your&nbsp;posts&nbsp;and&nbsp;information.  
&nbsp;  
Another&nbsp;solution&nbsp;is&nbsp;to&nbsp;use&nbsp;the&nbsp;group&nbsp;layer&nbsp;instead&nbsp;of&nbsp;MultiShapeFileFeatureLayer,&nbsp;there&nbsp;is&nbsp;only&nbsp;very&nbsp;minor&nbsp;changes.&nbsp;Following&nbsp;code&nbsp;snippet&nbsp;shows&nbsp;how&nbsp;to&nbsp;use&nbsp;the&nbsp;GroupLayer&nbsp;instead.  
&nbsp;  
`ValueStyle valueStyle = new ValueStyle();//valueStyle.ColumnName = "Column1";//valueStyle.ValueItems.Add(new ValueItem("value1", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2)));//valueStyle.ValueItems.Add(new ValueItem("value2", PointStyles.CreateSimpleCircleStyle(GeoColor.GetRandomGeoColor(RandomColorType.All), 2))); valueStyle.ColumnName = "LoadId";valueStyle.ValueItems.Add(new ValueItem("2752", PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Red, 2)));valueStyle.ValueItems.Add(new ValueItem("A", PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Yellow, 2)));valueStyle.ValueItems.Add(new ValueItem("DK2752", PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Blue, 2)));valueStyle.ValueItems.Add(new ValueItem("", PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Copper, 2))); string[] shapeFiles = new string[] { @"c:\data\Folder1\1.shp", @"c:\data\Folder2\1.shp" };GroupLayer groupLayer = new GroupLayer();foreach(string shapeFile in shapeFiles){    ShapeFileFeatureLayer.BuildIndexFile(shapeFile, BuildIndexMode.DoNotRebuild);    ShapeFileFeatureLayer shapeFileFeatureLayer = new ShapeFileFeatureLayer(shapeFile, ShapeFileReadWriteMode.ReadOnly);                shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);                shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;     groupLayer.Layers.Add(shapeFileFeatureLayer);}groupLayer.Name = "test1";           LayerOverlay layerOverlay = new LayerOverlay();layerOverlay.Layers.Add(groupLayer);winformsMap1.Overlays.Add("LayerOverlay", layerOverlay); winformsMap1.MapUnit = GeographyUnit.DecimalDegree;groupLayer.Open();winformsMap1.CurrentExtent = groupLayer.GetBoundingBox();groupLayer.Close(); winformsMap1.Refresh();`  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale
