ThinkGeo.com    |     Documentation    |     Premium Support

Create InMemoryFeatureLayer from data in ShapeFile

Hi, 


I did the following but I'm wondering whether there is a better way to achieve the same thing. 


 



            ShapeFileFeatureLayer LandUseA_regionLayer = new ShapeFileFeatureLayer(@"C:\WebServiceImageServer\NEW_CAN\LandUseA_region.shp", ShapeFileReadWriteMode.ReadOnly);
            FeatureLayer featureLayer = LandUseA_regionLayer;
            InMemoryFeatureLayer parkLayer = new InMemoryFeatureLayer();
            LandUseA_regionLayer.Open();
            Collection<Feature> allFeatures = LandUseA_regionLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);
            Collection<FeatureSourceColumn> columns = LandUseA_regionLayer.QueryTools.GetColumns();
            for (int i = 0; i < allFeatures.Count; i++)
            {
                if (allFeatures[i].ColumnValues["TYPE"].StartsWith("PARK") == true)
                {
                    parkLayer.InternalFeatures.Add(allFeatures[i]);
                }
            }
            LandUseA_regionLayer.Close();


Instead of using a for loop, is there a simpler way to select a subset of data? For example, maybe using a SQL statement? 


Thanks!



Tracy,


Thanks for your post!
 
Of course, in your case, using a Sql statement will much better than a loop considering the performance. Please try the Sql statement:
 

string sqlStatement = @"Select * From LandUseA_region where TYPE like 'F%'";
DataTable dataTable = worldShapeLayer.QueryTools.ExecuteQuery(sqlStatement);

 

And then parse out the features from the returned dataTable.
 
Let me know if you have any more problems.
 
Thanks.
 
Yale