コード例 #1
0
        public Task <string> DoGeoprocessingThing(CancellationToken cts, BackgroundWorker worker)
        {
            System.Object obj = "";
            Geoprocessor  gp1 = new Geoprocessor();
            GeoProcessor  gp  = new GeoProcessor();

            gp1.OverwriteOutput = true;
            try
            {
                // ################################################
                // Working call to an existing ArcGIS Toolbox Tool:
                CreateFileGDB createFileGdb = new CreateFileGDB();
                createFileGdb.out_folder_path = "c:/temp";
                createFileGdb.out_name        = "tmp.gdb";
                gp1.Execute(createFileGdb, null);
                // ###############################################

                // ###########################################
                // This process will fail if you've already started ArcObjects by opening the form UI dialog
                gp.AddToolbox(@"C:\temp\ArcObjectsIssue\HelloTest.tbx"); //path to your toolbox here!!!!!!!!!!!!!!!
                IVariantArray parameters = new VarArrayClass();
                parameters = new VarArrayClass();
                parameters.Add("Hello Geoprocessing Tool with Python Script!");
                gp.Execute("helloPython", parameters, null);
                cts.ThrowIfCancellationRequested();
                // ###########################################
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine(ReturnGpMessages(gp, obj)); //from a support library not shared here.

                throw new Exception("yeah things went south");
            }
            finally
            {
                gp  = null;
                gp1 = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            return(null);
        }
コード例 #2
0
ファイル: frmShp2Dwg.cs プロジェクト: siszoey/geosufan
        //利用quickexport进行数据转换  gdb-->dwg 有扩展属性的转换
        private void QuickExportToDWG(string strSource, string strdwgFile, DCtype type, string strTemplate)
        {
            ITrackCancel pTrackCancel = null;

            //找到tool
            ESRI.ArcGIS.Geoprocessing.GeoProcessor _geoPro = new GeoProcessor();
            pTrackCancel = new TrackCancelClass();
            IVariantArray pVArray    = new VarArrayClass();
            IVariantArray parameters = new VarArrayClass();

            //模板文件
            string strT = "";

            if (strTemplate != "")
            {
                strT = ",_TMPL," + strTemplate;// D:\南京\data\dddd.dwg
            }

            string strtoolName = "";

            if (type == DCtype.HasXdata)
            {
                parameters.Add(strSource);
                parameters.Add("ACAD," + strdwgFile);
                parameters.Add("RUNTIME_MACROS,");
                parameters.Add("_ATTRKIND,extended_entity_data,_REL,Release2000" + strT);
                parameters.Add(",META_MACROS,");
                parameters.Add("Dest_ATTRKIND,extended_entity_data,Dest_REL,Release2000" + strT);
                parameters.Add(",METAFILE,ACAD,COORDSYS,,__FME_DATASET_IS_SOURCE__,false");

                strtoolName = "QuickExport_interop";
            }
            else if (type == DCtype.NoXdata)
            {
                parameters.Add(strSource);
                parameters.Add("ACAD," + strdwgFile);
                parameters.Add("RUNTIME_MACROS,");
                parameters.Add("_ATTRKIND,ignore,_REL,Release2000" + strT);
                parameters.Add(",META_MACROS,");
                parameters.Add("Dest_ATTRKIND,ignore,Dest_REL,Release2000" + strT);
                parameters.Add(",METAFILE,ACAD,COORDSYS,,__FME_DATASET_IS_SOURCE__,false");

                strtoolName = "QuickExport_interop";
            }
            else if (type == DCtype.FmeXdata)
            {
                string strTblPath = Application.StartupPath + "\\dc.tbx";
                if (strTemplate == "")
                {
                    parameters.Add(strSource);
                    parameters.Add(strdwgFile);
                    _geoPro.AddToolbox(strTblPath);
                    strtoolName = "SpatialETLTool";
                }
                else
                {
                    parameters.Add(strSource);
                    parameters.Add(strdwgFile);
                    parameters.Add(strTemplate);
                    _geoPro.AddToolbox(strTblPath);
                    strtoolName = "SpatialETLTool";
                }
            }
            else
            {
                return;
            }

            IGPEnvironmentManager pgpEnv = new GPEnvironmentManager();
            IGPMessages           pGpMessages; //= _geoPro.Validate(parameters, false, pgpEnv);
            IGPComHelper          pGPCOMHelper = new GpDispatch();

            //这里是关键,如果不赋值的话,那么就会报错
            //IGPEnvironmentManager pEnvMgr = pGPCOMHelper.EnvironmentManager;
            //pgpEnv.PersistAll = true;
            //pGpMessages = new GPMessagesClass();

            // Execute the model tool by name.
            _geoPro.Execute(strtoolName, parameters, pTrackCancel);
        }