# IsoLines performance and Threading

**URL:** <https://community.thinkgeo.com/t/isolines-performance-and-threading/1925>\
**Category:** WinForms\
**Created:** [March 12, 2012, 12:55pm UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925 "2012-03-12T12:55:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@Richard3](https://community.thinkgeo.com/u/Richard3)\
**Post date:** [March 12, 2012, 12:55pm UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925/1 "2012-03-12T12:55:38Z")

</div>

We&nbsp;have&nbsp;been&nbsp;using&nbsp;the&nbsp;Isolines&nbsp;(GridIsoLineLayer,&nbsp;GridFeatureLayer)&nbsp;features&nbsp;to&nbsp;plot&nbsp;data&nbsp;we&nbsp;generate&nbsp;from&nbsp;simulations.&nbsp;&nbsp;The&nbsp;simplest&nbsp;plot&nbsp;use&nbsp;a&nbsp;5&nbsp;x&nbsp;5&nbsp;grid&nbsp;cell&nbsp;count&nbsp;and&nbsp;the&nbsp;isolines&nbsp;generate&nbsp;in&nbsp;seconds&nbsp;(or&nbsp;less).&nbsp;&nbsp;We&nbsp;have&nbsp;noticed&nbsp;a&nbsp;significant&nbsp;dropoff&nbsp;as&nbsp;the&nbsp;grid&nbsp;cell&nbsp;count&nbsp;increases.&nbsp;For&nbsp;example&nbsp;with&nbsp;a&nbsp;50&nbsp;x&nbsp;50&nbsp;&nbsp;grid&nbsp;the&nbsp;plots&nbsp;generate&nbsp;in&nbsp;around&nbsp;a&nbsp;minute.&nbsp;&nbsp;At&nbsp;100&nbsp;x&nbsp;100&nbsp;it&nbsp;may&nbsp;take&nbsp;several&nbsp;minutes.&nbsp;&nbsp;The&nbsp;largest&nbsp;I&nbsp;have&nbsp;worked&nbsp;on&nbsp;personnally&nbsp;was&nbsp;about&nbsp;800&nbsp;x&nbsp;800&nbsp;and&nbsp;it&nbsp;took&nbsp;around&nbsp;3&nbsp;hours&nbsp;and&nbsp;20&nbsp;minutes.&nbsp;&nbsp;Our&nbsp;user&nbsp;have&nbsp;tried&nbsp;some&nbsp;larger&nbsp;plots&nbsp;but&nbsp;I&nbsp;do&nbsp;not&nbsp;have&nbsp;a&nbsp;time&nbsp;for&nbsp;the&nbsp;plotting&nbsp;operation.&nbsp;&nbsp;

&nbsp;Our&nbsp;question&nbsp;is&nbsp;whether&nbsp;it&nbsp;is&nbsp;possible&nbsp;to&nbsp;generate&nbsp;the&nbsp;isolines&nbsp;in&nbsp;a&nbsp;secondary&nbsp;thread&nbsp;so&nbsp;that&nbsp;the&nbsp;GUI&nbsp;of&nbsp;our&nbsp;application&nbsp;(and&nbsp;the&nbsp;window&nbsp;containing&nbsp;the&nbsp;MapSuite&nbsp;map&nbsp;can&nbsp;continue&nbsp;to&nbsp;be&nbsp;responsive?&nbsp;&nbsp;As&nbsp;it&nbsp;is&nbsp;right&nbsp;now,&nbsp;when&nbsp;we&nbsp;call&nbsp;the&nbsp;method&nbsp;to&nbsp;generate&nbsp;the&nbsp;GridIsoLineLayer&nbsp;and&nbsp;GridFeatureLayer&nbsp;and&nbsp;then&nbsp;call&nbsp;the&nbsp;winformMap.Refresh&nbsp;to&nbsp;render&nbsp;it&nbsp;on&nbsp;the&nbsp;map,&nbsp;the&nbsp;thread&nbsp;that&nbsp;controls&nbsp;the&nbsp;GUI&nbsp;of&nbsp;our&nbsp;application&nbsp;has&nbsp;to&nbsp;wait&nbsp;until&nbsp;the&nbsp;isoline&nbsp;generation&nbsp;completes.&nbsp;&nbsp;This&nbsp;causes&nbsp;our&nbsp;GUI&nbsp;to&nbsp;have&nbsp;partially&nbsp;repainted&nbsp;or&nbsp;unresponive&nbsp;repainting&nbsp;of&nbsp;the&nbsp;GUI.&nbsp;&nbsp;&nbsp;&nbsp;It&nbsp;seems&nbsp;that&nbsp;the&nbsp;actual&nbsp;guts&nbsp;of&nbsp;the&nbsp;the&nbsp;GridIsoLineLayer&nbsp;(the&nbsp;interpolation&nbsp;calculations)&nbsp;are&nbsp;not&nbsp;being&nbsp;performed&nbsp;until&nbsp;I&nbsp;call&nbsp;the&nbsp;winformMap.Refresh.&nbsp;&nbsp;&nbsp;Since&nbsp;this&nbsp;also&nbsp;update&nbsp;the&nbsp;MapSuite&nbsp;map&nbsp;window,&nbsp;I&nbsp;have&nbsp;not&nbsp;tried&nbsp;it&nbsp;in&nbsp;a&nbsp;separate&nbsp;thread&nbsp;because&nbsp;we&nbsp;have&nbsp;had&nbsp;issues&nbsp;in&nbsp;the&nbsp;past&nbsp;with&nbsp;multiple&nbsp;threads&nbsp;accesing&nbsp;the&nbsp;GUI&nbsp;of&nbsp;our&nbsp;application.&nbsp;&nbsp;Is&nbsp;there&nbsp;a&nbsp;model&nbsp;for&nbsp;the&nbsp;code&nbsp;that&nbsp;will&nbsp;allow&nbsp;us&nbsp;to&nbsp;generate&nbsp;the&nbsp;isolines&nbsp;as&nbsp;a&nbsp;background&nbsp;or&nbsp;secondary&nbsp;thread&nbsp;and&nbsp;then&nbsp;render&nbsp;the&nbsp;output&nbsp;to&nbsp;the&nbsp;map&nbsp;in&nbsp;the&nbsp;thread&nbsp;that&nbsp;controls&nbsp;the&nbsp;GUI&nbsp;windows?

Richard

---

<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:** [March 21, 2012, 2:30am UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925/2 "2012-03-21T02:30:35Z")

</div>

Richard,  
&nbsp;  
I&nbsp;guess&nbsp;you&nbsp;must&nbsp;have&nbsp;had&nbsp;a&nbsp;huge&nbsp;number&nbsp;of&nbsp;reference&nbsp;points&nbsp;which&nbsp;makes&nbsp;it&nbsp;so&nbsp;slow&nbsp;to&nbsp;generate&nbsp;a&nbsp;big&nbsp;grid&nbsp;cell&nbsp;matrix.&nbsp;I&nbsp;tried&nbsp;generating&nbsp;a&nbsp;800\*800&nbsp;cell&nbsp;matrix&nbsp;in&nbsp;the&nbsp;DisplayIsoLine&nbsp;code&nbsp;community&nbsp;sample&nbsp;([wiki.thinkgeo.com/wiki/File:…111115.zip](http://wiki.thinkgeo.com/wiki/File:ServicesEditionSample_Isolines_CS_WinForms_111115.zip)),&nbsp;and&nbsp;it&nbsp;takes&nbsp;only&nbsp;46&nbsp;seconds.&nbsp;My&nbsp;test&nbsp;machine&nbsp;is&nbsp;with&nbsp;Q8200&nbsp;CPU&nbsp;and&nbsp;8G&nbsp;Memory.&nbsp;  
&nbsp;  
There&nbsp;are&nbsp;2&nbsp;steps&nbsp;to&nbsp;generate&nbsp;IsoLines&nbsp;in&nbsp;GridIsoLineFeatureLayer,&nbsp;first&nbsp;it&nbsp;generates&nbsp;a&nbsp;gridCellMatrix&nbsp;and&nbsp;second,&nbsp;it&nbsp;generate&nbsp;IsoLines&nbsp;based&nbsp;on&nbsp;that&nbsp;Matrix.&nbsp;We&nbsp;provide&nbsp;static&nbsp;methods&nbsp;for&nbsp;both&nbsp;of&nbsp;the&nbsp;2&nbsp;steps&nbsp;which&nbsp;you&nbsp;can&nbsp;put&nbsp;in&nbsp;a&nbsp;separate&nbsp;thread.&nbsp;The&nbsp;first&nbsp;method&nbsp;is&nbsp;in&nbsp;GridFeatureSource&nbsp;class:  
`public static GridCell[,] GenerateGridMatrix(GridDefinition gridDefinition, GridInterpolationModel gridInterpolationModel)`  
&nbsp;  
The&nbsp;second&nbsp;static&nbsp;methods&nbsp;in&nbsp;IsoLineLayer&nbsp;accept&nbsp;the&nbsp;generated&nbsp;gridMatrix&nbsp;and&nbsp;create&nbsp;IsoLineFeatures.&nbsp;&nbsp;  
`Collection<Feature> GetIsoFeatures(GridCell[,] gridMatrix, IEnumerable<double> isoLineLevels, string dataValueColumnName, IsoLineType isoLineType)`  
&nbsp;  
You&nbsp;can&nbsp;put&nbsp;them&nbsp;in&nbsp;another&nbsp;thread,&nbsp;generate&nbsp;the&nbsp;IsoLines&nbsp;features&nbsp;and&nbsp;load&nbsp;them&nbsp;when&nbsp;needed&nbsp;by&nbsp;adding&nbsp;them&nbsp;to&nbsp;an&nbsp;InmemoryFeatureLayer&nbsp;maybe.&nbsp;This&nbsp;gives&nbsp;you&nbsp;a&nbsp;responsive&nbsp;UI.&nbsp;  
&nbsp;  
Thanks,  
&nbsp;  
Ben

&nbsp;

---

<div class="post-metadata">

**Author:** ![Richard3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@Richard3](https://community.thinkgeo.com/u/Richard3)\
**Post date:** [March 21, 2012, 6:55am UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925/3 "2012-03-21T06:55:18Z")

</div>

Ben,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;the&nbsp;response.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yes,&nbsp;I&nbsp;guess&nbsp;we&nbsp;do&nbsp;have&nbsp;a&nbsp;lot&nbsp;of&nbsp;reference&nbsp;points.&nbsp;&nbsp;The&nbsp;reference&nbsp;points&nbsp;we&nbsp;are&nbsp;using&nbsp;are&nbsp;generated&nbsp;by&nbsp;a&nbsp;simulation.&nbsp;&nbsp;The&nbsp;simulation&nbsp;is&nbsp;already&nbsp;interpolating&nbsp;a&nbsp;value&nbsp;for&nbsp;each&nbsp;cell&nbsp;in&nbsp;the&nbsp;matrix&nbsp;of&nbsp;values.&nbsp;&nbsp;Therefore,&nbsp;if&nbsp;the&nbsp;grid&nbsp;size&nbsp;is&nbsp;5&nbsp;cells&nbsp;by&nbsp;5&nbsp;cells,&nbsp;we&nbsp;should&nbsp;have&nbsp;25&nbsp;values&nbsp;one&nbsp;per&nbsp;cell.&nbsp;&nbsp;If&nbsp;we&nbsp;are&nbsp;using&nbsp;a&nbsp;100&nbsp;by&nbsp;100&nbsp;grid&nbsp;size&nbsp;we&nbsp;would&nbsp;have&nbsp;10000&nbsp;reference&nbsp;points.&nbsp;&nbsp;On&nbsp;the&nbsp;800&nbsp;by&nbsp;800&nbsp;grid,&nbsp;we&nbsp;had&nbsp;640,000&nbsp;reference&nbsp;points.&nbsp;&nbsp;We&nbsp;do&nbsp;sometime&nbsp;have&nbsp;cells&nbsp;with&nbsp;the&nbsp;"NoDataValue"&nbsp;defined&nbsp;but&nbsp;these&nbsp;are&nbsp;usually&nbsp;a&nbsp;small&nbsp;percentage&nbsp;at&nbsp;the&nbsp;most.&nbsp;&nbsp;I&nbsp;would&nbsp;love&nbsp;to&nbsp;see&nbsp;it&nbsp;generate&nbsp;the&nbsp;isolines&nbsp;in&nbsp;46&nbsp;seconds&nbsp;but&nbsp;that&nbsp;is&nbsp;not&nbsp;the&nbsp;experience&nbsp;we&nbsp;are&nbsp;getting.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Since&nbsp;my&nbsp;original&nbsp;post,&nbsp;I&nbsp;have&nbsp;been&nbsp;trying&nbsp;to&nbsp;isolate&nbsp;the&nbsp;area&nbsp;that&nbsp;is&nbsp;taking&nbsp;the&nbsp;most&nbsp;time&nbsp;and&nbsp;it&nbsp;does&nbsp;appear&nbsp;to&nbsp;be&nbsp;the&nbsp;call&nbsp;we&nbsp;make&nbsp;to&nbsp;GridFeatureSource.GenerateGrid&nbsp;rather&nbsp;than&nbsp;the&nbsp;call&nbsp;to&nbsp;winformsMap1.Refresh.&nbsp;&nbsp;&nbsp;The&nbsp;refresh&nbsp;is&nbsp;the&nbsp;second&nbsp;longest&nbsp;running&nbsp;call&nbsp;is&nbsp;the&nbsp;process&nbsp;from&nbsp;what&nbsp;I&nbsp;have&nbsp;seen&nbsp;lately.&nbsp;&nbsp;I&nbsp;believe&nbsp;GridFeatureSource.GenerateGrid&nbsp;and&nbsp;the&nbsp;static&nbsp;GridFeatureSource.GenerateGridMatrix&nbsp;you&nbsp;mentioned&nbsp;above&nbsp;must&nbsp;be&nbsp;equivalent.&nbsp;&nbsp;I&nbsp;currently&nbsp;do&nbsp;not&nbsp;use&nbsp;GetIsoFeatures.&nbsp;&nbsp;The&nbsp;Isolines&nbsp;sample&nbsp;that&nbsp;I&nbsp;modeled&nbsp;my&nbsp;code&nbsp;after&nbsp;was&nbsp;serializing&nbsp;the&nbsp;output&nbsp;of&nbsp;the&nbsp;GenerateGrid&nbsp;to&nbsp;a&nbsp;temporary&nbsp;output&nbsp;file&nbsp;on&nbsp;disk.&nbsp;I&nbsp;then&nbsp;use&nbsp;the&nbsp;GridIsoLIneLayer&nbsp;constructor&nbsp;with&nbsp;an&nbsp;argument&nbsp;to&nbsp;the&nbsp;temporary&nbsp;file&nbsp;path.&nbsp;&nbsp;Would&nbsp;there&nbsp;be&nbsp;a&nbsp;big&nbsp;speed&nbsp;advantage&nbsp;in&nbsp;using&nbsp;GetIsoFeatures&nbsp;over&nbsp;the&nbsp;constructor&nbsp;using&nbsp;the&nbsp;serialized&nbsp;file?&nbsp;&nbsp;Since&nbsp;I&nbsp;do&nbsp;not&nbsp;call&nbsp;GetIsoFeatures&nbsp;directly&nbsp;is&nbsp;it&nbsp;being&nbsp;called&nbsp;indirectly&nbsp;from&nbsp;some&nbsp;other&nbsp;call&nbsp;I&nbsp;make&nbsp;such&nbsp;as&nbsp;the&nbsp;constructor&nbsp;for&nbsp;GridIsoLineLayer&nbsp;or&nbsp;on&nbsp;the&nbsp;refresh?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;&nbsp;  
&nbsp;Richard&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:** [March 21, 2012, 8:59pm UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925/4 "2012-03-21T20:59:33Z")

</div>

Richard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;right&nbsp;the&nbsp;GridFeatureSource.GenerateGrid()&nbsp;is&nbsp;taking&nbsp;the&nbsp;most&nbsp;time.&nbsp;As&nbsp;you’ve&nbsp;already&nbsp;serialized&nbsp;the&nbsp;grid&nbsp;to&nbsp;a&nbsp;file&nbsp;and&nbsp;load&nbsp;it&nbsp;back&nbsp;directly&nbsp;in&nbsp;GridIsoLineLayer’s&nbsp;constructor,&nbsp;this&nbsp;most&nbsp;time-consuming&nbsp;part&nbsp;has&nbsp;been&nbsp;skipped.&nbsp;GridIsoLineLayer&nbsp;internally&nbsp;calls&nbsp;the&nbsp;static&nbsp;GetIsoFeatures()&nbsp;to&nbsp;get&nbsp;the&nbsp;IsoLine&nbsp;Features,&nbsp;which&nbsp;is&nbsp;usually&nbsp;running&nbsp;fast&nbsp;especially&nbsp;compared&nbsp;with&nbsp;the&nbsp;GenerateGrid(),&nbsp;but&nbsp;you&nbsp;may&nbsp;still&nbsp;getting&nbsp;performance&nbsp;benefits&nbsp;by&nbsp;running&nbsp;GetIsoFeatures()&nbsp;first,&nbsp;serialize&nbsp;the&nbsp;return&nbsp;features,&nbsp;and&nbsp;deserialize&nbsp;those&nbsp;features&nbsp;when&nbsp;needed.&nbsp;This&nbsp;skips&nbsp;the&nbsp;GridCells-\>IsoLine&nbsp;calculation&nbsp;but&nbsp;spend&nbsp;time&nbsp;on&nbsp;Serialization/Deserialization,&nbsp;so&nbsp;the&nbsp;performance&nbsp;benefit&nbsp;depends&nbsp;on&nbsp;the&nbsp;number&nbsp;of&nbsp;grid&nbsp;cells&nbsp;and&nbsp;isoLines.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Since&nbsp;the&nbsp;original&nbsp;post,&nbsp;you&nbsp;certainly&nbsp;don’t&nbsp;want&nbsp;to&nbsp;put&nbsp;GenerateGrid()&nbsp;to&nbsp;your&nbsp;main&nbsp;UI&nbsp;thread,&nbsp;and&nbsp;probably&nbsp;you&nbsp;can&nbsp;also&nbsp;move&nbsp;GetIsoFeatures()&nbsp;to&nbsp;another&nbsp;thread&nbsp;and&nbsp;just&nbsp;load&nbsp;the&nbsp;returning&nbsp;features&nbsp;in&nbsp;the&nbsp;main&nbsp;thread&nbsp;when&nbsp;ready.&nbsp;&nbsp;In&nbsp;this&nbsp;way&nbsp;the&nbsp;UI&nbsp;thread&nbsp;just&nbsp;simply&nbsp;load&nbsp;features&nbsp;and&nbsp;move&nbsp;all&nbsp;the&nbsp;dirty&nbsp;work&nbsp;away.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Ben&nbsp;

---

<div class="post-metadata">

**Author:** ![Richard3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@Richard3](https://community.thinkgeo.com/u/Richard3)\
**Post date:** [March 23, 2012, 12:17pm UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925/5 "2012-03-23T12:17:29Z")

</div>

Ben,&nbsp;  
&nbsp;&nbsp;  
&nbsp;We&nbsp;have&nbsp;several&nbsp;additional&nbsp;questions&nbsp;that&nbsp;we&nbsp;need&nbsp;answers&nbsp;to.&nbsp;&nbsp;Do&nbsp;you&nbsp;have&nbsp;any&nbsp;description&nbsp;of&nbsp;how&nbsp;the&nbsp;InverseDistanceWeighterGridInterpolationModel&nbsp;class&nbsp;works&nbsp;to&nbsp;interpolate&nbsp;the&nbsp;data?&nbsp;&nbsp;Is&nbsp;the&nbsp;output&nbsp;of&nbsp;the&nbsp;GenerateGrid&nbsp;and&nbsp;GenerateGridMatrix&nbsp;always&nbsp;a&nbsp;rectangluar&nbsp;array?&nbsp;&nbsp;The&nbsp;output&nbsp;of&nbsp;the&nbsp;GenerateGridMatrix&nbsp;is&nbsp;shown&nbsp;as&nbsp;GridCell[,].&nbsp;&nbsp;Is&nbsp;this&nbsp;a&nbsp;jagged&nbsp;array&nbsp;or&nbsp;are&nbsp;the&nbsp;dimensions&nbsp;fully&nbsp;populated&nbsp;into&nbsp;a&nbsp;rectangular&nbsp;array?&nbsp;&nbsp;&nbsp;Is&nbsp;the&nbsp;purpose&nbsp;of&nbsp;the&nbsp;GenerateGrid&nbsp;and&nbsp;GenerateGridMatrix&nbsp;to&nbsp;take&nbsp;a&nbsp;randomly&nbsp;distributing&nbsp;set&nbsp;of&nbsp;input&nbsp;data&nbsp;points&nbsp;and&nbsp;use&nbsp;interpolation&nbsp;to&nbsp;output&nbsp;a&nbsp;rectangluar&nbsp;array&nbsp;of&nbsp;a&nbsp;single&nbsp;data&nbsp;point&nbsp;per&nbsp;grid&nbsp;cell?&nbsp;&nbsp;How&nbsp;does&nbsp;the&nbsp;interpolation&nbsp;handle&nbsp;the&nbsp;empty&nbsp;(NoDataValue)&nbsp;grid&nbsp;cells?&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;And&nbsp;one&nbsp;last&nbsp;question&nbsp;from&nbsp;a&nbsp;programmer.&nbsp;&nbsp;The&nbsp;GridIsoLineLayer&nbsp;class&nbsp;has&nbsp;four&nbsp;constructors.&nbsp;Three&nbsp;of&nbsp;them&nbsp;take&nbsp;a&nbsp;fileNamePath&nbsp;as&nbsp;an&nbsp;input&nbsp;argument.&nbsp;&nbsp;The&nbsp;fourth&nbsp;is&nbsp;the&nbsp;default&nbsp;constructor&nbsp;with&nbsp;no&nbsp;input&nbsp;arguments.&nbsp;&nbsp;Is&nbsp;there&nbsp;a&nbsp;way&nbsp;to&nbsp;use&nbsp;data&nbsp;loaded&nbsp;in&nbsp;memory&nbsp;as&nbsp;the&nbsp;input&nbsp;to&nbsp;the&nbsp;GirdIsoLineLayer&nbsp;and&nbsp;is&nbsp;there&nbsp;any&nbsp;sample&nbsp;code&nbsp;for&nbsp;this?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;help&nbsp;  
&nbsp;&nbsp;  
&nbsp;Richard

---

<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:** [March 25, 2012, 11:46pm UTC](https://community.thinkgeo.com/t/isolines-performance-and-threading/1925/6 "2012-03-25T23:46:21Z")

</div>

&nbsp;Richard,

You&nbsp;are&nbsp;right.&nbsp;The&nbsp;returned&nbsp;GridCell[,]&nbsp;is&nbsp;always&nbsp;a&nbsp;rectangular&nbsp;array,&nbsp;will&nbsp;never&nbsp;be&nbsp;a&nbsp;jagged&nbsp;array.&nbsp;The&nbsp;purpose&nbsp;of&nbsp;the&nbsp;GenerateGrid&nbsp;and&nbsp;GenerateGridMatrix&nbsp;is&nbsp;to&nbsp;take&nbsp;a&nbsp;randomly&nbsp;distributing&nbsp;set&nbsp;of&nbsp;input&nbsp;data&nbsp;points&nbsp;and&nbsp;use&nbsp;interpolation&nbsp;to&nbsp;output&nbsp;a&nbsp;rectangluar&nbsp;array&nbsp;of&nbsp;a&nbsp;single&nbsp;data&nbsp;point&nbsp;per&nbsp;grid&nbsp;cell.&nbsp;The&nbsp;key&nbsp;logic&nbsp;in&nbsp;InverseDistanceWeightedGridInterpolationModel&nbsp;is&nbsp;as&nbsp;following,&nbsp;you&nbsp;can&nbsp;see&nbsp;it’s&nbsp;pretty&nbsp;simple.

` protected override double InterpolateCore(RectangleShape cellExtent, GridDefinition gridDefinition)        {            double cellCenterX = cellExtent.GetCenterPoint().X;            double cellCenterY = cellExtent.GetCenterPoint().Y;            double cellValue = gridDefinition.NoDataValue;            double Zx1 = 0;            double Zx2 = 0;             foreach (PointShape closePoint in gridDefinition.DataPoints.Keys)            {                double distance = Math.Pow((cellCenterX - closePoint.X), 2) + Math.Pow((cellCenterY - closePoint.Y), 2);                 if (distance < searchRadius)                {                    double alpha = Math.Pow((1 / distance), power / 2);                     Zx1 = Zx1 + alpha * (gridDefinition.DataPoints[closePoint]);                    Zx2 = Zx2 + alpha;                }            }             if (Zx1 != 0 && Zx2 != 0)            {                cellValue = (Zx1 / Zx2);            }            return cellValue;        }`

If&nbsp;a&nbsp;cell&nbsp;value&nbsp;cannot&nbsp;be&nbsp;properly&nbsp;calculated&nbsp;while&nbsp;generating&nbsp;the&nbsp;grid&nbsp;cell&nbsp;matrix,&nbsp;it&nbsp;will&nbsp;be&nbsp;assigned&nbsp;as&nbsp;NoDataValue&nbsp;(-9999)&nbsp;by&nbsp;default.&nbsp;&nbsp;If&nbsp;passing&nbsp;a&nbsp;matrix&nbsp;with&nbsp;NoDataValue&nbsp;to&nbsp;a&nbsp;GridIsoLineLayer&nbsp;for&nbsp;example,&nbsp;the&nbsp;noDataValue&nbsp;will&nbsp;first&nbsp;be&nbsp;replaced&nbsp;by&nbsp;some&nbsp;other&nbsp;value&nbsp;by&nbsp;calling&nbsp;GridFeatureSource.ReplaceNoDataValue&nbsp;with&nbsp;a&nbsp;given&nbsp;GridInterpolationModel.&nbsp;&nbsp;You&nbsp;can&nbsp;also&nbsp;call&nbsp;it&nbsp;manually&nbsp;to&nbsp;replace&nbsp;the&nbsp;NoDataValue&nbsp;before&nbsp;using&nbsp;the&nbsp;matrix&nbsp;to&nbsp;generate&nbsp;IsoLines.&nbsp;(The&nbsp;ReplaceNoDataValue&nbsp;method&nbsp;is&nbsp;now&nbsp;only&nbsp;available&nbsp;in&nbsp;the&nbsp;DEV&nbsp;Branch&nbsp;(5.5.\*.0)).

To&nbsp;create&nbsp;a&nbsp;GridIsoLineLayer&nbsp;completely&nbsp;in&nbsp;Memory,&nbsp;you&nbsp;can&nbsp;use&nbsp;the&nbsp;StreamLoading&nbsp;event.&nbsp;&nbsp;Please&nbsp;check&nbsp;this&nbsp;post&nbsp;for&nbsp;detail,&nbsp;and&nbsp;you&nbsp;can&nbsp;also&nbsp;check&nbsp;the&nbsp;HowDoI&nbsp;sample&nbsp;to&nbsp;see&nbsp;how&nbsp;to&nbsp;use&nbsp;StreamLoading&nbsp;event.&nbsp;

[gis.thinkgeo.com/Support/Dis...fault.aspx](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/10147/afv/topic/Default.aspx)

Thanks,

Ben
