GIS软件使用
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Lesson1
IMapDocument mapDocument;
//加载地图文档
private void loadMapDocument()
{
mapDocument = new MapDocumentClass();
try
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
mapDocument.Open(filePath, "");
for (int i = 0; i < mapDocument.MapCount; i++)
{
axMapControl1.Map = mapDocument.get_Map(i);
}
axMapControl1.Refresh();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private void saveDocument()
{
if (mapDocument.get_IsReadOnly(mapDocument.DocumentFilename) == true)
{
MessageBox.Show("地图文档是只读的无法保存");
}
try
{
mapDocument.Save(esRelativePaths, true);
MessageBox.Show("保存地图成功");
}
catch (Exception e)
{
MessageBox.Show("保存地图文档失败?" + e.ToString());
}
}
//另存为地图
private void saveAsDocument()
{
if (mapDocument.get_IsReadOnly(mapDocument.DocumentFilename) == true)
{
MessageBox.Show("地图文档是只读无法保存");
}
System.Windows.Forms.SaveFileDialog saveFileDialog;
saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "打开地图文档;
saveFileDialog.Filter = "map documents(*.mxd)|*.mxd";
saveFileDialog.ShowDialog();
string fileSavePath = saveFileDialog.FileName;
{
mapDocument.SaveAs(fileSavePath, true, true);
MessageBox.Show("另存文档成功");
}
catch (Exception e)
{
MessageBox.Show("另存地图文失败!" + e.ToString());
}
}
Lesson2
//加载地图文档
private void loadMapDocument()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
if (axMapControl1.CheckMxFile(filePath))
{
//axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHand;
axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
//axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHand;
}
else
{
MessageBox.Show(filePath + "不是有效的地图文档");
}
}
//加载地图文档中特定地图
private void loadMapDocument2()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
if (axMapControl1.CheckMxFile(filePath))
{
IArray arrayMap = axMapControl1.ReadMxMaps(filePath, Type.Missing);
int i;
IMap map;
for (i = 0; i < arrayMap.Count; i++)
{
map = arrayMap.get_Element(i) as IMap;
if ( == "Layers")
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
break;
}
}