ArcGIS Pro SDK (九)几何 7 多点

ArcGIS Pro SDK (九)几何 7 多点

文章目录

  • [ArcGIS Pro SDK (九)几何 7 多点](#ArcGIS Pro SDK (九)几何 7 多点)
    • [1 构造多点 - 从映射点的枚举](#1 构造多点 - 从映射点的枚举)
    • [2 构造多点 - 使用 MultipointBuilderEx](#2 构造多点 - 使用 MultipointBuilderEx)
    • [3 修改多点的点](#3 修改多点的点)
    • [4 从多点检索点、2D 坐标、3D 坐标](#4 从多点检索点、2D 坐标、3D 坐标)

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

1 构造多点 - 从映射点的枚举

csharp 复制代码
// 使用 builderEx 的便捷方法或者使用 builderEx 构造函数。

List<MapPoint> list = new List<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(1.0, 1.0));
list.Add(MapPointBuilderEx.CreateMapPoint(1.0, 2.0));
list.Add(MapPointBuilderEx.CreateMapPoint(2.0, 2.0));
list.Add(MapPointBuilderEx.CreateMapPoint(2.0, 1.0));

// 使用 builderEx 构造函数 - 不需要在 MCT 上运行。
// 使用 AttributeFlags.NoAttributes - 我们在列表中有 2d 点
MultipointBuilderEx builderEx = new MultipointBuilderEx(list, AttributeFlags.None);
Multipoint multiPoint = builderEx.ToGeometry() as Multipoint;
int ptCount = builderEx.PointCount;

// builderEx 便捷方法不需要在 MCT 上运行
multiPoint = MultipointBuilderEx.CreateMultipoint(list);
// multiPoint.HasZ, HasM, HasID 将为 false - 属性是根据列表中点的属性状态确定的

// 或者具体设置状态
multiPoint = MultipointBuilderEx.CreateMultipoint(list, AttributeFlags.None);
// multiPoint.HasM = false

multiPoint = MultipointBuilderEx.CreateMultipoint(list, AttributeFlags.HasM);
// multiPoint.HasM = true

ptCount = multiPoint.PointCount;

2 构造多点 - 使用 MultipointBuilderEx

csharp 复制代码
Coordinate2D[] coordinate2Ds = new Coordinate2D[] { new Coordinate2D(1, 2), new Coordinate2D(-1, -2) };
SpatialReference sr = SpatialReferences.WGS84;

MultipointBuilderEx builder = new MultipointBuilderEx(coordinate2Ds, sr);

// builder.PointCount = 2

builder.HasZ = true;
// builder.Zs.Count = 2
// builder.Zs[0] = 0
// builder.Zs[1] = 0

builder.HasM = true;
// builder.Ms.Count = 2
// builder.Ms[0] = NaN
// builder.Ms[1] = NaN

builder.HasID = true;
// builder.IDs.Count = 2
// builder.IDs[0] = 0
// builder.IDs[1] = 0

// 设置为空
builder.SetEmpty();
// builder.Coords.Count = 0
// builder.Zs.Count = 0
// builder.Ms.Count = 0
// builder.IDs.Count = 0


// 重置坐标
List<Coordinate2D> inCoords = new List<Coordinate2D>() { new Coordinate2D(1, 2), new Coordinate2D(3, 4), new Coordinate2D(5, 6) };
builder.Coordinate2Ds = inCoords;
// builder.Coords.Count = 3
// builder.HasZ = true
// builder.HasM = true
// builder.HasID = true

double[] zs = new double[] { 1, 2, 1, 2, 1, 2 };
builder.Zs = zs;   
// builder.Zs.Count = 6

double[] ms = new double[] { 0, 1 };
builder.Ms = ms;   
// builder.Ms.Count = 2

// 坐标现在为   (x, y, z, m, id)
//  (1, 2, 1, 0, 0), (3, 4, 2, 1, 0) (5, 6, 1, NaN, 0)

MapPoint mapPoint = builder.GetPoint(2);
// mapPoint.HasZ = true
// mapPoint.HasM = true
// mapPoint.HasID = true
// mapPoint.Z  = 1
// mapPoint.M = NaN
// mapPoint.ID = 0

// 添加一个 M 到列表
builder.Ms.Add(2);
// builder.Ms.count = 3

// 坐标现在为   (x, y, z, m, id)
//  (1, 2, 1, 0, 0), (3, 4, 2, 1, 0) (5, 6, 1, 2, 0)

// 现在再次获取第二个点;它现在将有一个 M 值
mapPoint = builder.GetPoint(2);
// mapPoint.M = 2


int[] ids = new int[] { -1, -2, -3 };
// 分配 ID 值
builder.IDs = ids;

// 坐标现在为   (x, y, z, m, id)
//  (1, 2, 1, 0, -1), (3, 4, 2, 1, -2) (5, 6, 1, 2, -3)


// 创建一个新点
MapPoint point = MapPointBuilderEx.CreateMapPoint(-300, 400, 4);
builder.SetPoint(2, point);

// 坐标现在为   (x, y, z, m, id)
//  (1, 2, 1, 0, -1), (3, 4, 2, 1, -2) (-300, 400, 4, NaN, 0)


builder.RemovePoints(1, 3);
// builder.PointCount = 1

3 修改多点的点

csharp 复制代码
// 假设一个多点是由 4 个点构成的
// 修改后的多点将移除第一个点并移动最后一个点

// 使用 builderEx 构造函数 = 不需要在 MCT 上运行。
MultipointBuilderEx builderEx = new MultipointBuilderEx(multipoint);
// 移除第一个点
builderEx.RemovePoint(0);
// 修改最后一个点的坐标
var ptEx = builderEx.GetPoint(builderEx.PointCount - 1);
builderEx.RemovePoint(builderEx.PointCount - 1);

var newPtEx = MapPointBuilderEx.CreateMapPoint(ptEx.X + 1.0, ptEx.Y + 2.0);
builderEx.AddPoint(newPtEx);
Multipoint modifiedMultiPointEx = builderEx.ToGeometry() as Multipoint;

4 从多点检索点、2D 坐标、3D 坐标

csharp 复制代码
ReadOnlyPointCollection points = multipoint.Points;
IReadOnlyList<Coordinate2D> coords2d = multipoint.Copy2DCoordinatesToList();
IReadOnlyList<Coordinate3D> coords3d = multipoint.Copy3DCoordinatesToList();
相关推荐
FL162386312914 小时前
[C#][winform]segment-anything分割万物部署onnx模型一键抠图演示
开发语言·c#
love530love16 小时前
OpenClaw 手机直连配置全流程
人工智能·windows·python·智能手机·c#·agent·openclaw
bcbobo21cn17 小时前
C# byte类型和byte数组的使用
开发语言·c#·字节数组·byte类型
奔跑的呱呱牛19 小时前
GeoJSON 在大数据场景下为什么不够用?替代方案分析
java·大数据·servlet·gis·geojson
月巴月巴白勺合鸟月半19 小时前
一次PDF文件的处理(一)
pdf·c#
大鹏说大话21 小时前
Java 锁膨胀机制深度解析:从偏向锁到重量级锁的进化之路
开发语言·c#
武藤一雄1 天前
WPF处理耗时操作的7种方法
microsoft·c#·.net·wpf
武藤一雄1 天前
C#常见面试题100问 (第一弹)
windows·microsoft·面试·c#·.net·.netcore
2401_863801461 天前
3DTiles总体介绍,什么是3DTiles,主要用途
3d·arcgis·3dtiles
l1t1 天前
DeepSeek总结的用 C# 构建 DuckDB 插件说明
前端·数据库·c#·插件·duckdb