/// <summary>
        /// Test if <paramref name="featureSet"/> is a <see cref="DotSpatial.Data.Shapefile"/>
        /// and if so, try to read tree for it. Otherwise a new one is created.
        /// </summary>
        /// <param name="featureSet">The feature set</param>
        /// <returns>An index</returns>
        private static SbnTree TestShapefileTree(IFeatureSet featureSet)
        {
            // Is this really a shapefile?
            var shapefile = featureSet as Shapefile;

            if (shapefile == null)
            {
                return(null);
            }

            // Is there a sbn file floating around?
            if (!string.IsNullOrEmpty(shapefile.FilePath))
            {
                var sbnFilename = System.IO.Path.ChangeExtension(shapefile.FilePath, ".sbn");
                if (!System.IO.File.Exists(sbnFilename))
                {
                    var h    = shapefile.Header;
                    var tree = SharpSbn.SbnTree.Create(GetFeaturesBoundingBoxes(featureSet),
                                                       SharpSbn.DataStructures.Interval.Create(h.Zmin, h.Zmax),
                                                       SharpSbn.DataStructures.Interval.Create(h.Mmin, h.Mmax));

                    tree.Save(sbnFilename);
                }
#if QueryOnly
                return(SbnTree.Open(sbnFilename));
#else
                return(SbnTree.Load(sbnFilename));
#endif
            }
            return(null);
        }
        /// <summary>
        /// Creates an instance of this class
        /// </summary>
        /// <param name="featureSet">The feature set to choose</param>
        public SpatiallyIndexedFeatureSet(IFeatureSet featureSet)
        {
            System.Diagnostics.Debug.Assert(featureSet != null);

            _featureSet = featureSet;
            _tree       = TestShapefileTree(featureSet);

            if (_tree == null)
            {
                var z           = GetInterval(featureSet.Z);
                var m           = GetInterval(featureSet.M);
                var tree        = SharpSbn.SbnTree.Create(GetFeaturesBoundingBoxes(featureSet), z, m);
                var sbnFilename = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "sbn");
                tree.Save(sbnFilename);
#if QueryOnly
                _tree = SbnTree.Open(sbnFilename);
#else
                _tree = tree;
#endif
            }
        }