ThinkGeo.com    |     Documentation    |     Premium Support

Can't query InMemoryFeatureLayer

Hi - I am creating InMemoryFeatureLayers on the fly and showing them in the WinformsMap. The arrays adEasting, adNorthing, and adSampledValue contain the point information I want to use. 



Everything is going well until I try to query the layer to place field values in a table. My code is below. Why is omg.FeatureSource.CanExecuteSqlQuery false? 



Dim lFeature As New ThinkGeo.MapSuite.Core.Feature



Dim fscID As New FeatureSourceColumn("ID", "Integer", 30)

Dim fscValue As New FeatureSourceColumn("Value", "Double", 30)

Dim fscEasting As New FeatureSourceColumn("Easting", "Double", 30)
Dim fscNorthing As New FeatureSourceColumn("Northing", "Double", 30)



Dim lFeatureSourceColumn As New List(Of FeatureSourceColumn)



lFeatureSourceColumn.Add(fscID)
lFeatureSourceColumn.Add(fscValue)
lFeatureSourceColumn.Add(fscEasting)
lFeatureSourceColumn.Add(fscNorthing)



Dim lCollectionOfFeatureSourceColumns As New System.Collections.ObjectModel.Collection(Of FeatureSourceColumn)



lCollectionOfFeatureSourceColumns.Add(fscID)
lCollectionOfFeatureSourceColumns.Add(fscValue)
lCollectionOfFeatureSourceColumns.Add(fscEasting)
lCollectionOfFeatureSourceColumns.Add(fscNorthing)



Dim cc As System.Collections.Generic.IEnumerable(Of FeatureSourceColumn) = lFeatureSourceColumn.AsEnumerable






        Dim lFeatureList As New List(Of Feature)



        For i = 0 To adEasting.GetUpperBound(0)



                Dim c As New System.Collections.ObjectModel.Collection(Of String)
                c.Add("ID:" & i)
                c.Add("Value:" & adSampledValue(i))
                c.Add("Easting:" & adEasting(i))
                c.Add("Northing:" & adNorthing(i))
                lFeature = New ThinkGeo.MapSuite.Core.Feature(adEasting(i), adNorthing(i), Str(i), c)
                lFeatureList.Add(lFeature)
        Next i






        Dim lfeaturelist As System.Collections.Generic.IEnumerable(Of Feature) = lFeatureList.AsEnumerable






        Dim omg As New InMemoryFeatureLayer(cc, lfeaturelist)



Does anyone have an idea? A better suggestion to accomplish this? Thanks in advance for any advice.

so sorry the last two lines should read 
  
 Dim lfeaturelistenumerable As System.Collections.Generic.IEnumerable(Of Feature) = lFeatureList.AsEnumerable 
 Dim omg As New InMemoryFeatureLayer(cc, lfeaturelistenumerable) 


Hi Robert,  
  
 Thanks for your ticket, I am sorry to say that InMemoryFeatureLayer doesn’t support “ExecuteSqlQuery”, but a walk around could be to use linq with following code: 
  
  
 using System.Linq; 
 … 
 private void DisplayMap_Load(object sender, EventArgs e) 
 { 
 … 
 Feature feature1 = new Feature(0, 0); 
 Feature feature2 = new Feature(10, 10); 
 feature1.ColumnValues.Add(“id”, “1”); 
 feature2.ColumnValues.Add(“id”, “2”); 
  
 InMemoryFeatureLayer inm = new InMemoryFeatureLayer(); 
 inm.Open(); 
 inm.Columns.Add(new FeatureSourceColumn(“id”)); 
 inm.InternalFeatures.Add(feature1); 
 inm.InternalFeatures.Add(feature2); 
  
 IEnumerable<Feature> features=inm.InternalFeatures.Where<Feature>(f=>f.ColumnValues[“id”]==“1”); 
 List<Feature> fes = new List<Feature>(features); 
 …  
 } 
  
 if you have any more question , please feel free to let us know. 
  
 Best Regards 
  
 Summer