I would like to ask you about your question, for my understandings, you just want to highlight the features for US country or any other query results? If my understanding is right, it is easy to do, please refer the following code:
LayerOverlay worldOverlay = new LayerOverlay(); worldOverlay.Layers.Add("WorldLayer", worldLayer); winformsMap1.Overlays.Add("WorldOverlay", worldOverlay);
LayerOverlay highlightOverlay = new LayerOverlay(); highlightOverlay.Layers.Add("HighlightLayer", highlightLayer); winformsMap1.Overlays.Add("HighlightOverlay", highlightOverlay);
worldLayer.Open(); Collection<Feature> features = worldLayer.QueryTools.GetFeaturesByColumnValue("Country_Name", "US"); worldLayer.Close();
highlightLayer.InternalFeatures.Clear(); foreach (Feature feature in features) { highlightLayer.InternalFeatures.Add(feature); }
winformsMap1.CurrentExtent = new RectangleShape(-177.333203125, 92.96484375, 82.823046875, -89.84765625); winformsMap1.Refresh(); So you can see we just need to use the GetFeaturesByColumnValue method of QueryTools to implement this ability. Also if I misunderstood your requirements please tell me further information about your requirements,
What we need to do is to add the features selected out using the sql statement into the highlightLayer, try using the API ExecuteQuery API in inmemoryFeatureLayer to select out those features.
Any more quesetions please feel free to let me know.
Are you working with a shapefile? Assuming you are here is the issue, and suggestion. When you execute a SQL query, using the ExecuteSqlQuery on the map tools, we use Access’s JET to do the query on the DBF file. The issue is that the relationship between shapes in the SHP file and rows in the DBF file are are by location so the first record in the DBF is the first record in the SHP file. There is typically nothing else to link them. So when we get the result from JET we only know the rows but not the row numbers. In this way we have no way to link the returning rows back to their shapes in the SHP file. One way to get around this is to have a RecId column in your DBF that is numbered from 1 to the number of rows. In this way when you execute the SQL remember to return back the RecId so then you can use the QueryTools GetFeatureById and match up the rows returned with the shapes.
For your shapefiles we have a static API on the ShapeFileFeatureLayer called BuildRecordIdColumn which will create the new RecId column in your shape files for you.
I reviewed the code you provided and did not find anything wrong and this functionality should be expected to be working. While some stuffs not contained in the code provided, please double check to make sure: 1)The “HighlightOverlay” is added to the map control. 2)The corresponding Styles and ApplyToZoomLevel has been set to the “highlightLayer”. 3)There are some features added to the highlightLayer before calling the Refresh in the event cmd_apply_Click.
Any more questions please feel free to let me know
I made the changes accordingly. But m getting an error.
At runtime ' worldLayer1' contains NULL. ( It should contain the shapefilename )
And also I need assistance for hightlighting the query result. I have attached the GUI of the Query Tool n also the code has been attached. In the code below I have just fired a '=' query using the statement:
Collection<Feature> features = worldLayer1.QueryTools.GetFeaturesByColumnValue(column, findstr);
But I have to fire the query for all other comparisions given in GUI. Please help me out in this...
I reviewed the code you provided, and I think we need to use the following code snippet to find the target worldLayer as that is the key used to add to map control. Please try it. worldLayer1 = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer("WorldLayer1" );
Any more questions please feel free to let me know.
I am sorry to say that the API GetFeaturesByColumnValue cannot deal with the < or > functionalities, if you want to get this implemented, please try to use the following API: worldLayer.QueryTools .ExecuteQuery.
We have provided the following 2 how do I samples to show how to achieve this or similar functionality, please take a look at it when you are interested: How Do I \ Querying Feature layers How Do I \ Extending Map Suite\ Add event in OledbfeatuerLayer
Any more questions please feel free to let me know.
Collection<Feature> features = worldLayer1.QueryTools.GetFeaturesByColumnValue(column, findstr);
I am passing 'column' which is attribute and findstr is specific value. But it is not working whereas when I provide specific value , The region is highlighted.
Like
Collection<Feature> features = worldLayer1.QueryTools.GetFeaturesByColumnValue("CNTY_NAME","United States");
Can you test your query statements in the MapSuiteExplorer, according to my tests, we can carry out for the operations like <, >, <>, 'like'. Also you can use the following code to test, but before you execute the sql statement, please makre sure the USStates.shp was added to the map: