コード例 #1
0
        public void UpdateParameters(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager pEnvMgr)
        {
            IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

            IGPParameter3 inputLayersParameter = paramvalues.get_Element(in_LayersNumber) as IGPParameter3;
            IGPMultiValue inputLayersGPValue   = gpUtilities3.UnpackGPValue(inputLayersParameter) as IGPMultiValue;

            if (inputLayersGPValue == null)
            {
                return;
            }

            // check if there are input layer provided
            if (inputLayersGPValue.Count == 0)
            {
                return;
            }

            IGPParameter3 outputLayerParameter = paramvalues.get_Element(out_groupLayerNumber) as IGPParameter3;
            IGPValue      outputLayerGPValue   = gpUtilities3.UnpackGPValue(outputLayerParameter);

            // if the output layer value is still empty and build a proposal for a name
            if (outputLayerGPValue.IsEmpty())
            {
                // read the proposed name from the resources
                string proposedOutputLayerName = resourceManager.GetString("GPTools_GPCombineLayers_outputgrouplayer_proposedname");

                string proposedOutputLayerNameTest = proposedOutputLayerName;
                int    layerIndex = 2;

                // check if a layer with the same name already exists
                // if it does then attempt to append some index numbers to build a unique, new name
                ILayer foundLayer = gpUtilities3.FindMapLayer(proposedOutputLayerNameTest);

                while (foundLayer != null)
                {
                    proposedOutputLayerNameTest = proposedOutputLayerName + " (" + layerIndex + ")";

                    foundLayer = gpUtilities3.FindMapLayer(proposedOutputLayerNameTest);
                    layerIndex = layerIndex + 1;

                    if (layerIndex > 10000)
                    {
                        break;
                    }
                }

                outputLayerGPValue.SetAsText(proposedOutputLayerNameTest);
                gpUtilities3.PackGPValue(outputLayerGPValue, outputLayerParameter);
            }
        }
コード例 #2
0
        public void UpdateParameters(IArray paramvalues, IGPEnvironmentManager pEnvMgr)
        {
            IGPUtilities2 gpUtil = null;

            try
            {
                gpUtil = new GPUtilitiesClass();

                IGPParameter targetDatasetParameter = paramvalues.get_Element(in_osmFeatureDataset) as IGPParameter;
                IDataElement dataElement            = gpUtil.UnpackGPValue(targetDatasetParameter) as IDataElement;
                string       osmDatasetPath         = dataElement.CatalogPath;

                IGPParameter gppNetworkDataset = paramvalues.get_Element(out_NetworkDataset) as IGPParameter;
                IGPValue     gpvNetworkDataset = gpUtil.UnpackGPValue(gppNetworkDataset);
                string       ndsPath           = gpvNetworkDataset.GetAsText();

                string ndsDir = string.Empty;
                if (!string.IsNullOrEmpty(ndsPath))
                {
                    ndsDir = System.IO.Path.GetDirectoryName(ndsPath);
                }

                if (!ndsDir.Equals(osmDatasetPath))
                {
                    string ndsName = System.IO.Path.GetFileName(ndsPath);
                    if (string.IsNullOrEmpty(ndsName))
                    {
                        ndsName = _defaultNetworkDatasetName;
                    }

                    ndsName = System.IO.Path.GetFileName(osmDatasetPath) + "_" + ndsName;
                    gpvNetworkDataset.SetAsText(System.IO.Path.Combine(osmDatasetPath, ndsName));
                    gpUtil.PackGPValue(gpvNetworkDataset, gppNetworkDataset);
                }
            }
            finally
            {
                if (gpUtil != null)
                {
                    ComReleaser.ReleaseCOMObject(gpUtil);
                }
            }
        }
コード例 #3
0
        public void UpdateParameters(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager pEnvMgr)
        {
            IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

            #region update the output point parameter based on the input of template point layer
            IGPParameter inputPointLayerParameter = paramvalues.get_Element(in_osmPointLayerNumber) as IGPParameter;
            IGPValue     inputPointLayer          = gpUtilities3.UnpackGPValue(inputPointLayerParameter);

            IGPParameter3 outputPointLayerParameter = paramvalues.get_Element(out_osmPointLayerNumber) as IGPParameter3;
            if (((inputPointLayer).IsEmpty() == false) && (outputPointLayerParameter.Altered == false))
            {
                IGPValue outputPointGPValue = gpUtilities3.UnpackGPValue(outputPointLayerParameter);
                if (outputPointGPValue.IsEmpty())
                {
                    IClone   clonedObject  = inputPointLayer as IClone;
                    IGPValue clonedGPValue = clonedObject.Clone() as IGPValue;

                    // if it is an internal group layer
                    IGPGroupLayer inputPointGroupLayer = clonedObject as IGPGroupLayer;

                    if (inputPointGroupLayer != null)
                    {
                        string proposedLayerName = "Points";
                        string tempLayerName     = proposedLayerName;
                        int    index             = 1;
                        ILayer currentMapLayer   = gpUtilities3.FindMapLayer(proposedLayerName);

                        while (currentMapLayer != null)
                        {
                            tempLayerName = proposedLayerName + "_" + index.ToString();

                            currentMapLayer = gpUtilities3.FindMapLayer(tempLayerName);
                            index           = index + 1;
                        }

                        clonedGPValue.SetAsText(tempLayerName);
                        gpUtilities3.PackGPValue(clonedGPValue, outputPointLayerParameter);
                    }
                    else
                    {
                        IDELayer deLayer = clonedGPValue as IDELayer;

                        if (deLayer != null)
                        {
                            FileInfo sourceLyrFileInfo = new FileInfo(clonedGPValue.GetAsText());

                            // check the output location of the file with respect to the gp environment settings
                            sourceLyrFileInfo = new FileInfo(DetermineLyrLocation(pEnvMgr.GetEnvironments(), sourceLyrFileInfo));

                            if (sourceLyrFileInfo.Exists)
                            {
                                int    layerFileIndex  = 1;
                                string tempFileLyrName = sourceLyrFileInfo.DirectoryName + System.IO.Path.DirectorySeparatorChar + sourceLyrFileInfo.Name.Substring(0, sourceLyrFileInfo.Name.Length - sourceLyrFileInfo.Extension.Length) + "_" + layerFileIndex.ToString() + sourceLyrFileInfo.Extension;

                                while (File.Exists(tempFileLyrName))
                                {
                                    tempFileLyrName = sourceLyrFileInfo.DirectoryName + System.IO.Path.DirectorySeparatorChar + sourceLyrFileInfo.Name.Substring(0, sourceLyrFileInfo.Name.Length - sourceLyrFileInfo.Extension.Length) + "_" + layerFileIndex.ToString() + sourceLyrFileInfo.Extension;
                                    layerFileIndex  = layerFileIndex + 1;
                                }

                                clonedGPValue.SetAsText(tempFileLyrName);
                                gpUtilities3.PackGPValue(clonedGPValue, outputPointLayerParameter);
                            }
                            else
                            {
                                clonedGPValue.SetAsText(sourceLyrFileInfo.FullName);
                                gpUtilities3.PackGPValue(clonedGPValue, outputPointLayerParameter);
                            }
                        }
                    }
                }
            }
            #endregion

            #region update the output line parameter based on the input of template line layer
            IGPParameter inputLineLayerParameter = paramvalues.get_Element(in_osmLineLayerNumber) as IGPParameter;
            IGPValue     inputLineLayer          = gpUtilities3.UnpackGPValue(inputLineLayerParameter);

            IGPParameter3 outputLineLayerParameter = paramvalues.get_Element(out_osmLineLayerNumber) as IGPParameter3;
            if (((inputLineLayer).IsEmpty() == false) && (outputLineLayerParameter.Altered == false))
            {
                IGPValue outputLineGPValue = gpUtilities3.UnpackGPValue(outputLineLayerParameter);
                if (outputLineGPValue.IsEmpty())
                {
                    IClone   clonedObject  = inputLineLayer as IClone;
                    IGPValue clonedGPValue = clonedObject.Clone() as IGPValue;

                    // if it is an internal group layer
                    IGPGroupLayer inputLineGroupLayer = clonedObject as IGPGroupLayer;

                    if (inputLineGroupLayer != null)
                    {
                        string proposedLayerName = "Lines";
                        string tempLayerName     = proposedLayerName;
                        int    index             = 1;
                        ILayer currentMapLayer   = gpUtilities3.FindMapLayer(proposedLayerName);

                        while (currentMapLayer != null)
                        {
                            tempLayerName = proposedLayerName + "_" + index.ToString();

                            currentMapLayer = gpUtilities3.FindMapLayer(tempLayerName);
                            index           = index + 1;
                        }

                        clonedGPValue.SetAsText(tempLayerName);
                        gpUtilities3.PackGPValue(clonedGPValue, outputLineLayerParameter);
                    }
                    else
                    {
                        IDELayer deLayer = clonedGPValue as IDELayer;

                        if (deLayer != null)
                        {
                            FileInfo sourceLyrFileInfo = new FileInfo(clonedGPValue.GetAsText());

                            // check the output location of the file with respect to the gp environment settings
                            sourceLyrFileInfo = new FileInfo(DetermineLyrLocation(pEnvMgr.GetEnvironments(), sourceLyrFileInfo));

                            if (sourceLyrFileInfo.Exists)
                            {
                                int    layerFileIndex  = 1;
                                string tempFileLyrName = sourceLyrFileInfo.DirectoryName + System.IO.Path.DirectorySeparatorChar + sourceLyrFileInfo.Name.Substring(0, sourceLyrFileInfo.Name.Length - sourceLyrFileInfo.Extension.Length) + "_" + layerFileIndex.ToString() + sourceLyrFileInfo.Extension;

                                while (File.Exists(tempFileLyrName))
                                {
                                    tempFileLyrName = sourceLyrFileInfo.DirectoryName + System.IO.Path.DirectorySeparatorChar + sourceLyrFileInfo.Name.Substring(0, sourceLyrFileInfo.Name.Length - sourceLyrFileInfo.Extension.Length) + "_" + layerFileIndex.ToString() + sourceLyrFileInfo.Extension;
                                    layerFileIndex  = layerFileIndex + 1;
                                }

                                clonedGPValue.SetAsText(tempFileLyrName);
                                gpUtilities3.PackGPValue(clonedGPValue, outputLineLayerParameter);
                            }
                            else
                            {
                                clonedGPValue.SetAsText(sourceLyrFileInfo.FullName);
                                gpUtilities3.PackGPValue(clonedGPValue, outputLineLayerParameter);
                            }
                        }
                    }
                }
            }
            #endregion

            #region update the output polygon parameter based on the input of template polygon layer
            IGPParameter inputPolygonLayerParameter = paramvalues.get_Element(in_osmPolygonLayerNumber) as IGPParameter;
            IGPValue     inputPolygonLayer          = gpUtilities3.UnpackGPValue(inputPolygonLayerParameter);

            IGPParameter3 outputPolygonLayerParameter = paramvalues.get_Element(out_osmPolygonLayerNumber) as IGPParameter3;
            if (((inputPolygonLayer).IsEmpty() == false) && (outputPolygonLayerParameter.Altered == false))
            {
                IGPValue outputPolygonGPValue = gpUtilities3.UnpackGPValue(outputPolygonLayerParameter);
                if (outputPolygonGPValue.IsEmpty())
                {
                    IClone   clonedObject  = inputPolygonLayer as IClone;
                    IGPValue clonedGPValue = clonedObject.Clone() as IGPValue;

                    // if it is an internal group layer
                    IGPGroupLayer inputPolygonGroupLayer = clonedObject as IGPGroupLayer;

                    if (inputPolygonGroupLayer != null)
                    {
                        string proposedLayerName = "Polygons";
                        string tempLayerName     = proposedLayerName;
                        int    index             = 1;
                        ILayer currentMapLayer   = gpUtilities3.FindMapLayer(proposedLayerName);

                        while (currentMapLayer != null)
                        {
                            tempLayerName = proposedLayerName + "_" + index.ToString();

                            currentMapLayer = gpUtilities3.FindMapLayer(tempLayerName);
                            index           = index + 1;
                        }

                        clonedGPValue.SetAsText(tempLayerName);
                        gpUtilities3.PackGPValue(clonedGPValue, outputPolygonLayerParameter);
                    }
                    else
                    {
                        IDELayer deLayer = clonedGPValue as IDELayer;

                        if (deLayer != null)
                        {
                            FileInfo sourceLyrFileInfo = new FileInfo(clonedGPValue.GetAsText());

                            // check the output location of the file with respect to the gp environment settings
                            sourceLyrFileInfo = new FileInfo(DetermineLyrLocation(pEnvMgr.GetEnvironments(), sourceLyrFileInfo));

                            if (sourceLyrFileInfo.Exists)
                            {
                                int    layerFileIndex  = 1;
                                string tempFileLyrName = sourceLyrFileInfo.DirectoryName + System.IO.Path.DirectorySeparatorChar + sourceLyrFileInfo.Name.Substring(0, sourceLyrFileInfo.Name.Length - sourceLyrFileInfo.Extension.Length) + "_" + layerFileIndex.ToString() + sourceLyrFileInfo.Extension;

                                while (File.Exists(tempFileLyrName))
                                {
                                    tempFileLyrName = sourceLyrFileInfo.DirectoryName + System.IO.Path.DirectorySeparatorChar + sourceLyrFileInfo.Name.Substring(0, sourceLyrFileInfo.Name.Length - sourceLyrFileInfo.Extension.Length) + "_" + layerFileIndex.ToString() + sourceLyrFileInfo.Extension;
                                    layerFileIndex  = layerFileIndex + 1;
                                }

                                clonedGPValue.SetAsText(tempFileLyrName);
                                gpUtilities3.PackGPValue(clonedGPValue, outputPolygonLayerParameter);
                            }
                            else
                            {
                                clonedGPValue.SetAsText(sourceLyrFileInfo.FullName);
                                gpUtilities3.PackGPValue(clonedGPValue, outputPolygonLayerParameter);
                            }
                        }
                    }
                }
            }
            #endregion
        }