当前位置: 首页>>代码示例>>C#>>正文


C# Geoprocessor.Execute方法代码示例

本文整理汇总了C#中Geoprocessor.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Geoprocessor.Execute方法的具体用法?C# Geoprocessor.Execute怎么用?C# Geoprocessor.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Geoprocessor的用法示例。


在下文中一共展示了Geoprocessor.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FieldCal

        //执行计算,输出计算结果信息字符串
        private string FieldCal(IFeatureLayer pFtLayer, string strExpression)
        {
            txtMessage.Text = "正在计算请稍后……\r\n";
            try
            {
                Geoprocessor Gp = new Geoprocessor();
                Gp.OverwriteOutput = true;
                CalculateField calField = new CalculateField();
                
                calField.expression = strExpression;

                Gp.Execute(calField, null);

                for (int i = 0; i < Gp.MessageCount; i++)
                {
                    txtMessage.Text += Gp.GetMessage(i).ToString() + "\r\n";
                }
                return "计算成功";
            }
            catch (Exception e)
            {
                txtMessage.Text += e.Message;
                return "计算失败" + e.Message;
            }
        }
开发者ID:Kingvey,项目名称:ConstructionLandEvaluationSystem,代码行数:26,代码来源:FormAttributeSelection.cs

示例2: ClipByLayer

        /// <summary>
        /// 两图层进行裁剪运算
        /// </summary>
        /// <param name="inputLayer">被裁剪图层</param>
        /// <param name="clipLayer">裁剪图层</param>
        /// <param name="outputFullPath">输出图层完整路径</param>
        public void ClipByLayer(ILayer inputLayer, ILayer clipLayer, string outputFullPath)
        {
            string inputPath = GetLayerPath(inputLayer);
            string clipPath = GetLayerPath(clipLayer);

            Clip clipTool = new Clip();
            clipTool.in_features = inputPath;
            clipTool.clip_features = clipPath;
            clipTool.out_feature_class = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess process = null;
            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            FileInfo fi = new FileInfo(outputFullPath);
            string pathDir = fi.Directory.FullName;
            string name = fi.Name;
            IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace fws = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace;
            IFeatureClass featCls = fws.OpenFeatureClass(name);
            IFeatureLayer layer = new FeatureLayerClass();
            layer.FeatureClass = featCls;
            layer.Name = featCls.AliasName;
            m_mapControl.Map.AddLayer(layer as ILayer);
        }
开发者ID:chinasio,项目名称:minegis,代码行数:34,代码来源:ClipLayer.cs

示例3: WriteBuildErrorsToTurnFC

        public static void WriteBuildErrorsToTurnFC(string outputFileGdbPath, string fdsName, string turnFCName,
                                                    IGPMessages messages, ITrackCancel trackcancel)
        {
            messages.AddMessage("Writing build errors to the turn feature class...");

            // Create a new field on the turn feature class for the build errors

            Geoprocessor gp = new Geoprocessor();
            gp.AddOutputsToMap = false;
            AddField addFieldTool = new AddField();
            addFieldTool.in_table = outputFileGdbPath + "\\" + fdsName + "\\" + turnFCName;
            addFieldTool.field_name = "BuildError";
            addFieldTool.field_type = "SHORT";
            gp.Execute(addFieldTool, trackcancel);

            // Open the turn feature class in the file geodatabase and find the BuildError field on it

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var wsf = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var fws = wsf.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;
            IFeatureClass turnFC = fws.OpenFeatureClass(turnFCName);
            int buildErrorField = turnFC.FindField("BuildError");

            // Open the BuildErrors.txt file generated from building the network dataset

            string s, leftTrimmedString, oidString;
            int leftTrimAmt = 24 + turnFCName.Length;
            IFeature feat = null;
            string[] buildErrorsFiles = System.IO.Directory.GetFiles(Environment.GetEnvironmentVariable("TEMP"), "BuildErrors.txt", System.IO.SearchOption.AllDirectories);
            string buildErrorsFile = buildErrorsFiles[0];
            System.IO.StreamReader f = new System.IO.StreamReader(buildErrorsFile);

            // Loop through the BuildErrors.txt file and write the value 1 for each entry found.

            while ((s = f.ReadLine()) != null)
            {
                // ignore blank lines
                if (s.Length == 0)
                    continue;

                // ignore build errors not dealing with the turn source
                if (s.Remove(leftTrimAmt) != ("SourceName: " + turnFCName + ", ObjectID: "))
                    continue;

                leftTrimmedString = s.Substring(leftTrimAmt);
                oidString = leftTrimmedString.Remove(leftTrimmedString.IndexOf(", "));
                feat = turnFC.GetFeature(Convert.ToInt32(oidString, System.Globalization.CultureInfo.InvariantCulture));
                feat.set_Value(buildErrorField, 1);
                feat.Store();
            }
            f.Close();
        }
开发者ID:Esri,项目名称:street-data-processing-tools,代码行数:52,代码来源:TurnGeometryUtilities.cs

示例4: PolygonsPartitionAggregation

        public PolygonsPartitionAggregation(string dataPath,string dataName,string resultPath,string gradeField)
        {
            m_GP = new Geoprocessor();

            MakeFeatureLayer makefeaturelayer = new MakeFeatureLayer();
            makefeaturelayer.in_features = dataPath + dataName + ".shp";
            makefeaturelayer.out_layer = "origin_lyr";
            m_GP.Execute(makefeaturelayer, null);

            IFeatureLayer fealyr = m_GP.Open(makefeaturelayer.out_layer) as IFeatureLayer;
            m_FeaCls = fealyr.FeatureClass;
            m_PartitionField = gradeField;

            m_WorkingPath = resultPath;
        }
开发者ID:weigiser,项目名称:AOProjects,代码行数:15,代码来源:PolygonsPartitionAggregation.cs

示例5: RunGeoProcessor

 /// <summary>
 /// 运行地理分析工具
 /// </summary>
 /// <param name="gp"></param>
 /// <param name="process"></param>
 /// <param name="trackCancel"></param>
 /// <returns></returns>
 public static IGeoProcessorResult2 RunGeoProcessor(Geoprocessor gp, IGPProcess process, ITrackCancel trackCancel)
 {
     IGeoProcessorResult2 gpResult = null;
     try
     {
         gpResult = gp.Execute(process, trackCancel) as IGeoProcessorResult2; //执行分析
         return gpResult;
     }
     catch (Exception ex)
     {
     #if DEBUG
         System.Diagnostics.Debug.WriteLine(string.Format("#RunGP:{0};{1}", ex.Message, ex.StackTrace));
     #endif
         return gpResult;
     }
 }
开发者ID:Joe-xXx,项目名称:BatchGISTools,代码行数:23,代码来源:SpatialAnalysisHelper.cs

示例6: runTool

        protected virtual void runTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)
        {
            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;

            // Execute the tool
            try
            {
                geoprocessor.Execute(process, TC);
                ReturnMessages(geoprocessor);

            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                ReturnMessages(geoprocessor);
            }
        }
开发者ID:truonghinh,项目名称:TnX,代码行数:18,代码来源:GeoprocessorAbstract.cs

示例7: AddFields

        /// <summary>
        /// 添加属性字段
        /// </summary>
        /// <param name="dsTarget"></param>
        /// <param name="newFields"></param>
        /// <returns></returns>
        public static bool AddFields(ITable dsTarget, List<IField> newFields)
        {
            if (dsTarget == null || newFields == null || newFields.Count == 0)
                return false;

            try
            {
                Geoprocessor geoProcessor = new Geoprocessor();
                foreach (IField field in newFields)
                {
                    ESRI.ArcGIS.DataManagementTools.AddField gpAddField = new ESRI.ArcGIS.DataManagementTools.AddField();
                    gpAddField.in_table = dsTarget;
                    gpAddField.field_name = field.Name;
                    gpAddField.field_type = GetFieldTypeGpString(field.Type);

                    gpAddField.field_alias = field.AliasName;
                    if (field.Domain != null)
                        gpAddField.field_domain = field.Domain.Name;

                    gpAddField.field_is_nullable = field.IsNullable.ToString();
                    gpAddField.field_is_required = field.Required.ToString();
                    gpAddField.field_length = field.Length;
                    gpAddField.field_precision = field.Precision;
                    gpAddField.field_scale = field.Scale;

                    IGeoProcessorResult gpResult = geoProcessor.Execute(gpAddField, null) as IGeoProcessorResult;
                    if (gpResult.Status != esriJobStatus.esriJobSucceeded)
                        return false;
                }
               //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);

                return true;
            }
            catch(Exception exp)
            {
                ErrorMessage = exp.Message;
                return false;
            }
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:45,代码来源:GpTool.cs

示例8: Main

    /// <summary>
    /// This sample console app demonstrates listening to GP events as they happen
    /// </summary>
    /// <param name="args"></param>
    static void Main(string[] args)
    {
        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

      GPMessageEventHandler gpEventHandler = new GPMessageEventHandler();

      //get an instance of the geoprocessor
      Geoprocessor GP = new Geoprocessor();
      //register the event helper in order to be able to listen to GP events
      GP.RegisterGeoProcessorEvents(gpEventHandler);

      //wire the GP events
      gpEventHandler.GPMessage += new MessageEventHandler(OnGPMessage);
      gpEventHandler.GPPreToolExecute += new PreToolExecuteEventHandler(OnGPPreToolExecute);
      gpEventHandler.GPToolboxChanged += new ToolboxChangedEventHandler(OnGPToolboxChanged);
      gpEventHandler.GPPostToolExecute += new PostToolExecuteEventHandler(OnGPPostToolExecute);

      //instruct the geoprocessing engine to overwrite existing datasets
      GP.OverwriteOutput = true;

      //create instance of the 'create random points' tool. Write the output to the machine's temp directory
      CreateFeatureclass createFeatureClass = new CreateFeatureclass(System.IO.Path.GetTempPath(), "RandomPoints.shp");
      //execute the tool
      GP.Execute(createFeatureClass, null);

      //unwire the GP events
      gpEventHandler.GPMessage -= new MessageEventHandler(OnGPMessage);
      gpEventHandler.GPPreToolExecute -= new PreToolExecuteEventHandler(OnGPPreToolExecute);
      gpEventHandler.GPToolboxChanged -= new ToolboxChangedEventHandler(OnGPToolboxChanged);
      gpEventHandler.GPPostToolExecute -= new PostToolExecuteEventHandler(OnGPPostToolExecute);

      //unregister the event helper
      GP.UnRegisterGeoProcessorEvents(gpEventHandler);

      System.Diagnostics.Trace.WriteLine("Done");
    }
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:40,代码来源:GPEventListner.cs

示例9: ConvertMXDToMSD

        public static string ConvertMXDToMSD(string mxdfile, string convertMXDtoMSDtoolboxPath)
        {
            if (!File.Exists(convertMXDtoMSDtoolboxPath))
            {
                MessageBox.Show(string.Format("GP Toolbox {0} to convert mxd to msd is not found", convertMXDtoMSDtoolboxPath), "Convert MXD to MSD", MessageBoxButton.OK, MessageBoxImage.Error);
                return null;
            }

            Geoprocessor gp = new Geoprocessor()
            {
                OverwriteOutput = true
            };
            gp.AddToolbox(convertMXDtoMSDtoolboxPath);
            IVariantArray gpparams = new VarArrayClass();
            gpparams.Add(mxdfile);

            IGeoProcessorResult gpresult = null;
            try
            {
                gpresult = gp.Execute(Properties.Settings.Default.toolname, gpparams, null) as IGeoProcessorResult;
            }
            catch (Exception)
            {
                object sev = 2;
                System.Windows.MessageBox.Show(gp.GetMessages(ref sev));
                return null;
            }

            string msdfile = ((IGPString)gpresult.GetOutput(0)).Value;
            //MessageBox.Show(msdfile);

            gp = null;
            gpresult = null;

            return msdfile;
        }
开发者ID:ApexGIS,项目名称:developer-support,代码行数:36,代码来源:Utils.cs

示例10: Import3DFile

        public static bool Import3DFile(string str3DFile,  string outPut, string strSpatialRef)
        {
            try
            {
                ESRI.ArcGIS.Analyst3DTools.Import3DFiles gpImport3DFiles = new ESRI.ArcGIS.Analyst3DTools.Import3DFiles();
                gpImport3DFiles.in_files = str3DFile;
                gpImport3DFiles.out_featureClass = outPut;
                gpImport3DFiles.spatial_reference = strSpatialRef;

                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                IGeoProcessorResult gpResult = geoProcessor.Execute(gpImport3DFiles, null) as IGeoProcessorResult;
                //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);

                return gpResult.Status == esriJobStatus.esriJobSucceeded;

            }
            catch (Exception exp)
            {
                ErrorMessage = exp.Message;
                return false;
            }
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:23,代码来源:GpTool.cs

示例11: ExportLayerToUploadableRaster

        public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a raster layer
                ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source;
                
                // create a new raster to raster converter utility
                ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster
                    = new ESRI.ArcGIS.DataManagementTools.CopyRaster();

                // set the input raster layer
                raster2raster.in_raster = rasterLayer;

                // set the output path and Shapefile name
                /* The name and location of the raster dataset to be created.
                 * .bil—Esri BIL
                 * .bip—Esri BIP
                 * .bmp—BMP
                 * .bsq—Esri BSQ
                 * .dat—ENVI DAT
                 * .gif—GIF
                 * .img—ERDAS IMAGINE
                 * .jpg—JPEG
                 * .jp2—JPEG 2000
                 * .png—PNG
                 * .tif—TIFF
                 * no extension for Esri Grid
                 */
                raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif";

                // create a new GeoProcessor
                Geoprocessor geoprocessor = new Geoprocessor();
                geoprocessor.TemporaryMapLayers = true;

                // execute the RasterToOtherFormat
                geoprocessor.Execute(raster2raster, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
开发者ID:domesticmouse,项目名称:mapsengine-arcgis-connector,代码行数:44,代码来源:UploadToGoogleMapsEngine.cs

示例12: DeleteDataset

        /// <summary>
        /// 删除IDataset 
        /// </summary>
        /// <param name="dsTarget"></param>
        /// <returns></returns>
        public static bool DeleteDataset(IDataset dsTarget)
        {
            if (dsTarget == null)
                return false;

            try
            {
                ESRI.ArcGIS.DataManagementTools.Delete gpDetele = new ESRI.ArcGIS.DataManagementTools.Delete(dsTarget);
                Geoprocessor geoProcessor = new Geoprocessor();
                IGeoProcessorResult gpResult = geoProcessor.Execute(gpDetele, null) as IGeoProcessorResult;
                //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);

                return gpResult.Status == esriJobStatus.esriJobSucceeded;
            }
            catch(Exception exp)
            {
                ErrorMessage = exp.Message;
                return false;
            }
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:25,代码来源:GpTool.cs

示例13: CopyRaster

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strInput"></param>
        /// <param name="outPut"></param>
        /// <param name="isToFile"></param>
        /// <param name="strFormat">当isToFile为Ture时,可设置此值,默认值为TIFF,可选值:BMP、JPEG、PNG、GIF、TIFF、IMAGINE、GRID</param>
        /// <returns></returns>
        public static bool CopyRaster(string strInput, string outPut,bool isToFile,string strFormat)
        {
            try{
                IGPProcess gpTool = null;
                if (isToFile)
                {
                    RasterToOtherFormat gpToOther = new RasterToOtherFormat();
                    gpToOther.Input_Rasters = strInput;
                    gpToOther.Output_Workspace = outPut;
                    gpToOther.Raster_Format = strFormat;

                    gpTool = gpToOther;
                }
                else
                {
                    RasterToGeodatabase gpToGDB = new RasterToGeodatabase();
                    gpToGDB.Input_Rasters = strInput;
                    gpToGDB.Output_Geodatabase = outPut;

                    gpTool = gpToGDB;
                }

                Geoprocessor geoProcessor = new Geoprocessor();

                geoProcessor.OverwriteOutput = true;
                IGeoProcessorResult gpResult = geoProcessor.Execute(gpTool, null) as IGeoProcessorResult;
                //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);

                return gpResult.Status == esriJobStatus.esriJobSucceeded;

            }
            catch(Exception exp)
            {
                ErrorMessage = exp.Message;
                return false;
            }
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:45,代码来源:GpTool.cs

示例14: CopyFeatureClass

        /// <summary>
        /// 要素类复制
        /// </summary>
        /// <param name="strInput"></param>
        /// <param name="outPath"></param>
        /// <param name="outName"></param>
        /// <returns></returns>
        public static bool CopyFeatureClass(string strInput, string outPath,string outName)
        {
            try
            {
                FeatureClassToFeatureClass gpCopyFeatureClass = new FeatureClassToFeatureClass();
                gpCopyFeatureClass.in_features = strInput;
                gpCopyFeatureClass.out_path = outPath;
                gpCopyFeatureClass.out_name = outName;

                Geoprocessor geoProcessor = new Geoprocessor();
                geoProcessor.OverwriteOutput = true;
                IGeoProcessorResult gpResult = geoProcessor.Execute(gpCopyFeatureClass, null) as IGeoProcessorResult;
                //System.Runtime.InteropServices.Marshal.FinalReleaseComObject(geoProcessor);

                return gpResult.Status == esriJobStatus.esriJobSucceeded;

            }
            catch(Exception exp)
            {
                ErrorMessage = exp.Message;
                return false;
            }
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:30,代码来源:GpTool.cs

示例15: RunTool

        private static bool RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)
        {
            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;

            // Execute the tool
            try
            {
                geoprocessor.Execute(process, null);
                return ReturnMessages(geoprocessor);

            }
            catch (Exception err)
            {
                Debug.WriteLine(err.Message);
                ReturnMessages(geoprocessor);
            }
            return false;
        }
开发者ID:EAWCS1,项目名称:SUITT,代码行数:19,代码来源:ProjectTransactionCmd.cs


注:本文中的Geoprocessor.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。