• 1. AE二次开发——地图的基本操作(加载地图文档,加载shape,加载mdb,地图的保存,缩放,漫游)


    1. 加载数据Icommand方法

    ICommand Butdata = new ControlsAddDataCommandClass();
    Butdata.OnCreate(axMapControl1.Object);
    Butdata.OnClick();
    axMapControl1.CurrentTool = Butdata as ITool;

    2.加载mxd地图文档

    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.CheckFileExists = true;
    openFileDialog.Title = "打开地图文档";
    openFileDialog.Filter = "地图文档(*.mxd)|*.Mxd|地图模板(*.mxt)|*.Mxt";
    openFileDialog.Multiselect = false;
    openFileDialog.RestoreDirectory = true;
    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
    string sFileName = openFileDialog.FileName;
    axMapControl1.LoadMxFile(sFileName);
    }

    3.加载shape

    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.CheckFileExists = true;
    openFileDialog.Title = "打开shp";
    openFileDialog.Filter = "Shapefile(*.shp)|*.shp";
    openFileDialog.Multiselect = true;
    openFileDialog.RestoreDirectory = true;
    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
    FileInfo fileinfo = new FileInfo(openFileDialog.FileName);
    string path = fileinfo.Directory.ToString();
    string filename = fileinfo.Name.Substring(0, fileinfo.Name.IndexOf("."));
    try
    {
    axMapControl1.AddShapeFile(path, filename);
    }
    catch (Exception ce)
    {
    MessageBox.Show("添加失败!" + ce.ToString());
    }

    }

    3.加载mdb

    为完成

    4.保存

    try
    {
    string sMxdFileName = axMapControl1.DocumentFilename;
    IMapDocument pMapDocument = new MapDocumentClass();
    if (sMxdFileName != null && axMapControl1.CheckMxFile(sMxdFileName))
    {
    if (pMapDocument.get_IsReadOnly(sMxdFileName))
    {
    MessageBox.Show("本地图文档是只读,不能保存");
    pMapDocument.Close();
    return;
    }
    }
    else
    {
    SaveFileDialog pSaveFileDialog = new SaveFileDialog();
    pSaveFileDialog.Title = "选择保存路径";
    pSaveFileDialog.OverwritePrompt = true;
    pSaveFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
    pSaveFileDialog.RestoreDirectory = true;
    if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
    {
    sMxdFileName = pSaveFileDialog.FileName;
    }
    else
    {
    return;
    }
    }
    pMapDocument.New(sMxdFileName);
    pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents);
    pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
    pMapDocument.Close();
    MessageBox.Show("保存文档成功");

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    5.另存为

    try
    {
    SaveFileDialog psaveFileDialog = new SaveFileDialog();
    psaveFileDialog.Title = "另存为";
    psaveFileDialog.OverwritePrompt = true;
    psaveFileDialog.Filter = "ArcMap文档(*mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
    psaveFileDialog.RestoreDirectory = true;
    if (psaveFileDialog.ShowDialog() == DialogResult.OK)
    {
    string sFilePath = psaveFileDialog.FileName;
    IMapDocument pMapDocument = new MapDocumentClass();
    pMapDocument.New(sFilePath);
    pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents);
    pMapDocument.Save(true, true);
    pMapDocument.Close();
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    6.地图缩放(放大,缩小)


    ICommand Zoomin = new ControlsMapZoomInToolClass();
    Zoomin.OnCreate(axMapControl1.Object);
    Zoomin.OnClick();
    axMapControl1.CurrentTool = (ITool)Zoomin;

    ICommand Zoomout = new ControlsMapZoomOutToolClass();
    Zoomout.OnCreate(axMapControl1.Object);
    Zoomout.OnClick();
    axMapControl1.CurrentTool = (ITool)Zoomout;

    7.地图漫游

    ICommand Pan = new ControlsMapPanToolClass();
    Pan.OnCreate(axMapControl1.Object);
    Pan.OnClick();
    axMapControl1.CurrentTool = (ITool)Pan;

    8.全图显示

    ICommand Full = new ControlsMapFullExtentCommandClass();
    Full.OnCreate(axMapControl1.Object);
    Full.OnClick();

    9.属性查询

    ICommand Identify = new ControlsMapIdentifyToolClass();
    Identify.OnCreate(axMapControl1.Object);
    Identify.OnClick();
    axMapControl1.CurrentTool = (ITool)Identify;

  • 相关阅读:
    主键索引就是聚集索引吗?
    聚集索引以及非聚集索引
    IO阻塞模型、IO非阻塞模型、多路复用IO模型
    Log4j的使用说明
    前置机是什么
    转:图文理解区块链
    DQL、DML、DDL、DCL全名是啥?
    OLAP和OLTP的区别
    JAVA之运算符优先级
    JAVA之异常处理(一)
  • 原文地址:https://www.cnblogs.com/bby2014210552/p/6226554.html
Copyright © 2020-2023  润新知