ArcGIS Pro SDK (九)几何 7 多点

2024-07-21 1680阅读

ArcGIS Pro SDK (九)几何 7 多点

文章目录

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

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

      ArcGIS Pro SDK (九)几何 7 多点
      (图片来源网络,侵删)

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

      // 使用 builderEx 的便捷方法或者使用 builderEx 构造函数。
      List list = new List();
      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

      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 inCoords = new List() { 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 修改多点的点

      // 假设一个多点是由 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 坐标

      ReadOnlyPointCollection points = multipoint.Points;
      IReadOnlyList coords2d = multipoint.Copy2DCoordinatesToList();
      IReadOnlyList coords3d = multipoint.Copy3DCoordinatesToList();
      
VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]