Exemple #1
0
        internal ShapeDatasetElement(SHPFile file, IDataset dataset, IIndexTree tree)
        {
            _file      = file;
            this.Title = _file.Title;

            _class = new ShapeFeatureClass(_file, dataset, tree);
        }
Exemple #2
0
 public void Dispose()
 {
     if (_file != null)
     {
         _file.Close();
         _file = null;
     }
 }
Exemple #3
0
        public bool DeleteFeatureClass(string fcName)
        {
            if (_name == "")
            {
                return(false);
            }
            SHPFile file = new SHPFile(_name + @"\" + fcName + ".shp");

            return(file.Delete());
        }
Exemple #4
0
        public ShapeFeatureClass(SHPFile file, IDataset dataset, IIndexTree tree)
        {
            if (file == null)
            {
                return;
            }

            _file    = file;
            _dataset = dataset;
            _tree    = tree;

            _envelope = new Envelope(_file.Header.Xmin, _file.Header.Ymin, _file.Header.Xmax, _file.Header.Ymax);

            ISpatialReference sRef = null;

            if (file.PRJ_Exists)
            {
                StreamReader sr      = new StreamReader(file.PRJ_Filename);
                string       esriWKT = sr.ReadToEnd();
                sRef = gView.Framework.Geometry.SpatialReference.FromWKT(esriWKT);
                sr.Close();
            }

            switch (_file.Header.ShapeType)
            {
            case ShapeType.Point:
            case ShapeType.PointM:
            case ShapeType.PointZ:
            case ShapeType.MultiPoint:
            case ShapeType.MultiPointM:
            case ShapeType.MultiPointZ:
                _geomDef = new GeometryDef(geometryType.Point, sRef);
                break;

            case ShapeType.PolyLine:
            case ShapeType.PolyLineM:
            case ShapeType.PolyLineZ:
                _geomDef = new GeometryDef(geometryType.Polyline, sRef);
                break;

            case ShapeType.Polygon:
            case ShapeType.PolygonM:
            case ShapeType.PolygonZ:
                _geomDef = new GeometryDef(geometryType.Polygon, sRef);
                break;

            case ShapeType.MultiPatch:
                _geomDef = new GeometryDef(geometryType.Aggregate, sRef);
                break;

            default:
                _geomDef = new GeometryDef(geometryType.Unknown, sRef);
                break;
            }
        }
Exemple #5
0
        public Task <bool> DeleteFeatureClass(string fcName)
        {
            if (_name == "")
            {
                return(Task.FromResult(false));
            }

            SHPFile file = new SHPFile(_name + @"/" + fcName + ".shp");

            return(Task.FromResult(file.Delete()));
        }
Exemple #6
0
 override public void Dispose()
 {
     base.Dispose();
     if (_dataReader != null)
     {
         _dataReader.Dispose();
     }
     _dataReader = null;
     if (_file != null)
     {
         _file.Close();
     }
     _file = null;
 }
Exemple #7
0
 public ShapeFeatureCursor(IFeatureClass fc, SHPFile file, IQueryFilter filter, List <int> FIDs)
     : this(fc, file, filter, (IIndexTree)null)
 {
     _IDs = new List <int>();
     foreach (int fid in FIDs)
     {
         uint id = _file.GetIndexFromRecNumber((uint)fid);
         if (id > _file.Entities)
         {
             continue;
         }
         _IDs.Add((int)id);
     }
 }
Exemple #8
0
        public int CreateFeatureClass(string dsname, string fcname, IGeometryDef geomDef, IFields fields)
        {
            if (geomDef == null || fields == null)
            {
                return(-1);
            }

            string filename = _directoryName + @"\" + fcname;
            Fields f        = new Fields();

            foreach (IField field in fields)
            {
                f.Add(field);
            }

            if (!SHPFile.Create(filename, geomDef, f))
            {
                return(-1);
            }

            return(0);
        }
Exemple #9
0
        public Task <int> CreateFeatureClass(string dsname, string fcname, IGeometryDef geomDef, IFields fields)
        {
            if (geomDef == null || fields == null)
            {
                return(Task.FromResult(-1));
            }

            string filename = _directoryName + @"/" + fcname;
            Fields f        = new Fields();

            foreach (IField field in fields.ToEnumerable())
            {
                f.Add(field);
            }

            if (!SHPFile.Create(filename, geomDef, f))
            {
                return(Task.FromResult(-1));
            }

            return(Task.FromResult(0));
        }
Exemple #10
0
        public SHPFile(SHPFile file)
        {
            try
            {
                _file_SHP = file._file_SHP;
                _file_SHX = file._file_SHX;
                _file_IDX = file._file_IDX;
                _file_DBF = file._file_DBF;

                FileInfo fi = new FileInfo(_file_SHP);
                if (!fi.Exists)
                {
                    return;
                }
                fi = new FileInfo(_file_SHX);
                if (!fi.Exists)
                {
                    return;
                }

                _entities = (fi.Length - 100) / 8;
                _title    = fi.Name.Substring(0, fi.Name.Length - 4);

                this.Open();

                ReadHeader();

                fi = new FileInfo(_file_DBF);
                if (fi.Exists)
                {
                    _dbfFile = new DBFFile(_file_DBF);
                }
            }
            catch
            {
                Close();
            }
        }
Exemple #11
0
        public bool Insert(IFeatureClass fClass, List <IFeature> features)
        {
            if (fClass == null || !(fClass.Dataset is ShapeDataset) || features == null)
            {
                return(false);
            }
            if (features.Count == 0)
            {
                return(true);
            }

            SHPFile shpFile = new SHPFile(fClass.Dataset.ConnectionString + @"\" + fClass.Name + ".shp");

            foreach (IFeature feature in features)
            {
                if (!shpFile.WriteShape(feature))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #12
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;
             * }*/
        }
Exemple #13
0
        public IDatasetElement this[string title]
        {
            get
            {
                foreach (IDatasetElement element in _elements)
                {
                    if (element == null)
                    {
                        continue;
                    }
                    if (element.Title == title)
                    {
                        return(element);
                    }
                }
                try
                {
                    if (title.ToLower().EndsWith(".shp"))
                    {
                        title = title.Substring(0, title.Length - 4);
                    }
                    DirectoryInfo di = new DirectoryInfo(_connectionString);
                    FileInfo[]    fi = di.GetFiles(title + ".shp");
                    if (fi.Length == 0)
                    {
                        _errMsg = "Can't find shapefile...";
                        return(null);
                    }
                    SHPFile shpFile = new SHPFile(fi[0].FullName);

                    FileInfo idx = new FileInfo(shpFile.IDX_Filename);
                    if (!idx.Exists ||
                        idx.LastWriteTime < shpFile.LastWriteTime)
                    {
                        DualTree tree = new DualTree(500);

                        CreateSpatialIndexTree creator = new CreateSpatialIndexTree(shpFile, tree, (IEnvelope)(new Envelope(shpFile.Header.Xmin, shpFile.Header.Ymin, shpFile.Header.Xmax, shpFile.Header.Ymax)));

                        if (_useGUI)
                        {
                            IProgressDialog progress = ProgressDialog.CreateProgressDialogInstance();
                            if (progress != null && progress.UserInteractive)
                            {
                                Thread thread = new Thread(new ThreadStart(creator.Create));

                                progress.Text = "Create Spatial Index...";
                                progress.ShowProgressDialog(tree, null, thread);
                            }
                            else
                            {
                                creator.Create();
                            }
                        }
                        else
                        {
                            creator.Create();
                        }
                    }

                    gView.Framework.FDB.IIndexTree iTree = null;
                    if (shpFile.IDX_Exists)
                    {
                        iTree = new IDXIndexTree(shpFile.IDX_Filename);
                    }

                    ShapeDatasetElement element = new ShapeDatasetElement(shpFile, this, iTree);
                    _elements.Add(element);
                    return(element);
                }
                catch (Exception ex)
                {
                    _errMsg = ex.Message;
                }
                return(null);
            }
        }
Exemple #14
0
 public CreateSpatialIndexTree(SHPFile file, DualTree tree, IEnvelope bounds)
 {
     _file   = file;
     _tree   = tree;
     _bounds = bounds;
 }