ArcGIS Pro SDK (九)几何 6 包络

07-19 882阅读

ArcGIS Pro SDK (九)几何 6 包络

文章目录

  • ArcGIS Pro SDK (九)几何 6 包络
    • 1 构造包络
    • 2 构造包络 - 从 JSON 字符串
    • 3 合并两个包络
    • 4 与两个包络相交
    • 5 展开包络
    • 6 更新包络的坐标

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

      ArcGIS Pro SDK (九)几何 6 包络
      (图片来源网络,侵删)

      1 构造包络

      // 使用 builderEx 的便捷方法或者使用 builderEx 构造函数。
      MapPoint minPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
      MapPoint maxPt = MapPointBuilderEx.CreateMapPoint(2.0, 2.0);
      Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(minPt, maxPt);
      EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(minPt, maxPt);
      envelope = builderEx.ToGeometry() as Envelope;
      

      2 构造包络 - 从 JSON 字符串

      string jsonString = "{ \"xmin\" : 1, \"ymin\" : 2,\"xmax\":3,\"ymax\":4,\"spatialReference\":{\"wkid\":4326}}";
      Envelope envFromJson = EnvelopeBuilderEx.FromJson(jsonString);
      

      3 合并两个包络

      // 使用便利构建器
      Envelope env1 = EnvelopeBuilderEx.CreateEnvelope(0, 0, 1, 1, SpatialReferences.WGS84);
      Envelope env2 = EnvelopeBuilderEx.CreateEnvelope(0.5, 0.5, 1.5, 1.5, SpatialReferences.WGS84);
      Envelope env3 = env1.Union(env2);
      double area = env3.Area;
      double depth = env3.Depth;
      double height = env3.Height;
      double width = env3.Width;
      double len = env3.Length;
      MapPoint centerPt = env3.Center;
      Coordinate2D coord = env3.CenterCoordinate;
      bool isEmpty = env3.IsEmpty;
      int pointCount = env3.PointCount;
      // 坐标
      //env3.XMin, env3.XMax, env3.YMin, env3.YMax
      //env3.ZMin, env3.ZMax, env3.MMin, env3.MMax
      bool isEqual = env1.IsEqual(env2);    // false
      // 或者使用 builderEx 构造函数,不需要在 MCT 上运行。
      EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(0, 0, 1, 1, SpatialReferences.WGS84);
      builderEx.Union(env2);      // 更新 builder 为结果
      depth = builderEx.Depth;
      height = builderEx.Height;
      width = builderEx.Width;
      centerPt = builderEx.Center;
      coord = builderEx.CenterCoordinate;
      isEmpty = builderEx.IsEmpty;
      env3 = builderEx.ToGeometry() as Envelope;
      

      4 与两个包络相交

      // 使用便捷的 builder 方法
      Envelope env1 = EnvelopeBuilderEx.CreateEnvelope(0, 0, 1, 1, SpatialReferences.WGS84);
      Envelope env2 = EnvelopeBuilderEx.CreateEnvelope(0.5, 0.5, 1.5, 1.5, SpatialReferences.WGS84);
      bool intersects = env1.Intersects(env2); // true
      Envelope env3 = env1.Intersection(env2);
      // 或者使用 builderEx 构造函数 = 不需要在 MCT 上运行。
      EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(0, 0, 1, 1, SpatialReferences.WGS84);
      intersects = builderEx.Intersects(env2);
      builderEx.Intersection(env2);   // 注意这会将 builder 设置为相交的结果
      env3 = builderEx.ToGeometry() as Envelope;
      

      5 展开包络

      // 使用 builderEx 的便捷方法或者使用 builderEx 构造函数。
      // 便捷方法不需要在 MCT 上运行。
      Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(100.0, 100.0, 500.0, 500.0);
      // 缩小封套大小 50%
      Envelope result = envelope.Expand(0.5, 0.5, true);
      // builderEx 构造函数不需要在 MCT 上运行。
      EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(100.0, 100.0, 500.0, 500.0);
      builderEx.Expand(0.5, 0.5, true);
      envelope = builderEx.ToGeometry() as Envelope;
      

      6 更新包络的坐标

      Coordinate2D minCoord = new Coordinate2D(1, 3);
      Coordinate2D maxCoord = new Coordinate2D(2, 4);
      Coordinate2D c1 = new Coordinate2D(0, 5);
      Coordinate2D c2 = new Coordinate2D(1, 3);
      // 使用 EnvelopeBuilderEx。这个构造函数不需要在 MCT 上运行。
      EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(minCoord, maxCoord);
      // builderEx.XMin, YMin, Zmin, MMin  = 1, 3, 0, double.Nan
      // builderEx.XMax, YMax, ZMax, MMax = 2, 4, 0, double.Nan
      // 设置 XMin。如果 XMin > XMax,则同时更改 XMin 和 XMax
      builderEx.XMin = 6;
      // builderEx.XMin, YMin, ZMin, MMin  = 6, 3, 0, double.Nan
      // builderEx.XMax, YMax, ZMax, MMax = 6, 4, 0, double.Nan
      // 设置 XMax
      builderEx.XMax = 8;
      // builderEx.XMin, YMin, ZMin, MMin  = 6, 3, 0, double.Nan
      // builderEx.XMax, YMax, ZMax, MMax = 8, 4, 0, double.Nan
      // 设置 XMax。如果 XMax  ZMax,则同时更改 ZMin 和 ZMax
      builderEx.ZMin = 3;
      // builderEx.XMin, YMin, ZMin, MMin  = 3, 2, 3, double.Nan
      // builderEx.XMax, YMax, ZMax, MMax = 3, 4, 3, double.Nan
      // 设置 ZMax。如果 ZMax 
                      
                      
                      
VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]