# Idx (index) files?

**URL:** <https://community.thinkgeo.com/t/idx-index-files/124>\
**Category:** WinForms\
**Created:** [November 27, 2008, 4:42am UTC](https://community.thinkgeo.com/t/idx-index-files/124 "2008-11-27T04:42:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bentaylortheonly](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/bentaylortheonly/32/25019_2.png) [@bentaylortheonly](https://community.thinkgeo.com/u/bentaylortheonly)\
**Post date:** [November 27, 2008, 4:42am UTC](https://community.thinkgeo.com/t/idx-index-files/124/1 "2008-11-27T04:42:05Z")

</div>

Hello,

&nbsp;When&nbsp;adding&nbsp;feature&nbsp;layers&nbsp;in&nbsp;version&nbsp;3.0,&nbsp;I&nbsp;have&nbsp;to&nbsp;set&nbsp;'RequireIndex'&nbsp;to&nbsp;false&nbsp;in&nbsp;order&nbsp;for&nbsp;it&nbsp;to&nbsp;load,&nbsp;because&nbsp;we&nbsp;don't&nbsp;have&nbsp;any&nbsp;idx&nbsp;files.&nbsp;Can&nbsp;you&nbsp;please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;there&nbsp;is&nbsp;any&nbsp;way&nbsp;of&nbsp;generating&nbsp;these&nbsp;indexes,&nbsp;as&nbsp;I&nbsp;believe&nbsp;it&nbsp;may&nbsp;be&nbsp;useful&nbsp;in&nbsp;speeding&nbsp;up&nbsp;the&nbsp;map&nbsp;for&nbsp;our&nbsp;application.

&nbsp;Thanks&nbsp;  
  
&nbsp;

---

<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:** [November 27, 2008, 7:32pm UTC](https://community.thinkgeo.com/t/idx-index-files/124/2 "2008-11-27T19:32:43Z")

</div>

There&nbsp;is&nbsp;a&nbsp;static&nbsp;method&nbsp;in&nbsp;ShapeFileFeatureLayer&nbsp;which&nbsp;builds&nbsp;the&nbsp;index.&nbsp;  
&nbsp;&nbsp;  
&nbsp;ShapeFileFeatureLayer.BuildIndexFile("c:\shapeFile.shp")&nbsp;  
&nbsp;&nbsp;  
&nbsp;With&nbsp;Index,&nbsp;the&nbsp;querying&nbsp;will&nbsp;be&nbsp;greatly&nbsp;speeded&nbsp;up&nbsp;and&nbsp;I’m&nbsp;sure&nbsp;you&nbsp;can&nbsp;feel&nbsp;the&nbsp;performance&nbsp;improvements&nbsp;after&nbsp;that.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Ben.

---

<div class="post-metadata">

**Author:** ![bentaylortheonly](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/bentaylortheonly/32/25019_2.png) [@bentaylortheonly](https://community.thinkgeo.com/u/bentaylortheonly)\
**Post date:** [December 1, 2008, 9:55am UTC](https://community.thinkgeo.com/t/idx-index-files/124/3 "2008-12-01T09:55:20Z")

</div>

OK,&nbsp;thanks&nbsp;for&nbsp;that.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;have&nbsp;run&nbsp;a&nbsp;little&nbsp;program&nbsp;to&nbsp;generate&nbsp;index&nbsp;files&nbsp;for&nbsp;the&nbsp;shape&nbsp;files&nbsp;that&nbsp;we&nbsp;have,&nbsp;however&nbsp;for&nbsp;some&nbsp;of&nbsp;them&nbsp;it&nbsp;is&nbsp;throwing&nbsp;an&nbsp;exception,&nbsp;  
&nbsp;System.IO.IOException:&nbsp;  
&nbsp;“The&nbsp;spatial&nbsp;index&nbsp;generation&nbsp;failed&nbsp;for&nbsp;an&nbsp;unknown&nbsp;reason.&nbsp;&nbsp;&nbsp;&nbsp;Please&nbsp;see&nbsp;the&nbsp;inner&nbsp;exception.”&nbsp;  
&nbsp;&nbsp;  
&nbsp;and&nbsp;the&nbsp;inner&nbsp;exception&nbsp;is&nbsp;a&nbsp;System.NullReferenceException&nbsp;(‘Object&nbsp;reference&nbsp;not&nbsp;set&nbsp;to&nbsp;an&nbsp;instance&nbsp;of&nbsp;an&nbsp;object’)&nbsp;  
&nbsp;at:&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.xa65d8a7495fb9e05.Flush()&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.x5ebd7b97ce5cba6c.Flush()&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.ShapeFileFeatureSource.BuildIndexFile(String&nbsp;shapePathFilename,&nbsp;String&nbsp;indexPathFilename,&nbsp;Projection&nbsp;projection,&nbsp;String&nbsp;columnName,&nbsp;String&nbsp;regexExpression,&nbsp;BuildIndexMode&nbsp;buildIndexMode)&nbsp;  
&nbsp;&nbsp;  
&nbsp;It&nbsp;seems&nbsp;that&nbsp;for&nbsp;most&nbsp;of&nbsp;the&nbsp;important&nbsp;ones&nbsp;it&nbsp;has&nbsp;generated&nbsp;it&nbsp;ok,&nbsp;but&nbsp;just&nbsp;wondering&nbsp;if&nbsp;this&nbsp;is&nbsp;something&nbsp;you&nbsp;would&nbsp;like&nbsp;to&nbsp;know&nbsp;about.&nbsp;

---

<div class="post-metadata">

**Author:** ![bentaylortheonly](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/bentaylortheonly/32/25019_2.png) [@bentaylortheonly](https://community.thinkgeo.com/u/bentaylortheonly)\
**Post date:** [December 1, 2008, 11:17am UTC](https://community.thinkgeo.com/t/idx-index-files/124/4 "2008-12-01T11:17:46Z")

</div>

I’ve&nbsp;tried&nbsp;it&nbsp;using&nbsp;the&nbsp;generated&nbsp;index&nbsp;files&nbsp;and&nbsp;it’s&nbsp;still&nbsp;slow.&nbsp;  
&nbsp;Strangely&nbsp;it&nbsp;is&nbsp;not&nbsp;much&nbsp;faster&nbsp;with&nbsp;a&nbsp;much&nbsp;smaller&nbsp;set&nbsp;of&nbsp;files&nbsp;which&nbsp;I&nbsp;have&nbsp;filtered&nbsp;to&nbsp;a&nbsp;particular&nbsp;geographic&nbsp;area.&nbsp;  
&nbsp;The&nbsp;layers&nbsp;I&nbsp;have&nbsp;got&nbsp;on&nbsp;the&nbsp;map&nbsp;are:&nbsp;00,&nbsp;01,&nbsp;…,&nbsp;07,&nbsp;08&nbsp;(roads),&nbsp;wa&nbsp;(water&nbsp;areas),&nbsp;and&nbsp;rr&nbsp;(railways),&nbsp;the&nbsp;largest&nbsp;file&nbsp;of&nbsp;which&nbsp;is&nbsp;47MB,&nbsp;this&nbsp;is&nbsp;the&nbsp;06&nbsp;file&nbsp;(local&nbsp;roads).&nbsp;A&nbsp;zoom&nbsp;in,&nbsp;zoom&nbsp;out,&nbsp;or&nbsp;pan&nbsp;operation&nbsp;will&nbsp;cause&nbsp;an&nbsp;approx.&nbsp;3&nbsp;to&nbsp;4&nbsp;second&nbsp;wait&nbsp;for&nbsp;the&nbsp;map&nbsp;to&nbsp;refresh.&nbsp;Should&nbsp;it&nbsp;be&nbsp;this&nbsp;slow&nbsp;or&nbsp;do&nbsp;you&nbsp;suspect&nbsp;something&nbsp;is&nbsp;amiss?&nbsp;  
&nbsp;&nbsp;  
&nbsp;This&nbsp;is&nbsp;hte&nbsp;code&nbsp;which&nbsp;I&nbsp;am&nbsp;using:&nbsp;  
&nbsp;public&nbsp;partial&nbsp;class&nbsp;Window1&nbsp;:&nbsp;Window&nbsp;  
&nbsp;{&nbsp;  
&nbsp; private&nbsp;const&nbsp;string&nbsp;path&nbsp;=&nbsp;@“c:\teleatlasdata”;&nbsp;  
&nbsp; private&nbsp;readonly&nbsp;List\<string\>&nbsp;files;&nbsp;  
&nbsp; public&nbsp;Window1()&nbsp;  
&nbsp; {&nbsp;  
&nbsp; InitializeComponent();&nbsp;  
&nbsp; files&nbsp;=&nbsp;new&nbsp;List\<string\>(Directory.GetFiles(path,&nbsp;“\*.shp”));&nbsp;  
&nbsp; Loaded&nbsp;+=&nbsp;delegate&nbsp;  
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;  
&nbsp; AddRoadLayer(“08”,&nbsp;“LocalRoad4”);&nbsp;  
&nbsp; AddRoadLayer(“07”,&nbsp;“LocalRoad4”);&nbsp;  
&nbsp; AddRoadLayer(“06”,&nbsp;“LocalRoad3”);&nbsp;  
&nbsp; AddRoadLayer(“05”,&nbsp;“LocalRoad3”);&nbsp;  
&nbsp; AddRoadLayer(“04”,&nbsp;“MajorRoad3”);&nbsp;  
&nbsp; AddRoadLayer(“03”,&nbsp;“MajorRoad1”);&nbsp;  
&nbsp; AddRoadLayer(“02”,&nbsp;“SecondaryRoad1”);&nbsp;  
&nbsp; AddRoadLayer(“01”,&nbsp;“SecondaryRoad1”);&nbsp;  
&nbsp; AddRoadLayer(“00”,&nbsp;“Highway5”);&nbsp;  
&nbsp; AddWaterLayer(“wa”);&nbsp;  
&nbsp; AddRailwayLayer(“rr”);&nbsp;  
&nbsp; map.CurrentExtent&nbsp;=&nbsp;new&nbsp;RectangleShape(new&nbsp;PointShape(-1.268,&nbsp;53.140),&nbsp;new&nbsp;PointShape(-1.220,&nbsp;53.118));&nbsp;  
&nbsp; map.Refresh();&nbsp;  
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };&nbsp;  
&nbsp; }&nbsp;  
&nbsp;&nbsp;  
&nbsp; private&nbsp;void&nbsp;AddRoadLayer(string&nbsp;suffix,&nbsp;string&nbsp;lineStyle)&nbsp;  
&nbsp; {&nbsp;  
&nbsp; Debug.WriteLine("Adding&nbsp;"&nbsp;+&nbsp;suffix);&nbsp;  
&nbsp; foreach&nbsp;(var&nbsp;filename&nbsp;in&nbsp;from&nbsp;f&nbsp;in&nbsp;files&nbsp;where&nbsp;f.EndsWith(suffix&nbsp;+&nbsp;“.shp”)&nbsp;select&nbsp;f)&nbsp;  
&nbsp; {&nbsp;  
&nbsp;&nbsp;  
&nbsp; var&nbsp;lineStylesMethod&nbsp;=&nbsp;typeof&nbsp;(LineStyles).GetProperty(lineStyle,&nbsp;BindingFlags.Static&nbsp;|&nbsp;BindingFlags.Public);&nbsp;  
&nbsp; var&nbsp;shapeLayer&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureLayer(filename,&nbsp;ShapeFileReadWriteMode.ReadOnly);&nbsp;  
&nbsp;&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle&nbsp;=&nbsp;(LineStyle)&nbsp;lineStylesMethod.GetValue(null,&nbsp;new&nbsp;object[0]);&nbsp;  
&nbsp;&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp; map.StaticOverlay.Layers.Add(shapeLayer);&nbsp;  
&nbsp;&nbsp;  
&nbsp; var&nbsp;textStylesMethod&nbsp;=&nbsp;typeof&nbsp;(TextStyles).GetMethod(lineStyle,&nbsp;BindingFlags.Static&nbsp;|&nbsp;BindingFlags.Public);&nbsp;  
&nbsp; var&nbsp;labelNameLayer&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureLayer(filename,&nbsp;ShapeFileReadWriteMode.ReadOnly);&nbsp;  
&nbsp;&nbsp;  
&nbsp; labelNameLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle&nbsp;=&nbsp;(TextStyle)&nbsp;textStylesMethod.Invoke(null,&nbsp;new[]&nbsp;{“NAME”});&nbsp;  
&nbsp;&nbsp;  
&nbsp; labelNameLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp; map.StaticOverlay.Layers.Add(labelNameLayer);&nbsp;  
&nbsp; }&nbsp;  
&nbsp; }&nbsp;  
&nbsp;&nbsp;  
&nbsp; private&nbsp;void&nbsp;AddWaterLayer(string&nbsp;suffix)&nbsp;  
&nbsp; {&nbsp;  
&nbsp; foreach&nbsp;(var&nbsp;filename&nbsp;in&nbsp;from&nbsp;f&nbsp;in&nbsp;files&nbsp;where&nbsp;f.EndsWith(suffix&nbsp;+&nbsp;“.shp”)&nbsp;select&nbsp;f)&nbsp;  
&nbsp; {&nbsp;  
&nbsp; var&nbsp;shapeLayer&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureLayer(filename,&nbsp;ShapeFileReadWriteMode.ReadOnly);&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle&nbsp;=&nbsp;LineStyles.River1;&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle&nbsp;=&nbsp;AreaStyles.Water1;&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp; map.StaticOverlay.Layers.Add(shapeLayer);&nbsp;  
&nbsp;&nbsp;  
&nbsp; var&nbsp;labelLayer&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureLayer(filename,&nbsp;ShapeFileReadWriteMode.ReadOnly);&nbsp;  
&nbsp; labelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle&nbsp;=&nbsp;TextStyles.Water1(“NAME”);&nbsp;  
&nbsp; labelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp; map.StaticOverlay.Layers.Add(labelLayer);&nbsp;  
&nbsp; }&nbsp;  
&nbsp;&nbsp;  
&nbsp; }&nbsp;  
&nbsp;&nbsp;  
&nbsp; private&nbsp;void&nbsp;AddRailwayLayer(string&nbsp;suffix)&nbsp;  
&nbsp; {&nbsp;  
&nbsp; foreach&nbsp;(var&nbsp;filename&nbsp;in&nbsp;from&nbsp;f&nbsp;in&nbsp;files&nbsp;where&nbsp;f.EndsWith(suffix&nbsp;+&nbsp;“.shp”)&nbsp;select&nbsp;f)&nbsp;  
&nbsp; {&nbsp;  
&nbsp; var&nbsp;shapeLayer&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureLayer(filename,&nbsp;ShapeFileReadWriteMode.ReadOnly);&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle&nbsp;=&nbsp;LineStyles.Railway1;&nbsp;  
&nbsp; shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp; map.StaticOverlay.Layers.Add(shapeLayer);&nbsp;  
&nbsp;&nbsp;  
&nbsp; var&nbsp;labelLayer&nbsp;=&nbsp;new&nbsp;ShapeFileFeatureLayer(filename,&nbsp;ShapeFileReadWriteMode.ReadOnly);&nbsp;  
&nbsp; labelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle&nbsp;=&nbsp;TextStyles.Railway1(“NAME”);&nbsp;  
&nbsp; labelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp; map.StaticOverlay.Layers.Add(labelLayer);&nbsp;  
&nbsp; }&nbsp;  
&nbsp; }&nbsp;  
&nbsp;}

---

<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:** [December 3, 2008, 12:46am UTC](https://community.thinkgeo.com/t/idx-index-files/124/5 "2008-12-03T00:46:27Z")

</div>

Thanks&nbsp;for&nbsp;your&nbsp;code!&nbsp;&nbsp;Ben&nbsp;

Can&nbsp;you&nbsp;try&nbsp;the&nbsp;following&nbsp;steps&nbsp;to&nbsp;see&nbsp;where&nbsp;the&nbsp;time-consuming&nbsp;part&nbsp;is?  
1,&nbsp;Get&nbsp;the&nbsp;latest&nbsp;Beta&nbsp;(3.0.131,&nbsp;will&nbsp;be&nbsp;released&nbsp;tomorrow)&nbsp;which&nbsp;did&nbsp;some&nbsp;improvements&nbsp;for&nbsp;building&nbsp;index,&nbsp;please&nbsp;make&nbsp;sure&nbsp;every&nbsp;shape&nbsp;file&nbsp;has&nbsp;its&nbsp;idx/ids&nbsp;files.&nbsp;Or&nbsp;to&nbsp;be&nbsp;safe,&nbsp;remove&nbsp;all&nbsp;the&nbsp;idx/ids&nbsp;and&nbsp;build&nbsp;index&nbsp;again.  
&nbsp;  
2,&nbsp;Get&nbsp;the&nbsp;elapsed&nbsp;time&nbsp;for&nbsp;Map.Refresh().&nbsp;I&nbsp;saw&nbsp;you&nbsp;are&nbsp;using&nbsp;reflection,&nbsp;which&nbsp;usually&nbsp;doesn’t&nbsp;take&nbsp;that&nbsp;much&nbsp;time,&nbsp;but&nbsp;still&nbsp;want&nbsp;to&nbsp;make&nbsp;sure&nbsp;most&nbsp;time&nbsp;is&nbsp;consumed&nbsp;on&nbsp;drawing&nbsp;the&nbsp;map.&nbsp;The&nbsp;code&nbsp;may&nbsp;be&nbsp;like&nbsp;this:  
&nbsp;  
`	using System.Diagnostics;	// ……	Stopwatch stopWatch = new Stopwatch();        stopWatch.Start();        map.Refresh();        Debug.WriteLine(stopWatch.ElapsedMilliseconds + “ms”);`  
3,&nbsp;If&nbsp;most&nbsp;time&nbsp;is&nbsp;consumed&nbsp;in&nbsp;map.Refresh(),&nbsp;please&nbsp;print&nbsp;out&nbsp;the&nbsp;drawing&nbsp;time&nbsp;for&nbsp;every&nbsp;layer,&nbsp;you&nbsp;can&nbsp;do&nbsp;it&nbsp;with&nbsp;the&nbsp;following&nbsp;function.  
&nbsp;  
`  private void PrintLayersDrawingTime()        {            foreach (ShapeFileFeatureLayer layer in winformsMap1.StaticOverlay.Layers)            {                System.Diagnostics.Debug.WriteLine(layer.ShapePathFileName + ": " + layer.DrawingTime.Milliseconds + "ms");            }        }`  
&nbsp;  
4,&nbsp;Analyze&nbsp;the&nbsp;result.&nbsp;In&nbsp;most&nbsp;cases&nbsp;there&nbsp;is&nbsp;only&nbsp;one&nbsp;or&nbsp;two&nbsp;layer&nbsp;which&nbsp;takes&nbsp;extremely&nbsp;longer&nbsp;drawing&nbsp;time.&nbsp;Can&nbsp;you&nbsp;just&nbsp;draw&nbsp;those&nbsp;layers&nbsp;with&nbsp;other&nbsp;layers&nbsp;commented&nbsp;out.&nbsp;If&nbsp;possible,&nbsp;can&nbsp;you&nbsp;send&nbsp;me&nbsp;a&nbsp;snapshot&nbsp;of&nbsp;the&nbsp;map&nbsp;in&nbsp;that&nbsp;case&nbsp;or&nbsp;send&nbsp;the&nbsp;data&nbsp;to&nbsp;me&nbsp;for&nbsp;a&nbsp;further&nbsp;investigation.  
&nbsp;  
Let&nbsp;us&nbsp;know&nbsp;for&nbsp;any&nbsp;more&nbsp;queries.  
&nbsp;  
Ben
