Example #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);
        }
 public static void Messages(Exception ex, ref IGeoProcessor2 gp)
 {
     _msg.Items.Add("..EXCEPTION: " + ex.Message);
     if (gp.MessageCount <= 0)
     {
         return;
     }
     for (var i = 0; i < gp.MessageCount; i++)
     {
         _msg.Items.Add(".." + gp.GetMessage(i));
     }
     _msg.Items.Add(">>>>>>>>>>>>>>>"); _msg.Refresh();
 }
        /// <summary>IDisposable::Dispose - clean up GP if possible</summary>
        public void Dispose()
        {
            if (_gp != null)
            {
                IGPUtilities3 gpUtil = new GPUtilitiesClass();
                gpUtil.ClearInMemoryWorkspace();
                gpUtil.ReleaseInternals();
                gpUtil.RemoveInternalData();
                gpUtil.RemoveInternalValues();

                _gp.ResetEnvironments();
                ComReleaser.ReleaseCOMObject(_gp);
                _gp = null;
            }
        }
        /// <summary>IDisposable::Dispose - clean up GP if possible</summary>
        public void Dispose()
        {
            if (_gp != null)
            {
                IGPUtilities3 gpUtil = new GPUtilitiesClass();
                gpUtil.ClearInMemoryWorkspace();
                gpUtil.ReleaseInternals();
                gpUtil.RemoveInternalData();
                gpUtil.RemoveInternalValues();

                _gp.ResetEnvironments();
                ComReleaser.ReleaseCOMObject(_gp);
                _gp = null;
            }
        }
        public ArcPadSampleForm()
        {
            InitializeComponent();

            _msg = this.msgListBox;

            this.checkOutButton.Enabled    = false;
            this.openAxfButton.Enabled     = false;
            this.checkInButton.Enabled     = false;
            this.pyOptionsGroupBox.Enabled = false;

            MiscClass.GetToolboxPath();
            _gpManaged = new Geoprocessor {
                OverwriteOutput = true
            };
            _gpUnManaged = new GeoProcessorClass {
                OverwriteOutput = true
            };
        }
Example #6
0
        public static String[] GetFeatures(IWorkspace workspace, ref IGeoProcessor2 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)); }
        }
        /// <summary>
        /// Set a mask on the gp object to buffer the output to the specified distance
        /// </summary>
        /// <param name="workspace">IFeatureWorkspace</param>
        /// <param name="geomList">List of geometries to create the mask</param>
        /// <param name="gp">IGeoProcessor2</param>
        /// <param name="fcName">Name of feature class</param>
        private string SetGPMask(IFeatureWorkspace workspace, List <IGeometry> geomList, IGeoProcessor2 gp, string fcName)
        {
            IFeatureClass maskFc = CreateMaskFeatureClass(workspace, SelectedSurfaceSpatialRef, fcName + "_" + RunCount.ToString());

            foreach (IGeometry geom in geomList)
            {
                //create a new point feature
                IFeature ipFeature = maskFc.CreateFeature();
                ipFeature.Shape = geom;
                ipFeature.Store();
            }
            IDataset ds   = (IDataset)maskFc;
            string   path = ds.Workspace.PathName + "\\" + ds.BrowseName;

            gp.SetEnvironmentValue("mask", path);

            return(path);
        }
        private void UpdateSpatialGridIndex(ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geodatabase.IGPMessages message, IGeoProcessor2 geoProcessor, string inputFeatureClass)
        {
            IVariantArray parameterArrary = null;
            IGeoProcessorResult2 gpResults2 = null;

            parameterArrary = CreateDefaultGridParamterArrary(inputFeatureClass);
            gpResults2 = geoProcessor.Execute("CalculateDefaultGridIndex_management", parameterArrary, TrackCancel) as IGeoProcessorResult2;

            List<double> gridIndexList = new List<double>(3);

            for (int index = 0; index < gpResults2.OutputCount; index++)
            {
                string gridIndexString = gpResults2.GetOutput(index).GetAsText();

                double gridIndexValue = 0;

                Double.TryParse(gridIndexString, out gridIndexValue);

                gridIndexList.Add(gridIndexValue);
            }

            // delete the current spatial index if it does exist
            // this is expected to fail if no such index exists
            try
            {
                gpResults2 = geoProcessor.Execute("RemoveSpatialIndex_management", parameterArrary, TrackCancel) as IGeoProcessorResult2;
            }
            catch (Exception ex)
            {
                message.AddWarning(ex.Message);
                if (gpResults2 != null)
                {
                    message.AddMessages(gpResults2.GetResultMessages());
                }
            }

            parameterArrary = CreateAddGridIndexParameterArray(inputFeatureClass, gridIndexList[0], gridIndexList[1], gridIndexList[2]);
            gpResults2 = geoProcessor.Execute("AddSpatialIndex_management", parameterArrary, TrackCancel) as IGeoProcessorResult2;
        }
        /// <summary>
        /// Set a mask on the gp object to buffer the output to the specified distance
        /// </summary>
        /// <param name="workspace">IFeatureWorkspace</param>
        /// <param name="geomList">List of geometries to create the mask</param>
        /// <param name="gp">IGeoProcessor2</param>
        private string SetGPMask(IFeatureWorkspace workspace, List<IGeometry> geomList, IGeoProcessor2 gp, string fcName)
        {
            IFeatureClass maskFc = CreateMaskFeatureClass(workspace, fcName + "_" + RunCount.ToString());

            foreach (IGeometry geom in geomList)
            {
                //create a new point feature
                IFeature ipFeature = maskFc.CreateFeature();
                ipFeature.Shape = geom;
                ipFeature.Store();
            }
            IDataset ds = (IDataset)maskFc;
            string path = ds.Workspace.PathName + "\\" + ds.BrowseName;
            gp.SetEnvironmentValue("mask", path);

            return path;
        }