ARCGIS PRO DSK GraphicsLayer创建文本要素

简介: ARCGIS PRO DSK GraphicsLayer创建文本要素

一、判断GraphicsLayer层【地块注记】是否存在,如果不存在则新建、如果存在则删除所有要素

Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() '获取当前map对象中的GetLayer图层
Await QueuedTask.Run(Sub()
If GraphicsLayer Is Nothing = True Then
'创建 GraphicsLayer
If pmap.MapType <> MapType.Map Then Exit Sub ' Not 2D
Dim gl_param = New GraphicsLayerCreationParams
gl_param.Name = "地块注记"
'默认情况下会添加到目录的顶部
GraphicsLayer = LayerFactory.Instance.CreateLayer(Of ArcGIS.Desktop.Mapping.GraphicsLayer)(gl_param, pmap)
Else
'全选文本
Dim zj_zdmane As String = ""
zj_zdmane = "地块注记"
Dim elements = GraphicsLayer.GetElementsAsFlattenedList().Where(Function(gele As GraphicElement) gele.Name.StartsWith(zj_zdmane)) ’获取GetLayer图层中定义的元素(本例为text)
'删除选择text
GraphicsLayer.SelectElements(elements)
GraphicsLayer.RemoveElements(GraphicsLayer.GetSelectedElements())
End If
MapView.Active.Redraw(True) '视图刷新
End Sub)
二、CreateTextGraphicElement 方法
​GraphicElement CreateTextGraphicElement(
IElementContainer elementContainer,
TextType textType,
Geometry geometry,
CIMTextSymbol textSymbol,
string text,
string elementName,
bool select, 【可选】
ElementInfo elementInfo 【可选】
)
textType:要创建的文本图形的类型​

成员 描述
CircleParagraph 圆文本
EllipseParagraph 椭圆文本
None None- 默认
PointText 点文本
PolygonParagraph 多边形文本
RectangleParagraph 矩形文本
SplinedText 沿直线或曲线样条的文本
三、检查应用程序中是否有特定字体可用于 Pro 会话。 必须在 MCT 上调用此方法。IsFontAvailable 方法 (SymbolFactory)
public bool IsFontAvailable(
string fontName,
string fontStyle,
FontType fontType,
List fontVariationSettings
)
fontName:字体簇的名称。
fontStyle :字体样式的名称。
fontType:字体类型。
fontVariationSettings:要应用的任何字体变体设置。可以为 null。
返回值:一个布尔值,表示字体是否可用。例如:

Dim BOOT=SymbolFactory.Instance.IsFontAvailable("Arial", "Bold", FontType.Unspecified, null)
四、创建文本
1、创建简单的文本符号(Creates a simple text symbol)创建一个大小为8.5、字体系列为“Corbel”、字体样式为“Regular”的简单黑色文本符号。

Await QueuedTask.Run(Sub()
pmap = MapView.Active.Map ‘获取激活的map对象
Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() ‘获取的GraphicsLayer对象
Dim TextSymbol =SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular")
'文本的偏移量
TextSymbol.OffsetX = 0.5
TextSymbol.OffsetY = 0.5
Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)
Dim text As String = "Forest Grove"
Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")
End Sub)
效果:

2、创建创建带有光晕环的文本符号(Creates a text symbol with a halo)

Await QueuedTask.Run(Sub()
pmap = MapView.Active.Map ‘获取激活的map对象
Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() ‘获取的GraphicsLayer对象

                     Dim haloPoly = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid)

                     Dim TextSymbol = SymbolFactory.Instance.ConstructTextSymbol(haloPoly, 10, "Arial", "Bold")
                     '文本的偏移量
                     TextSymbol.OffsetX = 0.5
                     TextSymbol.OffsetY = 0.5
                     Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)
                     Dim text As String = "Portland"
                     Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")
                 End Sub)

效果:

3、创建简单的牵引文本符号(Creates a text symbol with a halo)

Await QueuedTask.Run(Sub()
pmap = MapView.Active.Map ‘获取激活的map对象
Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() ‘获取的GraphicsLayer对象

                     Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 10, "Verdana", "Regular")

                     Dim lineCalloutSymbol = new CIMSimpleLineCallout()
                     Dim lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot)
                     lineCalloutSymbol.LineSymbol = lineSymbol
                     '文本的偏移量
                     TextSymbol.OffsetX = 10
                     TextSymbol.OffsetY = 10
                     textSymbol.Callout = lineCalloutSymbol
                     Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)
                     Dim text As String = "Forest Grove"
                     Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")
                 End Sub)

效果:

4、创建圆角矩形的牵引文本框符号(Creates a balloon callout text symbol)

Await QueuedTask.Run(Sub()
pmap = MapView.Active.Map ‘获取激活的map对象
Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() ‘获取的GraphicsLayer对象
Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)
Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular")
Dim balloonCallout = new CIMBalloonCallout()
BalloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangle

                     Dim polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid)
                     BalloonCallout.BackgroundSymbol = polySymbol
                     BalloonCallout.Margin = new CIMTextMargin
                     With BalloonCallout.Margin
                        .Left = 5
                        .Right = 5
                        .Bottom = 5
                        .Top = 5
                    End With
                    TextSymbol.Callout = balloonCallout
                    Dim text As String = "Forest Grove"
                    Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.RectangleParagraph, Location, TextSymbol, text, "地块注记")
                 End Sub)

效果:

5、创建点符号的文本符号(Creates a point callout text symbol)

Await QueuedTask.Run(Sub()
pmap = MapView.Active.Map ‘获取激活的map对象
Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() ‘获取的GraphicsLayer对象

                     Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 6, "Tahoma", "Bold")
                     Dim shieldCalloutSymbol = new CIMPointSymbolCallout()
                     Dim symbolStyleItem = GetPointSymbol("ArcGIS 2D", "Shield 1")             
                     ShieldCalloutSymbol.PointSymbol = symbolStyleItem.Symbol as CIMPointSymbol
                     ShieldCalloutSymbol.PointSymbol.SetSize(18.0)
                     TextSymbol.Callout = shieldCalloutSymbol
                     Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)
                     Dim text As String = "I5"
                     Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")
                 End Sub)

效果:

6、创建设置矩形背景色的牵引文本框符号(Creates a background callout text symbol)

Await QueuedTask.Run(Sub()
pmap = MapView.Active.Map ‘获取激活的map对象
Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() ‘获取的GraphicsLayer对象
Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)
Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Tahoma", "Bold")
Dim backgroundCalloutSymbol = new CIMBackgroundCallout()
Dim lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot)
Dim aquaBackground = ColorFactory.Instance.CreateRGBColor(190, 255, 232, 100)
Dim polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(aquaBackground, SimpleFillStyle.Solid)
BackgroundCalloutSymbol.LeaderLineSymbol = lineSymbol
TextSymbol.OffsetX = 10
TextSymbol.OffsetY = 10
BackgroundCalloutSymbol.BackgroundSymbol = polySymbol
Dim accentSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)
BackgroundCalloutSymbol.AccentBarSymbol = accentSymbol
BackgroundCalloutSymbol.Margin = new CIMTextMargin
With BalloonCallout.Margin
.Left = 5
.Right = 5
.Bottom = 5
.Top = 5
End With
TextSymbol.Callout = backgroundCalloutSymbol
Dim text As String = "Forest Grove"
Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer,TextType.RectangleParagraph, poly, TextSymbol, text, "地块注记")
End Sub)
原文链接:https://blog.csdn.net/xa13850869/article/details/140301570

相关文章
|
3月前
|
数据采集 存储 编解码
使用Arcgis pro做流域分析(河网+集水区)
【8月更文挑战第10天】使用ArcGIS Pro进行流域分析包括河网与集水区提取。首先准备DEM及河流数据,然后在软件中加载。若无河网数据,可用“Fill”填洼、“Flow Direction”计算流向、“Flow Accumulation”计算累积量,并通过“Stream Definition”定义河流。集水区分析则使用“Watershed”工具确定特定点的流域范围。最后,通过符号化展示结果,并结合其他数据深入分析流域特性。注意数据质量与参数选择以保证分析准确性。
203 1
|
6月前
|
机器学习/深度学习 弹性计算 算法
ArcGIS Pro遥感影像分类:随机森林、支持向量机方法
ArcGIS Pro遥感影像分类:随机森林、支持向量机方法
374 1
|
6月前
|
存储 数据管理 定位技术
2024最新ArcGIS Pro 3.0.2 官方原版简体中文直装版
ArcGIS Pro是由Esri开发的专业地理信息系统(GIS)软件,提供先进的地图制图、空间分析和数据管理功能。它支持多维数据集成,具有直观的用户界面,适用于各种地理信息应用,包括城市规划、环境管理和资源分析。
|
6月前
|
定位技术
ArcGIS面要素最小外接矩形、外接圆的绘制方法
ArcGIS面要素最小外接矩形、外接圆的绘制方法
101 1
|
6月前
|
定位技术
ArcGIS手动分割矢量面要素从而划分为多个面部分的方式:Cut Polygons Tool
ArcGIS手动分割矢量面要素从而划分为多个面部分的方式:Cut Polygons Tool
168 1
|
6月前
ArcGIS中ArcMap求取点要素在栅格图像中的行列号的方法
ArcGIS中ArcMap求取点要素在栅格图像中的行列号的方法
|
6月前
|
编解码 定位技术 Python
Python中ArcPy实现ArcGIS自动批量制图与地图要素批量设置
Python中ArcPy实现ArcGIS自动批量制图与地图要素批量设置
181 1
|
6月前
|
数据库
ArcGIS中ArcMap新建矢量点线面要素图层并手动划定要素图层范围区域
ArcGIS中ArcMap新建矢量点线面要素图层并手动划定要素图层范围区域
158 1
|
6月前
ArcGIS中ArcMap相交分析Intersect解决要素落入另一多部分矢量面要素的问题
ArcGIS中ArcMap相交分析Intersect解决要素落入另一多部分矢量面要素的问题
|
人工智能 数据可视化 API
ArcGIS API for Python
ArcGIS API for Python
68 0