Beispiel #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();
            }
        }
Beispiel #2
0
 public static bool ReadOnlyTheLyrs(string path, int i)
 {
     try
     {
         Geodatabase geodatabase = Geodatabase.Open(path);
         if (i == 1)
         {
             foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty))
             {
                 pointsChildDatasets.Add(ds.Substring(1));
             }
         }
         else if (i == 2)
         {
             foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty))
             {
                 linesChildDatasets.Add(ds.Substring(1));
             }
         }
         else if (i == 3)
         {
             foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty))
             {
                 PolygonsChildDatasets.Add(ds.Substring(1));
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Determine the DataType of a geodatabase item
        /// </summary>
        /// <remarks>
        /// This is done by searching the database for all items of each type in turn, until a match is found.
        /// Many of the DataTypes are very uncommon, so we search the likely suspects first.
        /// </remarks>
        /// <param name="itemPath">The full name of the item</param>
        /// <returns>One of the well known data types</returns>
        public string GetDataType(string itemPath)
        {
            // To avoid searching each type for an item does not exist
            if (!Exists(itemPath))
            {
                return(null);
            }
            // Searching is done by folder (feature dataset); bu the item names returned are the full path.
            // All paths start with a single backslash and will have an additional backslash if in a feature dataset.
            // the folder name includes the first backslash, but not the second.
            var index = itemPath.LastIndexOf('\\');

            if (index < 0)
            {
                return(null);
            }
            var folder = index == 0 ? @"\" : itemPath.Remove(index, itemPath.Length - index);

            foreach (var datatype in CommonDataSetTypes)
            {
                foreach (var item in _geodatabase.GetChildDatasets(folder, datatype))
                {
                    if (string.Equals(item, itemPath, System.StringComparison.OrdinalIgnoreCase))
                    {
                        return(datatype);
                    }
                }
            }
            foreach (var datatype in OtherDataSetTypes)
            {
                foreach (var item in _geodatabase.GetChildDatasets(folder, datatype))
                {
                    if (string.Equals(item, itemPath, System.StringComparison.OrdinalIgnoreCase))
                    {
                        return(datatype);
                    }
                }
            }
            return(null);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Geodatabase geo = Geodatabase.Open("");

            List <Table> tables = new List <Table>();

            List <string> featureClasses = geo.GetChildDatasets("\\", "Feature Class").ToList();

            foreach (string featureClassName in featureClasses)
            {
                tables.Add(geo.OpenTable(featureClassName));
            }

            string createTableSqlCommand = CreateTableColumns(tables[0].FieldInformation);

            FieldInfo fieldInfo = tables[0].FieldInformation;
            var       fields    = new List <string>();

            for (int i = 0; i < fieldInfo.Count; i++)
            {
                fields.Add(fieldInfo.GetFieldName(i));
            }

            var           countStatements = $"SELECT * FROM VAULTSCOT_AUTH_POINT_OCT18";
            RowCollection rows            = geo.ExecuteSQL(countStatements);
            WKBReader     reader          = new WKBReader();

            foreach (Row row in rows)
            {
                MultiPointShapeBuffer geometry = row.GetGeometry();
                var point = geometry.Points;
                //MULTIPOINT (295512,712727,0) throwing format exception - Resolved in upcoming commit.
                var geometryWKT = processMultiPointBuffer(geometry);
            }

            var           countEnumerator = rows.GetEnumerator();
            List <object> fieldValues     = new List <object>();

            if (rows != null)
            {
                countEnumerator.MoveNext();
                var shape = countEnumerator.Current["Shape"];

                for (int i = 0; i < fieldInfo.Count - 1; i++)
                {
                    var count = countEnumerator.Current[fields[i]];
                    fieldValues.Add(count);
                }
            }

            InsertTableValues(fieldValues, fieldInfo);
        }
Beispiel #5
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, ""));
                        }
                    }
                }
            }
        }
Beispiel #6
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;
            }
        }