Just curious what the difference between these two objects are, as it looks like they have similar functions. Also, I noticed that QueryTools is sometimes null for a layer, is there anything that I should be doing before using it to ensure it isn’t null?
QueryTools vs SpatialQuery
featureLayer.QueryTools is essentially a shortcut to featureLayer.FeatureSource .
They both expose the same query methods, so the following two lines are functionally identical:
featureLayer.QueryTools.GetFeaturesInsideBoundingBox(bbox, ReturningColumnsType.AllColumns);
featureLayer.FeatureSource.GetFeaturesInsideBoundingBox(bbox, ReturningColumnsType.AllColumns);
The QueryTools (and the underlying FeatureSource ) remain null until you open the layer, so just make sure to call the following code.
featureLayer.Open();
Thanks! good to know
No problem! 
Hi Ben, I’m seeing the issue where QueryTools is null even after opening the layer.
Example:
layer.Open();
var features = layer.QueryTools.GetFeaturesIntersecting(baseShape, ReturningColumnsType.AllColumns); // QueryTools is null here
Here are the values for the layer:

So feature source is populated and both the layer and featuresource are open.
The only thing I can think of is that the layer is derived from InMemoryFeatureLayer and I am creating and passing the FeatureSourceColumn manually into base() like so:
public class CustomLayer: InMemoryFeatureLayer
{
public CustomLayer(IReadOnlyList<FeatureSourceColumn> featureSourceColumns) : base(featureSourceColumns)
{
}
}
This happens before any features get added. So the process is:
- Create layer with passed in FeatureSourceColumn collection
- Set the layer’s FeatureSource.ProjectionConverter
- Open the layer’s FeatureSource and .BeginTransaction()
- Add features via FeatureSource.AddFeature()
- FeatureSource.CommitTransaction()
I would assume after that and opening the layer that QueryTools would not be null, but it is.
hi @Dan_Weaver,
You don’t need to open the layer’s FeatureSource directly, you just need to open the layer, it will open FeatureSource also.
If FeatureSource is open first and then Layer.Open is called, SetupTools method will be skipped.
By the way, there’s a projectionConverter issue in ThinkGeo.Core 14.5.0-beta015, if you’re using it, please upgrade to ThinkGeo.Core 14.5.0-beta017.
Regards,
Leo
Thanks! I’ll try that. Currently on 13.1.2 but I’ll keep that in mind if I upgrade soon.
No problem, let us know if you have any questions upgrading!