Reichrh 2022-11-30 19:06
浏览 4
已结题

ArcEngine二次开发利用trackbar进行矢量图层实时渲染

ArcEngine想要不依靠按钮完成矢量图层的简单渲染

img

主窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;

namespace GIS软件
{
    public partial class FormGIS : Form
    {
        public FormGIS(/*string Form_name*/)
        {
            InitializeComponent();
            //this.Text = Form_name;
            //this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void FormGIS_Load(object sender, EventArgs e)
        {

        }

        private void 输入矢量文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ofDShp.ShowDialog() == DialogResult.OK)
            {
                //string sFile = ofDShp.FileName;
                //string sFile_path = sFile.Substring(0, sFile.LastIndexOf('\\'));
                //string sFile_name = sFile.Substring(sFile.LastIndexOf('\\') + 1);

                FileInfo sFile = new FileInfo(ofDShp.FileName);

                //string sFile_path = sFile.Directory.ToString();
                string sFile_path = sFile.DirectoryName;
                string sFile_name = sFile.Name;

                axMapControl1.AddShapeFile(sFile_path, sFile_name);

            }
            axMapControl1.Refresh();
        }
        private void 简单渲染HSVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormHSV hsvFsimpleRender = new FormHSV(this.axMapControl1);

            //hsvFsimpleRender.Show();

            if (hsvFsimpleRender.ShowDialog() == DialogResult.OK)
            {


                IHsvColor hsvFeature = new HsvColor();
                hsvFeature.Hue = hsvFsimpleRender.H;
                hsvFeature.Saturation = hsvFsimpleRender.S;
                hsvFeature.Value = hsvFsimpleRender.V;

                ISimpleFillSymbol sfsFeature = new SimpleFillSymbol();
                sfsFeature.Style = esriSimpleFillStyle.esriSFSSolid;

                sfsFeature.Outline.Width = 1;
                sfsFeature.Color = hsvFeature as IColor;

                ISimpleRenderer srFeature = new SimpleRenderer();
                srFeature.Symbol = sfsFeature as ISymbol;

                IFeatureLayer flWord = null; /*axMapControl1.get_Layer(0) as IFeatureLayer;*/
                int IlayerCount = axMapControl1.LayerCount;
                for (int i = 0; i < IlayerCount; i++)
                {
                    ILayer iLayerTemp = axMapControl1.get_Layer(i);
                    if (hsvFsimpleRender.Strlayername == iLayerTemp.Name)
                    {
                        flWord = iLayerTemp as IFeatureLayer;
                    }
                }

                //if (flWord == null)
                //{
                //    MessageBox.Show("您当前选择的图层不是矢量图层,请重新选择后,在进行渲染!");
                //    return;
                //}

                IGeoFeatureLayer gflWord = flWord as IGeoFeatureLayer;
                gflWord.Renderer = srFeature as IFeatureRenderer;

                axMapControl1.Refresh();

            }
        }
    }
}
调用的简单渲染HSV窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;

namespace GIS软件
{
    public partial class FormHSV : Form
    {
        AxMapControl axMapControl1;

        string m_StrlayerName;
        int m_iundH;
        int m_iundS;
        int m_iundV;

        public string Strlayername
        {
            get
            {
                return m_StrlayerName = CBlayers.Text;
            }
            set
            {
                m_StrlayerName = value;
            }

        }
        public int H
        {
            get
            {
                return m_iundH = tbH.Value;
            }
            set
            {
                m_iundH = value;
            }

        }

        public int S
        {
            get
            {
                return m_iundS = tbS.Value;
            }
            set
            {
                m_iundS = value;
            }

        }

        public int V
        {
            get
            {
                return m_iundV = tbV.Value;
            }
            set
            {
                m_iundV = value;
            }

        }

        public FormHSV()
        {
            InitializeComponent();
        }
        public FormHSV(AxMapControl mapForRender)
        {
            InitializeComponent();

            axMapControl1 = mapForRender;
        }

        private void FormHSV_Load(object sender, EventArgs e)
        {
            int IlayerCount = axMapControl1.LayerCount;
            for (int i = 0; i < IlayerCount; i++)
            {
                string sLayerName = axMapControl1.get_Layer(i).Name;
                CBlayers.Items.Add(sLayerName as object);
            }
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            m_StrlayerName = CBlayers.Text;
            m_iundH = tbH.Value;
            m_iundS = tbS.Value;
            m_iundV = tbV.Value;

            this.DialogResult = DialogResult.OK;

        }

        private void btNO_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void tbH_Scroll(object sender, EventArgs e)
        {
            //MessageBox.Show(tbH.Value.ToString());
            m_StrlayerName = CBlayers.Text;
            m_iundH = tbH.Value;
            m_iundS = tbS.Value;
            m_iundV = tbV.Value;


        }
    }
}
不利用按钮直接滑动trackbar的滑块就可以实时改变图层颜色
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 12月8日
    • 创建了问题 11月30日

    悬赏问题

    • ¥15 PointNet++的onnx模型只能使用一次
    • ¥20 西南科技大学数字信号处理
    • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
    • ¥30 STM32 INMP441无法读取数据
    • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
    • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
    • ¥15 用visualstudio2022创建vue项目后无法启动
    • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
    • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
    • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。