ArcGIS Pro SDK (九)几何 8 线段
文章目录
- [ArcGIS Pro SDK (九)几何 8 线段](#ArcGIS Pro SDK (九)几何 8 线段)
-
- [1 使用两个地图点构造线段](#1 使用两个地图点构造线段)
- [2 更改线段坐标](#2 更改线段坐标)
环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0
1 使用两个地图点构造线段
csharp
// 使用 builderEx 的便捷方法或使用 builderEx 构造函数。
MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
MapPoint endPt = MapPointBuilderEx.CreateMapPoint(2.0, 1.0);
// BuilderEx 的便捷方法不需要在 MCT 上运行。
LineSegment lineFromMapPoint = LineBuilderEx.CreateLineSegment(startPt, endPt);
// coordinate2D
Coordinate2D start2d = (Coordinate2D)startPt;
Coordinate2D end2d = (Coordinate2D)endPt;
LineSegment lineFromCoordinate2D = LineBuilderEx.CreateLineSegment(start2d, end2d);
// coordinate3D
Coordinate3D start3d = (Coordinate3D)startPt;
Coordinate3D end3d = (Coordinate3D)endPt;
LineSegment lineFromCoordinate3D = LineBuilderEx.CreateLineSegment(start3d, end3d);
// lineSegment
LineSegment anotherLineFromLineSegment = LineBuilderEx.CreateLineSegment(lineFromCoordinate3D);
// builderEx 的构造函数不需要在 MCT 上运行
LineBuilderEx lbEx = new LineBuilderEx(startPt, endPt);
lineFromMapPoint = lbEx.ToSegment() as LineSegment;
lbEx = new LineBuilderEx(start2d, end2d);
lineFromCoordinate2D = lbEx.ToSegment() as LineSegment;
lbEx = new LineBuilderEx(start3d, end3d);
lineFromCoordinate3D = lbEx.ToSegment() as LineSegment;
lbEx = new LineBuilderEx(startPt, endPt);
lineFromMapPoint = lbEx.ToSegment() as LineSegment;
lbEx = new LineBuilderEx(lineFromCoordinate3D);
anotherLineFromLineSegment = lbEx.ToSegment() as LineSegment;
2 更改线段坐标
csharp
// builderEx 的构造函数不需要在 MCT 上运行
LineBuilderEx lbuilderEx = new LineBuilderEx(lineSegment);
// 查找现有的坐标
lbuilderEx.QueryCoords(out startPt, out endPt);
// 或者使用
//startPt = lbuilderEx.StartPoint;
//endPt = lbuilderEx.EndPoint;
// 更新坐标
lbuilderEx.SetCoords(GeometryEngine.Instance.Move(startPt, 10, 10) as MapPoint, GeometryEngine.Instance.Move(endPt, -10, -10) as MapPoint);
// 或者使用
//lbuilderEx.StartPoint = GeometryEngine.Instance.Move(startPt, 10, 10) as MapPoint;
//lbuilderEx.EndPoint = GeometryEngine.Instance.Move(endPt, -10, -10) as MapPoint;
LineSegment segment2 = lbuilderEx.ToSegment() as LineSegment;