东华理工GIS二次开发实验报告新Word文件下载.docx
- 文档编号:22413230
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:52
- 大小:1.30MB
东华理工GIS二次开发实验报告新Word文件下载.docx
《东华理工GIS二次开发实验报告新Word文件下载.docx》由会员分享,可在线阅读,更多相关《东华理工GIS二次开发实验报告新Word文件下载.docx(52页珍藏版)》请在冰豆网上搜索。
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
private
void
OpenMXD_Click(object
sender,
EventArgs
e)//“打开MXD文件”按钮
{
OpenFileDialog
ofDialog
=
new
OpenFileDialog();
ofDialog.Title
"
输入ArcMap文档名称"
;
ofDialog.Filter
ArcView
MXD文件|*.mxd"
ofDialog.Multiselect
false;
if
(ofDialog.ShowDialog()
==
DialogResult.OK)
openFile(ofDialog.FileName,
false);
}
Openshape_Click(object
e)//“打开shape文件”按钮
IWorkspaceFactory
shpFactory
ShapefileWorkspaceFactoryClass();
Shape文件|*.shp"
string
fileName
ofDialog.FileName;
filePath
fileName.Substring(0,
fileName.LastIndexOf('
\\'
));
IWorkspace
shpWorkspace
shpFactory.OpenFromFile(filePath,
0);
IFeatureLayer
ftlayer
FeatureLayerClass();
IEnumDataset
ds
shpWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset
featureClass
ds.Next();
ftlayer.FeatureClass
(IFeatureClass)featureClass;
ftlayer.Name
fileName;
ILayer
layer
as
ILayer;
IMap
mmap
sizelist[(int)superTabControl.SelectedTab.Tag].Map;
mmap.AddLayer(layer);
IActiveView
act
IActiveView;
act.Refresh();
●执行“打开文档”命令,代码如下:
35
36
37
38
39
40
41
42
43
44
45
46
47
public
openFile(string
fileName,
bool
isRecentFile)//打开文档
ribbonTabItem2.Enabled
ribbonTabItem1.Enabled
true;
m_ipPathFinder
null;
(!
isRecentFile)//如果不是从“最近打开”处打开的则记录该文档名
writeRecentFile(fileName);
(switch1)//当不是空文档时
switch2
//新建一个文档标签为去地址文件名的标签
SuperTabItem
tabItem
superTabControl.CreateTab(System.IO.Path.GetFileNameWithoutExtension(fileName));
AxMapControl
newaxmap
AxMapControl();
sizelist.Add(newaxmap);
newaxmap.SendToBack();
newaxmap.Dock
DockStyle.Fill;
tabItem.AttachedControl.Controls.Add(newaxmap);
superTabControl.SelectNextTab();
superTabControl.SelectedTab.Tag
n++;
newaxmap.LoadMxFile(fileName);
axTOCClayer.SetBuddyControl(newaxmap);
newaxmap.OnMouseMove
+=
IMapControlEvents2_Ax_OnMouseMoveEventHandler(axMapControlOnMouseMove);
newaxmap.OnMouseDown
+=
IMapControlEvents2_Ax_OnMouseDownEventHandler(axMapControlOnMouseDown);
else//否则直接载入
superTabControl.SelectedTab.Text
System.IO.Path.GetFileNameWithoutExtension(fileName);
sizelist[(int)superTabControl.SelectedTab.Tag].LoadMxFile(fileName);
switch1
anotherrefresh();
//刷新标签
bar4.Show();
//鹰眼框,图层框可用
bar5.Show();
bar5.AutoHide
axMapEagleEye.Extent
axMapEagleEye.FullExtent;
axMapEagleEye.ActiveView.Refresh();
//读取刚载入的地图的图层和字段信息
getLayerInfo(sizelist[(int)superTabControl.SelectedTab.Tag]);
getAttributeInfo(sizelist[(int)superTabControl.SelectedTab.Tag]);
●本系统支持快速打开最近曾经打开过的文档,代码如下:
writeRecentFile(string
filename)//写入“最近文档”的记录文件
try
StreamWriter
s
StreamWriter("
\\Menu.ini"
true);
s.WriteLine(filename);
s.Flush();
s.Close();
catch
{
readRecentFile()//读取最近打开的文档
itemContainer4.SubItems.Clear();
StreamReader
sr
StreamReader("
);
while
(sr.Peek()
>
0)
ButtonItem
recentFile
ButtonItem();
recentFile.Tag
sr.ReadLine();
recentFile.Text
&
+
System.IO.Path.GetFileNameWithoutExtension((string)recentFile.Tag);
recentFile.Click
EventHandler(openRecentFile);
itemContainer4.SubItems.Add(recentFile);
openRecentFile(object
e)//打开最近打开的文档
tempButton
(ButtonItem)sender;
openFile((string)tempButton.Tag,
●清除“最近打开栏”中的记录,代码如下:
clearRecentFile_Click(object
e)//清除“最近打开”
System.IO.FileStream
stream
File.Open("
FileMode.OpenOrCreate,
FileAccess.Write);
stream.Seek(0,
SeekOrigin.Begin);
stream.SetLength(0);
stream.Close();
●当当前标签没有加载地图时,初始化一个空文档,代码如下:
FormWithNoDocument()//初始化一个空文档
//空文档下不能进行图层选择操作
bar5.Hide();
//鹰眼框,图层框,属性表框都隐藏
superTabControl.CreateTab("
空文档"
//创建标签为“空文档”的标签
bar4.Hide();
bar3.Hide();
//动态创建一个axmapcontrol
newaxmap.BeginInit();
superTabControl.SelectedTab.AttachedControl.Controls.Add(newaxmap);
//将其加入该标签
newaxmap.OnExtentUpdated
IMapControlEvents2_Ax_OnExtentUpdatedEventHandler(axMapControlOnExtentUpdated);
newaxmap.EndInit();
//设置为关联组件
BTNattribute1.SubItems.Clear();
//初始化所有图层、字段选择框
BTNlayer1.SubItems.Clear();
buttonItem4.SubItems.Clear();
buttonItem7.SubItems.Clear();
单击文件按钮,弹出菜单
4多标签切换实现
●相应“关闭标签”事件,代码如下:
superTabControl1_TabItemClose(object
SuperTabStripTabItemCloseEventArgs
e)
(superTabControl.Tabs.Count
1)//如果只剩下唯一一个t标签(一定是“空文档”标签)
FormWithNoDocument();
●相应“标签切换”事件,代码如下:
//当不是空文档时切换的文档标签切换事件
superTabControl_SelectedTabChanged
(object
SuperTabStripSelectedTabChangedEventArgs
(switch2)
axMapEagleEye.LoadMxFile
(sizelist[(int)superTabControl.SelectedTab.Tag].DocumentFilename);
//加载该文档
axTOCClayer.SetBuddyControl
(sizelist[(int)superTabControl.SelectedTab.Tag]);
//重新设置关联组件
axTOCClayer.ActiveView.Refresh();
nowSelectedLayer
0;
//初始化选择的图层
//重新读取该文档的信息
anotherrefresh()//当是空文档时切换的文档标签切换事件
5属性表实现
●相应右键菜单“查看属性表”,代码如下:
查看属性表ToolStripMenuItem_Click(object
barisshow)
shuxingbiao();
barisshow
//表示属性表已打开
查看属性表ToolStripMenuItem.Enabled
●相应ArcGis图层列表单击事件,代码如下:
m_Layer;
//记录图层,提供给数据窗
axTOCControlOnMouseDown(object
ITOCControlEvents_OnMouseDownEvent
e)//右键菜单
AxTOCControl
axt1
(AxTOCControl)sender;
esriTOCControlItem
Item
esriTOCControlItem.esriTOCControlItemNone;
IBasicMap
pBasicMap
pLayer
object
other
index
//根据点击位置实现赋值
axt1.HitTest(e.x,
e.y,
ref
Item,
pBasicMap,
pLayer,
other,
index);
m_Layer
pLayer;
(Item
esriTOCControlItem.esriTOCControlItemLayer
||
esriTOCControlItem.esriTOCControlItemLegendClass)//如果点击的地方是图层名或者图例
(e.button
2)//显示右键菜单,并定义其相对控件的位置,正好在鼠标出显示
contextMenuStrip1.Show(axt1,
System.Drawing.Point(e.x,
e.y));
else
(barisshow)//若已打开属性表框则左键点击直接显示其属性
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 东华 理工 GIS 二次开发 实验 报告