C# ArcEngine 添加打开Shp矢量数据.doc
文本预览下载声明
using System;
using System.Collections.Generic;
usingSystem.ComponentModel;
using System.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingESRI.ArcGIS.Carto;
usingESRI.ArcGIS.DataSourcesFile;
usingESRI.ArcGIS.Geodatabase;
private void 打开矢量数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
? ? OpenFileDialog ?file ?= ?new ?OpenFileDialog();
? ? file.Filter ?= ?Shp文件|*.shp;
? ? if ( file.ShowDialog() == DialogResult.OK )
? ? ? ? {
? ? ? ? ? ? string ?path ?= ?file.FileName;
? ? ? ? ? ? string ?folder ?= ?System.IO.Path.GetDirectoryName(path);
? ? ? ? ? ? string ?filename ?= ?System.IO.Path.GetFileName(path);
? ? ? ? ? ? IWorkspaceFactory ?wsf ?= ?new ?ShapefileWorkspaceFactory();
? ? ? ? ? ? IWorkspace ?ws ?= ?wsf.OpenFromFile(folder,0);
? ? ? ? ? ? IFeatureWorkspace ?fws ?= ?ws ?as ?IFeatureWorkspace;
? ? ? ? ? ? IFeatureClass ?fc ?= ?fws.OpenFeatureClass(filename);
? ? ? ? ? ? IFeatureLayer ?fl ?= ?new ?FeatureLayer();
? ? ? ? ? ? fl.FeatureClass ?= ?fc;
? ? ? ? ? ? fl.Name ?= ?fc.AliasName;
? ? ? ? ? ? axMapControl1.AddLayer(fl);
? ? ? ? ? ??axMapControl1.ActiveView.Refresh();
? ? ? ? }
? ? else
? ? ? ? return;
}
显示全部