Ejemplo n.º 1
0
        public static bool CheckForArcPadTools(IGeoProcessor2 gp, bool finalCheck = false)
        {
            while (true)
            {
                string        tool;
                List <string> tools          = new List <string>();
                IGpEnumList   toolCollection = gp.ListToolboxes("arc*");

                while ((tool = toolCollection.Next()) != null)
                {
                    tools.Add(tool);
                }

                if (!tools.Contains("ArcPad Tools(ArcPad)"))
                {
                    if (!finalCheck)
                    {
                        gp.AddToolbox(ArcPadTbxPath);
                        finalCheck = true;
                        continue;
                    }
                    else
                    {
                        throw new Exception("Missing ArcPad Tools.");
                    }
                }
                break;
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Borra los archivos raster del directorio temporal
        /// </summary>
        private void BorrarTemporales()
        {
            Geoprocessor gp = new Geoprocessor();

            gp.SetEnvironmentValue("workspace", System.IO.Path.GetTempPath());
            IGpEnumList rasters = gp.ListRasters("*", "All");
            Delete      del     = new Delete();
            string      sRaster = rasters.Next();

            del.data_type = "RasterDataset";
            while (sRaster != "")
            {
                del.in_data = System.IO.Path.GetTempPath() + "\\" + sRaster;
                gp.Execute(del, null);
                sRaster = rasters.Next();
            }

            try
            {
                IGpEnumList ws      = gp.ListWorkspaces("*", "FileGDB");
                string      sRutaWs = ws.Next();
                del.data_type = "";
                while (sRutaWs != "")
                {
                    del.in_data = sRutaWs;
                    gp.Execute(del, null);
                    sRutaWs = ws.Next();
                }
                MessageBox.Show("Archivos Temporales Borrados");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        //执行GP的数据修复功能
        //田晶添加20080916
        //修改,提高效率
        //靳军杰2011-11-30
        /// <summary>
        /// 修复面图层自相交错误
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns></returns>
        public bool FeatureRepair(string sPath)
        {
            if (string.IsNullOrEmpty(sPath))
            {
                return(false);
            }

            IGeoProcessor pGP = new GeoProcessorClass();

            try
            {
                //GT_CARTO.XApplication.ProgressBar.ShowGifProgress(null);
                //GT_CARTO.XApplication.ProgressBar.ShowHint("正在预处理地类图斑数据...");
                //string sPath = pWks.PathName;
                pGP.OverwriteOutput = true;
                pGP.SetEnvironmentValue("workspace", (object)sPath);

                IGpEnumList pfds = pGP.ListFeatureClasses("", "Polygon", "Dataset");

                string sFeatClsName = pfds.Next();

                //IGeoProcessorResult pResult;

                while (!string.IsNullOrEmpty(sFeatClsName))
                {
                    if (!sFeatClsName.Contains("_Standard") &&
                        !sFeatClsName.Equals("TK", StringComparison.OrdinalIgnoreCase))
                    {
                        //要修复的FeatureClass路径
                        string        sInFeatureClassPath = string.Format("{0}\\dataset\\{1}", sPath, sFeatClsName);
                        IVariantArray pValues             = new VarArrayClass();
                        pValues.Add(sInFeatureClassPath);
                        pGP.Execute("RepairGeometry", pValues, null);
                        object obj = 2;
                        //GT_CONST.LogAPI.CheckLog.AppendErrLogs(pGP.GetMessages(ref obj));
                    }
                    sFeatClsName = pfds.Next();
                }
                return(true);
            }

            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                //GT_CARTO.XApplication.ProgressBar.Hide();
                return(false);
            }
            finally
            {
                //GT_CARTO.XApplication.ProgressBar.Hide();
                Marshal.ReleaseComObject(pGP);
            }
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
0
        private void DisplayEnvironmentPameters(Geoprocessor gp)
        {
            IGpEnumList environments = gp.ListEnvironments("*");

            environments.Reset();
            string env = environments.Next();

            while (env != "")
            {
                txtMessages.Text += "环境参数: " + env + "\r\n";
                env = environments.Next();
            }
            txtMessages.Update();
        }
Ejemplo n.º 6
0
        /// <summary>Loads the custom OSM toolbox to the geoprocessor</summary>
        private void LoadCustomToolbox()
        {
            const string osmToolbox = @"ArcToolbox\Toolboxes\OpenStreetMap Toolbox.tbx";

            string toolboxPath = System.IO.Path.Combine(OSMGPFactory.GetArcGIS10InstallLocation(), osmToolbox);

            if (System.IO.File.Exists(toolboxPath))
            {
                IGpEnumList list = _gp.ListToolboxes("osmtools");
                if (string.IsNullOrEmpty(list.Next()))
                {
                    _gp.AddToolbox(toolboxPath);
                }
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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();
            }
        }