Exemplo n.º 1
0
        /// <summary>
        /// 初始化:检查文件夹是否有子成员,有的话加入特殊节点
        /// </summary>
        void Initialize()
        {
            if (Type == FileSystemObjectType.Folder && CheckChildObject())
            {
                if (ShowFile.check_gdb(Path))  //对于gdb文件夹
                {
                    Geodatabase geo = Geodatabase.Open(Path);
                    if (geo.GetChildDatasets(@"\", "Feature Class").Length != 0 || geo.GetChildDatasets(@"\", "Feature Dataset").Length != 0)
                    {
                        AddSpecialChild();
                    }
                    geo.Close();
                }
                else //对于普通文件夹
                {
                    AddSpecialChild();
                }
            }


            if (Type == FileSystemObjectType.GDB) //对于GDB内feature dataset的文件夹
            {
                Geodatabase geo = Geodatabase.Open(ParentPath);
                if (geo.GetChildDatasets(@Path, "Feature Class").Length != 0 || geo.GetChildDatasets(@Path, "Feature Dataset").Length != 0)
                {
                    AddSpecialChild();
                }
                geo.Close();
            }
        }
Exemplo n.º 2
0
 public void Close()
 {
     if (_geodatabase == null)
     {
         return;
     }
     _geodatabase.Close();
 }
Exemplo n.º 3
0
 public void Release()
 {
     if (_geodatabase != null)
     {
         _openedTables.ForEach(table =>
         {
             table.Close();
             table.Dispose();
         });
         _openedTables.Clear();
         _geodatabase.Close();
         _geodatabase = null;
         _openedGeoDb = false;
     }
 }
Exemplo n.º 4
0
 public ActionResult States()
 {
     try
     {
         var           path        = Server.MapPath("/App_Data/mvc_samples.gdb");
         Geodatabase   gdb         = Geodatabase.Open(path);
         Table         statesTable = gdb.OpenTable("\\us_states");
         RowCollection rows        = statesTable.Search("*", "STATE_NAME LIKE 'M%'", RowInstance.Recycle);
         var           rval        = rows.ToGeoJson();
         gdb.Close();
         //gdb.Dispose();
         Response.ContentType = "application/json";
         object result = this.Content(rval);
         return(result as ActionResult);;
     }
     catch { return(null); }
 }
Exemplo n.º 5
0
        //查看是否是geodatabase类型
        public static bool check_gdb(string path)
        {
            if (FileSystemObjectViewModel.getextension(FileSystemObjectViewModel.GetFileName(path)) != "gdb")
            {
                return(false);
            }

            try
            {
                Geodatabase geo = Geodatabase.Open(@path);
                geo.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 节点被展开后的操作
        /// </summary>
        protected virtual void OnExpanded()
        {
            //是否有特殊节点
            if (HasSpecialChild)
            {
                //将要展开的节点拥有没有列举的子成员(第一次打开)

                //我们需要移除特殊节点,并将子文件夹加入到Children中
                RemoveSpecialChild();
                List <int> li = merge_file();
                if (ShowFile.check_gdb(Path))  //对于geodatabase文件夹的处理
                {
                    Geodatabase geo = Geodatabase.Open(Path);
                    foreach (var fc in geo.GetChildDatasets(@"\", "Feature Class"))
                    {
                        _Children.Add(new FileSystemObjectViewModel(fc, GetFileName(fc), FileSystemObjectType.File, Path));
                    }

                    foreach (var fds in geo.GetChildDatasets(@"\", "Feature Dataset"))
                    {
                        _Children.Add(new FileSystemObjectViewModel(fds, GetFileName(fds), FileSystemObjectType.GDB, Path));
                    }
                    geo.Close();
                }
                else if (Type == FileSystemObjectType.GDB) //对于geodatabase内feature dataset 的处理
                {
                    Geodatabase geo = Geodatabase.Open(ParentPath);
                    foreach (var fc in geo.GetChildDatasets(@Path, "Feature Class"))
                    {
                        _Children.Add(new FileSystemObjectViewModel(fc, GetFileName(fc), FileSystemObjectType.File, Path));
                    }

                    foreach (var fds in geo.GetChildDatasets(Path, "Feature Dataset"))
                    {
                        _Children.Add(new FileSystemObjectViewModel(fds, GetFileName(fds), FileSystemObjectType.GDB, Path));
                    }
                    geo.Close();
                }
                else //对于其他普通文件的处理
                {
                    foreach (var dir in GetSubDirs())
                    {
                        _Children.Add(new FileSystemObjectViewModel(dir, GetFileName(dir), FileSystemObjectType.Folder, ""));
                    }


                    IEnumerable <string> ss = GetSubFiles();
                    for (int i = 0; i < ss.Count(); i++)
                    {
                        bool b = false;
                        for (int pos = 0; pos < li.Count(); pos++)
                        {
                            if (li.ElementAt(pos) == i)
                            {
                                b = true;
                                break;
                            }
                        }
                        if (!b)
                        {
                            _Children.Add(new FileSystemObjectViewModel(ss.ElementAt(i), GetFileName(ss.ElementAt(i)), FileSystemObjectType.File, ""));
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static void ReadData(string path)
        {
            try
            {
                Geodatabase geodatabase = Geodatabase.Open(path);
                foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty))
                {
                    string sqlStatement = @"SELECT * FROM " + ds.Substring(1);
                    foreach (Row attrQueryRow in geodatabase.ExecuteSQL(sqlStatement))
                    {
                        for (int nFieldNumber = 0; nFieldNumber < attrQueryRow.FieldInformation.Count; nFieldNumber++)
                        {
                            string fieldName = attrQueryRow.FieldInformation.GetFieldName(nFieldNumber);
                            if (attrQueryRow.IsNull(fieldName))
                            {
                                continue;
                            }

                            switch (attrQueryRow.FieldInformation.GetFieldType(nFieldNumber))
                            {
                            case FieldType.SmallInteger:
                                attrQueryRow.GetShort(fieldName);
                                break;

                            case FieldType.Integer:
                                attrQueryRow.GetInteger(fieldName);
                                break;

                            case FieldType.Single:
                                attrQueryRow.GetFloat(fieldName);
                                break;

                            case FieldType.Double:
                                attrQueryRow.GetDouble(fieldName);
                                break;

                            case FieldType.String:
                                attrQueryRow.GetString(fieldName);
                                break;

                            case FieldType.Date:
                                attrQueryRow.GetDate(fieldName).ToShortTimeString();
                                break;

                            case FieldType.OID:
                                attrQueryRow.GetOID();
                                break;

                            case FieldType.Geometry:
                                byte[]   shapeBuffer = attrQueryRow.GetGeometry().shapeBuffer;
                                double[] vs          = new double[shapeBuffer.Length / 8];

                                for (int i = 0; i < vs.Length; i++)
                                {
                                    vs[i] = BitConverter.ToDouble(shapeBuffer, i * 8);
                                }

                                break;

                            case FieldType.GUID:
                                attrQueryRow.GetGUID(fieldName).ToString();
                                break;

                            case FieldType.GlobalID:
                                attrQueryRow.GetGlobalID().ToString();
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                geodatabase.Close();
            }
            catch (Exception)
            {
                return;
            }
        }