关于地图导出的方法有很多,但是核心技术就那么一点。下面是从项目实战中总结的一部分地图导出的方法:(以全域导出和区域导出为例)

1.由于地图导出用到的函数和方法容易重复,增加了工作量故首先将其进行封装成类(ExportMap类):用到的主要接口为:IActiveView(活动视图接口)、IGeometry(几何接口)、IRgbColor(颜色接口)、IElement(要素接口)等。

具体的封装代码如下:

   class ExportMap
{
#region 输出视图
public static void ExportView(IActiveView view, IGeometry pGeo, int Outputresoultion, int Width, int Height, string ExpPath, bool bRegion)
{
IExport pExport = null;
tagRECT exportrect = new tagRECT();
IEnvelope pEnvelop = pGeo.Envelope;
string sType = System.IO.Path.GetExtension(ExpPath);
switch (sType)
{
case ".jpg":
pExport = new ExportJPEGClass();
break;
case ".bmp":
pExport = new ExportBMPClass();
break;
case ".gif":
pExport = new ExportGIFClass();
break;
case ".tif":
pExport = new ExportTIFFClass();
break;
case ".png":
pExport = new ExportPNGClass();
break;
case ".pdf":
pExport = new ExportPDFClass();
break;
default:
MessageBox.Show("没有输出格式,默认JPEG");
pExport = new ExportJPEGClass();
break;
}
pExport.ExportFileName = ExpPath;
exportrect.left = ;
exportrect.top = ;
exportrect.right = Width;
exportrect.bottom = Height;
if (bRegion)
{
view.GraphicsContainer.DeleteAllElements();
view.Refresh();
}
IEnvelope envelop = new EnvelopeClass();
envelop.PutCoords((double)exportrect.left, (double)exportrect.top, (double)exportrect.right, (double)exportrect.bottom);
pExport.PixelBounds = envelop;
view.Output(pExport.StartExporting(), Outputresoultion, ref exportrect, pEnvelop, null);
pExport.FinishExporting();
pExport.Cleanup();
}
#endregion
#region 获取RGB颜色
private static IRgbColor GetRgbColor(int intR,int intG,int intB)
{
IRgbColor pRgbColor=null;
if(intR<||intR>||intG<||intG>||intB<||intB>)
{
return pRgbColor;
}
pRgbColor=new RgbColorClass();
pRgbColor.Red=intR;
pRgbColor.Green=intG;
pRgbColor.Blue=intB;
return pRgbColor;
}
#endregion
#region 创建图形元素
/// <summary>
///
/// </summary>
/// <param name="pGeomentry">几何图形</param>
/// <param name="lineColor">边框颜色</param>
/// <param name="fillColor">填充颜色</param>
/// <returns></returns>
public static IElement CreateElement(IGeometry pGeomentry, IRgbColor lineColor, IRgbColor fillColor)
{
if (pGeomentry == null || lineColor == null || fillColor == null)
{
return null;
}
IElement pElem = null;
try
{
if (pGeomentry is IEnvelope) pElem = new RectangleElementClass();
else if (pGeomentry is IPolygon)
pElem = new PolygonElementClass();
else if (pGeomentry is ICircularArc)
{
ISegment pSegCircle = pGeomentry as ISegment;
ISegmentCollection pSegColl = new PolygonClass();
object o = Type.Missing;
pSegColl.AddSegment(pSegCircle, ref o, ref o);
IPolygon pPolygon = pSegCircle as IPolygon;
pGeomentry = pPolygon as IGeometry;
pElem = new CircleElementClass();
}
else if (pGeomentry is IPolyline)
pElem = new LineElementClass();
if (pElem == null)
return null;
pElem.Geometry = pGeomentry;
IFillShapeElement pFElem = pElem as IFillShapeElement;
ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass();
pSymbol.Color=fillColor ;
pSymbol.Outline.Color=lineColor;
pSymbol.Style = esriSimpleFillStyle.esriSFSCross;//图形元素的样式
if (pSymbol == null)
{
return null;
}
pFElem.Symbol = pSymbol;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
return pElem;
}
#endregion
#region 视图窗口绘制几何图形元素
/// <summary>
///
/// </summary>
/// <param name="pGeometry">几何图形</param>
/// <param name="activeView">活动视图</param>
public static void AddElement(IGeometry pGeometry,IActiveView activeView)
{
IRgbColor fillColor=GetRgbColor(,,);
IRgbColor lineColor=GetRgbColor(,,);
IElement pEle=CreateElement(pGeometry,lineColor,fillColor );//调用图形元素的函数
IGraphicsContainer pGC = activeView.GraphicsContainer;
if (pGC != null)
{
pGC.AddElement(pEle, );
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pEle, null);
}
}
#endregion
#region 全域导出
/// <summary>
/// 全域导出
/// </summary>
/// <param name="OutputResolution">输出分辨率</param>
/// <param name="ExpPath">输出路径</param>
/// <param name="view">视图</param>
public static void ExportActiveView(int OutputResolution, string ExpPath, IActiveView view)
{
IExport pExport = null;
tagRECT exportRect;
IEnvelope envelop2 = view.Extent;
int num = (int)Math.Round(view.ScreenDisplay.DisplayTransformation.Resolution);
string sType = System.IO.Path.GetExtension(ExpPath);
switch (sType)
{
case ".jgp":
pExport = new ExportJPEGClass();
break;
case ".bmp":
pExport = new ExportBMPClass();
break;
case ".gif":
pExport = new ExportGIFClass();
break;
case ".tif":
pExport = new ExportTIFFClass();
break;
case ".png":
pExport = new ExportPNGClass();
break;
case ".pdf":
pExport = new ExportPDFClass();
break;
default: MessageBox.Show("No Export Foemat,the default format is JPEG!");
pExport = new ExportJPEGClass();
break;
}
pExport.ExportFileName = ExpPath;
exportRect.left = ; exportRect.top = ;
exportRect.right = (int)Math.Round((double)(view.ExportFrame.right * (((double)OutputResolution) / ((double)num))));
exportRect.bottom = (int)Math.Round((double)(view.ExportFrame.bottom * (((double)OutputResolution) / ((double)num))));
IEnvelope envelop = new EnvelopeClass();
envelop.PutCoords((double)exportRect.left, (double)exportRect.top, (double)exportRect.right, (double)exportRect.bottom);
pExport.PixelBounds = envelop;
view.Output(pExport.StartExporting(), OutputResolution, ref exportRect, envelop2, null);
pExport.FinishExporting();
pExport.Cleanup();
}
#endregion
#region 区域导出
/// <summary>
/// 区域导出
/// </summary>
/// <param name="pGeo">输出的图形</param>
/// <param name="OutputResolution">输出的范围</param>
/// <param name="ExpPath">输出路径</param>
/// <param name="view">视图</param>
public static void ExportRegion(IGeometry pGeo, int OutputResolution, string ExpPath, IActiveView view)
{
IExport export = null;
IWorldFileSettings setting = null;
IEnvelope envelope2 = pGeo.Envelope;
string str = ExpPath.Substring(ExpPath.Length - , ).ToUpper();
switch (str)
{
case "JPG":
setting = new ExportJPEGClass();
export = new ExportJPEGClass();
setting = export as IWorldFileSettings;
setting.MapExtent = envelope2;
setting.OutputWorldFile = false;
break;
case "BMP":
setting = new ExportBMPClass();
export = new ExportBMPClass();
setting = export as IWorldFileSettings;
setting.MapExtent = envelope2;
setting.OutputWorldFile = false;
break;
case "TIF":
setting = new ExportTIFFClass();
export = new ExportTIFFClass();
setting = export as IWorldFileSettings;
setting.MapExtent = envelope2;
setting.OutputWorldFile = false;
break;
case "PNG":
setting = new ExportPNGClass();
export = new ExportPNGClass();
setting = export as IWorldFileSettings;
setting.MapExtent = envelope2;
setting.OutputWorldFile = false;
break;
default: break;
}
if (setting == null)
{
export.ExportFileName = ExpPath;
int num = (int)Math.Round(view.ScreenDisplay.DisplayTransformation.Resolution);
tagRECT grect2 = new tagRECT();//实例化矩形
IEnvelope envelop3 = new EnvelopeClass();
view.ScreenDisplay.DisplayTransformation.TransformRect(envelope2, ref grect2, );
grect2.left = ;
grect2.top = ;
grect2.right = (int)Math.Round((double)(grect2.right - grect2.left) * (((double)OutputResolution) / ((double)num)));
grect2.bottom = (int)Math.Round((double)((grect2.bottom - grect2.top) * (((double)OutputResolution) / ((double)num))));
envelop3.PutCoords((double)grect2.left, (double)grect2.top, (double)grect2.right, (double)grect2.bottom);
export.PixelBounds = envelop3;
view.GraphicsContainer.DeleteAllElements();
view.Output(export.StartExporting(), OutputResolution, ref grect2, envelope2, null);
export.FinishExporting();
export.Cleanup();
AddElement(pGeo, view);
} }
#endregion
}

2.添加输出设置窗体,分别有,输出图片的高、宽、分辨率、输出保存路径、导出按钮。

具体的设置代码如下:

 public partial class ExportMapForm : DevExpress.XtraEditors.XtraForm
{
//定义全局变量
private string pSavePath = "";
private IActiveView pActiveView;
private IGeometry pGeometry = null;
#region 只读属性,地图导出空间图形
public IGeometry GetGeometry
{
set { pGeometry = value; }
}
private bool bRegion = true;
#endregion
/// <summary>
/// 只读属性,是全域导出还是区域导出
/// </summary>
public bool IsRegion
{
set { bRegion = value; }
} //获取主窗口的MapControl控件
public ExportMapForm(AxMapControl mainAxMapControl)
{
InitializeComponent(); pActiveView = mainAxMapControl.ActiveView; } private void ExportMapForm_Load(object sender, EventArgs e)
{ }
#region 输入窗口的大小
private void InitFormSize()
{
cboResoultion.Text = pActiveView.ScreenDisplay.DisplayTransformation.Resolution.ToString();
cboResoultion.Items.Add(cboResoultion.Text);
if (bRegion)
{
IEnvelope pEnvelop = pGeometry.Envelope;
tagRECT pRECT = new tagRECT();
pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnvelop, ref pRECT,);
if (cboResoultion.Text != "")
{
txtWidth.Text = pRECT.right.ToString();
txtHeight.Text = pRECT.bottom.ToString();
}
}
else
{
if (cboResoultion.Text != "")
{
txtWidth.Text = pActiveView.ExportFrame.right.ToString();
txtHeight.Text = pActiveView.ExportFrame.bottom.ToString();
}
}
}
#endregion
#region combox的ChangeIndex事件
private void cboResoultion_SelectedIndexChanged(object sender, EventArgs e)
{
double num = (int)Math.Round(pActiveView.ScreenDisplay.DisplayTransformation.Resolution);
if (cboResoultion.Text == "")
{
txtWidth.Text = "";
txtHeight.Text = "";
return;
}
if (bRegion)
{
IEnvelope pEnvelop = pGeometry.Envelope;
tagRECT pRECT = new tagRECT();
pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnvelop, ref pRECT,);
if (cboResoultion.Text != "")
{
txtWidth.Text = Math.Round((double)(pRECT.right * (double.Parse(cboResoultion.Text) / (double)num))).ToString();
}
}
else
{
txtWidth.Text = Math.Round((double)(pActiveView.ExportFrame.right * (double.Parse(cboResoultion.Text) / (double)num))).ToString();
txtHeight.Text = Math.Round((double)(pActiveView.ExportFrame.bottom * (double.Parse(cboResoultion.Text) / (double)num))).ToString();
}
}
#endregion
#region 保存按钮的单击事件
private void btnExPath_Click(object sender, EventArgs e)
{
SaveFileDialog sfdExportMap = new SaveFileDialog();
sfdExportMap.DefaultExt = "jpg|bmp|gif|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;
}
}
#endregion
#region 导出按钮单击事件
private void btnExPort_Click(object sender, EventArgs e)
{
if (txtExPath.Text == "")
{
MessageBox.Show("请先确定导出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (cboResoultion.Text == "")
{
if (txtExPath.Text == "")
{
MessageBox.Show("请输入分辨率!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else if (Convert.ToInt16(cboResoultion.Text) == )
{
MessageBox.Show("请正确输入分辨率!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
try
{
int resoultion = int.Parse(cboResoultion.Text);//输出图片的分辨率
int width = int.Parse(cboResoultion.Text);//输出图片的宽度
int height = int.Parse(cboResoultion.Text);//输出图片的高度
ExportMap.ExportView(pActiveView, pGeometry, resoultion, width, height, pSavePath, bRegion);
pActiveView.GraphicsContainer.DeleteAllElements();
pActiveView.Refresh();
MessageBox.Show("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception)
{
MessageBox.Show("导出失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
#endregion
#region 取消按钮的单击事件
private void btnCancel_Click(object sender, EventArgs e)
{
//局部导出时没有导出图像就退出
pActiveView.GraphicsContainer.DeleteAllElements();
pActiveView.Refresh();
Dispose();
}
#endregion
#region 图片导出窗口Close事件
private void ExportMapForm_FormClosed(object sender, FormClosedEventArgs e)
{
//局部导出时没有导出图像就关闭
pActiveView.GraphicsContainer.DeleteAllElements();
pActiveView.Refresh();
Dispose(); }
#endregion

3.在main窗体中进行实例化输出窗体:private ExportMapForm frmExpMap = null;

4.在MainMap Control_OnMouseDown中进行写入case:(只适合区域导出,单击选择边框)

 #region 地图的区域导出
case "ExportRegion":
//删除视图中的数据
mainMapControl.ActiveView.GraphicsContainer.DeleteAllElements();
mainMapControl.ActiveView.Refresh();
IPolygon pPolygon = DrawPolygon(mainMapControl);
if (pPolygon == null) return;
ExportMap.AddElement(pPolygon, mainMapControl.ActiveView);
if (frmExpMap == null || frmExpMap.IsDisposed)
{
frmExpMap = new ExportMapForm(mainMapControl);
}
frmExpMap.IsRegion = true;
frmExpMap.GetGeometry = pPolygon as IGeometry;
frmExpMap.Show();
frmExpMap.Activate();
break;
#endregion

5.全域导出和区域导出按钮的单击事件代码:

       #region 地图导出之全域导出
private void btnExportMap_ItemClick(object sender, ItemClickEventArgs e)
{
if (frmExpMap == null || frmExpMap.IsDisposed)
{
frmExpMap = new ExportMapForm(mainMapControl);
}
frmExpMap.IsRegion = false;
frmExpMap.GetGeometry = mainMapControl.ActiveView.Extent;
frmExpMap.Show();
frmExpMap.Activate();
}
#endregion
#region 地图导出之区域导出
private void btnExportRegionMap_ItemClick(object sender, ItemClickEventArgs e)
{
mainMapControl.CurrentTool = null;
mainMapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
pMouseOperate = "ExportRegion";
}
#endregion

ArcGIS Engine开发之地图导出的更多相关文章

  1. ArcGIS Engine开发之地图基本操作(4)

    ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...

  2. ArcGIS Engine开发之地图基本操作(3)

    地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...

  3. ArcGIS Engine开发之地图基本操作(2)

    地图数据的加载 1.加载地图文档 ArcGIS Engine支持加载多种类型的数据,有矢量数据的Coverage.Shapefile.dwg/dxf文件,栅格数据的BMP.GRID.控件数据库等.很多 ...

  4. ArcGIS Engine开发之地图基本操作(1)

    ArcGIS提供的各类数据形式以及相应接口 1. 空间数据 在GIS软件中,空间数据有多种不同的形式存在.按照不同的划分标准可以分为矢量数据和栅格数据.GIS格式数据和非GIS格式数据(CAD格式). ...

  5. ArcGIS Engine开发之地图浏览

    地图的浏览功能包括缩放.移动.量测旋转等. 1.放大与缩小 无论是放大还是缩小,都是通过改变MapControl中当前视图的范围Extent属性来实现的,主要用到包络线(Envelope)类. 包络线 ...

  6. ArcGIS Engine开发前基础知识(2)

    ArcGIS基本控件简介 ArcGIS Engine控件是一组可视化的开发组件,每个ArcGIS Engine控件都是一个COM组件.这些组件包括MapControl,PageLayoutContro ...

  7. C#,ArcGIS Engine开发入门教程

    C#,ArcGIS Engine开发入门教程 转自:http://blog.csdn.net/yanleigis/article/details/2233674  目录(?)[+] 五实现 一 加载A ...

  8. ArcGIS Engine开发基础总结(一)

    标准Engine功能 地图浏览    地图制作 数据查询 数据分析 及 所有的开发控件 —MapControl, PageLayout, Toolbar, TOC, ArcReader 对所有矢量和栅 ...

  9. ArcGIS Engine开发鹰眼图的功能(基础篇)

    鹰眼是用于调节全视域范围内主地图显示范围情况的副地图.它体现了地图整体与详细局部的关系. 用户可以通过鼠标单击或者画框等动作实现鹰眼与主地图的交互情况. 鹰眼功能的原理是通过主地图窗口的地图控件和鹰眼 ...

随机推荐

  1. 在centos7(EL7.3 即 kernel-3.10.0-514.X )上安装BCM4312无线网卡驱动要注意的问题

    我新装的centos7主机无法使用里面自带的网卡,查询后发现网卡型号为BCM4312.我在看资料安装的过程中遇到了些问题,纠结了好久,现在分享下要注意的点,为后来的遇到同样问题的人提供点帮助.现在开始 ...

  2. .NET基础拾遗(2)面向对象的实现和异常的处理基础

    Index : (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理基础 (3)字符串.集合与流 (4)委托.事件.反射与特性 (5)多线程开发基础 (6)ADO.NET与数据库开 ...

  3. iOS开发系列--音频播放、录音、视频播放、拍照、视频录制

    --iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...

  4. .NET Web的身份认证

    百度一下”asp.net身份认证“,你会得到很多相关的资料,这些资料通常上来就会介绍诸如”Form认证“”Windows认证“等内容,而没有给出一个完整的流程.初学者对此往往一头雾水,我也曾经被坑过很 ...

  5. ABP源码分析二十八:ABP.MemoryDB

    这个模块简单,且无实际作用.一般实际项目中都有用数据库做持久化,用了数据库就无法用这个MemoryDB 模块了.原因在于ABP限制了UnitOfWork的类型只能有一个(前文以作介绍),一般用了数据库 ...

  6. TCP同步与异步,长连接与短连接【转载】

    原文地址:TCP同步与异步,长连接与短连接作者:1984346023 [转载说明:http://zjj1211.blog.51cto.com/1812544/373896   这是今天看到的一篇讲到T ...

  7. 5.如何使主机和虚拟机IP处于同一网段(内网渗透专用)

    先说一下正常流程: 1.打开虚拟机网络设置选项,选择桥接模式(Bridged)[如果是Kali 2.0的话,执行第一步后就OK了(90%)] 2.打开Kali里面的网络设置 3.设置一个ip4或者ip ...

  8. SQL Server 批量完整备份

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 实现方式一(One) 实现方式二(Two) 实现方式三(Thr ...

  9. JavaScript的同步与异步

    1.手绘一张图说明. 2.为什么JavaScript是单线程(这里引用阮一峰老师的话) JavaScript的单线程,与它的用途有关. 作为浏览器脚本语言,JavaScript的主要用途是与用户互动, ...

  10. Python标准模块--asyncio

    1 模块简介 asyncio模块作为一个临时的库,在Python 3.4版本中加入.这意味着,asyncio模块可能做不到向后兼容甚至在后续的Python版本中被删除.根据Python官方文档,asy ...