AE二次开发中几个功能速成归纳(符号设计器、创建要素、图形编辑、属性表编辑、缓冲区分析)...

/*
 * 实习课上讲进阶功能所用文档,因为赶时间从网上抄抄改改,凑合能用,记录一下以备个人后用。
 *
 * -------------------------------------------------------------------
 *
 * 使用前提:已搭建好AE的GIS基本框架,包括TOC、mapcontrol、toolbar拖控件,mxd、shp文件载入显示,查看图层属性表等
 *
 * -------------------------------------------------------------------
 */
/* Form1中的using */

using System;

using System.Windows.Forms;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Controls;

using ESRI.ArcGIS.Display;

using ESRI.ArcGIS.Geometry;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.SystemUI;

using ESRI.ArcGIS.esriSystem;

using System.Drawing;

using System.Runtime.InteropServices;

using ESRI.ArcGIS.DataSourcesFile;

using System.Collections;


/*
 * 一、符号设计
 *
 * 在TOC的doubleclick事件中写入:
 */

esriTOCControlItem toccItem = esriTOCControlItem.esriTOCControlItemNone;

ILayer iLayer = null;

IBasicMap iBasicMap = null;

object unk = null;

object data = null;

axTOCControl1.HitTest( e.x, e.y, ref toccItem, ref iBasicMap, ref iLayer, ref unk, ref data ); /* 获取所点击图例及其图层 */

if ( e.button == 1 )

{
    if ( toccItem == esriTOCControlItem.esriTOCControlItemLegendClass )

    {
        ILegendClass pLC = new LegendClassClass();

        pLC = ( (ILegendGroup) unk).get_Class( (int) data ); /* 获取图例 */

        ISymbol pSym = pLC.Symbol; /* 获取图例的符号 */

        ESRI.ArcGIS.DisplayUI.ISymbolSelector pSS = new ESRI.ArcGIS.DisplayUI.SymbolSelectorClass(); /* 创建符号选择器 */

        bool a = false;

        pSS.AddSymbol( pSym );

        a = pSS.SelectSymbol( 0 ); /* 打开符号选择器 */

        if ( a )

        {
            pLC.Symbol = pSS.GetSymbolAt( 0 );
        }

        this.axMapControl1.ActiveView.Refresh();

        this.axTOCControl1.Refresh();
    }
}


/*
 * 二、创建要素
 *
 * 1.创建并添加shp新图层
 */

/* 点shp的创建并添加 */

private void 点ToolStripMenuItem_Click( object sender, EventArgs e )

{
    string pointshppath = "";

    SaveFileDialog spointdlg = new SaveFileDialog(); /* 打开保存文件对话框,设置保存路径和shp文件名 */

    if ( spointdlg.ShowDialog() == DialogResult.OK )

    {
        pointshppath = spointdlg.FileName;
    }else {
        return;
    }

/* 准备好要素类空对象 */

    IFeatureClass m_pointfeatureclass = null;

/* 从文件路径中分解出文件夹路径和文件名称 */

    int count = pointshppath.LastIndexOf ("\");

string folder = pointshppath.Substring(0, count);

string name = pointshppath.Substring(count + 1, pointshppath.Length - count - 1);

//根据文件夹路径创建工作空间工厂和工作空间

IWorkspace ipws;

IWorkspaceFactory ipwsf = new ShapefileWorkspaceFactoryClass();

ipws = ipwsf.OpenFromFile(folder, 0);

//转为要素工作空间

IFeatureWorkspace ifeatws;

ifeatws = ipws as IFeatureWorkspace;

//对shp文件的一些必要设置,除了红字部分外都不用改

IFields pFields = new FieldsClass();

IField pField = new FieldClass();

IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

IFieldEdit pFieldEdit = pField as IFieldEdit;

IGeometryDef ipGeodef = new GeometryDefClass();

IGeometryDefEdit ipGeodefEdit = ipGeodef as IGeometryDefEdit;

ISpatialReference ipSpatialRef;

IUnknownCoordinateSystem iunknowncoord = new UnknownCoordinateSystemClass();

ipSpatialRef = iunknowncoord;

ipGeodefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;//确定你要生成的shp的几何类型(点线面)

ipSpatialRef.SetMDomain(-10000, 10000);

ipGeodefEdit.HasM_2 = false;

ipGeodefEdit.HasZ_2 = false;

ipGeodefEdit.SpatialReference_2 = ipSpatialRef;

pFieldEdit.Name_2 = "Shape ";

pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

pFieldEdit.GeometryDef_2 = ipGeodef;

pFieldsEdit.AddField(pField);

//

//创建要素类并导出shp文件于预设文件路径

m_pointfeatureclass = ifeatws.CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "Shape ", " ");

//加载新创建的shp文件并调到图层显示顺序的最顶层

axMapControl1.AddShapeFile(folder,name);

axMapControl1.MoveLayerTo(0, axMapControl1.LayerCount - 1);

return;

}

//线shp的创建并添加

private void 线ToolStripMenuItem_Click(object sender, EventArgs e)

{

string lineshppath = " ";

SaveFileDialog slinedlg = new SaveFileDialog();//打开保存文件对话框,设置保存路径和shp文件名

if (slinedlg.ShowDialog() == DialogResult.OK)

{

lineshppath = slinedlg.FileName;

}

else

{

return;

}

  • 2
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值