Exemplo n.º 1
0
        public bool RunTool(string toolName, IVariantArray parameters, ITrackCancel TC, bool showResultDialog)
        {
            GeoProcessor        gp     = new GeoProcessor();
            IGeoProcessorResult result = null;

            // Execute the tool
            try
            {
                result = (IGeoProcessorResult)gp.Execute(toolName, parameters, TC);
                string re = result.GetOutput(0).GetAsText();
                if (showResultDialog)
                {
                    ReturnMessages(result, "");
                }
                if (result.MaxSeverity == 2) //error
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (COMException err)
            {
                MessageBox.Show(err.Message + " in RunTool");
                ReturnMessages(result, "");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + " in RunTool");
                ReturnMessages(result, "");
            }
            return(false);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            RuntimeManager.Bind(ProductCode.Desktop);
            GeoProcessor gp =new  GeoProcessor();
            IVariantArray parameters = new VarArrayClass();
               
            //input layer location
            parameters.Add(@"C:\junk\122.mdb\test");
            //output location
            parameters.Add(@"C:\\Users\\shri7493\\Documents\\ArcGIS\\Default.gdb\\TBL_HYDRANT_Statistics");
            //summary field followed by summary method - in this case "MAX" - maximium value
            parameters.Add("OBJECTID MAX");

            IGeoProcessorResult gpResult = gp.Execute("Statistics_analysis", parameters, null);
            for (int i = 0; i < gpResult.MessageCount; i++)
            {
            Console.Write (gpResult.GetMessage(i).ToString());
            }


            gp.ClearMessages();
        }
Exemplo n.º 4
0
        //gp的执行
        private void ExecuteGP(IVariantArray parameters, string strToolName)
        {
            ITrackCancel pTrackCancel = null;

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

            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);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            RuntimeManager.Bind(ProductCode.Desktop);
            GeoProcessor  gp         = new  GeoProcessor();
            IVariantArray parameters = new VarArrayClass();

            //input layer location
            parameters.Add(@"C:\junk\122.mdb\test");
            //output location
            parameters.Add(@"C:\\Users\\shri7493\\Documents\\ArcGIS\\Default.gdb\\TBL_HYDRANT_Statistics");
            //summary field followed by summary method - in this case "MAX" - maximium value
            parameters.Add("OBJECTID MAX");

            IGeoProcessorResult gpResult = gp.Execute("Statistics_analysis", parameters, null);

            for (int i = 0; i < gpResult.MessageCount; i++)
            {
                Console.Write(gpResult.GetMessage(i).ToString());
            }


            gp.ClearMessages();
        }
Exemplo n.º 6
0
        //利用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);
        }
        private byte[] OperazioneRestDownloadFeatureHandler(NameValueCollection boundVariables,
                                                            JsonObject operationInput,
                                                            string outputFormat,
                                                            string requestProperties,
                                                            out string responseProperties)
        {
            responseProperties = null;

            #region Istanzio il JSON Result
            JsonObject result = new JsonObject();
            result.AddBoolean("hasError", false);
            #endregion

            bool found = operationInput.TryGetArray("listaOID", out object[] paramListaOID);
            if (!found || paramListaOID == null)
            {
                throw new ArgumentNullException("listaOID");
            }

            bool okParam2 = operationInput.TryGetString("URLServiceLayer", out string paramURL);
            if (!okParam2 || paramURL == String.Empty)
            {
                throw new ArgumentNullException("URLServiceLayer");
            }

            IGeoProcessor2 gp = new GeoProcessor() as IGeoProcessor2;
            gp.OverwriteOutput = true;

            try
            {
                result.AddArray("interno", paramListaOID);

                // Ricavo Feature Class dietro al Service Layer
                IFeatureClass featureClass = MapServiceHelper_GiancaGIS.RicavaFCDaURLServiceLayer(this.serverObjectHelper, paramURL);

                IFeatureLayer fLayer = new FeatureLayerClass
                {
                    FeatureClass     = featureClass,
                    Name             = "Mio Layer",
                    SpatialReference = ((IGeoDataset)featureClass).SpatialReference
                };

                IFeatureSelection featureSelection = fLayer as IFeatureSelection;


                IQueryFilter2 queryFilter = new QueryFilterClass
                {
                    WhereClause = "OBJECTID IN (" + String.Join(",", paramListaOID) + ")"
                };

                featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);


                this.CreaWorkSpaceOutput(out IWorkspaceName WorkspaceNameOUT, out string pathFGDB);

                IVariantArray parameters = new VarArrayClass();
                parameters.Add(fLayer);
                parameters.Add(System.IO.Path.Combine(pathFGDB, "output"));

                gp.Execute("CopyFeatures_management", parameters, null);

                this.ZippaFGDB(System.IO.Path.GetDirectoryName(pathFGDB), out string pathZip);
                result.AddString("zip", pathZip);
            }
            catch (Exception errore)
            {
                object severity = null;
                string errGp    = gp.GetMessages(ref severity);
                if (!string.IsNullOrEmpty(errGp))
                {
                    result.AddBoolean("GeoProcessingError", true);
                    result.AddString("erroreGp", errGp);
                }

                result.AddString("errorDescription", errore.Message);
                result.AddBoolean("hasError", true);
            }

            return(Encoding.UTF8.GetBytes(result.ToJson()));
        }