Example #1
0
 override public void Dispose()
 {
     base.Dispose();
     if (_dataReader != null)
     {
         _dataReader.Dispose();
     }
     _dataReader = null;
     if (_file != null)
     {
         _file.Close();
     }
     _file = null;
 }
Example #2
0
        public ShapeFeatureCursor(IFeatureClass fc, SHPFile file, IQueryFilter filter, IIndexTree tree)
            : base((fc != null) ? fc.SpatialReference : null,
                   (filter != null) ? filter.FeatureSpatialReference : null)
        {
            base.KnowsFunctions = false;

            if (file == null)
            {
                return;
            }
            _file = new SHPFile(file);

            _filter = filter;
            if (filter is ISpatialFilter)
            {
                IEnvelope env = ((ISpatialFilter)filter).Geometry.Envelope;
                if (tree != null)
                {
                    _IDs = tree.FindShapeIds(env);
                    _IDs.Sort();
                }
                //_IDs = tree.FindShapeIds(env);
                _bounds        = new Envelope(env);
                _spatialFilter = filter as ISpatialFilter;
                _queryGeometry = ((ISpatialFilter)filter).Geometry;
                _queryShape    = true;
            }
            else
            {
                foreach (string fname in filter.SubFields.Split(' '))
                {
                    if (fname == "SHAPE" || fname == "*")
                    {
                        _queryShape = true;
                        break;
                    }
                }
            }

            if (filter.WhereClause != "" && _filter.SubFields != "*" && !(filter is IRowIDFilter))
            {
                //StringBuilder sb = new StringBuilder();
                //sb.Append("FID");

                QueryFilter f = new QueryFilter();
                f.SubFields = _filter.SubFields;
                foreach (IField field in _file.Fields.ToEnumerable())
                {
                    if (field.name == "FID")
                    {
                        continue;
                    }
                    if (filter.WhereClause.IndexOf(" " + field.name + " ") != -1 ||
                        filter.WhereClause.IndexOf("(" + field.name + " ") != -1 ||
                        filter.WhereClause.IndexOf(" " + field.name + "=") != -1 ||
                        filter.WhereClause.IndexOf("(" + field.name + "=") != -1 ||
                        filter.WhereClause.IndexOf(" " + field.name + "<") != -1 ||
                        filter.WhereClause.IndexOf("(" + field.name + "<") != -1 ||
                        filter.WhereClause.IndexOf(" " + field.name + ">") != -1 ||
                        filter.WhereClause.IndexOf("(" + field.name + ">") != -1 ||
                        filter.WhereClause.IndexOf("[" + field.name + "]") != -1 ||
                        filter.WhereClause.IndexOf(field.name + " ") == 0 ||
                        filter.WhereClause.IndexOf(field.name + "=") == 0 ||
                        filter.WhereClause.IndexOf(field.name + "<") == 0 ||
                        filter.WhereClause.IndexOf(field.name + ">") == 0
                        )
                    {
                        f.AddField(field.name);
                    }
                }

                /*
                 * _dataReader = _file.DBFDataReader(sb.ToString());
                 * for (uint i = 1; i <= _file.Entities; i++)
                 *  _dataReader.AddRecord(i);
                 *
                 * DataRow [] rows=_dataReader.Table.Select(_filter.WhereClause);
                 *
                 * _IDs = new ArrayList();
                 * foreach (DataRow row in rows)
                 * {
                 *  uint id=_file.GetIndexFromRecNumber((uint)row["FID"]);
                 *  _IDs.Add((int)id);
                 * }
                 * _dataReader.Dispose();
                 */

                _dataReader = _file.DBFDataReader(f.SubFields.Replace(" ", ",").Replace("DISTINCT(", "").Replace(")", ""));
            }
            else
            {
                _dataReader = _file.DBFDataReader(filter.SubFields.Replace(" ", ",").Replace("DISTINCT(", "").Replace(")", ""));
            }

            if (_filter is IDistinctFilter)
            {
                _unique      = new List <object>();
                _uniqueField = _filter.SubFields.Replace("DISTINCT(", "").Replace(")", "");
            }

            if (_filter is FunctionFilter)
            {
            }

            /*
             * if (!(filter is ISpatialFilter))
             * {
             *  DataTable tab = _dataReader.AllRecords;
             *  tab = null;
             * }*/
        }