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

相关推荐
玩大数据的龙威13 小时前
农经权二轮延包—付费软件插件与免费软件插件汇总
python·arcgis
墨黎芜1 天前
ArcGIS从入门到精通——地图符号、注记的初步使用
学习·arcgis·信息可视化
GIS地信小匠2 天前
(31)ArcGIS Pro 定义投影与批量投影:矢量数据坐标转换工具实操
arcgis·空间分析·数据处理·gis教程·arcgls pro
非科班Java出身GISer3 天前
ArcGIS JS 基础教程(3):地图缩放、平移、旋转(基础交互)
arcgis·arcgis js地图交互·arcgis js缩放·arcgis js平移·arcgis js旋转·arcgis js基础交互
城数派3 天前
2025年我国省市县三级的平均坡度数据(Excel\Shp格式)
arcgis·信息可视化·数据分析·excel
装疯迷窍_A3 天前
以举证方位线生成工具为例,分享如何在Arcgis中创建Python工具箱(含源码)
开发语言·python·arcgis·变更调查·举证照片
Trustport4 天前
ArcGIS Maps SDK For Kotlin 加载Layout中的MapView出错
android·开发语言·arcgis·kotlin
GIS地信小匠4 天前
(30)ArcGIS Pro 查找相同项+删除相同项:矢量数据去重实操
arcgis·空间分析·数据处理·gis教程·arcgls pro
城数派5 天前
2025年我国乡镇的平均高程数据(Excel\Shp格式)
数据库·arcgis·信息可视化·数据分析·excel
城数派6 天前
2025年省市县三级的平均高程数据(Excel\Shp格式)
数据库·arcgis·信息可视化·excel