Exemple #1
0
        private void ShowWind_Click(object sender, EventArgs e)
        {
            ILayer        pLayer        = MainMap.get_Layer(0);
            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

            int indexDir   = pFeatureClass.Fields.FindField("Dir");
            int indexSpeed = pFeatureClass.Fields.FindField("Speed");

            ISymbol          pSymbol          = AOUtil.FetchSymbol("dir");
            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
            ISimpleRenderer  pSimpleRenderer  = pGeoFeatureLayer.Renderer as ISimpleRenderer;

            pSimpleRenderer.Symbol = pSymbol;

            IRotationRenderer pRotationRender = pSimpleRenderer as IRotationRenderer;

            pRotationRender.RotationField = "dir";

            ISizeRenderer pSizeRender = pSimpleRenderer as ISizeRenderer;

            pSizeRender.SizeRendererExpression = "[Speed]";
            pSizeRender.SizeRendererFlags      = 1;

            MainMap.Refresh();
        }
Exemple #2
0
        protected void simpleRender(IFeatureLayer layer, IColor borderColor, double borderWidth)
        {
            ISimpleRenderer  simpleRender = null;
            IFillSymbol      fillSymbol   = null;
            ILineSymbol      lineSymbol   = null;
            IColor           fillColor    = null;
            IGeoFeatureLayer geoLayer     = null;

            if (layer != null && borderColor != null)
            {
                fillColor           = new RgbColorClass();
                fillColor.NullColor = true;

                fillSymbol       = new SimpleFillSymbolClass();
                lineSymbol       = new SimpleLineSymbolClass();
                fillSymbol.Color = fillColor;

                lineSymbol.Color   = borderColor;
                lineSymbol.Width   = borderWidth;
                fillSymbol.Outline = lineSymbol;

                geoLayer = layer as IGeoFeatureLayer;
                if (geoLayer != null)
                {
                    simpleRender        = new SimpleRendererClass();
                    simpleRender.Symbol = fillSymbol as ISymbol;
                    geoLayer.Renderer   = simpleRender as IFeatureRenderer;
                }
            }
        }
        private void 生成等高线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取TIN图层
            ITinLayer pTinLayer           = axSceneControl1.Scene.get_Layer(0) as ITinLayer;
            ITin      pTin                = pTinLayer.Dataset as ITin;
            string    contourFileName     = pTinLayer.Name + "_Contour";
            string    contourFileName_shp = WorkSpaceName + @"/" + contourFileName + ".shp";

            if (System.IO.File.Exists(contourFileName_shp))
            {
                System.IO.File.Delete(contourFileName_shp);
                System.IO.File.Delete(System.IO.Path.ChangeExtension(contourFileName_shp, ".dbf"));
                System.IO.File.Delete(System.IO.Path.ChangeExtension(contourFileName_shp, ".shx"));
            }
            IFeatureClass contourFeatureClass = Create_ContourLine(pTin, WorkSpaceName, contourFileName);
            //添加等高线图层
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = contourFeatureClass;
            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;

            pGeoFeatureLayer.DisplayAnnotation = true;
            pGeoFeatureLayer.DisplayField      = "Contour";
            pGeoFeatureLayer.Name = contourFileName + "_Contour";
            //设置线样式
            ILineSymbol pLineSymbol = new SimpleLineSymbolClass();

            pLineSymbol.Color = Get_RGBColor(100, 50, 30);
            pLineSymbol.Width = 2;
            ISimpleRenderer pRender = pGeoFeatureLayer.Renderer as ISimpleRenderer;

            pRender.Symbol = pLineSymbol as ISymbol;
            axMapControl1.AddLayer(pFeatureLayer as ILayer);
        }
Exemple #4
0
        public RenderLayerPoint(IFeatureLayer featureLayer, MainForm frm)
        {
            InitializeComponent();
            m_featureLayer = featureLayer;
            m_fraMain      = frm;

            //Get properties of the current symbol
            IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
            IFeatureRenderer featureRenderer = geoFeatureLayer.Renderer;

            if (featureRenderer is ISimpleRenderer)
            {
                ISimpleRenderer     simpleRenderer     = geoFeatureLayer.Renderer as ISimpleRenderer;
                ISimpleMarkerSymbol simpleMarkerSymbol = simpleRenderer.Symbol as ISimpleMarkerSymbol;

                if (simpleMarkerSymbol != null)
                {
                    //Get the current size of points
                    tbSize.Text = simpleMarkerSymbol.Size.ToString();

                    //Get the current color of points
                    IRgbColor rgbColor = new RgbColorClass();
                    rgbColor     = simpleMarkerSymbol.Color as IRgbColor;
                    tbRed.Text   = rgbColor.Red.ToString();
                    tbGreen.Text = rgbColor.Green.ToString();
                    tbBlue.Text  = rgbColor.Blue.ToString();

                    //Change the value of track bar
                    tkbSize.Value = int.Parse(tbSize.Text);
                }
            }
        }
Exemple #5
0
        private void mnuSymbol_Click(object sender, EventArgs e)
        {
            ILayer pLayer = MainMap.get_Layer(0);

            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
            IFeatureRenderer pFeatureRender   = pGeoFeatureLayer.Renderer;
            ISimpleRenderer  pSimpleRender    = pFeatureRender as ISimpleRenderer;

            ILineFillSymbol pLineFillSymbol = new LineFillSymbolClass();
            ILineSymbol     pLineSymbol     = new SimpleLineSymbolClass();

            IRgbColor pRgbColor = new RgbColorClass();

            pRgbColor.Red   = 96;
            pRgbColor.Green = 96;
            pRgbColor.Blue  = 196;

            pLineSymbol.Color          = pRgbColor as IColor;
            pLineSymbol.Width          = 2;
            pLineFillSymbol.LineSymbol = pLineSymbol;
            pLineFillSymbol.Outline    = pLineSymbol;

            pSimpleRender.Symbol = pLineFillSymbol as ISymbol;
            MainMap.ActiveView.Refresh();
        }
        public void Apply()
        {
            this.isimpleRenderer_0.Label       = this.txtLabel.Text;
            this.isimpleRenderer_0.Description = this.txtDescription.Text;
            IObjectCopy     copy     = new ObjectCopyClass();
            ISimpleRenderer renderer = copy.Copy(this.isimpleRenderer_0) as ISimpleRenderer;

            this.igeoFeatureLayer_0.Renderer = renderer as IFeatureRenderer;
        }
Exemple #7
0
        //
        public void ApplySimple(IGeoFeatureLayer geoLayer, ISymbol aSymbol)
        {
            //SimpleRender is not engaged with feature data
            //Old code
            // ISimpleRenderer simpleRender = new SimpleRenderer();
            //geoLayer.Renderer = simpleRender as IFeatureRenderer;
            //Get the render of the GeoFeatureLayer
            ISimpleRenderer simpleRender = geoLayer.Renderer as ISimpleRenderer;

            simpleRender.Symbol = aSymbol as ISymbol;
            axMapControl1.ActiveView.Refresh();
            axTOCControl1.Update();
        }
Exemple #8
0
        private static void Render_tool(ISimpleRenderer pSimpleRenderer, string filename)
        {
            //提供要素图层对成员控制地理特征渲染的入口,获取渲染图层
            IGeoFeatureLayer pGeoFeatureLayer = getGeoLayer(filename);

            if (pGeoFeatureLayer != null)
            {
                //调用Renderer属性, 具体说明如何通过图层要素渲染器渲染图层
                pGeoFeatureLayer.Renderer = pSimpleRenderer as IFeatureRenderer;
            }
            CSR_mapControl.ActiveView.ContentsChanged();
            CSR_mapControl.ActiveView.Refresh();
        }
        /// <summary>
        /// 设置要素图片显示样式
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <param name="pictureName"></param>
        /// <param name="size"></param>
        public static void SetFeaturePictureSymbol(IFeatureLayer featureLayer, string pictureName, int size)
        {
            IGeoFeatureLayer     geoLayer     = featureLayer as IGeoFeatureLayer;
            IPictureMarkerSymbol pPicturemksb = CreatePictureSymbol(pictureName, size);
            ISimpleRenderer      simpleRender = geoLayer.Renderer as ISimpleRenderer;

            if (simpleRender == null)
            {
                simpleRender = new SimpleRendererClass();
            }
            simpleRender.Symbol = pPicturemksb as ISymbol;
            geoLayer.Renderer   = simpleRender as IFeatureRenderer;
        }
Exemple #10
0
 //修改符号角度
 public static void Angle_Symbol(ILayer layer, double angle)
 {
     try
     {
         IGeoFeatureLayer geoFeatureLayer;
         geoFeatureLayer = layer as IGeoFeatureLayer;
         ISimpleRenderer simpleRenderer = (ISimpleRenderer)geoFeatureLayer.Renderer;
         IMarkerSymbol   mark           = simpleRenderer.Symbol as IMarkerSymbol;
         mark.Angle = angle;
         geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer;
     }
     catch { }
 }
Exemple #11
0
        public static IFeatureRenderer  HideSymbolOfLayer(IGeoFeatureLayer pGeoFeatureLayer)
        {
            IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;

            ISymbol pSymbol = null;

            if (pFeatureRenderer is ISimpleRenderer)
            {
                ISimpleRenderer pSimpleRender = pFeatureRenderer as ISimpleRenderer;
                pSimpleRender.Symbol = null;
                //pSymbol = pSimpleRender.Symbol;
                //SetSymbolNoColor(pGeoFeatureLayer, ref pSymbol);
                //pSimpleRender.Symbol = pSymbol;
                return(pSimpleRender as IFeatureRenderer);
            }
            else if (pFeatureRenderer is IUniqueValueRenderer)
            {
                IUniqueValueRenderer pUniqueRender = pFeatureRenderer as IUniqueValueRenderer;

                for (int i = 0; i < pUniqueRender.ValueCount; i++)
                {
                    string sValue = pUniqueRender.get_Value(i);
                    pUniqueRender.set_Symbol(sValue, null);
                    //pSymbol = pUniqueRender.get_Symbol(sValue);
                    //SetSymbolNoColor(pGeoFeatureLayer, ref pSymbol);
                    //pUniqueRender.set_Symbol(sValue, pSymbol);
                }
                return(pUniqueRender as IFeatureRenderer);
            }
            else if (pFeatureRenderer is IClassBreaksRenderer)
            {
                IClassBreaksRenderer pClassRenderer = pFeatureRenderer as IClassBreaksRenderer;
                for (int i = 0; i < pClassRenderer.BreakCount; i++)
                {
                    pClassRenderer.set_Symbol(i, null);
                }
                pClassRenderer.BackgroundSymbol = null;
                return(pClassRenderer as IFeatureRenderer);
            }
            else if (pFeatureRenderer is IProportionalSymbolRenderer)
            {
            }
            else if (pFeatureRenderer is IChartRenderer)
            {
                IChartRenderer pChartRenderer = pFeatureRenderer as IChartRenderer;
                pChartRenderer.BaseSymbol  = null;
                pChartRenderer.ChartSymbol = null;
            }
            return(null);
        }
Exemple #12
0
        private static IGeoFeatureLayer PointsRender(IFeatureLayer layer, RgbColor color, IObjectFactory objFactory)
        {
            Type   renderType   = typeof(SimpleRendererClass);
            string typeRenderID = renderType.GUID.ToString("B");

            ISimpleRenderer renderer = (ISimpleRenderer)objFactory.Create(typeRenderID);

            renderer.Symbol = GetSymbol(esriGeometryType.esriGeometryPoint, color, objFactory);

            IGeoFeatureLayer geoFL = layer as IGeoFeatureLayer;

            geoFL.Renderer = renderer as IFeatureRenderer;

            return(geoFL);
        }
        /// <summary>
        /// 设置要素图片填充
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <param name="pictureName"></param>
        public static void SetFeaturePictureFillSymbol(IFeatureLayer featureLayer, string pictureName)
        {
            IGeoFeatureLayer   geoLayer    = featureLayer as IGeoFeatureLayer;
            IPictureFillSymbol pFillSymbol = new PictureFillSymbolClass();

            pFillSymbol.CreateFillSymbolFromFile(esriIPictureType.esriIPicturePNG, pictureName);
            ISimpleRenderer simpleRender = geoLayer.Renderer as ISimpleRenderer;

            if (simpleRender == null)
            {
                simpleRender = new SimpleRendererClass();
            }
            simpleRender.Symbol = pFillSymbol as ISymbol;
            geoLayer.Renderer   = simpleRender as IFeatureRenderer;
        }
        /// <summary>
        /// 设置图层颜色
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="red"></param>
        /// <param name="blue"></param>
        /// <param name="green"></param>
        public static void SetLayerColor(ILayer layer, int red, int blue, int green)
        {
            IGeoFeatureLayer geoLayer      = layer as IGeoFeatureLayer;
            IFeatureRenderer featureRender = geoLayer.Renderer;
            ILineSymbol      pOutline      = new SimpleLineSymbolClass();

            pOutline.Color = SymbolUtil.GetColor(red, green, blue);
            // ISimpleRenderer pSimpleRenderer = new SimpleRendererClass()
            ISimpleRenderer pSimpleRenderer = featureRender as ISimpleRenderer;

            pSimpleRenderer.Label       = "NAME";
            pSimpleRenderer.Description = "ss";
            pSimpleRenderer.Symbol      = (ISymbol)pOutline;
            // pSimpleRenderer.a
            geoLayer.Renderer = pSimpleRenderer as IFeatureRenderer;
        }
Exemple #15
0
        private void SimpleRendererPolygon()
        {
            simpleRenderer = (ISimpleRenderer)featureRenderer;
            symbol         = simpleRenderer.Symbol;
            fillSymbol     = (IFillSymbol)symbol;

            fillColor    = ColorTranslator.FromOle(fillSymbol.Color.RGB);
            fillColorHEX = String.Format("#{0:X6}", fillColor.ToArgb() & 0x00FFFFFF);

            outlineColor    = ColorTranslator.FromOle(fillSymbol.Outline.Color.RGB);
            outlineColorHEX = String.Format("#{0:X6}", outlineColor.ToArgb() & 0x00FFFFFF);

            outlineWidth = fillSymbol.Outline.Width.ToString().Replace(",", ".");

            ExportSLD(labelOpenOrClosed);
        }
Exemple #16
0
        private void InitRendererObject(IFeatureRenderer pRenderer, esriSymbologyStyleClass _SymbologyStyleClass)
        {
            m_SymbologyStyleClass = _SymbologyStyleClass;
            ISimpleRenderer pSimpleRenderer = pRenderer as ISimpleRenderer;

            txtName.Text = pSimpleRenderer.Label;
            txtDesc.Text = pSimpleRenderer.Description;
            if (pSimpleRenderer.Symbol == null)
            {
                labelPreviewFore.Tag = ModuleCommon.CreateSymbol(m_SymbologyStyleClass);
            }
            else
            {
                labelPreviewFore.Tag = pSimpleRenderer.Symbol;
            }
            labelPreviewFore.Image = ModuleCommon.Symbol2Picture(labelPreviewFore.Tag as ISymbol, ModuleCommon.ImageWidth, ModuleCommon.ImageHeight);
        }
Exemple #17
0
        private void mnuColor_Click(object sender, EventArgs e)
        {
            ILayer pLayer = MainMap.get_Layer(0);

            IGeoFeatureLayer  pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
            IFeatureRenderer  pFeatureRender   = pGeoFeatureLayer.Renderer;
            ISimpleRenderer   pSimpleRender    = pFeatureRender as ISimpleRenderer;
            ISimpleFillSymbol pSym             = pSimpleRender.Symbol as ISimpleFillSymbol;

            IRgbColor pRGBColor = new RgbColorClass();

            pRGBColor.Red   = 200;
            pRGBColor.Green = 10;
            pRGBColor.Blue  = 50;

            pSym.Color = pRGBColor as IColor;
            MainMap.ActiveView.Refresh();
        }
Exemple #18
0
        public RenderLayerFill(IFeatureLayer featureLayer, MainForm frm)
        {
            InitializeComponent();
            m_featureLayer = featureLayer;
            m_fraMain      = frm;

            //Get properties of the current symbol
            IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
            IFeatureRenderer featureRenderer = geoFeatureLayer.Renderer;

            if (featureRenderer is ISimpleRenderer)
            {
                ISimpleRenderer   simpleRenderer   = geoFeatureLayer.Renderer as ISimpleRenderer;
                ISimpleFillSymbol simpleFillSymbol = simpleRenderer.Symbol as ISimpleFillSymbol;

                if (simpleFillSymbol != null)
                {
                    //Get the width of outline
                    tbOutlineWidth.Text = simpleFillSymbol.Outline.Width.ToString();


                    //Get the fill color
                    IRgbColor rgbColorFill = new RgbColorClass();
                    rgbColorFill     = simpleFillSymbol.Color as IRgbColor;
                    tbRedFill.Text   = rgbColorFill.Red.ToString();
                    tbGreenFill.Text = rgbColorFill.Green.ToString();
                    tbBlueFill.Text  = rgbColorFill.Blue.ToString();

                    //Get the color of outline
                    IRgbColor rgbColorOutline = new RgbColorClass();
                    rgbColorOutline     = simpleFillSymbol.Outline.Color as IRgbColor;
                    tbRedOutline.Text   = rgbColorOutline.Red.ToString();
                    tbGreenOutline.Text = rgbColorOutline.Green.ToString();
                    tbBlueOutline.Text  = rgbColorOutline.Blue.ToString();

                    //Change the value of track bar
                    tkbOutlineWidth.Value = (int)System.Convert.ToDouble(tbOutlineWidth.Text);
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// 获取指定图层,指定类型的符号
        /// </summary>
        /// <param name="pfLayer">图层</param>
        /// <param name="subtype">类型</param>
        /// <returns></returns>
        public static ISymbol GetLayerSymbol(IFeatureLayer pfLayer, string subtype)
        {
            IGeoFeatureLayer pGeoFLayer = pfLayer as IGeoFeatureLayer;
            IFeatureRenderer pfRenderer = pGeoFLayer.Renderer;

            if (subtype == "")
            {
                ISimpleRenderer pSimpleRenderer = pfRenderer as ISimpleRenderer;
                if (pSimpleRenderer != null)
                {
                    return(pSimpleRenderer.Symbol);
                }
            }

            IUniqueValueRenderer pUniqueRenderer = pfRenderer as IUniqueValueRenderer;

            if (pUniqueRenderer != null)
            {
                return(pUniqueRenderer.get_Symbol(subtype));
            }

            return(null);
        }
Exemple #20
0
        //目前只支持简单符号和质地填充符号
        public static IFeatureRenderer SetColorOfRenderer(IGeoFeatureLayer pGeoFeatureLayer, IRgbColor pFillRgbColor,
                                                          IRgbColor pBorderColor, double PointSize, double LineWidth)
        {
            IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
            ISymbol          pSymbol          = null;

            if (pFeatureRenderer is ISimpleRenderer)
            {
                ISimpleRenderer pSimpleRender = pFeatureRenderer as ISimpleRenderer;
                pSymbol = pSimpleRender.Symbol;
                SetSymbolColor(pGeoFeatureLayer, ref pSymbol, pFillRgbColor, pBorderColor, PointSize, LineWidth);
                pSimpleRender.Symbol = pSymbol;
                return(pSimpleRender as IFeatureRenderer);
            }
            else if (pFeatureRenderer is IUniqueValueRenderer)
            {
                IUniqueValueRenderer pUniqueRender = pFeatureRenderer as IUniqueValueRenderer;
                for (int i = 0; i < pUniqueRender.ValueCount; i++)
                {
                    string sValue = pUniqueRender.get_Value(i);
                    pSymbol = pUniqueRender.get_Symbol(sValue);
                    SetSymbolColor(pGeoFeatureLayer, ref pSymbol, pFillRgbColor, pBorderColor, PointSize, LineWidth);
                    pUniqueRender.set_Symbol(sValue, pSymbol);
                }
                return(pUniqueRender as IFeatureRenderer);
            }
            else if (pFeatureRenderer is IClassBreaksRenderer)
            {
            }
            else if (pFeatureRenderer is IProportionalSymbolRenderer)
            {
            }
            else if (pFeatureRenderer is IChartRenderer)
            {
            }
            return(null);
        }
Exemple #21
0
        //打开符号系统界面;
        private void 修改符号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (pesriGeometryTyp)
            {
            case esriGeometryType.esriGeometryPoint:
                ToolStripMenuItem5.Enabled = false;
                IGeoFeatureLayer    pGeoFeatureLayer    = layer_Toccontrol as IGeoFeatureLayer;
                ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();

                ISimpleRenderer     ppSimpleRenderer = pGeoFeatureLayer.Renderer as ISimpleRenderer;
                ISimpleMarkerSymbol ppSymbol         = ppSimpleRenderer.Symbol as ISimpleMarkerSymbol;
                size   = ppSymbol.Size;
                pcolor = ppSymbol.Color;
                angle  = ppSymbol.Angle;

                //选择符号的大小,颜色,符号类型
                Form symbol = new symbol(ToolStripMenuItem5, pcolor, size, angle);
                symbol.ShowDialog();

                pSimpleMarkerSymbol.Size  = size;
                pSimpleMarkerSymbol.Color = pcolor;
                pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                pSimpleMarkerSymbol.Angle = angle;

                ISimpleRenderer pSimpleRenderer = new SimpleRenderer();
                pSimpleRenderer.Symbol = pSimpleMarkerSymbol as ISymbol;

                pGeoFeatureLayer.Renderer = pSimpleRenderer as IFeatureRenderer;

                mapcontrol.Refresh();
                axTOCControl1.Update();
                break;

            default: break;
            }
        }
Exemple #22
0
        private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {
            try
            {
                esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                IBasicMap          map = null; ILayer layer = null;
                object             other = null; object index = null;

                //Determine what kind of item is selected
                m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

                if (item == esriTOCControlItem.esriTOCControlItemNone)
                {
                    return;
                }

                // Load TOC context menu
                if (e.button == 2)
                {
                    if (item == esriTOCControlItem.esriTOCControlItemMap)
                    {
                        m_tocControl.SelectItem(map, null);
                    }
                    else
                    {
                        m_tocControl.SelectItem(layer, null);
                    }

                    //Set the layer into the CustomProperty (this is used by the custom layer commands)
                    m_mapControl.CustomProperty = layer;

                    //Popup the correct context menu
                    if (item == esriTOCControlItem.esriTOCControlItemMap)
                    {
                        return;
                    }
                    if (item == esriTOCControlItem.esriTOCControlItemLayer)
                    {
                        m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd);
                    }
                }
                //Ensure the item gets selected

                //Load Simple Color pallette 071017 HK
                if (e.button == 1 && item == esriTOCControlItem.esriTOCControlItemLegendClass)
                {
                    IFeatureLayer    featureLayer    = layer as IFeatureLayer;
                    IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;

                    DialogResult DR;
                    if (geoFeatureLayer.Renderer is ISimpleRenderer) // Only apply this function to simple Renderer
                    {
                        DR = cdColor.ShowDialog();
                    }
                    else
                    {
                        return;
                    }

                    IRgbColor pRGBcolor = new RgbColorClass();
                    if (DR == DialogResult.OK)
                    {
                        pRGBcolor = m_pSnippet.getRGB(cdColor.Color.R, cdColor.Color.G, cdColor.Color.B);
                    }

                    ISimpleRenderer simpleRenderer = (ISimpleRenderer)geoFeatureLayer.Renderer;

                    ISymbol pSymbol = simpleRenderer.Symbol;

                    //Update only color
                    switch (featureLayer.FeatureClass.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        ISimpleMarkerSymbol pSimpleMarkerSymobl = (ISimpleMarkerSymbol)pSymbol;
                        pSimpleMarkerSymobl.Color = (IColor)pRGBcolor;
                        pSymbol = (ISymbol)pSimpleMarkerSymobl;
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        ISimpleLineSymbol pSimpleLineSymobl = (ISimpleLineSymbol)pSymbol;
                        pSimpleLineSymobl.Color = (IColor)pRGBcolor;
                        pSymbol = (ISymbol)pSimpleLineSymobl;
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        ISimpleFillSymbol pSimpleFillSymobl = (ISimpleFillSymbol)pSymbol;
                        pSimpleFillSymobl.Color = (IColor)pRGBcolor;
                        pSymbol = (ISymbol)pSimpleFillSymobl;

                        break;
                    }
                    simpleRenderer.Symbol    = pSymbol;
                    geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer;
                    m_tocControl.ActiveView.ContentsChanged();
                    m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemple #23
0
        public static List <YTEditTemplate> Create(IFeatureLayer ifeatureLayer_0)
        {
            YTEditTemplate        jLKEditTemplate;
            int                   i;
            string                field;
            List <YTEditTemplate> jLKEditTemplates;
            List <YTEditTemplate> jLKEditTemplates1 = new List <YTEditTemplate>();

            if (ifeatureLayer_0 is IGeoFeatureLayer)
            {
                IGeoFeatureLayer ifeatureLayer0 = ifeatureLayer_0 as IGeoFeatureLayer;
                if (ifeatureLayer0.Renderer is ISimpleRenderer)
                {
                    ISimpleRenderer renderer = ifeatureLayer0.Renderer as ISimpleRenderer;
                    jLKEditTemplate = new YTEditTemplate();
                    jLKEditTemplate.Init(ifeatureLayer_0);
                    jLKEditTemplate.Symbol = (renderer.Symbol as IClone).Clone() as ISymbol;
                    jLKEditTemplate.InitBitmap();
                    jLKEditTemplates1.Add(jLKEditTemplate);
                }
                else if (!(ifeatureLayer0.Renderer is IUniqueValueRenderer))
                {
                    jLKEditTemplate = new YTEditTemplate();
                    jLKEditTemplate.Init(ifeatureLayer_0);
                    jLKEditTemplate.InitBitmap();
                    jLKEditTemplates1.Add(jLKEditTemplate);
                }
                else
                {
                    EditTemplateSchems   editTemplateSchem   = new EditTemplateSchems();
                    IUniqueValueRenderer uniqueValueRenderer = ifeatureLayer0.Renderer as IUniqueValueRenderer;
                    for (i = 0; i < uniqueValueRenderer.FieldCount; i++)
                    {
                        field = uniqueValueRenderer.Field[i];
                        editTemplateSchem.AddField(field);
                    }
                    EditTemplateSchem symbol = new EditTemplateSchem();
                    for (int j = 0; j < uniqueValueRenderer.ValueCount; j++)
                    {
                        symbol = new EditTemplateSchem();
                        string value = uniqueValueRenderer.Value[j];
                        jLKEditTemplate = new YTEditTemplate();
                        jLKEditTemplate.Init(ifeatureLayer_0);
                        jLKEditTemplate.Symbol = (uniqueValueRenderer.Symbol[value] as IClone).Clone() as ISymbol;
                        jLKEditTemplate.Name   = uniqueValueRenderer.Heading[value];
                        symbol.Symbol          = jLKEditTemplate.Symbol;
                        symbol.Value           = value;
                        symbol.Label           = uniqueValueRenderer.Label[value];
                        symbol.Description     = uniqueValueRenderer.Description[value];
                        if (uniqueValueRenderer.FieldCount != 1)
                        {
                            string[] strArrays = value.Split(uniqueValueRenderer.FieldDelimiter.ToCharArray());
                            for (i = 0; i < uniqueValueRenderer.FieldCount; i++)
                            {
                                field = uniqueValueRenderer.Field[i];
                                string str = strArrays[i].Trim();
                                if (str.Length > 0)
                                {
                                    jLKEditTemplate.SetFieldValue(field, str);
                                }
                                symbol.Add(field, str);
                            }
                        }
                        else
                        {
                            string field1 = uniqueValueRenderer.Value[0];
                            jLKEditTemplate.SetFieldValue(field1, value);
                            symbol.Add(field1, value);
                        }
                        editTemplateSchem.Add(symbol);
                        jLKEditTemplate.InitBitmap();
                        jLKEditTemplate.EditTemplateSchems = editTemplateSchem;
                        jLKEditTemplates1.Add(jLKEditTemplate);
                    }
                }
            }
            else if (ifeatureLayer_0.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
            {
                IAnnoClass        extension        = ifeatureLayer_0.FeatureClass.Extension as IAnnoClass;
                ISymbolCollection symbolCollection = extension.SymbolCollection;
                IAnnotateLayerPropertiesCollection2 annoProperties =
                    extension.AnnoProperties as IAnnotateLayerPropertiesCollection2;
                symbolCollection.Reset();
                for (ISymbolIdentifier k = symbolCollection.Next(); k != null; k = symbolCollection.Next())
                {
                    jLKEditTemplate = new YTEditTemplate();
                    jLKEditTemplate.Init(ifeatureLayer_0);
                    jLKEditTemplate.Symbol = (k.Symbol as IClone).Clone() as ISymbol;
                    jLKEditTemplate.Name   = annoProperties.Properties[k.ID].Class;
                    jLKEditTemplate.SetFieldValue("SymbolID", k.ID.ToString());
                    jLKEditTemplate.InitBitmap();
                    jLKEditTemplates1.Add(jLKEditTemplate);
                }
            }
            if (jLKEditTemplates1.Count <= 0)
            {
                jLKEditTemplates = null;
            }
            else
            {
                jLKEditTemplates = jLKEditTemplates1;
            }
            return(jLKEditTemplates);
        }
 private static void RandomizeMarkerColor(ISimpleRenderer renderer)
 {
     var symbol = renderer.Symbol as IMarkerSymbol;
     if (symbol != null)
         symbol.Color = RandomColor();
 }
Exemple #25
0
        public override void InitRendererObject(IFeatureRenderer _Renderer, esriSymbologyStyleClass _SymbologyStyleClass)
        {
            m_SymbologyStyleClass = _SymbologyStyleClass;

            ISimpleRenderer _SimpleRenderer = null;

            if ((_Renderer is ISimpleRenderer) == false)
            {
                _SimpleRenderer             = new SimpleRendererClass();
                _SimpleRenderer.Label       = "";
                _SimpleRenderer.Description = "";
                _SimpleRenderer.Symbol      = ModuleCommon.CreateSymbol(_SymbologyStyleClass);
            }
            else
            {
                _SimpleRenderer = _Renderer as ISimpleRenderer;
            }

            #region RendererName

            m_RendererName               = new StringValue();
            m_RendererName.ControlName   = "RendererName";
            m_RendererName.Caption       = "Ãû³Æ";
            m_RendererName.ControlWidth  = 100;
            m_RendererName.ControlHeight = 23;
            m_RendererName.DataValue     = _SimpleRenderer.Label;

            DevComponents.AdvTree.Node node = new DevComponents.AdvTree.Node();
            node.Text = m_RendererName.Caption;
            node.Name = "node" + m_RendererName.ControlName;
            DevComponents.AdvTree.Cell cell = new DevComponents.AdvTree.Cell();
            cell.HostedControl = GetTextBox(m_RendererName);
            node.Cells.Add(cell);
            m_TreeProperty.Nodes.Add(node);

            #endregion

            #region RendererDesc

            m_RendererDesc               = new StringValue();
            m_RendererDesc.ControlName   = "RendererDesc";
            m_RendererDesc.Caption       = "ÃèÊö";
            m_RendererDesc.ControlWidth  = 100;
            m_RendererDesc.ControlHeight = 23;
            m_RendererDesc.DataValue     = _SimpleRenderer.Description;

            node               = new DevComponents.AdvTree.Node();
            node.Text          = m_RendererDesc.Caption;
            node.Name          = "node" + m_RendererDesc.ControlName;
            cell               = new DevComponents.AdvTree.Cell();
            cell.HostedControl = GetTextBox(m_RendererDesc);
            node.Cells.Add(cell);
            m_TreeProperty.Nodes.Add(node);

            #endregion

            #region ForeSymbol

            m_ForeSymbol               = new SymbolValue();
            m_ForeSymbol.ControlName   = "SimpleSymbol";
            m_ForeSymbol.Caption       = "·ûºÅ";
            m_ForeSymbol.ControlWidth  = 100;
            m_ForeSymbol.ControlHeight = 50;
            m_ForeSymbol.DataValue     = _SimpleRenderer.Symbol;

            node               = new DevComponents.AdvTree.Node();
            node.Text          = m_ForeSymbol.Caption;
            node.Name          = "node" + m_ForeSymbol.ControlName;
            cell               = new DevComponents.AdvTree.Cell();
            cell.HostedControl = GetSymbolButton(m_ForeSymbol);
            node.Cells.Add(cell);
            m_TreeProperty.Nodes.Add(node);

            #endregion
        }
Exemple #26
0
        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);
            }
        }
Exemple #27
0
        public override void OnClick()
        {
            ILayer layer = (ILayer)m_mapControl.CustomProperty;
            // m_mapControl.Extent = layer.AreaOfInterest;

            //IBasicMap map = new MapClass();
            //ILayer layer = new FeatureLayerClass();
            //object other = new Object();
            //object index = new Object();
            //esriTOCControlItem item = new esriTOCControlItem();

            //Determine what kind of item has been clicked on
            // axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

            //QI to IFeatureLayer and IGeoFeatuerLayer interface
            // if (layer == null) return;
            IFeatureLayer featureLayer = layer as IFeatureLayer;

            if (featureLayer == null)
            {
                return;
            }
            IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
            ISimpleRenderer  simpleRenderer  = null;

            if (geoFeatureLayer.Renderer is ISimpleRenderer)
            {
                simpleRenderer = (ISimpleRenderer)geoFeatureLayer.Renderer;
            }
            else
            {
                MessageBox.Show("demo½öÖ§³Ö¼òµ¥Í¼Àý");
                return;
            }

            //Create the form with the SymbologyControl
            RendererForm symbolForm = new RendererForm();

            //Get the IStyleGalleryItem
            IStyleGalleryItem styleGalleryItem = null;

            //Select SymbologyStyleClass based upon feature type
            switch (featureLayer.FeatureClass.ShapeType)
            {
            case esriGeometryType.esriGeometryPoint:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols, simpleRenderer.Symbol);
                break;

            case esriGeometryType.esriGeometryPolyline:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols, simpleRenderer.Symbol);
                break;

            case esriGeometryType.esriGeometryPolygon:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols, simpleRenderer.Symbol);
                break;
            }

            // Release the form
            // symbolForm.Close();
            symbolForm.Dispose();
            MainForm.Instance.Activate();

            if (styleGalleryItem == null)
            {
                return;
            }

            //Create a new renderer
            simpleRenderer = new SimpleRendererClass();
            //Set its symbol from the styleGalleryItem
            simpleRenderer.Symbol = (ISymbol)styleGalleryItem.Item;
            //Set the renderer into the geoFeatureLayer
            geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer;

            //Fire contents changed event that the TOCControl listens to
            IActiveView activeView = MapUtils.GetActiveView();

            activeView.ContentsChanged();
            activeView.Refresh();
            // axPageLayoutControl1.ActiveView.ContentsChanged();
            // Refresh the display
            // axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
        /// <summary>
        /// The add XY event layer.
        /// </summary>
        /// <param name="table">
        /// The table.
        /// </param>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <param name="tweetShow">
        /// The tweet show.
        /// </param>
        public static void AddXyEventLayer(ITable table, string query, bool tweetShow = true)
        {
            var mxdoc = ArcMap.Application.Document as IMxDocument;

            if (mxdoc != null)
            {
                var map = mxdoc.FocusMap;

                // Get the table named XYSample.txt
                var stTableCollection = map as IStandaloneTableCollection;

                // Get the table name object
                var dataset   = table as IDataset;
                var tableName = dataset.FullName;

                // Specify the X and Y fields
                var xyEvent2FieldsProperties = new XYEvent2FieldsProperties() as IXYEvent2FieldsProperties;
                if (xyEvent2FieldsProperties != null)
                {
                    xyEvent2FieldsProperties.XFieldName = "x";
                    xyEvent2FieldsProperties.YFieldName = "y";
                    xyEvent2FieldsProperties.ZFieldName = string.Empty;

                    // Specify the projection
                    var spatialReferenceFactory   = new SpatialReferenceEnvironment() as ISpatialReferenceFactory;
                    var projectedCoordinateSystem =
                        spatialReferenceFactory.CreateGeographicCoordinateSystem(
                            (int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

                    // Create the XY name object as set it's properties
                    var xyEventSourceName = new XYEventSourceName() as IXYEventSourceName;
                    xyEventSourceName.EventProperties  = xyEvent2FieldsProperties;
                    xyEventSourceName.SpatialReference = projectedCoordinateSystem;
                    xyEventSourceName.EventTableName   = tableName;

                    IName          xyName        = xyEventSourceName as IName;
                    IXYEventSource xyEventSource = xyName.Open() as IXYEventSource;

                    // Create a new Map Layer
                    IFeatureLayer featureLayer = new FeatureLayer() as IFeatureLayer;
                    featureLayer.FeatureClass = xyEventSource as IFeatureClass;
                    featureLayer.Name         = query;

                    // Add the layer extension (this is done so that when you edit
                    // the layer's Source properties and click the Set Data Source
                    // button, the Add XY Events Dialog appears)
                    ILayerExtensions          layerExtensions  = featureLayer as ILayerExtensions;
                    XYDataSourcePageExtension resPageExtension = new XYDataSourcePageExtension();
                    layerExtensions.AddExtension(resPageExtension);

                    IGeoFeatureLayer geoLayer       = (IGeoFeatureLayer)featureLayer;
                    ISimpleRenderer  simpleRenderer = (ISimpleRenderer)geoLayer.Renderer;

                    var randomNumber = NumberRandom.Next(0, Colors.Count - 1);
                    var color        = Colors[randomNumber];

                    IRgbColor rgbColor = new RgbColorClass();
                    rgbColor.Blue  = color.B;
                    rgbColor.Red   = color.R;
                    rgbColor.Green = color.G;

                    IMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass();
                    markerSymbol.Color    = rgbColor;
                    markerSymbol.Size     = 5;
                    simpleRenderer.Symbol = (ISymbol)markerSymbol;

                    try
                    {
                        map.AddLayer(featureLayer);
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error.Message);
                    }
                }
            }
        }
Exemple #29
0
        /// <summary>
        /// 设置图层渲染方式
        /// </summary>
        /// <param name="fetureLayer"></param>
        /// <param name="annotationField"></param>
        public static void SetLayerRenderer(IFeatureLayer fetureLayer, String annotationField = "")
        {
            IGeoFeatureLayer geoLayer = fetureLayer as IGeoFeatureLayer;

            if (geoLayer == null)
            {
                return;
            }

            IFeatureRenderer  renderer       = geoLayer.Renderer;
            IssArcGISRenderer ssRenderer     = new ssArcGISRendererClass();
            IFeatureClass     ipFeatureClass = geoLayer.FeatureClass;
            // 设置图层类型 0 点 1 线 2 面 3 注记
            int nLayerFeatureType  = 0;
            esriGeometryType stype = ipFeatureClass.ShapeType;

            if (stype == esriGeometryType.esriGeometryPoint || stype == esriGeometryType.esriGeometryMultipoint)
            {
                nLayerFeatureType = 0;
            }
            else if (stype == esriGeometryType.esriGeometryLine || stype == esriGeometryType.esriGeometryCircularArc ||
                     stype == esriGeometryType.esriGeometryEllipticArc || stype == esriGeometryType.esriGeometryBezier3Curve ||
                     stype == esriGeometryType.esriGeometryPath || stype == esriGeometryType.esriGeometryPolyline)
            {
                nLayerFeatureType = 1;
            }
            else
            {
                nLayerFeatureType = 2;
            }

            IFields ipFields = ipFeatureClass.Fields;
            // 判断是否为注记图层
            long textFieldIndex = -1;

            if (String.IsNullOrEmpty(annotationField))
            {
                annotationField = "注记内容";
            }

            textFieldIndex = ipFields.FindField(annotationField);
            if (nLayerFeatureType == 1 && textFieldIndex > -1)
            {
                nLayerFeatureType = 3;
            }

            ssRenderer.LayerFeatureType = nLayerFeatureType;

            // 设置符号显示视野区间(米)
            ssRenderer.SetSymbolLevel(0, 500);
            // 设置符号化模板名称
            ssRenderer.TemplateFileName = "广州基础地理模板_500.mdt";
            // 设置要素代码字段名
            ssRenderer.CodeFieldName = "要素代码";
            // 设置图形特征字段名
            ssRenderer.GraphicInfoFieldName = "图形特征";
            // 设置注记内容字段名
            ssRenderer.TextFieldName = "注记内容";
            // 设置控制点点名字段名
            ssRenderer.PointNameFieldName = "点名";
            // 设置高程字段名
            ssRenderer.ZFieldName = "高程";

            // 设置其它符号化所需字段名(^号分隔)
            ssRenderer.OhterUseFieldNames = "";
            // 设置符号模板字段名称与ArcGIS字段名称对照,格式: 模板字段1:ArcGIS字段1;模板字段2:ArcGIS字段2;...
            ssRenderer.FieldNameRelation = "";
            // 设置符号化显示状态 VARIANT_FALSE 骨架线 VARIANT_TRUE 符号化
            ssRenderer.UseFeatureDraw = true;
            // 设置是否使用符号化缓存 0 不使用 1 使用
            ssRenderer.SetUseCacheStatus(1);
            // 设置颜色使用状态 0 随符号描述 1 随实体 2 自定义
            ssRenderer.SetUseColorStatus(0);
            // 设置自定义颜色,只有颜色使用状态为2时有效
            ssRenderer.SetDrawObjCustomColor(0);

            ssRenderer.FeatureLayer = geoLayer;

            ssRenderer.FeatureClass = geoLayer.FeatureClass;
            ssRenderer.LayerName    = geoLayer.Name;
            ISimpleRenderer simpleRenderer = (ISimpleRenderer)renderer;

            ssRenderer.Symbol = simpleRenderer.Symbol;
            // 替换渲染器
            geoLayer.Renderer = (ESRI.ArcGIS.Carto.IFeatureRenderer)ssRenderer;
        }
Exemple #30
0
        private esriSymbologyStyleClass _symbolStyle; //符号样式的类型:点、线、面

        #endregion Fields

        #region Constructors

        public SymbolForm(ISimpleRenderer currentSimpleRender)
        {
            InitializeComponent();
            m_styleGalleryItem = new ServerStyleGalleryItemClass();
            m_styleGalleryItem.Item = (object)currentSimpleRender.Symbol;//窗体初始加载时显示当前图层的当前样式图标
        }
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            //Exit if not right mouse button
            if (e.button != 2)
            {
                return;
            }

            IBasicMap          map   = new MapClass();
            ILayer             layer = new FeatureLayerClass();
            object             other = new Object();
            object             index = new Object();
            esriTOCControlItem item  = new esriTOCControlItem();

            //Determine what kind of item has been clicked on
            axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

            //QI to IFeatureLayer and IGeoFeatuerLayer interface
            if (layer == null)
            {
                return;
            }
            IFeatureLayer featureLayer = layer as IFeatureLayer;

            if (featureLayer == null)
            {
                return;
            }
            IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
            ISimpleRenderer  simpleRenderer  = (ISimpleRenderer)geoFeatureLayer.Renderer;

            //Create the form with the SymbologyControl
            frmSymbol symbolForm = new frmSymbol();

            //Get the IStyleGalleryItem
            IStyleGalleryItem styleGalleryItem = null;

            //Select SymbologyStyleClass based upon feature type
            switch (featureLayer.FeatureClass.ShapeType)
            {
            case esriGeometryType.esriGeometryPoint:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols, simpleRenderer.Symbol);
                break;

            case esriGeometryType.esriGeometryPolyline:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols, simpleRenderer.Symbol);
                break;

            case esriGeometryType.esriGeometryPolygon:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols, simpleRenderer.Symbol);
                break;
            }

            //Release the form
            symbolForm.Dispose();
            this.Activate();

            if (styleGalleryItem == null)
            {
                return;
            }

            //Create a new renderer
            simpleRenderer = new SimpleRendererClass();
            //Set its symbol from the styleGalleryItem
            simpleRenderer.Symbol = (ISymbol)styleGalleryItem.Item;
            //Set the renderer into the geoFeatureLayer
            geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer;

            //Fire contents changed event that the TOCControl listens to
            axPageLayoutControl1.ActiveView.ContentsChanged();
            //Refresh the display
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Exemple #32
0
        private esriSymbologyStyleClass _symbolStyle;//符号样式的类型:点、线、面


        public SymbolForm(ISimpleRenderer currentSimpleRender)
        {
            InitializeComponent();
            m_styleGalleryItem      = new ServerStyleGalleryItemClass();
            m_styleGalleryItem.Item = (object)currentSimpleRender.Symbol;//窗体初始加载时显示当前图层的当前样式图标
        }