コード例 #1
0
ファイル: SymbolUtils.cs プロジェクト: arcpad/epsgis
        /// <summary>
        /// 获取图层对应的所有标志字段
        /// </summary>
        /// <param name="pfLayer">图层</param>
        /// <param name="sArrFields">所有标志字段</param>
        /// <returns>是否存在分层字段</returns>
        public static bool GetUniqueFields(IFeatureLayer pfLayer, out string[] sArrFields)
        {
            IGeoFeatureLayer pGeoFLayer = pfLayer as IGeoFeatureLayer;
            IFeatureRenderer pfRenderer = pGeoFLayer.Renderer;

            if (pfRenderer is IUniqueValueRenderer)
            {
                IUniqueValueRenderer pUVRenderer = pfRenderer as IUniqueValueRenderer;
                int nFieldCount = pUVRenderer.FieldCount;
                sArrFields = new string[nFieldCount];
                // 一般nFieldCount为1,在特殊情况下为多个域,此时value的值由分割符',' 或'|'等分割
                for (int i = 0; i < nFieldCount; i++)
                {
                    sArrFields[i] = pUVRenderer.get_Field(i);
                }
                return(true);
            }
            sArrFields = null;
            return(false);
        }
コード例 #2
0
        private void cmbInlayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbfield1.Items.Clear();
            ILayer playermap = ClsGDBDataCommon.GetLayerFromName(pMapControl.Map, cmbInlayer.Text);

            if (playermap is IFeatureLayer)
            {
                IFeatureLayer    pfeaturelayer    = (IFeatureLayer)playermap;
                IGeoFeatureLayer pGeofeaturelayer = (IGeoFeatureLayer)pfeaturelayer;
                if (pGeofeaturelayer.Renderer is IUniqueValueRenderer)
                {
                    pInLayer     = playermap;
                    pInFLayer    = (IFeatureLayer)pInLayer;
                    pInGeoFLayer = (IGeoFeatureLayer)pInFLayer;
                    pUniquerend  = pInGeoFLayer.Renderer as IUniqueValueRenderer;
                }
            }

            if (pUniquerend.FieldCount == 1)
            {
                cmbfield2.Enabled = false;
                cmbfield3.Enabled = false;
                ITable  pTbale  = pLayer as ITable;
                IFields pFields = pTbale.Fields;
                for (int i = 2; i < pFields.FieldCount; i++)
                {
                    cmbfield1.Items.Add(pFields.get_Field(i).Name);
                }
                string uniquefield = pUniquerend.get_Field(0);
                if (cmbfield1.Items.Contains(uniquefield))
                {
                    cmbfield1.Text = uniquefield;
                }
                else
                {
                    MessageBox.Show("当前图层中不包含导入符号图层的独立值字段", "提示", MessageBoxButtons.OK);
                    //this.Close();
                }
            }
        }
コード例 #3
0
ファイル: LayerInfo.cs プロジェクト: MadhavKrishna/MXDReader
        public void processFeatureLayer(ILayer lyr)
        {
            type = "Vektor";
            fillLayerProps(lyr);
            fillDatalayerProps(lyr);
            IFeatureLayer flyr = lyr as IFeatureLayer;

            fillDefQueryProps(flyr);
            processJoins(flyr);
            processRelates(flyr);

            IGeoFeatureLayer gflyr = flyr as IGeoFeatureLayer;

            if (gflyr.DisplayAnnotation == true)
            {
                IAnnotateLayerPropertiesCollection labelPropsColl = gflyr.AnnotationProperties;
                for (int collIndex = 0; collIndex < labelPropsColl.Count; collIndex++)
                {
                    IAnnotateLayerProperties annoLayerProps;
                    IElementCollection       elCol1;
                    IElementCollection       elCol2;
                    labelPropsColl.QueryItem(collIndex, out annoLayerProps, out elCol1, out elCol2);
                    string sql = annoLayerProps.WhereClause;
                    ILabelEngineLayerProperties2 labelEngineProps = (ILabelEngineLayerProperties2)annoLayerProps;
                    string expr = labelEngineProps.Expression;
                    this.label = this.label + sql + "?" + expr + "/";
                }
            }
            this.label = this.label.TrimEnd('/');

            IFeatureRenderer rend = gflyr.Renderer;

            if (rend is IUniqueValueRenderer)
            {
                string felder          = "";
                IUniqueValueRenderer u = rend as IUniqueValueRenderer;
                for (int i = 0; i < u.FieldCount; i++)
                {
                    felder = felder + u.get_Field(i) + "/";
                }
                symbfields = felder.TrimEnd('/') + " (UniqueValueRenderer)";
            }
            else if (rend is IProportionalSymbolRenderer)
            {
                IProportionalSymbolRenderer prop = rend as IProportionalSymbolRenderer;
                symbfields = prop.Field + " (ProportionalSymbolRenderer)";
            }
            else if (rend is IClassBreaksRenderer)
            {
                IClassBreaksRenderer cl = rend as IClassBreaksRenderer;
                symbfields = cl.Field + " (ClassBreaksRenderer)";;
            }
            else if (rend is ISimpleRenderer)
            {
                symbfields = "kein Feld (SimpleRenderer)";
            }
            else
            {
                symbfields = "unbekannter Renderer";
            }
        }
コード例 #4
0
ファイル: DataUtils2D.cs プロジェクト: wwcc19870805/DIFGIS
        private static void AddSymbolNode(TreeNodeComLayer tnComLayer, object renderer)
        {
            int             index;
            LogicBaseTree   logicBT    = new LogicBaseTree();
            ImageCollection treeImages = logicBT.TreeList.StateImageList as ImageCollection;

            if (renderer is SimpleRenderer)
            {
                ISimpleRenderer simpleRenderer = (ISimpleRenderer)renderer;
                ISymbol         symbol         = simpleRenderer.Symbol;
                Image           img            = ConvertSymbolToImage.Convert(symbol, 16, 16);
                index = treeImages.Images.Add(img);
                //img.Save("d:\\" + index + ".JPG");

                string         label    = simpleRenderer.Label;
                TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                {
                    Name = label, CustomValue = symbol
                };
                tnSymbol.ImageIndex = index;
                tnComLayer.Add(tnSymbol);
            }
            else if (renderer is UniqueValueRenderer)
            {
                string renderLabel = "";
                IUniqueValueRenderer uniqueValueRenderer = renderer as IUniqueValueRenderer;
                for (int i = 0; i < uniqueValueRenderer.FieldCount - 1; i++)
                {
                    renderLabel += uniqueValueRenderer.get_Field(i) + " /";
                }
                renderLabel += uniqueValueRenderer.get_Field(uniqueValueRenderer.FieldCount - 1);//FieldCount为地物分类数
                //getImage(esriGeometryType.esriGeometryPolygon, Color.White).Save("D:\\111.jpg");
                index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                {
                    Name = renderLabel, CustomValue = uniqueValueRenderer
                };
                tnChartNode.ImageIndex = index;
                tnComLayer.Add(tnChartNode);

                for (int i = 0; i < uniqueValueRenderer.ValueCount; i++)//ValueCount为地物分类下的设施种类数
                {
                    ISymbol symbol = uniqueValueRenderer.get_Symbol(uniqueValueRenderer.get_Value(i));

                    Image img = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    //img.Save("D:\\121121.jpg");


                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = uniqueValueRenderer.get_Label(uniqueValueRenderer.get_Value(i)), CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
                if (uniqueValueRenderer.UseDefaultSymbol)
                {
                    ISymbol symbol = uniqueValueRenderer.DefaultSymbol;
                    Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = uniqueValueRenderer.DefaultLabel, CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
            }
            else if (renderer is IChartRenderer)
            {
                IChartRenderer  chartRenderer = renderer as IChartRenderer;
                IRendererFields pFields       = chartRenderer as IRendererFields;
                string          renderLabel   = "";
                for (int i = 0; i < pFields.FieldCount - 1; i++)
                {
                    renderLabel += pFields.get_FieldAlias(i) + " /";
                }
                renderLabel += pFields.get_FieldAlias(pFields.FieldCount - 1);

                index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                {
                    Name = renderLabel, CustomValue = chartRenderer
                };
                tnChartNode.ImageIndex = index;
                tnComLayer.Add(tnChartNode);


                ISymbolArray symArray = chartRenderer.ChartSymbol as ISymbolArray;
                for (int i = 0; i < symArray.SymbolCount; i++)
                {
                    ISymbol symbol = symArray.get_Symbol(i);

                    Image img = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = pFields.get_FieldAlias(i), CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
            }
            else if (renderer is IClassBreaksRenderer)
            {
                IClassBreaksRenderer classRenderer = renderer as IClassBreaksRenderer;
                index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                {
                    Name = classRenderer.Field, CustomValue = classRenderer
                };
                tnChartNode.ImageIndex = index;
                tnComLayer.Add(tnChartNode);


                for (int i = 0; i < classRenderer.BreakCount; i++)
                {
                    ISymbol symbol = classRenderer.get_Symbol(i);

                    Image img = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = classRenderer.get_Label(i), CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
            }
            else if (renderer is IRasterRenderer)
            {
                if (renderer is IRasterClassifyColorRampRenderer)
                {
                    //MessageBox.Show("IRasterClassifyColorRampRenderer");
                }
                else if (renderer is IRasterUniqueValueRenderer)
                {
                    //MessageBox.Show("IRasterUniqueValueRenderer");
                }
                else if (renderer is IRasterStretchColorRampRenderer)
                {
                    ////MessageBox.Show("IRasterStretchColorRampRenderer");
                    IRasterStretchColorRampRenderer pRSCRR = renderer as IRasterStretchColorRampRenderer;

                    index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));
                    TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                    {
                        Name = "<Value>", CustomValue = pRSCRR
                    };
                    tnChartNode.ImageIndex = index;
                    tnComLayer.Add(tnChartNode);

                    if (pRSCRR.ColorRamp.Size >= 3)
                    {
                        IEnumColors colors = pRSCRR.ColorRamp.Colors;
                        colors.Reset();
                        IColor  c      = colors.Next();
                        Color[] cArray = new Color[3];
                        int     count  = 0;
                        while (c != null)
                        {
                            count++;
                            if (count == 1)
                            {
                                cArray[0] = Color.FromArgb(c.RGB);
                            }
                            else if (count == pRSCRR.ColorRamp.Size / 2)
                            {
                                cArray[1] = Color.FromArgb(c.RGB);
                            }
                            else if (count == pRSCRR.ColorRamp.Size)
                            {
                                cArray[2] = Color.FromArgb(c.RGB);
                            }
                            c = colors.Next();
                        }
                        for (int i = 0; i < 3; i++)
                        {
                            Image img = getImage(esriGeometryType.esriGeometryPolygon, cArray[i]);
                            index = treeImages.Images.Add(img);

                            string label = "";
                            if (i == 0)
                            {
                                label = pRSCRR.LabelLow;
                            }
                            else if (i == 1)
                            {
                                label = pRSCRR.LabelMedium;
                            }
                            else if (i == 2)
                            {
                                label = pRSCRR.LabelHigh;
                            }

                            TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                            {
                                Name = label, CustomValue = cArray[i]
                            };
                            tnSymbol.ImageIndex = index;
                            tnComLayer.Add(tnSymbol);
                        }
                    }
                }

                else if (renderer is IRasterRGBRenderer)
                {
                    //MessageBox.Show("IRasterRGBRenderer");
                }
                else if (renderer is IRasterColormap)
                {
                    //MessageBox.Show("IRasterColormap");
                }
                else
                {
                    //MessageBox.Show("未处理的IRasterRenderer类型:  " + renderer.GetType().FullName);
                }
            }
            else if (renderer is ITinRenderer)
            {
                if (renderer is ITinColorRampRenderer)
                {
                    ////MessageBox.Show("ITinColorRampRenderer");
                    ITinColorRampRenderer pTCRR = renderer as ITinColorRampRenderer;

                    index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));
                    TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                    {
                        Name = "Elevation", CustomValue = pTCRR
                    };
                    tnChartNode.ImageIndex = index;
                    tnComLayer.Add(tnChartNode);



                    for (int i = 0; i < pTCRR.BreakCount; i++)
                    {
                        ISymbol symbol = pTCRR.get_Symbol(i);
                        Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                        index = treeImages.Images.Add(img);
                        TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                        {
                            Name = pTCRR.get_Label(i), CustomValue = symbol
                        };
                        tnSymbol.ImageIndex = index;
                        tnComLayer.Add(tnSymbol);
                    }
                }
                else if (renderer is ITinUniqueValueRenderer)
                {
                    ////MessageBox.Show("ITinUniqueValueRenderer");
                    ITinUniqueValueRenderer pTUVR = renderer as ITinUniqueValueRenderer;

                    index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                    TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                    {
                        Name = "Elevation", CustomValue = pTUVR
                    };
                    tnChartNode.ImageIndex = index;
                    tnComLayer.Add(tnChartNode);


                    for (int i = 0; i < pTUVR.ValueCount; i++)
                    {
                        string  val    = pTUVR.get_Value(i);
                        ISymbol symbol = pTUVR.get_Symbol(val);
                        Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                        index = treeImages.Images.Add(img);

                        TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                        {
                            Name = pTUVR.get_Label(val), CustomValue = symbol
                        };
                        tnSymbol.ImageIndex = index;
                        tnComLayer.Add(tnSymbol);
                    }
                    if (pTUVR.UseDefaultSymbol)
                    {
                        ISymbol symbol = pTUVR.DefaultSymbol;
                        Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                        index = treeImages.Images.Add(img);

                        TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                        {
                            Name = pTUVR.DefaultLabel, CustomValue = symbol
                        };
                        tnSymbol.ImageIndex = index;
                        tnComLayer.Add(tnSymbol);
                    }
                }
                else if (renderer is ITinSingleSymbolRenderer)
                {
                    ////MessageBox.Show("ITinSingleSymbolRenderer");
                    ITinSingleSymbolRenderer pTSSR = renderer as ITinSingleSymbolRenderer;
                    ISymbol symbol = pTSSR.Symbol;
                    Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = pTSSR.Label, CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
                else
                {
                    //MessageBox.Show("未处理的ITinRenderer类型:  " + renderer.GetType().FullName);
                }
            }
            else
            {
                //MessageBox.Show("未处理的Renderer类型:  " + renderer.GetType().FullName);
            }
        }