ArcGIS Pro SDK 将几何输出为要素

需求:

在获取到一个几何(geometry)的数据,我们需要将其输出为要素

解决方案:

1.创建要素

2.将几何写进要素中

cs 复制代码
//构建面几何
ArcGIS.Core.Geometry.Polygon mfGeoPolygon = new PolygonBuilderEx(mfGeoList, mapFrame.Map.SpatialReference).ToGeometry();
// 用于存储消息的字符串
string message = string.Empty;
// 标记创建结果的布尔值
bool creationResult = false;
var testName = $@"示例点{DateTime.Now:HHmmss}";
//创建要素类
 var hasZ = false;
var hasM = false;
// 创建一个ShapeDescription
var shapeDescription = new ShapeDescription(GeometryType.Polygon, SpatialReferences.WebMercator)
    {
        HasM = hasM,
        HasZ = hasZ
    };
                        // 定义字段
                        var stringFieldDescription = new ArcGIS.Core.Data.DDL.FieldDescription("字符串字段", FieldType.String);
                        // 打开默认数据库gdb
                        using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(gdbPath))))
                        {
                            var fcName = $@"{testName}";
                            try
                            {
                                // 收集字段列表
                                var fieldDescriptions = new List<ArcGIS.Core.Data.DDL.FieldDescription>() {
                                        stringFieldDescription
                              };
                                // 创建FeatureClassDescription
                                var fcDescription = new FeatureClassDescription(fcName, fieldDescriptions, shapeDescription);
                                // 创建SchemaBuilder
                                SchemaBuilder schemaBuilder = new SchemaBuilder(gdb);
                                // 将创建任务添加到DDL任务列表中
                                schemaBuilder.Create(fcDescription);
                                // 执行DDL
                                bool success = schemaBuilder.Build();

                                // 打开示例要素
                                using FeatureClass enterpriseFeatureClass = gdb.OpenDataset<FeatureClass>(fcName);
                                // 创建编辑操作对象
                                EditOperation editOperation = new EditOperation();
                                editOperation.Callback(context =>
                                {
                                    // 获取要素定义
                                    FeatureClassDefinition featureClassDefinition = enterpriseFeatureClass.GetDefinition();
                                    // 创建RowBuffer
                                    using RowBuffer rowBuffer = enterpriseFeatureClass.CreateRowBuffer();
                                    // 写入字段值
                                    //rowBuffer["SHP名称"] = "新名称";
                                    // 设置一组点集合,用来构面
                                    rowBuffer[featureClassDefinition.GetShapeField()] = mfGeoPolygon;
                                    // 在表中创建新行
                                    using Feature feature = enterpriseFeatureClass.CreateRow(rowBuffer);
                                    context.Invalidate(feature);      // 标记行为无效状态
                                }, enterpriseFeatureClass);
                                try
                                {
                                    // 执行编辑操作
                                    creationResult = editOperation.Execute();
                                    // 如果操作失败,存储错误消息
                                    if (!creationResult) { message = editOperation.ErrorMessage; }

                                }
                                catch (GeodatabaseException exObj)
                                {
                                    // 如果出现地理数据库异常,存储异常消息
                                    message = exObj.Message;
                                    throw;
                                }
                                if (!string.IsNullOrEmpty(message))
                                {
                                    // 如果消息不为空,显示消息框
                                    MessageBox.Show(message);
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show($@"Exception: {ex}");
                            }

参考文献:

【ArcGIS Pro二次开发】(40):创建行(Row)和要素(Feature)-CSDN博客

【ArcGIS Pro二次开发】(19):创建要素类(FeatureClass)_gdb要素类-CSDN博客

https://blog.csdn.net/xcc34452366/category_12199819_2.html(值得查看)

相关推荐
玩大数据的龙威7 小时前
农经权二轮延包—各种地块示意图
python·arcgis
雯0609~7 小时前
hiprint:实现项目部署与打印3-vue版本-独立出模板设计与模板打印页面
前端·vue.js·arcgis
玩大数据的龙威8 小时前
农经权二轮延包—一键生成界址点界址线(ArcGIS插件)
arcgis
leaguecn2 天前
ArcGIS授权管理器断网后自动停止
网络·arcgis·授权
咔咔一顿操作2 天前
轻量无依赖!autoviwe 页面自适应组件实战:从安装到源码深度解析
javascript·arcgis·npm·css3·html5
杨超越luckly2 天前
从传统 GIS 向智能/自动化脚本演进:地铁接驳公交识别的 ArcGIS 与 Python 双路径实践
开发语言·arcgis·php·交互·数据可视化
枝上棉蛮4 天前
2026年GIS软件精选:五款工具的专业性与实用性解析
arcgis·gis·qgis·超图·gisbox·地图数据处理·gis工具
激动的兔子4 天前
Arcgis二次开发--评价单元综合限制级别判断矩阵工具
线性代数·arcgis·矩阵
yngsqq4 天前
arcgis 制作图例、视图页面设置
arcgis
规划酱5 天前
Arcgis中pip安装ezdxf部分GIS有pyparsing安装失败的情况处理
python·arcgis·pip·规划酱