# GetFeaturesByColumnValue

**URL:** <https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559>\
**Category:** WinForms\
**Created:** [July 22, 2009, 1:30pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559 "2009-07-22T13:30:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 22, 2009, 1:30pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/1 "2009-07-22T13:30:53Z")

</div>

Hello,

I&nbsp;need&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;highlight&nbsp;features&nbsp;based&nbsp;on&nbsp;a&nbsp;particular&nbsp;attribute&nbsp;matching&nbsp;various&nbsp;different&nbsp;values.&nbsp;For&nbsp;instance,&nbsp;I&nbsp;may&nbsp;need&nbsp;to&nbsp;highlight&nbsp;300+&nbsp;parcels&nbsp;and&nbsp;only&nbsp;have&nbsp;a&nbsp;set&nbsp;of&nbsp;ID's&nbsp;to&nbsp;highlight&nbsp;them&nbsp;by.&nbsp;The&nbsp;way&nbsp;I&nbsp;am&nbsp;currently&nbsp;doing&nbsp;this&nbsp;is&nbsp;by&nbsp;looping&nbsp;through&nbsp;my&nbsp;string&nbsp;array&nbsp;of&nbsp;ID's&nbsp;and&nbsp;having&nbsp;to&nbsp;do&nbsp;a&nbsp;GetFeaturesByColumnValue&nbsp;with&nbsp;just&nbsp;that&nbsp;one&nbsp;match&nbsp;then&nbsp;add&nbsp;that&nbsp;feature&nbsp;to&nbsp;a&nbsp;collection&nbsp;to&nbsp;highlight&nbsp;and&nbsp;then&nbsp;iterate&nbsp;to&nbsp;my&nbsp;next&nbsp;ID.&nbsp;The&nbsp;overhead&nbsp;is&nbsp;insane.

I&nbsp;am&nbsp;running&nbsp;a&nbsp;Core&nbsp;2&nbsp;Quad&nbsp;@&nbsp;2.66Ghz&nbsp;and&nbsp;4GB&nbsp;of&nbsp;ram&nbsp;and&nbsp;lighting&nbsp;up&nbsp;300&nbsp;parcels&nbsp;in&nbsp;this&nbsp;manner&nbsp;takes&nbsp;2&nbsp;minutes&nbsp;+/-&nbsp;.&nbsp;To&nbsp;do&nbsp;something&nbsp;with&nbsp;a&nbsp;1990's&nbsp;era&nbsp;Map&nbsp;Objects&nbsp;took&nbsp;about&nbsp;15&nbsp;seconds&nbsp;on&nbsp;a&nbsp;machine&nbsp;of&nbsp;that&nbsp;era.&nbsp;I&nbsp;am&nbsp;not&nbsp;doing&nbsp;much&nbsp;in&nbsp;the&nbsp;way&nbsp;of&nbsp;elaborate&nbsp;syntax.

The&nbsp;below&nbsp;represents&nbsp;a&nbsp;simple&nbsp;excerpt&nbsp;of&nbsp;what&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;do.&nbsp;I&nbsp;am&nbsp;imagining&nbsp;that&nbsp;behind&nbsp;the&nbsp;scenes,&nbsp;a&nbsp;connection&nbsp;is&nbsp;established&nbsp;to&nbsp;the&nbsp;DBF,&nbsp;the&nbsp;features&nbsp;are&nbsp;filtered&nbsp;down&nbsp;to,&nbsp;and&nbsp;then&nbsp;the&nbsp;connection&nbsp;is&nbsp;closed&nbsp;with&nbsp;the&nbsp;collection&nbsp;returned.&nbsp;This&nbsp;whole&nbsp;process&nbsp;is&nbsp;killing&nbsp;the&nbsp;retrieval&nbsp;times.&nbsp;How&nbsp;can&nbsp;I&nbsp;get&nbsp;around&nbsp;this?&nbsp;An&nbsp;overload&nbsp;accepting&nbsp;an&nbsp;array&nbsp;or&nbsp;collection&nbsp;of&nbsp;values&nbsp;to&nbsp;match&nbsp;up&nbsp;to&nbsp;would&nbsp;be&nbsp;ideal.

&nbsp;

&nbsp;

`        For idCount As Integer = 0 To UIDs.Count - 1            Dim valProgress As Integer = ((idCount + 1) / UIDs.Count) * 100            backWorker.ReportProgress(valProgress)            If backWorker.CancellationPending Then                If layerToSearchSHP.IsOpen Then layerToSearchSHP.Close()                Exit For            End If            Dim fCollection As Collection(Of Feature) = layerToSearchSHP.FeatureSource.GetFeaturesByColumnValue(UID_Field, UIDs(idCount))            'Make sure somehow we don't have a duplicate or cross match and then add to our output collection            For Each feat As Feature In fCollection                If Not fCollectionToHighlight.Contains(feat) Then                    fCollectionToHighlight.Add(feat)                End If            Next        Next`

---

<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 22, 2009, 8:58pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/2 "2009-07-22T20:58:24Z")

</div>

Nelson,

For&nbsp;the&nbsp;API&nbsp;GetFeaturesByCoummnValue,&nbsp;it&nbsp;exactly&nbsp;did&nbsp;what&nbsp;you&nbsp;are&nbsp;thinking!&nbsp;For&nbsp;better&nbsp;performance,&nbsp;I&nbsp;suggest&nbsp;you&nbsp;using&nbsp;the&nbsp;SqlStatement&nbsp;instead&nbsp;of&nbsp;loop&nbsp;each&nbsp;feature&nbsp;within&nbsp;the&nbsp;GetFeaturesByCoummnValue&nbsp;API.  
&nbsp;  
Following&nbsp;2&nbsp;ways&nbsp;get&nbsp;the&nbsp;same&nbsp;result:  
&nbsp;  
  
_Using&nbsp;the&nbsp;GetFeaturesByColumnValue&nbsp;way:_  
  
`shapeFileLayer.Open();Collection<Feature> capticalFeatures = shapeFileLayer.FeatureSource.GetFeaturesByColumnValue("TYPE", "DR");shapeFileLayer.Close();`  
&nbsp;  
  
_Using&nbsp;the&nbsp;SqlStatement&nbsp;way:_  
  
`string sqlStatement = "Select * From CanadaStreets where TYPE='DR'";shapeFileLayer.Open();DataTable dataTable = shapeFileLayer.FeatureSource.ExecuteQuery(sqlStatement);shapeFileLayer.Close();`  
&nbsp;  
  
After&nbsp;this,&nbsp;you&nbsp;can&nbsp;get&nbsp;any&nbsp;information&nbsp;from&nbsp;the&nbsp;returned&nbsp;DataTable.  
&nbsp;  
Any&nbsp;more&nbsp;quetions&nbsp;just&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale

---

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 23, 2009, 7:36am UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/3 "2009-07-23T07:36:48Z")

</div>

Yale,&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;I’m&nbsp;confused.&nbsp;I&nbsp;want&nbsp;to&nbsp;filter&nbsp;for&nbsp;the&nbsp;feature,&nbsp;not&nbsp;necessarily&nbsp;the&nbsp;attribute&nbsp;data.&nbsp;The&nbsp;intention&nbsp;is&nbsp;to&nbsp;highlight&nbsp;all&nbsp;of&nbsp;the&nbsp;parcels&nbsp;in&nbsp;a&nbsp;given&nbsp;array&nbsp;of&nbsp;values&nbsp;that&nbsp;match&nbsp;a&nbsp;particular&nbsp;column.&nbsp;So,&nbsp;if&nbsp;my&nbsp;column&nbsp;is&nbsp;LOTS\_&nbsp;and&nbsp;I&nbsp;have&nbsp;an&nbsp;array&nbsp;of&nbsp;3&nbsp;values&nbsp;of&nbsp;{23,&nbsp;56,&nbsp;40}&nbsp;I&nbsp;want&nbsp;to&nbsp;highlight&nbsp;them&nbsp;all.&nbsp;Obviously&nbsp;this&nbsp;is&nbsp;a&nbsp;very&nbsp;small&nbsp;example&nbsp;and&nbsp;with&nbsp;only&nbsp;3&nbsp;parcels&nbsp;the&nbsp;performance&nbsp;is&nbsp;not&nbsp;a&nbsp;huge&nbsp;issue.&nbsp;  
&nbsp;&nbsp;  
&nbsp;So,&nbsp;my&nbsp;problem&nbsp;I&nbsp;think&nbsp;is&nbsp;that&nbsp;I&nbsp;have&nbsp;to&nbsp;use&nbsp;GetFeaturesByColumnValue&nbsp;as&nbsp;it&nbsp;will&nbsp;return&nbsp;the&nbsp;feature&nbsp;object&nbsp;to&nbsp;me&nbsp;and&nbsp;then&nbsp;must&nbsp;move&nbsp;to&nbsp;my&nbsp;next&nbsp;value&nbsp;from&nbsp;the&nbsp;array&nbsp;and&nbsp;use&nbsp;GetFeaturesByColumnValue&nbsp;again&nbsp;and&nbsp;again&nbsp;and&nbsp;again&nbsp;until&nbsp;I&nbsp;have&nbsp;processed&nbsp;my&nbsp;entire&nbsp;array.&nbsp;In&nbsp;itself&nbsp;this&nbsp;might&nbsp;not&nbsp;be&nbsp;so&nbsp;bad&nbsp;except&nbsp;I&nbsp;am&nbsp;opening&nbsp;and&nbsp;closing&nbsp;a&nbsp;connection&nbsp;for&nbsp;every&nbsp;executiong&nbsp;of&nbsp;GetFeatureByColumnValue.&nbsp;This&nbsp;is&nbsp;killing&nbsp;my&nbsp;performance,&nbsp;if&nbsp;that&nbsp;is&nbsp;indeed&nbsp;true.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;So,&nbsp;I&nbsp;would&nbsp;like&nbsp;a&nbsp;way&nbsp;to&nbsp;establish&nbsp;the&nbsp;connection&nbsp;once,&nbsp;then&nbsp;retrieve&nbsp;features&nbsp;for&nbsp;every&nbsp;value&nbsp;in&nbsp;the&nbsp;array&nbsp;that&nbsp;matches&nbsp;against&nbsp;the&nbsp;LOTS\_&nbsp;and&nbsp;put&nbsp;them&nbsp;in&nbsp;the&nbsp;collection&nbsp;and&nbsp;finally&nbsp;close&nbsp;the&nbsp;connection.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Does&nbsp;this&nbsp;make&nbsp;sense?&nbsp;Is&nbsp;this&nbsp;possible?

---

<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 23, 2009, 8:19pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/4 "2009-07-23T20:19:53Z")

</div>

Nelson,

Thanks&nbsp;for&nbsp;your&nbsp;post!  
&nbsp;  
I&nbsp;am&nbsp;sorry&nbsp;I&nbsp;did&nbsp;not&nbsp;make&nbsp;myself&nbsp;clear&nbsp;enough&nbsp;for&nbsp;you!&nbsp;Your&nbsp;requirement&nbsp;is&nbsp;very&nbsp;clear&nbsp;and&nbsp;makes&nbsp;sense.  
&nbsp;  
&nbsp;  
Unfortunately,&nbsp;the&nbsp;component&nbsp;did&nbsp;not&nbsp;have&nbsp;this&nbsp;API&nbsp;directly&nbsp;did&nbsp;what&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;achieve,&nbsp;following&nbsp;provided&nbsp;2&nbsp;ways&nbsp;will&nbsp;work&nbsp;for&nbsp;you,&nbsp;one&nbsp;way&nbsp;is&nbsp;still&nbsp;using&nbsp;SqlStatement&nbsp;way,&nbsp;the&nbsp;other&nbsp;is&nbsp;to&nbsp;read&nbsp;all&nbsp;the&nbsp;data&nbsp;into&nbsp;memory&nbsp;and&nbsp;filter&nbsp;it&nbsp;out&nbsp;one&nbsp;by&nbsp;one:  
&nbsp;  
**_Using&nbsp;SqlStatement&nbsp;way:_**  
`	private DataTable UsingSqlStatement(Collection<string> columns, Collection<string> matchValues)        {            string shapeFile = @"C:\temp\LOTS\LOTS.shp";            ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(shapeFile);            string sqlStatement = "Select * From LOTS";            StringBuilder sb = new StringBuilder();            sb.Append(sqlStatement);            if (columns.Count > 0 && columns.Count == matchValues.Count)            {                sb.Append(" where ");            }            for (int i = 0; i < columns.Count; i++)            {                sb.Append(string.Format("[{0}]='{1}'",columns[i],matchValues[i]));                if (i != columns.Count - 1)                {                    sb.Append(" OR ");                }            }            string finalSqlStatement = sb.ToString();            shapeFileLayer.Open();            DataTable dataTable = shapeFileLayer.FeatureSource.ExecuteQuery(finalSqlStatement);            int rows = dataTable.Rows.Count;            shapeFileLayer.Close();            return dataTable;        }`  
&nbsp;  
  
**_Using&nbsp;Filter&nbsp;way:_**  
  
`	private Collection<Feature> UsingGetAllFeatures(Collection<string> columns, Collection<string> matchValues)        {            string shapeFile = @"C:\temp\LOTS\LOTS.shp";            ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(shapeFile);            shapeFileLayer.Open();            Collection<Feature> allFeatures = shapeFileLayer.QueryTools.GetAllFeatures(columns);            shapeFileLayer.Close();            Collection<Feature> returnFeatures = new Collection<Feature>();            foreach (Feature feature in allFeatures)            {                for(int i = 0 ; i < columns.Count ; i++)                {                    if(string.Equals( feature.ColumnValues[columns<i>],matchValues<i>))                    {                        returnFeatures.Add(feature);                        break;                    }                }            }            return returnFeatures;        }`  
&nbsp;  
  
**_Let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;still&nbsp;have&nbsp;any&nbsp;more&nbsp;questions.  
&nbsp;  
Thanks.  
&nbsp;  
Yale&nbsp;_**

---

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [July 24, 2009, 9:48am UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/5 "2009-07-24T09:48:07Z")

</div>

When&nbsp;altered&nbsp;a&nbsp;bit,&nbsp;the&nbsp;second&nbsp;example&nbsp;provided&nbsp;works&nbsp;nicely.&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 26, 2009, 7:38pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/6 "2009-07-26T19:38:15Z")

</div>

Nelson,&nbsp;You&nbsp;are&nbsp;always&nbsp;welcome!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Let&nbsp;me&nbsp;know&nbsp;if&nbsp;any&nbsp;more&nbsp;questions!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale

---

<div class="post-metadata">

**Author:** ![Behnam](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/b4bc9f/32.png) [@Behnam](https://community.thinkgeo.com/u/Behnam)\
**Post date:** [May 19, 2010, 9:25am UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/7 "2010-05-19T09:25:25Z")

</div>

If&nbsp;we&nbsp;ran&nbsp;a&nbsp;query&nbsp;over&nbsp;the&nbsp;shape&nbsp;file&nbsp;and&nbsp;it&nbsp;returns&nbsp;for&nbsp;us&nbsp;a&nbsp;DataTable.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;What’s&nbsp;the&nbsp;best&nbsp;way&nbsp;to&nbsp;convert&nbsp;the&nbsp;DataTable&nbsp;to&nbsp;Collection\<Feature\>?&nbsp;  
&nbsp;&nbsp;  
&nbsp;the&nbsp;reason&nbsp;that&nbsp;I&nbsp;want&nbsp;to&nbsp;do&nbsp;this&nbsp;conversion&nbsp;is&nbsp;&nbsp;that&nbsp;I&nbsp;want&nbsp;to&nbsp;show&nbsp;the&nbsp;result&nbsp;of&nbsp;query&nbsp;on&nbsp;the&nbsp;map&nbsp;control&nbsp;(I&nbsp;mean&nbsp;changing&nbsp;the&nbsp;color&nbsp;of&nbsp;the&nbsp;result&nbsp;on&nbsp;the&nbsp;map).

---

<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 20, 2010, 12:38am UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/8 "2010-05-20T00:38:04Z")

</div>

&nbsp;

Ben,  
&nbsp;  
Thanks&nbsp;for&nbsp;your&nbsp;post.&nbsp;  
&nbsp;  
I&nbsp;think&nbsp;the&nbsp;data&nbsp;table&nbsp;and&nbsp;a&nbsp;collection&nbsp;of&nbsp;features&nbsp;are&nbsp;different&nbsp;things.&nbsp;They&nbsp;can&nbsp;be&nbsp;converted&nbsp;to&nbsp;each&nbsp;other&nbsp;only&nbsp;if&nbsp;a&nbsp;data&nbsp;row&nbsp;can&nbsp;represent&nbsp;a&nbsp;feature.&nbsp;Normally,&nbsp;the&nbsp;data&nbsp;table&nbsp;information&nbsp;will&nbsp;not&nbsp;contain&nbsp;the&nbsp;shape&nbsp;information&nbsp;which&nbsp;is&nbsp;very&nbsp;important&nbsp;part&nbsp;of&nbsp;the&nbsp;feature.  
&nbsp;  
Following&nbsp;post&nbsp;shows&nbsp;you&nbsp;how&nbsp;to&nbsp;convert&nbsp;Features&nbsp;to&nbsp;DataTable:  
_gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/5881/afv/topic/Default.aspx_  
_gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/5714/afv/topic/Default.aspx_  
&nbsp;  
Following&nbsp;post&nbsp;shows&nbsp;you&nbsp;how&nbsp;to&nbsp;convert&nbsp;DataTable&nbsp;to&nbsp;Features:  
_gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/5411/afv/topic/Default.aspx_  
&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:** ![Behnam](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/b4bc9f/32.png) [@Behnam](https://community.thinkgeo.com/u/Behnam)\
**Post date:** [May 24, 2010, 6:30pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/9 "2010-05-24T18:30:44Z")

</div>

It&nbsp;seems&nbsp;that&nbsp;when&nbsp;we&nbsp;want&nbsp;to&nbsp;convert&nbsp;the&nbsp;DataTable&nbsp;to&nbsp;Feature&nbsp;we&nbsp;need&nbsp;to&nbsp;now&nbsp;the&nbsp;destination&nbsp;layer&nbsp;type&nbsp;(Polygon&nbsp;and&nbsp;…).&nbsp;  
&nbsp;is&nbsp;there&nbsp;any&nbsp;simple&nbsp;way&nbsp;to&nbsp;convert&nbsp;datatable&nbsp;to&nbsp;feature&nbsp;like&nbsp;the&nbsp;way&nbsp;we&nbsp;convert&nbsp;feature&nbsp;to&nbsp;datatable?

---

<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 24, 2010, 9:18pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/10 "2010-05-24T21:18:16Z")

</div>

Ben,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;response.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;am&nbsp;not&nbsp;sure&nbsp;why&nbsp;the&nbsp;destination&nbsp;alyer&nbsp;type&nbsp;should&nbsp;be&nbsp;known&nbsp;when&nbsp;converted.&nbsp;  
&nbsp;&nbsp;  
&nbsp;A&nbsp;feature&nbsp;should&nbsp;correspond&nbsp;to&nbsp;a&nbsp;row&nbsp;in&nbsp;the&nbsp;DataTable.&nbsp;The&nbsp;WKB&nbsp;or&nbsp;WKT&nbsp;in&nbsp;the&nbsp;row&nbsp;forms&nbsp;the&nbsp;baseshape&nbsp;in&nbsp;the&nbsp;feature,&nbsp;other&nbsp;informations&nbsp;forms&nbsp;the&nbsp;column&nbsp;values&nbsp;in&nbsp;the&nbsp;feature.&nbsp;  
&nbsp;&nbsp;  
&nbsp;A&nbsp;DataTable&nbsp;should&nbsp;be&nbsp;coresponding&nbsp;to&nbsp;a&nbsp;collecion&nbsp;of&nbsp;features,&nbsp;the&nbsp;number&nbsp;of&nbsp;the&nbsp;features&nbsp;equals&nbsp;to&nbsp;the&nbsp;number&nbsp;of&nbsp;rows&nbsp;in&nbsp;the&nbsp;DataTable.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale&nbsp;

---

<div class="post-metadata">

**Author:** ![Behnam](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/b4bc9f/32.png) [@Behnam](https://community.thinkgeo.com/u/Behnam)\
**Post date:** [May 25, 2010, 3:50am UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/11 "2010-05-25T03:50:22Z")

</div>

Many&nbsp;thanks&nbsp;for&nbsp;your&nbsp;attention,

I&nbsp;write&nbsp;the&nbsp;below&nbsp;code&nbsp;to&nbsp;convert&nbsp;the&nbsp;DataTable&nbsp;to&nbsp;Feature

&nbsp;

`            DataTable dt =                ((ShapeFileFeatureLayer)wpfMap1.FindFeatureLayer("Cardiff_Roads_polyline")).                        QueryTools.ExecuteQuery(" Select top 10 * from Cardiff_Roads_polyline where fcode=3002  ");            Collection<Feature> returnFeatures = new Collection<Feature>();            try            {                foreach (DataRow dr in dt.Rows)                {                    Feature feature = new Feature();                    foreach (DataColumn dc in dt.Columns)                    {                        if (!dr.IsNull(dc))                        {                            feature.ColumnValues.Add(dc.ColumnName, Convert.ToString(dr[dc]));                        }                    }                    returnFeatures.Add(feature);                }            }            catch (Exception ex)            {                Debug.WriteLine(ex.ToString());            }            return returnFeatures;`

but&nbsp;when&nbsp;it&nbsp;come&nbsp;to**&nbsp;feature.ColumnValues.Add(dc.ColumnName,&nbsp;Convert.ToString(dr[dc]));**&nbsp;it&nbsp;returns&nbsp; **"object&nbsp;reference&nbsp;null&nbsp;error&nbsp;"** ,&nbsp;&nbsp;what's&nbsp;the&nbsp;problem&nbsp;you&nbsp;think?

---

<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 25, 2010, 7:05pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/12 "2010-05-25T19:05:17Z")

</div>

Ben,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;input.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;the&nbsp;problem&nbsp;is&nbsp;probably&nbsp;exactly&nbsp;the&nbsp;same&nbsp;with&nbsp;the&nbsp;problem&nbsp;describled&nbsp;in&nbsp;following&nbsp;post:&nbsp;  
&nbsp;[gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/7559/afv/topic/Default.aspx#17162](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/7559/afv/topic/Default.aspx#17162)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Try&nbsp;to&nbsp;firgure&nbsp;out&nbsp;the&nbsp;rows&nbsp;in&nbsp;the&nbsp;DataTatable&nbsp;dt&nbsp;is&nbsp;exactly&nbsp;the&nbsp;rows&nbsp;we&nbsp;want&nbsp;before&nbsp;we&nbsp;convert&nbsp;it&nbsp;into&nbsp;features.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale&nbsp;

---

<div class="post-metadata">

**Author:** ![Behnam](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/b4bc9f/32.png) [@Behnam](https://community.thinkgeo.com/u/Behnam)\
**Post date:** [May 27, 2010, 3:54am UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/13 "2010-05-27T03:54:39Z")

</div>

Yale,&nbsp;Many&nbsp;thanks&nbsp;for&nbsp;your&nbsp;answers,

I&nbsp;think&nbsp;the&nbsp;problem&nbsp;is&nbsp;about **&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**** feature.ColumnValues.Add(**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

I&nbsp;wrote&nbsp;the&nbsp;below&nbsp;sample:

`Feature feature = new Feature();feature.ColumnValues.Add("Name","12");`  
but&nbsp;it&nbsp;return&nbsp;error,&nbsp;Would&nbsp;you&nbsp;please&nbsp;descripe&nbsp;for&nbsp;me&nbsp;How&nbsp;I&nbsp;should&nbsp;use&nbsp; **&nbsp;**  
**feature.ColumnValues.Add(**&nbsp;&nbsp;  
  
many&nbsp;thanks,&nbsp;in&nbsp;advance.

&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:** [May 27, 2010, 7:26pm UTC](https://community.thinkgeo.com/t/getfeaturesbycolumnvalue/559/14 "2010-05-27T19:26:57Z")

</div>

Ben,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;questions.

The&nbsp;thing&nbsp;is&nbsp;that&nbsp;the&nbsp;feature&nbsp;is&nbsp;structure&nbsp;and&nbsp;the&nbsp;shape&nbsp;is&nbsp;a&nbsp;class,&nbsp;so&nbsp;when&nbsp;you&nbsp;create&nbsp;a&nbsp;feature,&nbsp;it&nbsp;is&nbsp;always&nbsp;attached&nbsp;a&nbsp;shape.&nbsp;So,&nbsp;please&nbsp;pass&nbsp;in&nbsp;a&nbsp;vertex&nbsp;if&nbsp;it&nbsp;is&nbsp;point&nbsp;or&nbsp;the&nbsp;WKT&nbsp;or&nbsp;WKB&nbsp;for&nbsp;the&nbsp;shape&nbsp;in&nbsp;the&nbsp;feature.&nbsp;Like&nbsp;following&nbsp;simple&nbsp;way:

`Feature feature = new Feature(0.0,0.0);feature.ColumnValues.Add("TestColumn1", "TestValue1");feature.ColumnValues.Add("TestColumn2", "TestValue2");feature.ColumnValues.Add("TestColumn3", "TestValue3");feature.ColumnValues.Add("TestColumn4", "TestValue4");`

Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.

Thanks.

Yale  
  
&nbsp;
