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(值得查看)

相关推荐
En^_^Joy2 天前
Vue项目创建与入口配置全攻略
前端·vue.js·arcgis
图件制作GIS,储量计算3 天前
补充耕地项目类、非项目类资料清单
arcgis
不在逃避q3 天前
Trae/Vs Code/Cursor命令行无法跑npm命令
前端·arcgis·npm
GISerQ.4 天前
ArcGIS实现矢量拓扑检查与修复
arcgis·拓扑检查·拓扑修复
NutShell Wang4 天前
零依赖架构实战:451个HTML文件如何用63KB平均体积交付3584个交互模块
前端·人工智能·arcgis·npm·开源·html·vibe coding
开开心心就好4 天前
电脑内存优化工具一键释放内存超简单
java·开发语言·macos·arcgis·ocr·excel·音视频
半句唐诗5 天前
Ubuntu 离线安装 OpenSpec CLI、CodeGraph CLI 与相关工具实战笔记
ubuntu·arcgis
GIS思维6 天前
2026年最新可用ArcGIS在线地图图源集——影像、地形图、道路交通、海图、地形图 ······
arcgis·arcgispro·arcgisonline·高清影像图
非科班Java出身GISer6 天前
ArcGIS JS 基础教程(22):BuildingSceneLayer 建筑场景图层
arcgis·arcgis js 建筑·arcgis building·arcgis加载bim数据·arcgis js bim·arcgis加载建筑数据·arcgis js加载建筑
图件制作GIS,储量计算9 天前
补充耕地质量验收实施细则(试行)
arcgis·数据挖掘·数据分析