欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > ArcGIS Pro SDK (七)编辑 13 注解

ArcGIS Pro SDK (七)编辑 13 注解

2025/1/31 15:35:10 来源:https://blog.csdn.net/szy13323042191/article/details/140150680  浏览:    关键词:ArcGIS Pro SDK (七)编辑 13 注解

ArcGIS Pro SDK (七)编辑 13 注解

文章目录

  • ArcGIS Pro SDK (七)编辑 13 注解
    • 1 注释构建工具
    • 2 以编程方式启动编辑批注
    • 3 更新批注文本
    • 4 修改批注形状
    • 5 修改批注文本图形
    • 6 接地到网格

环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0

1 注释构建工具

// 在您的 config.daml 中设置 categoryRefID
// <tool id="..." categoryRefID="esri_editing_construction_annotation" caption="Create Anno" ...>// 在构造函数中选择 Sketch 类型 Point 或 Line 或 BezierLine...
internal class AnnoConstructionTool : MapTool
{public AnnoConstructionTool(){IsSketchTool = true;UseSnapping = true;SketchType = SketchGeometryType.Point;}protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry){if (CurrentTemplate == null || geometry == null)return false;// 创建编辑操作var createOperation = new EditOperation();createOperation.Name = string.Format("Create {0}", CurrentTemplate.Layer.Name);createOperation.SelectNewFeatures = true;var insp = CurrentTemplate.Inspector;var result = await QueuedTask.Run(() =>{// 获取注释属性类AnnotationProperties annoProperties = insp.GetAnnotationProperties();// 设置自定义注释属性annoProperties.TextString = "自定义文本";annoProperties.Color = ColorFactory.Instance.RedRGB;annoProperties.FontSize = 24;annoProperties.FontName = "Arial";annoProperties.HorizontalAlignment = ArcGIS.Core.CIM.HorizontalAlignment.Right;annoProperties.Shape = geometry;// 将注释属性分配回检查器insp.SetAnnotationProperties(annoProperties);// 队列特征创建createOperation.Create(CurrentTemplate.Layer, insp);// 执行操作return createOperation.Execute();});return result;}

2 以编程方式启动编辑批注

var plugin = FrameworkApplication.GetPlugInWrapper("esri_editing_EditVerticesText");
if (plugin.Enabled)((ICommand)plugin).Execute(null);

3 更新批注文本

await QueuedTask.Run(() =>
{// annoLayer 是您的注释图层...// 使用检查器方法学// 在 2.x 版本中 - var insp = new Inspector(true);var insp = new Inspector();insp.Load(annoLayer, oid);// 获取注释属性AnnotationProperties annoProperties = insp.GetAnnotationProperties();// 设置属性annoProperties.TextString = "Hello World";// 将注释属性分配回检查器insp.SetAnnotationProperties(annoProperties);// 创建和执行编辑操作EditOperation op = new EditOperation();op.Name = "Update annotation";op.Modify(insp);op.Execute();
});

4 修改批注形状

await QueuedTask.Run(() =>{// 不要使用 'Shape'....Shape 是注释文本的边界框,这不是您想要的...// 在 2.x 版本中 - var insp = new Inspector(true);var insp = new Inspector();insp.Load(annoLayer, oid);AnnotationProperties annoProperties = insp.GetAnnotationProperties();var shape = annoProperties.Shape;if (shape.GeometryType != GeometryType.GeometryBag){var newGeometry = GeometryEngine.Instance.Move(shape, 10, 10);annoProperties.Shape = newGeometry;insp.SetAnnotationProperties(annoProperties);EditOperation op = new EditOperation();op.Name = "Change annotation angle";op.Modify(insp);op.Execute();}});

5 修改批注文本图形

await QueuedTask.Run(() =>{var selection = annoLayer.GetSelection();if (selection.GetCount() == 0)return;// 使用第一个选中的要素// 在 2.x 版本中 - var insp = new Inspector(true);var insp = new Inspector();insp.Load(annoLayer, selection.GetObjectIDs().FirstOrDefault());// 如果不是注释要素,则应返回 null 的 getAnnoPropertiesAnnotationProperties annoProperties = insp.GetAnnotationProperties();// 获取文本图形CIMTextGraphic textGraphic = annoProperties.TextGraphic;// 修改文本textGraphic.Text = "Hello world";// 通过符号设置 x、y 偏移量var symbol = textGraphic.Symbol.Symbol;var textSymbol = symbol as CIMTextSymbol;textSymbol.OffsetX = 2;textSymbol.OffsetY = 3;textSymbol.HorizontalAlignment = HorizontalAlignment.Center;// 加载更新后的文本图形annoProperties.LoadFromTextGraphic(textGraphic);// 将注释属性分配回去insp.SetAnnotationProperties(annoProperties);EditOperation op = new EditOperation();op.Name = "modify symbol";op.Modify(insp);bool result = op.Execute();});

6 接地到网格

CIMGroundToGridCorrection correction = null;
bool isCorecting = correction.IsCorrecting();   // 等同于 correction != null && correction.Enabled;
bool UsingOffset = correction.UsingDirectionOffset();   // 等同于 correction.IsCorrecting() && correction.UseDirection;
double dOffset = correction.GetDirectionOffset(); // 等同于 correction.UsingDirectionOffset() ? correction.Direction : DefaultDirectionOffset;
bool usingDistanceFactor = correction.UsingDistanceFactor();  // 等同于 correction.IsCorrecting() && correction.UseScale;
bool usingElevation = correction.UsingElevationMode(); // 等同于 correction.UsingDistanceFactor() && c.ScaleType == GroundToGridScaleType.ComputeUsingElevation;
bool usingSFactor = correction.UsingConstantScaleFactor();  //; 等同于 correction.UsingDistanceFactor() && correction.ScaleType == GroundToGridScaleType.ConstantFactor;
double dSFactor = correction.GetConstantScaleFactor(); // 等同于 correction.UsingDistanceFactor() ? correction.ConstantScaleFactor : DefaultConstantScaleFactor;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com