GIS软件设计程序说明

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

GIS软件设计与实现
程序说明
组员:王兴平、邵瑞
王平凯
班级:测绘1103班
指导老师:李光强
2015/1/5
一、小组成员表:
二、程序功能概述
本程序的功能有:
1.实现一次加载多个shp文件;
2.使用ITOCControl接口,对TOC控件中的图层显示顺序进行调整;
3.实现鹰眼功能;
以上为已经经过测试,实现了的功能,
相关功能截图:
1.软件设计界面
2.加载shp文件
3.图层顺序调整
4.鹰眼功能
程序相关代码:
public Form1()
{
InitializeComponent();
}
///<summary>
///声明窗体层全局变量
///</summary>
ITOCControl mTOCControl;
ILayer pMovelayer;//需要调整显示顺序的图层
int toIndex;//存放目标图层的索引
///<summary>
///实现同时加载多个shp文件
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
privatevoid LoadFile_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Shape file(*.shp)|*.shp";
dlg.Title = "打开 Shape数据文档";
dlg.Multiselect = true;
//定义存放打开 IFeatureClass 的字符串数组
string[] FilePath;
if (dlg.ShowDialog() == DialogResult.OK)
{
FilePath = newstring[dlg.FileNames.Length];
FilePath = dlg.FileNames;
if (FilePath.Length> 0)
{
string WorkSpacePath = System.IO.Path.GetDirectoryName(FilePath[0]);
string[] ShapeFilePath = newstring[FilePath.Length];
//获得打开 IFeatureClass 的字符串数组
for (int i = 0; i<FilePath.Length; i++)
{
ShapeFilePath[i] = System.IO.Path.GetFileName(FilePath[i]);
}
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(WorkSpacePath, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
for (int i = 0; i<ShapeFilePath.Length; i++)
{
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(ShapeFilePath[i]);
IDataset pDataset = pFeatureClass as IDataset;
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureClass;
= ;
ILayer pLayer = pFeatureLayer as ILayer;
this.axMapControl1.Map.AddLayer(pLayer);
this.axMapControl2.Map.AddLayer(pLayer);
}
}
}
}
///<summary>
///实现地图的鹰眼功能
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
privatevoid axMapControl1_OnMapReplaced(object sender,
ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
{
IMap pMap;
pMap = axMapControl1.Map;
for (int i = 0; i<yerCount; i++)
{
axMapControl2.Map.AddLayer(pMap.get_Layer(i));
}
axMapControl2.Extent = axMapControl2.FullExtent;
}
//在鹰眼中移动红色矩形框时,axMapControl2中的地图范围要发生相应的变化
privatevoid axMapControl2_OnMouseDown(object sender,
ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 1)//探测鼠标左键
{
IPoint pPt = new PointClass();
pPt.X = e.mapX;
pPt.Y = e.mapY;
IEnvelope pEnvelope = axMapControl1.Extent as IEnvelope;
pEnvelope.CenterAt(pPt);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
elseif (e.button == 2)//鼠标右键功能:范围显示
{
IEnvelope pEnvelope = axMapControl2.TrackRectangle();
axMapControl1.Extent = pEnvelope;
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
}
///<summary>
///当主视图的显示范围发生变化时,会触发空间的OnExtentUpdated事件
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
privatevoid axMapControl2_OnMouseMove(object sender,
ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.button != 1)
return;
IPoint pPt = new PointClass();
pPt.X = e.mapX;
pPt.Y = e.mapY;
axMapControl1.CenterAt(pPt);
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
///<summary>
///绘制鹰眼中红色矩形框
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
privatevoid axMapControl1_OnExtentUpdated(object sender,
ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView pAv = pGraphicsContainer as IActiveView;
//在绘制前,清除axMapControl2中的任何图形
pGraphicsContainer.DeleteAllElements();
IRectangleElement pRecElement = new RectangleElementClass();
IElement pEle = pRecElement as IElement;
IEnvelope pEnv;
pEnv = e.newEnvelope as IEnvelope;
pEle.Geometry = pEnv;
//设置颜色
IRgbColor pColor = new RgbColorClass();
pColor.Red = 200;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 255;
//产生一个线符号对象
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
pLineSymbol.Width = 2;
pLineSymbol.Color = pColor;
//设置填充符号的属性
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
//设置透明颜色
pColor.Transparency = 0;
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pLineSymbol;
IFillShapeElement pFillShapeElement = pRecElement as IFillShapeElement; pFillShapeElement.Symbol = pFillSymbol;
pGraphicsContainer.AddElement(pEle, 0);
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
//在窗体Form1_Load事件中对mTOCControl进行实例化
privatevoid Form1_Load(object sender, EventArgs e)
{
mTOCControl = axTOCControl1.Object as ITOCControl;
}
///<summary>
///实现axTOCControl的图层显示顺序调整
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
privatevoid axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) {
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
if (e.button == 1)
{
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
mTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
if (layer is IAnnotationSublayer)
return;
else
{
pMovelayer = layer;
}
}
}
//图层顺序的调整
privatevoid axTOCControl1_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e) {
if (e.button == 1)
{
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
mTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
IMap pMap = axMapControl1.ActiveView.FocusMap;
if (item == esriTOCControlItem.esriTOCControlItemLayer || layer != null) ;
{
if (pMovelayer != layer)
{
ILayer pTemplayer;
for (int i = 0; i<yerCount; i++)
{
pTemplayer = pMap.get_Layer(i);
if (pTemplayer == layer)
{
toIndex = i;
}
}
pMap.MoveLayer(pMovelayer, toIndex);//移动原图层到目标图层位置
axMapControl1.ActiveView.Refresh();
axMapControl2.ActiveView.Refresh();
mTOCControl.Update();
}
}
}
}。

相关文档
最新文档