Arcgis二次开发-ArcEngine导出地图

地图导出为图片是一种将地图保存为图片格式文件的方法,它可以方便地在其他软件中进行浏览和打印,而无需打印出纸质地图。本系统设计使用了ExportMap类来实现局部导出功能,通过ExportMap类提供的这些各具特色的功能,用户可以轻松地将想要的地图内容截取出来,并进行灵活的处理和编辑。计算公式为:

 

具体逻辑为:

  1. 引入了 ESRI ArcGIS 的相关类库,用于地图的可视化、数据访问和分析等功能。
  2. 定义了一个名为 FmExportMap 的窗体类,用于地图导出操作。
  3. 类中定义了私有字段 pSavePath 用于保存导出路径,pActiveView 用于获取地图的当前视图,pGeometry 用于存储地图的几何要素,bRegion 用于标识是否为区域导出。
  4. 构造函数 FmExportMap 接受一个 AxPageLayoutControl 参数,初始化窗体,并设置 pActiveView
  5. 实现了窗体加载事件 FormExportMap_Load,在加载窗体时初始化窗体大小。
  6. 实现了导出按钮 btnExport_Click 的点击事件,首先检查是否设置了导出路径和分辨率,然后调用 ExportMap.ExportView 方法执行地图导出操作。
  7. 实现了选择导出路径按钮 btnExPath_Click 的点击事件,使用 SaveFileDialog 获取用户选择的导出路径,并更新 pSavePath
  8. 实现了分辨率下拉框 cboResolution_SelectedIndexChanged 的选中事件,根据选中的分辨率计算并更新导出图片的宽度和高度。
  9. 实现了取消按钮 btnCancel_Click 和窗体关闭事件 FormExportMap_FormClosed,用于关闭当前窗体。
  10. 其他一些辅助方法和事件处理方法,如 InitFormSize 用于初始化窗体大小,txtExPath_TextChanged 用于处理导出路径文本框内容变化事件等。

主要代码为:


        private void btnExport_Click(object sender, EventArgs e)
        {
            if (txtExPath.Text == "")
            {
                MessageBox.Show("请先确定导出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (cboResolution.Text == "")
            {
                if (txtExPath.Text == "")
                {
                    MessageBox.Show("请输入分辨率!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else if (Convert.ToInt16(cboResolution.Text) == 0)
            {

                    MessageBox.Show("请正确输入分辨率!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
              
            }
            else
            {
                try
                {
                    int resolution = int.Parse(cboResolution.Text);  //输出图片的分辨率
                    int width = int.Parse(txtWidth.Text);            //输出图片的宽度,以像素为单位
                    int height = int.Parse(txtHeight.Text);          //输出图片的高度,以像素为单位
                    ExportMap.ExportView(pActiveView, pGeometry, resolution, width, height, pSavePath, bRegion);
                    MessageBox.Show("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception)
                {
                    MessageBox.Show("导出失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void FormExportMap_FormClosed(object sender, FormClosedEventArgs e)
        {

            Dispose();
        }

        private void btnExPath_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfdExportMap = new SaveFileDialog();
            sfdExportMap.DefaultExt = "jpg|bmp|gig|tif|png|pdf";
            sfdExportMap.Filter = "JPGE 文件(*.jpg)|*.jpg|BMP 文件(*.bmp)|*.bmp|GIF 文件(*.gif)|*.gif|TIF 文件(*.tif)|*.tif|PNG 文件(*.png)|*.png|PDF 文件(*.pdf)|*.pdf";
            sfdExportMap.OverwritePrompt = true;
            sfdExportMap.Title = "保存为";
            txtExPath.Text = "";
            if (sfdExportMap.ShowDialog() != DialogResult.Cancel)
            {
                pSavePath = sfdExportMap.FileName;
                txtExPath.Text = sfdExportMap.FileName;
            }  
        }

        private void cboResolution_SelectedIndexChanged(object sender, EventArgs e)
        {
            double num = (int)Math.Round(pActiveView.ScreenDisplay.DisplayTransformation.Resolution);
            if (cboResolution.Text == "")
            {
                txtWidth.Text = "";
                txtHeight.Text = "";
                return;
            }
            if (bRegion)
            {
                IEnvelope pEnvelope = pGeometry.Envelope;
                tagRECT pRECT = new tagRECT();
                pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnvelope, ref pRECT, 9);
                if (cboResolution.Text != "")
                {
                    txtWidth.Text = Math.Round((double)(pRECT.right * (double.Parse(cboResolution.Text) / (double)num))).ToString();
                    txtHeight.Text = Math.Round((double)(pRECT.bottom * (double.Parse(cboResolution.Text) / (double)num))).ToString();
                }
            }
            else
            {
                txtWidth.Text = Math.Round((double)(pActiveView.ExportFrame.right * (double.Parse(cboResolution.Text) / (double)num))).ToString();
                txtHeight.Text = Math.Round((double)(pActiveView.ExportFrame.bottom * (double.Parse(cboResolution.Text) / (double)num))).ToString();
            }
        }

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值