# Getting Features row-by-row

**URL:** <https://community.thinkgeo.com/t/getting-features-row-by-row/2986>\
**Category:** WPF\
**Created:** [April 28, 2011, 5:16am UTC](https://community.thinkgeo.com/t/getting-features-row-by-row/2986 "2011-04-28T05:16:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David6](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@David6](https://community.thinkgeo.com/u/David6)\
**Post date:** [April 28, 2011, 5:16am UTC](https://community.thinkgeo.com/t/getting-features-row-by-row/2986/1 "2011-04-28T05:16:20Z")

</div>

I'm&nbsp;trying&nbsp;to&nbsp;GetAllFeatures&nbsp;from&nbsp;a&nbsp;given&nbsp;FeatureLayer,&nbsp;but&nbsp;I&nbsp;don't&nbsp;want&nbsp;to&nbsp;load&nbsp;it&nbsp;all&nbsp;into&nbsp;memory&nbsp;first.&nbsp;Ideally&nbsp;I&nbsp;need&nbsp;some&nbsp;sort&nbsp;stepping&nbsp;through&nbsp;each&nbsp;Feature&nbsp;without&nbsp;first&nbsp;loading&nbsp;them&nbsp;in.&nbsp;Anyone&nbsp;know&nbsp;of&nbsp;a&nbsp;way&nbsp;for&nbsp;me&nbsp;to&nbsp;do&nbsp;this?

Lets&nbsp;say&nbsp;I&nbsp;have&nbsp;a&nbsp;Shape&nbsp;file&nbsp;with&nbsp;200,000&nbsp;rows.&nbsp;I&nbsp;want&nbsp;to&nbsp;grab&nbsp;the&nbsp;first&nbsp;10,000,&nbsp;run&nbsp;them&nbsp;through&nbsp;a&nbsp;method&nbsp;and&nbsp;inject&nbsp;them&nbsp;into&nbsp;a&nbsp;SQL&nbsp;database,&nbsp;then&nbsp;repeat&nbsp;this&nbsp;process&nbsp;for&nbsp;the&nbsp;next&nbsp;10,000.

Currently&nbsp;i'm&nbsp;using&nbsp;FeatureLayer.GetAllFeatures(ReturningColumnsType.AllColumns)&nbsp;but&nbsp;my&nbsp;application&nbsp;throws&nbsp;an&nbsp;out&nbsp;of&nbsp;memory&nbsp;exception&nbsp;on&nbsp;large&nbsp;datasets.

&nbsp;

* * *
  

After&nbsp;thinking&nbsp;about&nbsp;the&nbsp;problem&nbsp;further...&nbsp;Is&nbsp;there&nbsp;a&nbsp;way&nbsp;to&nbsp;grab&nbsp;a&nbsp;list&nbsp;of&nbsp;all&nbsp;ID's&nbsp;in&nbsp;the&nbsp;FeatureLayer/FeatureSource&nbsp;and&nbsp;use&nbsp;that&nbsp;list&nbsp;later&nbsp;to&nbsp;query&nbsp;the&nbsp;source&nbsp;in&nbsp;bite&nbsp;sized&nbsp;chunks?

  
&nbsp;&nbsp;&nbsp;&nbsp;1. Open&nbsp;the&nbsp;FeatureSource
  
&nbsp;&nbsp;&nbsp;&nbsp;2. \*Grab&nbsp;all&nbsp;feature&nbsp;ID's&nbsp;(new&nbsp;method?)
  
&nbsp;&nbsp;&nbsp;&nbsp;3. Grab&nbsp;first&nbsp;10,000&nbsp;features&nbsp;and&nbsp;associated&nbsp;attribute&nbsp;columns&nbsp;based&nbsp;on&nbsp;the&nbsp;ID's&nbsp;and&nbsp;GetFeaturesByIds(ids)
  

  

All&nbsp;three&nbsp;stages&nbsp;would&nbsp;be&nbsp;fast&nbsp;(and&nbsp;manageable),&nbsp;and&nbsp;would&nbsp;suit&nbsp;me&nbsp;quite&nbsp;well.&nbsp;Although&nbsp;stepping&nbsp;through&nbsp;each&nbsp;feature&nbsp;1&nbsp;at&nbsp;a&nbsp;time&nbsp;would&nbsp;be&nbsp;better.

---

<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:** [April 28, 2011, 9:42pm UTC](https://community.thinkgeo.com/t/getting-features-row-by-row/2986/2 "2011-04-28T21:42:16Z")

</div>

Hi&nbsp;David,

In&nbsp;ShapeFileFeatureSource,&nbsp;we&nbsp;use&nbsp;Record&nbsp;Index&nbsp;as&nbsp;the&nbsp;feature&nbsp;Id&nbsp;(from&nbsp;1&nbsp;to&nbsp;record&nbsp;count).&nbsp;In&nbsp;your&nbsp;scenario,&nbsp;you&nbsp;just&nbsp;need&nbsp;to&nbsp;loop&nbsp;the&nbsp;record&nbsp;count&nbsp;and&nbsp;get&nbsp;features&nbsp;piece&nbsp;by&nbsp;piece.&nbsp;Here&nbsp;I&nbsp;provide&nbsp;some&nbsp;code&nbsp;snippet&nbsp;for&nbsp;your&nbsp;reference.

`var interval = 10;yourLayer.Open();int recordCount = yourLayer.QueryTools.GetCount();for (int i = 0; i <= recordCount / interval; i++){    Collection<string> ids = new Collection<string>();    int startIndex = i * interval + 1;    int endIndex = (i + 1) * interval > recordCount ? recordCount : (i + 1) * interval;    for (int j = startIndex; j <= endIndex; j++)    {        ids.Add(j.ToString());    }    Collection<Feature> features = yourLayer.QueryTools.GetFeaturesByIds(ids, ReturningColumnsType.AllColumns);}yourLayer.Close();`

Please&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;further&nbsp;questions.

Regards,

Ivan

---

<div class="post-metadata">

**Author:** ![David6](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@David6](https://community.thinkgeo.com/u/David6)\
**Post date:** [May 5, 2011, 6:29am UTC](https://community.thinkgeo.com/t/getting-features-row-by-row/2986/3 "2011-05-05T06:29:38Z")

</div>

Hi&nbsp;Ivan,

Thanks&nbsp;for&nbsp;your&nbsp;reply.&nbsp;Your&nbsp;example&nbsp;works&nbsp;perfectly&nbsp;for&nbsp;Shape&nbsp;files,&nbsp;but&nbsp;I&nbsp;will&nbsp;also&nbsp;be&nbsp;importing&nbsp;Tab&nbsp;files&nbsp;and&nbsp;possibly&nbsp;other&nbsp;sources&nbsp;as&nbsp;well.&nbsp;Using&nbsp;this&nbsp;consecutive&nbsp;ID's&nbsp;method&nbsp;fails&nbsp;when&nbsp;the&nbsp;either&nbsp;the&nbsp;ID&nbsp;column&nbsp;does&nbsp;not&nbsp;exist,&nbsp;or&nbsp;is&nbsp;not&nbsp;consecutive.

Any&nbsp;thoughts?

David

---

<div class="post-metadata">

**Author:** ![David6](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@David6](https://community.thinkgeo.com/u/David6)\
**Post date:** [May 5, 2011, 7:34am UTC](https://community.thinkgeo.com/t/getting-features-row-by-row/2986/4 "2011-05-05T07:34:27Z")

</div>

My&nbsp;previous&nbsp;statement…&nbsp;`Using this consecutive ID’s method fails when the either the ID column does not exist, or is not consecutive.`&nbsp;was&nbsp;incorrect.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I’ve&nbsp;run&nbsp;a&nbsp;few&nbsp;experiments&nbsp;and&nbsp;concluded&nbsp;that&nbsp;there&nbsp;is&nbsp;a&nbsp;problem&nbsp;somewhere&nbsp;within&nbsp;the&nbsp;reading&nbsp;of&nbsp;\*.tab&nbsp;files&nbsp;(I&nbsp;haven’t&nbsp;test&nbsp;any&nbsp;other&nbsp;formats&nbsp;yet)&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;process&nbsp;explained&nbsp;in&nbsp;Ivan’s&nbsp;post&nbsp;above&nbsp;works&nbsp;fine&nbsp;for&nbsp;\*.shp&nbsp;files,&nbsp;but&nbsp;if&nbsp;you&nbsp;tried&nbsp;the&nbsp;same&nbsp;on&nbsp;\*.tab&nbsp;files&nbsp;it&nbsp;would&nbsp;fail&nbsp;with&nbsp;an&nbsp;internal&nbsp;exception:-&nbsp;  
&nbsp;`Exception has been thrown by the target of an invocation.`&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;experimented&nbsp;further&nbsp;and&nbsp;found&nbsp;that&nbsp;if&nbsp;the&nbsp;chunk/interval&nbsp;size&nbsp;was&nbsp;\<=&nbsp;256,&nbsp;then&nbsp;it&nbsp;would&nbsp;work.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;It&nbsp;seems&nbsp;that&nbsp;this&nbsp;magic&nbsp;number&nbsp;256&nbsp;is&nbsp;the&nbsp;limit&nbsp;of&nbsp;ID’s&nbsp;which&nbsp;you&nbsp;can&nbsp;pass&nbsp;to&nbsp;GetFeaturesByIds()&nbsp;for&nbsp;\*.tab&nbsp;files.&nbsp;Can&nbsp;anyone&nbsp;confirm&nbsp;my&nbsp;findings,&nbsp;and&nbsp;possible&nbsp;offer&nbsp;an&nbsp;alternative?&nbsp;I&nbsp;was&nbsp;thinking&nbsp;that&nbsp;if&nbsp;FeatureSource&nbsp;or&nbsp;FeatureLayer&nbsp;exposed&nbsp;an&nbsp;IDataSource&nbsp;object&nbsp;that&nbsp;we&nbsp;could&nbsp;use&nbsp;to&nbsp;iterate&nbsp;over&nbsp;the&nbsp;data,&nbsp;it&nbsp;would&nbsp;solve&nbsp;alot&nbsp;of&nbsp;my&nbsp;problems.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<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:** [May 5, 2011, 10:24pm UTC](https://community.thinkgeo.com/t/getting-features-row-by-row/2986/5 "2011-05-05T22:24:33Z")

</div>

David,

Please&nbsp;check&nbsp;the&nbsp;following&nbsp;answers&nbsp;for&nbsp;your&nbsp;questions:

**1.&nbsp;It&nbsp;seems&nbsp;that&nbsp;this&nbsp;magic&nbsp;number&nbsp;256&nbsp;is&nbsp;the&nbsp;limit&nbsp;of&nbsp;ID's&nbsp;which&nbsp;you&nbsp;can&nbsp;pass&nbsp;to&nbsp;GetFeaturesByIds()&nbsp;for&nbsp;\*.tab&nbsp;files.&nbsp;Can&nbsp;anyone&nbsp;confirm&nbsp;my&nbsp;findings,&nbsp;and&nbsp;possible&nbsp;offer&nbsp;an&nbsp;alternative?**

I&nbsp;have&nbsp;checked&nbsp;the&nbsp;source&nbsp;code&nbsp;for&nbsp;"TabFileFeatureLayer"&nbsp;(in&nbsp;"FdoExtension.dll")&nbsp;and&nbsp;there&nbsp;isn't&nbsp;any&nbsp;limitation&nbsp;about&nbsp;method&nbsp;GetFeaturesByIds().&nbsp;In&nbsp;the&nbsp;next&nbsp;main&nbsp;release&nbsp;(May&nbsp;2011&nbsp;Release),&nbsp;we&nbsp;will&nbsp;integrate&nbsp;\*.tab&nbsp;file&nbsp;support&nbsp;into&nbsp;"MapSuiteCore.dll"&nbsp;and&nbsp;provide&nbsp;a&nbsp;new&nbsp;FeatureLayer&nbsp;named&nbsp;"TabFeatureLayer",&nbsp;at&nbsp;that&nbsp;time&nbsp;you&nbsp;can&nbsp;use&nbsp;this&nbsp;new&nbsp;featurelayer&nbsp;to&nbsp;have&nbsp;another&nbsp;try.

**2.&nbsp;&nbsp;I&nbsp;was&nbsp;thinking&nbsp;that&nbsp;if&nbsp;FeatureSource&nbsp;or&nbsp;FeatureLayer&nbsp;exposed&nbsp;an&nbsp;IDataSource&nbsp;object&nbsp;that&nbsp;we&nbsp;could&nbsp;use&nbsp;to&nbsp;iterate&nbsp;over&nbsp;the&nbsp;data,&nbsp;it&nbsp;would&nbsp;solve&nbsp;alot&nbsp;of&nbsp;my&nbsp;problems.&nbsp;**

Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;suggestion,&nbsp;we'll&nbsp;carefully&nbsp;consider&nbsp;your&nbsp;requirement.&nbsp;Hopefully&nbsp;we&nbsp;can&nbsp;integrate&nbsp;this&nbsp;new&nbsp;feature&nbsp;into&nbsp;our&nbsp;products&nbsp;in&nbsp;the&nbsp;near&nbsp;future.

Regards,

Ivan
