GIS-ArcGIS应用与开发技术(36)

Excel点坐标文件生成shapefile点要素

1.添加菜单

2.编写代码

  private void 生成shapefile文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
         

            //比如Excel文件:大学校区.xls,表包括(sheet1,sheet2,sheet2)
            //tableName即表路径,该路径形式例如:D:\\DataFile\\大学校区.xls\\sheet1$
            string tableName;
            string x;
            string y;
            string outName;
            IFeatureClass featureClass;
            tableName = @"D:\课程\ArcGIS应用及开发技术\校园地理信息系统-集成结果\降水量.xls\Sheet1$"; 

            x = "X";//X坐标

            y = "Y";//Y坐标

            outName = "降水量"; ;

            //添加XY事件

            MakeXYEventLayer MxyLayer = new MakeXYEventLayer(tableName, x, y, outName);
            string tempPath = @"./"; //要素临时存储路径

            featureClass = ConvertExcelToFeatureClass(MxyLayer, tempPath);

            if (featureClass != null)

            {

                FeatureLayerClass pFeatureLater = new FeatureLayerClass();

                pFeatureLater.FeatureClass = featureClass;

                pFeatureLater.Name = featureClass.AliasName;

                axMapControl1.Map.AddLayer(pFeatureLater as ILayer);

                axMapControl1.Extent = axMapControl1.FullExtent;

            }
        }


 private IFeatureClass ConvertExcelToFeatureClass(MakeXYEventLayer xyEventLayer, string out_Layer_Path)

        {

            try
            {
                Geoprocessor GP = new Geoprocessor();
                GP.OverwriteOutput = true;
                GP.Execute(xyEventLayer, null);//执行XY事件  

                //复制要素

                ESRI.ArcGIS.DataManagementTools.CopyFeatures cf = new ESRI.ArcGIS.DataManagementTools.CopyFeatures();

                cf.in_features = xyEventLayer.out_layer;

                cf.out_feature_class = out_Layer_Path + xyEventLayer.out_layer;

                IGeoProcessorResult gpResult = GP.Execute(cf, null) as IGeoProcessorResult;

                IFeatureClass _featureClass;

                IQueryFilter qf;//查询过滤

                IGPUtilities gpUtils = new GPUtilitiesClass();

                gpUtils.DecodeFeatureLayer(gpResult.GetOutput(0), out _featureClass, out qf);

                IFeatureCursor cursor = _featureClass.Insert(true);

                return _featureClass;

            }
            catch (Exception ex)
            {
                MessageBox.Show("导入要素失败,原因:" + ex.ToString());
                return null;
            }

        }



3.添加引用



using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值