public Group AddGroup(short label, List <uint> nodeIds)
        {
            if (HasGroup(nodeIds))
            {
                return(null);
            }

            List <Node> nodeList = nodeIds.Select <uint, Node>(delegate(uint id)
            {
                Node v = FindNode(id);
                if (v == null)
                {
                    return(null);
                }
                if (v.Group != null)
                {
                    v.Group.RemoveMember(v);
                }
                return(v);
            }).ToList();

            if (nodeList.Exists(v => v == null))
            {
                return(null);
            }

            Group g = new Group(this, label, nodeList);

            GroupLayer.Add(g);
            return(g);
        }
        public bool MoveToGroupLayer(string theGroupLayerName, ILayer aLayer,  bool Messages = false)
        {
            bool blExists = false;
            IGroupLayer myGroupLayer = new GroupLayer(); 
            // Does the group layer exist?
            if (GroupLayerExists(theGroupLayerName))
            {
                myGroupLayer = (IGroupLayer)GetGroupLayer(theGroupLayerName);
                blExists = true;
            }
            else
            {
                myGroupLayer.Name = theGroupLayerName;
            }
            string theOldName = aLayer.Name;

            // Remove the original instance, then add it to the group.
            RemoveLayer(aLayer);
            myGroupLayer.Add(aLayer);
            
            if (!blExists)
            {
                // Add the layer to the map.
                IMap pMap = GetMap();
                pMap.AddLayer(myGroupLayer);
            }
            RefreshTOC();
            return true;
        }
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            try
            {
                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPValue inputLayersGPValue = gpUtilities3.UnpackGPValue(paramvalues.get_Element(in_LayersNumber));
                IGPMultiValue inputLayersMultiValue = gpUtilities3.UnpackGPValue(inputLayersGPValue) as IGPMultiValue;

                IGPParameter outputGroupLayerParameter = paramvalues.get_Element(out_groupLayerNumber) as IGPParameter;
                IGPValue outputGPGroupLayer = gpUtilities3.UnpackGPValue(outputGroupLayerParameter);
                IGPCompositeLayer outputCompositeLayer = outputGPGroupLayer as IGPCompositeLayer;

                if (outputCompositeLayer == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), outputGroupLayerParameter.Name));
                    return;
                }

                IGroupLayer groupLayer = null;

                // find the last position of the "\" string
                // in case we find such a thing, i.e. position is >= -1 then let's assume that we are dealing with a layer file on disk
                // otherwise let's create a new group layer instance
                string outputGPLayerNameAsString = outputGPGroupLayer.GetAsText();
                int separatorPosition = outputGPLayerNameAsString.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                string layerName = String.Empty;

                if (separatorPosition > -1)
                {
                    layerName = outputGPGroupLayer.GetAsText().Substring(separatorPosition + 1);
                }
                else
                {
                    layerName = outputGPGroupLayer.GetAsText();
                }

                ILayer foundLayer = null;
                IGPLayer existingGPLayer = gpUtilities3.FindMapLayer2(layerName, out foundLayer);

                if (foundLayer != null)
                {
                    gpUtilities3.RemoveFromMapEx((IGPValue)existingGPLayer);
                    gpUtilities3.RemoveInternalLayerEx(foundLayer);
                }

                groupLayer = new GroupLayer();
                ((ILayer)groupLayer).Name = layerName;

                for (int layerIndex = 0; layerIndex < inputLayersMultiValue.Count; layerIndex++)
                {
                    IGPValue gpLayerToAdd = inputLayersMultiValue.get_Value(layerIndex) as IGPValue;

                    ILayer sourceLayer = gpUtilities3.DecodeLayer(gpLayerToAdd);

                    groupLayer.Add(sourceLayer);
                }

                outputGPGroupLayer = gpUtilities3.MakeGPValueFromObject(groupLayer);

                if (separatorPosition > -1)
                {
                    try
                    {
                        // in the case that we are dealing with a layer file on disk
                        // let's persist the group layer information into the file
                        ILayerFile pointLayerFile = new LayerFileClass();

                        if (System.IO.Path.GetExtension(outputGPLayerNameAsString).ToUpper().Equals(".LYR"))
                        {
                            if (pointLayerFile.get_IsPresent(outputGPLayerNameAsString))
                            {
                                try
                                {
                                    gpUtilities3.Delete(outputGPGroupLayer);
                                }
                                catch (Exception ex)
                                {
                                    message.AddError(120001, ex.Message);
                                    return;
                                }
                            }

                            pointLayerFile.New(outputGPLayerNameAsString);

                            pointLayerFile.ReplaceContents(groupLayer);

                            pointLayerFile.Save();

                        }

                         outputGPGroupLayer = gpUtilities3.MakeGPValueFromObject(pointLayerFile.Layer);
                    }
                    catch (Exception ex)
                    {
                        message.AddError(120002, ex.Message);
                        return;
                    }
                }

                gpUtilities3.PackGPValue(outputGPGroupLayer, outputGroupLayerParameter);

            }
            catch (Exception ex)
            {
                message.AddError(120049, ex.Message);
            }
        }
Exemple #4
0
        private void MapUserIdentify(double mapX, double mapY)
        {
            try
            {
                //axMapControl1.Map.ClearSelection();
                ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = (IMapControl3)axMapControl1.Object;
                IMap        pMap        = axMapControl1.Map;
                IGroupLayer pGroupLayer = new GroupLayer();

                if (pMap.LayerCount == 0)
                {
                    return;
                }
                IEnumLayer pEnumLayer;
                ILayer     pLayer;
                pEnumLayer = pMap.get_Layers(null, true);
                if (pEnumLayer == null)
                {
                    return;
                }
                pEnumLayer.Reset();
                double dCurrScale = m_mapControl.MapScale;
                for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
                {
                    if (pLayer.Visible)
                    {
                        if (pLayer is IGroupLayer)
                        {
                            continue;
                        }
                        if (pLayer.MinimumScale != 0 && dCurrScale > pLayer.MinimumScale)
                        {
                            continue;
                        }
                        if (pLayer.MaximumScale != 0 && dCurrScale < pLayer.MaximumScale)
                        {
                            continue;
                        }
                        pGroupLayer.Add(pLayer);
                    }
                }

                IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
                pPoint.X = mapX; pPoint.Y = mapY;
                IIdentifyObj        pIdObj;
                IIdentify           pIdentify = pGroupLayer as IIdentify;
                IArray              pIDArray;
                IFeatureIdentifyObj pFeatIdObj;

                IEnvelope pEnv             = pPoint.Envelope;
                IDisplayTransformation pDT = m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation;
                pEnv.Expand(pDT.VisibleBounds.Width / 200, pDT.VisibleBounds.Height / 200, false);

                pIDArray = pIdentify.Identify(pEnv);

                if (pIDArray == null || pIDArray.Count == 0)
                {
                    return;
                }

                pFeatIdObj = pIDArray.get_Element(0) as IFeatureIdentifyObj;
                pIdObj     = pFeatIdObj as IIdentifyObj;

                IRowIdentifyObject pRowIdentifyObj = pFeatIdObj as IRowIdentifyObject;
                IFeature           pFeature        = pRowIdentifyObj.Row as IFeature;
                if (pFeature != null && pFeature.Shape != null && !pFeature.Shape.IsEmpty)
                {
                    //axMapControl1.FlashShape(pFeature.Shape);
                    axMapControl1.Map.SelectFeature(pIdObj.Layer, pFeature);
                    FlashFeature(axMapControl1, pFeature.Shape);
                }

                //  pIdObj.Flash(m_mapControl.ActiveView.ScreenDisplay);//The Flash method is not supported with ArcGIS Engine, use the IHookActions.DoActions() method with the esriHookActionsFlash for this functionality.
                ILayer pIdentiyLayer = pIdObj.Layer;

                DataTable  pTable      = new DataTable();
                DataColumn pDataColumn = pTable.Columns.Add();
                pDataColumn.ColumnName = "列名";
                pDataColumn            = pTable.Columns.Add();
                pDataColumn.ColumnName = "值";

                DataRow pFirestDataRow = pTable.Rows.Add();
                pFirestDataRow[0] = "所在层";
                pFirestDataRow[1] = pIdentiyLayer.Name;

                if (pIdentiyLayer is IFeatureLayer)
                {
                    IRowIdentifyObject pRowObj = pIdObj as IRowIdentifyObject;
                    //   IRow pRow = pRowObj.Row;

                    IFeature pRow    = pRowObj.Row as IFeature;
                    IFields  pFields = pRow.Fields;

                    for (int i = 0; i < pFields.FieldCount; i++)
                    {
                        IField  pField   = pFields.get_Field(i);
                        DataRow pDataRow = null;

                        /*
                         * switch (pField.Type)
                         * {
                         *  case esriFieldType.esriFieldTypeOID:
                         *      pDataRow = pTable.Rows.Add();
                         *      pDataRow[0] = pField.Name;
                         *      pDataRow[1] = pRow.OID.ToString();
                         *      break;
                         *  case esriFieldType.esriFieldTypeGeometry:
                         *      //pDataRow[0] = "Geometry";
                         *      //pDataRow[1] = QueryShapeType(pField.GeometryDef.GeometryType);;
                         *      break;
                         *  default:
                         *      pDataRow = pTable.Rows.Add();
                         *      pDataRow[0] = pField.Name;
                         *      pDataRow[1] = pRow.get_Value(i).ToString();
                         *      break;
                         * }
                         * * */

                        //////////////////////////////////////////////////
                        string sValue   = pRow.get_Value(i).ToString();
                        string strFName = pField.AliasName.ToUpper();
                        string strUName = strFName.ToUpper();
                        if (strUName == "SHAPE" || strUName == "LENGTH" || strUName == "OBJECTID" || strUName == "ID" || strUName == "FNODE_" || strUName == "TNODE_" || strUName == "LPOLY_" || strUName == "RPOLY_" || strUName == "SDXL_" || strUName == "SDXL_ID" || strUName == "OBJECTID_1" || strUName == "FID")
                        {
                            continue;
                        }
                        else if (strUName == "SHAPE.LEN" || strUName == "SHAPE_LENG")
                        {
                            strFName = "几何长度";
                        }
                        else if (strUName == "SHAPE_AREA" || strUName == "SHAPE.AREA")
                        {
                            strFName = "多边形面积";
                        }
                        else if (strUName == "HEIGHT")
                        {
                            strFName = "高程";
                        }
                        else if (strUName == "NAME")
                        {
                            strFName = "名称";
                        }
                        else if (strUName == "TYPE")
                        {
                            strFName = "类型";
                        }
                        else if (strUName == "SUBTYPE")
                        {
                            strFName = "子类型";
                        }

                        if (strUName == "LENGTH" || strUName == "SHAPE.LEN")
                        {
                            IUnitConverter myUnit = new UnitConverterClass();
                            sValue = Math.Round(myUnit.ConvertUnits((double)pRow.get_Value(i), esriUnits.esriMeters, esriUnits.esriKilometers), 2).ToString();
                            sValue = sValue.ToString() + "千米";
                        }
                        if (strUName == "SHAPE_AREA" || strUName == "SHAPE.AREA")
                        {
                            IGeometry pGeo = pRow.ShapeCopy;
                            pGeo.Project(axMapControl1.Map.SpatialReference);
                            IPolygon pPolygon = (IPolygon)pGeo;
                            IArea    pArea    = (IArea)pPolygon;
                            double   strValue = pArea.Area * 0.000001;
                            //// double strValue = Math.Abs((double)pFeature.get_Value(j)) * 10585;
                            strValue = Math.Round(strValue, 2);
                            sValue   = strValue.ToString() + "平方千米";
                        }
                        esriFieldType tFieldTypy = pField.Type;
                        if (tFieldTypy == esriFieldType.esriFieldTypeGeometry)
                        {
                            sValue = pField.GeometryDef.GeometryType.ToString();
                            sValue = sValue.Substring(12, sValue.Length - 12);
                        }

                        pDataRow    = pTable.Rows.Add();
                        pDataRow[0] = strFName;
                        pDataRow[1] = sValue;

                        //////////////////////////////////////////////////
                    }
                }
                else if (pIdentiyLayer is ITinLayer)
                {
                    ITinLayer   pTinLayer   = (ITinLayer)pIdentiyLayer;
                    ITinSurface pTinSurface = (ITinSurface)pTinLayer.Dataset;
                    if (pTinSurface == null)
                    {
                        return;
                    }
                    ITinSurfaceElement pTinSurfaceElement = pTinSurface.GetSurfaceElement(pPoint);

                    if (pTinSurfaceElement == null)
                    {
                        return;
                    }
                    IFields pFields  = pTinLayer.Dataset.Fields;
                    DataRow pDataRow = null;

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "高度";
                    pDataRow[1] = pTinSurfaceElement.Elevation.ToString();

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "坡度";
                    pDataRow[1] = pTinSurfaceElement.SlopeDegrees.ToString();

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "方向";
                    pDataRow[1] = pTinSurfaceElement.AspectDegrees.ToString();
                }

                if (pIdentiyLayer is IRasterLayer)
                {
                    MessageBox.Show("aa");
                }
                //ShowIndetify(pTable);
                //m_pMainform.ShowIndetify(pTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
        }
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            try
            {
                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPValue      inputLayersGPValue    = gpUtilities3.UnpackGPValue(paramvalues.get_Element(in_LayersNumber));
                IGPMultiValue inputLayersMultiValue = gpUtilities3.UnpackGPValue(inputLayersGPValue) as IGPMultiValue;

                IGPParameter      outputGroupLayerParameter = paramvalues.get_Element(out_groupLayerNumber) as IGPParameter;
                IGPValue          outputGPGroupLayer        = gpUtilities3.UnpackGPValue(outputGroupLayerParameter);
                IGPCompositeLayer outputCompositeLayer      = outputGPGroupLayer as IGPCompositeLayer;

                if (outputCompositeLayer == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), outputGroupLayerParameter.Name));
                    return;
                }


                IGroupLayer groupLayer = null;

                // find the last position of the "\" string
                // in case we find such a thing, i.e. position is >= -1 then let's assume that we are dealing with a layer file on disk
                // otherwise let's create a new group layer instance
                string outputGPLayerNameAsString = outputGPGroupLayer.GetAsText();
                int    separatorPosition         = outputGPLayerNameAsString.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                string layerName = String.Empty;

                if (separatorPosition > -1)
                {
                    layerName = outputGPGroupLayer.GetAsText().Substring(separatorPosition + 1);
                }
                else
                {
                    layerName = outputGPGroupLayer.GetAsText();
                }

                ILayer   foundLayer      = null;
                IGPLayer existingGPLayer = gpUtilities3.FindMapLayer2(layerName, out foundLayer);

                if (foundLayer != null)
                {
                    gpUtilities3.RemoveFromMapEx((IGPValue)existingGPLayer);
                    gpUtilities3.RemoveInternalLayerEx(foundLayer);
                }

                groupLayer = new GroupLayer();
                ((ILayer)groupLayer).Name = layerName;

                for (int layerIndex = 0; layerIndex < inputLayersMultiValue.Count; layerIndex++)
                {
                    IGPValue gpLayerToAdd = inputLayersMultiValue.get_Value(layerIndex) as IGPValue;

                    ILayer sourceLayer = gpUtilities3.DecodeLayer(gpLayerToAdd);

                    groupLayer.Add(sourceLayer);
                }

                outputGPGroupLayer = gpUtilities3.MakeGPValueFromObject(groupLayer);

                if (separatorPosition > -1)
                {
                    try
                    {
                        // in the case that we are dealing with a layer file on disk
                        // let's persist the group layer information into the file
                        ILayerFile pointLayerFile = new LayerFileClass();

                        if (System.IO.Path.GetExtension(outputGPLayerNameAsString).ToUpper().Equals(".LYR"))
                        {
                            if (pointLayerFile.get_IsPresent(outputGPLayerNameAsString))
                            {
                                try
                                {
                                    gpUtilities3.Delete(outputGPGroupLayer);
                                }
                                catch (Exception ex)
                                {
                                    message.AddError(120001, ex.Message);
                                    return;
                                }
                            }

                            pointLayerFile.New(outputGPLayerNameAsString);

                            pointLayerFile.ReplaceContents(groupLayer);

                            pointLayerFile.Save();
                        }

                        outputGPGroupLayer = gpUtilities3.MakeGPValueFromObject(pointLayerFile.Layer);
                    }
                    catch (Exception ex)
                    {
                        message.AddError(120002, ex.Message);
                        return;
                    }
                }

                gpUtilities3.PackGPValue(outputGPGroupLayer, outputGroupLayerParameter);
            }
            catch (Exception ex)
            {
                message.AddError(120049, ex.Message);
            }
        }