ArcEngine开发:创建shp数据文件,并存入Geometry类型的要素到shp数据文件

首先是一个创建shp数据文件的函数,具体参数能根据变量名称看出来。函数如下:

public static void CreatShpFile(string shpFullFilePath, ISpatialReference spatialReference, esriGeometryType pGeometryType, string shpFileName)
        {
            string pFileName = shpFullFilePath + shpFileName + ".shp";
            try
            {
                string shpFolder = System.IO.Path.GetDirectoryName(shpFullFilePath);
                IWorkspaceFactory pWorkspaceFac = new ShapefileWorkspaceFactoryClass();
                IWorkspace pWorkSpace = pWorkspaceFac.OpenFromFile(shpFolder, 0);
                IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace;
                //如果文件已存在               
                if (System.IO.File.Exists(pFileName))
                {
                    if (MessageBox.Show("文件已存在,是否覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                    {
          
C#中使用ArcGIS Engine开发环境来创建和操作二维图形控件涉及到以下几个步骤: 1. **添加引用**:首先,你需要在项目中添加对ArcGIS Engine和Shapefile库的引用。这通常可以在解决方案资源管理器中找到,并通过右键点击添加参考。 2. **初始化工作空间**:使用`ArcMap.DocumentClass.ArcMap`实例打开 ArcGIS 应用程序,然后通过`IApplication.Workspaces`属性获取工作空间目录。你可以使用`.Open()`方法加载.shp和.lyr文件。 ```csharp // 初始化工作空间 IArcMap map = (IArcMap)ArcMap.Application; IVsWorkbooks workbooks = map.Workspaces; IVsWorkspace workspace = workbooks.Open("路径到.shp和.lyr文件", 0); ``` 3. **加载数据**:使用`.OpenDataset()`方法加载Shapefile(`.shp`),并通过`.Layers`属性获取层集合。`.lyr`文件通常是包含图层定义的数据,如果需要,可以单独加载并添加到地图上。 ```csharp // 加载shapefile IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Shapefile名称"; featureLayer.Path = "path_to_shp_file.shp"; map.MapDocument.AddLayer(featureLayer); // 加载layer文件 ILayer lyr = featureLayer.GetTable().GetLayerByFilename("path_to_lyr_file.lyr"); map.MapDocument.AddLayer(lyr); ``` 4. **操作图形和访问属性**:你可以通过`IFeature`接口访问要素类的属性。例如,使用`Feature.Geometry`获取几何形状,`IFeature.Class.Fields`获取字段列表。 ```csharp // 获取第一个要素 IFeature selectedFeature = featureLayer.GetNextFeature(); // 访问属性 IFeatureClass featureClass = selectedFeature.Class; IField[] fields = featureClass.Fields; for (int i = 0; i < fields.Length; i++) { IField field = fields[i]; string fieldName = field.Name; object fieldValue = selectedFeature[fieldName]; Console.WriteLine($"{fieldName}: {fieldValue}"); } ``` 5. **显示控件**:对于图形控件,你可以选择使用 ArcGIS 的 UI 控件,如 `GraphicsControl` 来显示地图和要素。使用 `.AddChild` 方法将图形添加到控件中。 ```csharp IGraphicsContainer container = map.GraphicDisplay.Controls[0] as IGraphicsContainer; container.Add(selectedFeature); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值