I’ve found two different ways to query my shape file for a particular address but have run into road blocks on each one. I need a little help to figure out what to do next.
The first way was to use GetFeaturesByColumnValue. This works fine so long as I know the full name of the street. Some of our users only enter partial street names (HILL instead of HILLLSIDE) and I need to be able to get every feature which matches the information passed in. GetFeaturesByColumnValue doesn’t allow a wild card character that I can find, so this seems to be a dead end.
The second way was to generate a SQL query and use ExecuteQuery. This would probably work better than the first attempt except it returns it as a DataTable instead of Collection<Feature>. I’ve scoured the message boards and wiki and can’t find a simple answer to converting these back to features. Most of them involve using a UID and then reloading the feature based on that, but I don’t control the shapefiles and can’t count on a UID being available. It would really be nice if there was a different return value offered which used Collection<Feature> instead of the DataTable.
So, suggestions? I’m not sure which way to go here.
Needing help with a query
Hi Clay,
There are two solutions here:
1. This solution will takes more memory.
The code as below is just for reference, you should want to use linq here.
string columnName;
string columnValue;
ShapeFileFeatureLayer layer;
Collection<Feature> features = layer.QueryTools.GetAllFeatures(ReturningColumnType.All);
features.AsParallel().Where(f => f.ColumnValues[columnName].Contains(columnValue)).List();
2. You should want to find one column like the sid you mentioned in your shape file.
Then you can use layer.FeatureSource.ExecuteQuery to query and get the id and find corresponding feature.
Regards,
Don
Just so I’m clear, there is no way to convert from the DataTable back to an actual Feature? Like I said, I have no real control over the shape file as we receive it, and I don’t want to add something arbitrary tot he shape file that would increase maintenance each time they send a new file. Is there not an override that can be done that would return a Feature collection instead of a data table? I’d really rather use the second option as I can create the SQL on the fly for the query. I’ve got that already done but I just need the Feature instead of a row from a DataTable.
Clay,
Sorry to say we can’t convert the datatable to feature collections, this is because the datatable doesn’t include any geometry information but only the feature columns.
As you mentioned you tend to use option 2, then please make sure the ExecuteQuery will return a result which includes the feature Id or an unique column value. After get it, then we can the feature from shape file.
Thanks,
Troy