I have a PostgreSQL database, there are many tables to store the vehicle's point position, one table for each vehicle. On the GUI, the user can choose the vehicle to view its points data, if the user selects more than one vehicle, I will retrieve them one by one. Once the data is retrieved using the PosgreSQLFeatureLayer, I select all the features from it and add the features to an InMemoryFeatureLayer.
The problem is, when I added the feature to the InmemoryFeatureLayer, I checked the column values are all right. But later when I select any features from the InMemoryFeatureLayer, the column values are all blank.
I think the problem is you DID NOT add the correct columns for your InMemoryFeatureLayer.
Following is some codes how to create right InmemoryFeatureLayer for query: ShapeFileFeatureLayer worldShapeLayer = new ShapeFileFeatureLayer(@"..\..\..\..\..\PostsData\Countries02.shp"); worldShapeLayer.Open(); Collection<Feature> allFeatures= worldShapeLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns); Collection<FeatureSourceColumn> columns = worldShapeLayer.QueryTools.GetColumns(); worldShapeLayer.Close();
InMemoryFeatureLayer inmemoryFeatureLayer = new InMemoryFeatureLayer(columns,new Feature[]{}); foreach (Feature feature in allFeatures) { inmemoryFeatureLayer.InternalFeatures.Add(feature); }
Thanks for your response. I did add the correct columns for my InMemoryFeatureLayer.But when I query the features from the InMemoryFeatureLayer using following code, the column values are blank for the features in selectedFeatures, I want to add the selected features in a DataGridView.:
Dim selectedFeatures As Collection(Of Feature) Dim inMemoryLyr As InMemoryFeatureLayer = DirectCast(Map1.FindFeatureLayer("PointsLayer"), InMemoryFeatureLayer)
This work fine in my test sample, see my attached sample. Only difference with your requirements is that the features added to the InmemoryFeatureLayer is from the shape file instead of the database as you said.
I don't why the columnValues for the selectedFeatures from the InMemoryFeatureLayer using the QueryTool are all zero, I checked the InternalFeatures of the InMemoryFeatureLayer before I use the QueryTool, I could see the column values are not blank..