【036】◀▶ 自己写的程序源代码

●·● 目录:

A1 ………… ESRI_01.zip
A2 ………… 实现:新建shapefile文件
A3 ………… 实现:只显示筛选的要素(IFeatureLayerDefinition)
A4 ………… 实现:高亮显示筛选的要素(IFeatureSelection)
A5 ………… 实现:类似 ArcMap 中 Identify 工具的效果(IIdentify、IArray、IIdentifyObj)
A6 ………… 实现:在 MapControl 上绘制几何图形

---------------------------------------------------------------------------------------------------------

Visual Studio 2008 + ArcGIS Engine 9.3

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣   返回目录   ╠══════════════════════════════════════════════════╣
            ╚════════╝

点击下载: >->-> ESRI_01.zip <-<-<  标注:实现了基本 GIS 功能,部分截图如下!

 

全局:

【036】◀▶ 自己写的程序源代码_第1张图片

鹰眼:

【036】◀▶ 自己写的程序源代码_第2张图片
自定义工具对话框:

【036】◀▶ 自己写的程序源代码_第3张图片

面符号:

【036】◀▶ 自己写的程序源代码_第4张图片

线符号:

【036】◀▶ 自己写的程序源代码_第5张图片

点符号:

【036】◀▶ 自己写的程序源代码_第6张图片

右键菜单:

【036】◀▶ 自己写的程序源代码_第7张图片

图层属性表:

【036】◀▶ 自己写的程序源代码_第8张图片

--------------------------------------------------------------------------------------------------------- 

Visual Studio 2010 + ArcGIS Engine 10.0

--------------------------------------------------------------------------------------------------------- 

            ╔════════╗
╠════╣   返回目录   ╠══════════════════════════════════════════════════╣
            ╚════════╝

点击下载: >->-> NewPoints.zip <-<-<  标注:实现新建shapefile文件,部分截图如下!

 

【036】◀▶ 自己写的程序源代码_第9张图片

属性截图如下:

【036】◀▶ 自己写的程序源代码_第10张图片

实现步骤:

  • 新建工作空间工厂 IWorkspaceFactory!(矢量数据)
  • 新建要素工作空间 IFeatureWorkspace!  <IWorkspaceFactory.OpenFromFile()>
  • 若指定的文件名存在了,则将其内部的数据删除!  <IDataset.Delete()>
  • 为要素集新建字段 IFields!
  • 新建要素集 IFeatureClass!  <IFeatureWorkspace.CreateFeatureClass()>
  • 新建要素 IFeature!  <IFeatureClass.CreateFeature()>

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using System.IO;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geometry;

namespace NewPoints
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 保存文件的完整路径
        /// </summary>
        string saveFullPath = string.Empty;

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.InitialDirectory = Directory.GetCurrentDirectory();
            sfd.Filter = "Shp文件(*.shp)|*.shp";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                saveFullPath = sfd.FileName;
            }
            textBox1.Text = saveFullPath;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            IFeatureLayer pFeatureLayer = CreateShpFromPoint(saveFullPath);
            pFeatureLayer.Name = "Point";
            axMapControl1.Map.AddLayer(pFeatureLayer);
        }

        private IFeatureLayer CreateShpFromPoint(string outfileNamePath)
        {
            string folder = System.IO.Path.GetDirectoryName(outfileNamePath);
            string file = System.IO.Path.GetFileName(outfileNamePath);

            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWS = pWSF.OpenFromFile(folder, 0) as IFeatureWorkspace;

            if (File.Exists(outfileNamePath))
            {
                IFeatureClass featureClass = pFWS.OpenFeatureClass(file);
                IDataset pDataset = featureClass as IDataset;
                pDataset.Delete();
            }

            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;
            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
            pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            pField = new FieldClass();
            pFieldEdit = pField as IFieldEdit;
            pFieldEdit.Name_2 = "X";
            pFieldEdit.Length_2 = 20;
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            pField = new FieldClass();
            pFieldEdit = pField as IFieldEdit;
            pFieldEdit.Name_2 = "Y";
            pFieldEdit.Length_2 = 20;
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            IFeatureClass pFeatureClass = pFWS.CreateFeatureClass(file, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            
            for (int i = 0; i < 100;i+=10 )
            {
                for (int j = 0; j < 100;j+=10 )
                {
                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(i, j);
                    IFeature pFeature = pFeatureClass.CreateFeature();
                    pFeature.Shape = pPoint as IPoint;
                    pFeature.set_Value(pFeature.Fields.FindField("X"), i.ToString());
                    pFeature.set_Value(pFeature.Fields.FindField("Y"), j.ToString());
                    pFeature.Store();
                }
            }

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            pFeatureLayer.FeatureClass = pFeatureClass;
            return pFeatureLayer;
        }
    }
}

 

 

你可能感兴趣的:(源代码)