Пример #1
0
        public static void GPListFeatureClasses(Geoprocessor GP)
        {
            // List all feature classes in the workspace starting with d.
            GP.SetEnvironmentValue("workspace", @"C:\Uc2003\Portland_OR.gdb");
            IGpEnumList fcs = GP.ListFeatureClasses("d*", "", "");
            string      fc  = fcs.Next();

            while (fc != "")
            {
                Console.WriteLine(fc);
                fc = fcs.Next();
            }
        }
Пример #2
0
        public static List <string> ListFeatureClasses(Geoprocessor gp, string ws)
        {
            // List all feature classes in the workspace starting with d.
            gp.SetEnvironmentValue("workspace", ws);
            IGpEnumList   fcs = gp.ListFeatureClasses("*", "", "");
            string        fc  = fcs.Next();
            List <string> li  = new List <string>();

            while (fc != "")
            {
                //Console.WriteLine(fc);
                li.Add(fc);
                fc = fcs.Next();
            }
            return(li);
        }
Пример #3
0
        public static String[] GetFeatures(IWorkspace workspace, ref Geoprocessor gp, String wildCard = "", String featureType = "")
        {
            try
            {
                gp.SetEnvironmentValue("workspace", workspace.PathName);
                wildCard = (string.IsNullOrEmpty(wildCard) ? wildCard : wildCard + "*");
                var features = gp.ListFeatureClasses(wildCard, featureType, "");

                String feature;
                var    featList = new List <String>();
                while ((feature = features.Next()) != string.Empty)
                {
                    featList.Add(Path.Combine(workspace.PathName, feature));
                }

                return(featList.ToArray());
            }
            catch (Exception) { return(GetRootFeatures(workspace)); }
        }
Пример #4
0
        /// <summary>
        /// Batches the copy feature class.
        /// </summary>
        /// <param name="workspacePath">The workspace path.</param>
        /// <param name="sourceDatasetName">Name of the source dataset.</param>
        /// <param name="Layerfilter">The layerfilter.</param>
        /// <param name="targetPath">The target path.</param>
        /// <param name="targetDatasetName">Name of the target dataset.</param>
        /// <returns></returns>
        public bool BatchCopyFeatureClass(string workspacePath, string sourceDatasetName, List <string> Layerfilter, string targetPath
                                          , string targetDatasetName)
        {
            try
            {
                Geoprocessor  pGP         = new Geoprocessor();
                List <string> featclsList = new List <string>();
                pGP.OverwriteOutput = true;
                pGP.SetEnvironmentValue("workspace", (object)workspacePath);

                IGpEnumList pFeatDatasetList = pGP.ListDatasets("", "");

                IGpEnumList pFeatClsList = null;

                string strDatasetName = pFeatDatasetList.Next();

                if (strDatasetName != "")
                {
                    while (strDatasetName != "")
                    {
                        pFeatClsList = pGP.ListFeatureClasses("", "", strDatasetName);

                        string strName = pFeatClsList.Next();
                        while (strName != "")
                        {
                            if (Layerfilter.Contains(strName.ToUpper()) && !featclsList.Contains(strName))
                            {
                                featclsList.Add(strName.ToUpper());
                            }
                            strName = pFeatClsList.Next();
                        }
                        strDatasetName = pFeatDatasetList.Next();
                    }
                }
                else
                {
                    pFeatClsList = pGP.ListFeatureClasses("", "", "");
                    string strName = pFeatClsList.Next();
                    while (strName != "")
                    {
                        if (Layerfilter.Contains(strName.ToUpper()) && !featclsList.Contains(strName))
                        {
                            featclsList.Add(strName.ToUpper());
                        }
                        strName = pFeatClsList.Next();
                    }
                }

                if (featclsList.Count == 0)
                {
                    return(false);
                }

                CopyFeatures pCopyFeature = new CopyFeatures();

                foreach (string str in featclsList)
                {
                    if (string.IsNullOrEmpty(strDatasetName))
                    {
                        pCopyFeature.in_features = string.Format("{0}\\{1}", workspacePath, str);
                    }
                    else
                    {
                        pCopyFeature.in_features = string.Format("{0}\\{1}\\{2}", workspacePath, strDatasetName, str);
                    }
                    pCopyFeature.out_feature_class = string.Format("{0}\\{1}\\{2}_Standard", targetPath, targetDatasetName, str);
                    pGP.Execute(pCopyFeature, null);
                    object obj = null;
                    //GT_CONST.LogAPI.CheckLog.AppendErrLogs(pGP.GetMessages(ref obj));
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
            return(true);
        }
Пример #5
0
        private static void ConvertPersonalGeodatabaseToFileGeodatabase()
        {
            // Initialize the Geoprocessor
            Geoprocessor geoprocessor = new Geoprocessor();

            // Allow for the overwriting of file geodatabases, if they previously exist.
            geoprocessor.OverwriteOutput = true;

            // Set the workspace to a folder containing personal geodatabases.
            geoprocessor.SetEnvironmentValue("workspace", @"C:\data");

            // Identify personal geodatabases.
            IGpEnumList workspaces = geoprocessor.ListWorkspaces("*", "Access");
            string      workspace  = workspaces.Next();

            while (workspace != "")
            {
                // Set workspace to current personal geodatabase
                geoprocessor.SetEnvironmentValue("workspace", workspace);

                // Create a file geodatabase with the same name as the personal geodatabase
                string gdbname = System.IO.Path.GetFileName(workspace).Replace(".mdb", "");
                string dirname = System.IO.Path.GetDirectoryName(workspace);

                // Execute CreateFileGDB tool
                CreateFileGDB createFileGDBTool = new CreateFileGDB(dirname, gdbname + ".gdb");
                geoprocessor.Execute(createFileGDBTool, null);

                // Initialize the Copy Tool
                Copy copyTool = new Copy();

                // Identify feature classes and copy to file geodatabase
                IGpEnumList fcs = geoprocessor.ListFeatureClasses("", "", "");
                string      fc  = fcs.Next();
                while (fc != "")
                {
                    Console.WriteLine("Copying " + fc + " to " + gdbname + ".gdb");
                    copyTool.in_data  = fc;
                    copyTool.out_data = dirname + "\\" + gdbname + ".gdb" + "\\" + fc;
                    geoprocessor.Execute(copyTool, null);
                    fc = fcs.Next();
                }

                // Identify feature datasets and copy to file geodatabase
                IGpEnumList fds = geoprocessor.ListDatasets("", "");
                string      fd  = fds.Next();
                while (fd != "")
                {
                    Console.WriteLine("Copying " + fd + " to " + gdbname + ".gdb");
                    copyTool.in_data   = fd;
                    copyTool.data_type = "FeatureDataset";
                    copyTool.out_data  = dirname + "\\" + gdbname + ".gdb" + "\\" + fd;
                    try
                    {
                        geoprocessor.Execute(copyTool, null);
                    }
                    catch (Exception ex)
                    {
                        object sev = null;
                        System.Windows.Forms.MessageBox.Show(ex.Message);
                    }
                    fd = fds.Next();
                }

                // Identify tables and copy to file geodatabase
                IGpEnumList tbls = geoprocessor.ListTables("", "");
                string      tbl  = tbls.Next();
                while (tbl != "")
                {
                    Console.WriteLine("Copying " + tbl + " to " + gdbname + ".gdb");
                    copyTool.in_data  = tbl;
                    copyTool.out_data = dirname + "\\" + gdbname + ".gdb" + "\\" + tbl;
                    geoprocessor.Execute(copyTool, null);
                    tbl = tbls.Next();
                }

                workspace = workspaces.Next();
            }
        }
Пример #6
0
        /// <summary>
        /// Batches the copy feature class.
        /// </summary>
        /// <param name="workspacePath">The workspace path.</param>
        /// <param name="sourceDatasetName">Name of the source dataset.</param>
        /// <param name="Layerfilter">The layerfilter.</param>
        /// <param name="targetPath">The target path.</param>
        /// <param name="targetDatasetName">Name of the target dataset.</param>
        /// <returns></returns>
        public bool BatchCopyFeatureClass(string workspacePath, string sourceDatasetName,List<string> Layerfilter, string targetPath
                           ,string targetDatasetName)
        {
            try
            {
                Geoprocessor pGP = new Geoprocessor();
                List<string> featclsList = new List<string>();
                pGP.OverwriteOutput = true;
                pGP.SetEnvironmentValue("workspace", (object)workspacePath);

                IGpEnumList pFeatDatasetList = pGP.ListDatasets("", "");

                IGpEnumList pFeatClsList = null;

                string strDatasetName = pFeatDatasetList.Next();

                if (strDatasetName != "")
                {
                    while (strDatasetName !="")
                    {
                        pFeatClsList = pGP.ListFeatureClasses("", "", strDatasetName);

                        string strName = pFeatClsList.Next();
                        while (strName != "")
                        {
                            if (Layerfilter.Contains(strName.ToUpper()) && !featclsList.Contains(strName))
                            {
                                featclsList.Add(strName.ToUpper());
                            }
                            strName = pFeatClsList.Next();
                        }
                        strDatasetName = pFeatDatasetList.Next();
                    }
                }
                else
                {
                    pFeatClsList = pGP.ListFeatureClasses("", "", "");
                    string strName = pFeatClsList.Next();
                    while (strName != "")
                    {
                        if (Layerfilter.Contains(strName.ToUpper()) && !featclsList.Contains(strName))
                        {
                            featclsList.Add(strName.ToUpper());
                        }
                        strName = pFeatClsList.Next();
                    }
                }

                if (featclsList.Count == 0) return false;

                CopyFeatures pCopyFeature = new CopyFeatures();

                foreach (string str in featclsList)
                {
                    if (string.IsNullOrEmpty(strDatasetName))
                    {
                        pCopyFeature.in_features = string.Format("{0}\\{1}", workspacePath, str);
                    }
                    else
                    {
                        pCopyFeature.in_features = string.Format("{0}\\{1}\\{2}", workspacePath, strDatasetName, str);
                    }
                    pCopyFeature.out_feature_class = string.Format("{0}\\{1}\\{2}_Standard", targetPath, targetDatasetName, str);
                    pGP.Execute(pCopyFeature, null);
                    object obj = null;
                    //GT_CONST.LogAPI.CheckLog.AppendErrLogs(pGP.GetMessages(ref obj));
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return false;
            }
            return true;
        }
        private static void ConvertPersonalGeodatabaseToFileGeodatabase()
        {
            // Initialize the Geoprocessor
            Geoprocessor geoprocessor = new Geoprocessor();

            // Allow for the overwriting of file geodatabases, if they previously exist.
            geoprocessor.OverwriteOutput = true;

            // Set the workspace to a folder containing personal geodatabases.
            geoprocessor.SetEnvironmentValue("workspace", @"C:\data");

            // Identify personal geodatabases.
            IGpEnumList workspaces = geoprocessor.ListWorkspaces("*", "Access");
            string workspace = workspaces.Next();
            while (workspace != "")
            {
                // Set workspace to current personal geodatabase
                geoprocessor.SetEnvironmentValue("workspace", workspace);

                // Create a file geodatabase with the same name as the personal geodatabase
                string gdbname = System.IO.Path.GetFileName(workspace).Replace(".mdb", "");
                string dirname = System.IO.Path.GetDirectoryName(workspace);

                // Execute CreateFileGDB tool
                CreateFileGDB createFileGDBTool = new CreateFileGDB(dirname, gdbname + ".gdb");
                geoprocessor.Execute(createFileGDBTool, null);

                // Initialize the Copy Tool
                Copy copyTool = new Copy();

                // Identify feature classes and copy to file geodatabase
                IGpEnumList fcs = geoprocessor.ListFeatureClasses("", "", "");
                string fc = fcs.Next();
                while (fc != "")
                {
                    Console.WriteLine("Copying " + fc + " to " + gdbname + ".gdb");
                    copyTool.in_data = fc;
                    copyTool.out_data = dirname + "\\" + gdbname + ".gdb" + "\\" + fc;
                    geoprocessor.Execute(copyTool, null);
                    fc = fcs.Next();
                }

                // Identify feature datasets and copy to file geodatabase
                IGpEnumList fds = geoprocessor.ListDatasets("", "");
                string fd = fds.Next();
                while (fd != "")
                {
                    Console.WriteLine("Copying " + fd + " to " + gdbname + ".gdb");
                    copyTool.in_data = fd;
                    copyTool.data_type = "FeatureDataset";
                    copyTool.out_data = dirname + "\\" + gdbname + ".gdb" + "\\" + fd;
                    try
                    {
                        geoprocessor.Execute(copyTool, null);
                    }
                    catch (Exception ex)
                    {
                        object sev = null;
                        System.Windows.Forms.MessageBox.Show(ex.Message);
                    }
                    fd = fds.Next();
                }

                // Identify tables and copy to file geodatabase
                IGpEnumList tbls = geoprocessor.ListTables("", "");
                string tbl = tbls.Next();
                while (tbl != "")
                {
                    Console.WriteLine("Copying " + tbl + " to " + gdbname + ".gdb");
                    copyTool.in_data = tbl;
                    copyTool.out_data = dirname + "\\" + gdbname + ".gdb" + "\\" + tbl;
                    geoprocessor.Execute(copyTool, null);
                    tbl = tbls.Next();
                }

                workspace = workspaces.Next();
            }
        }