ArcGIS Pro SDK (九)几何 6 包络

ArcGIS Pro SDK (九)几何 6 包络

文章目录

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

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

1 构造包络

csharp 复制代码
// 使用 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 字符串

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

3 合并两个包络

csharp 复制代码
// 使用便利构建器
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 与两个包络相交

csharp 复制代码
// 使用便捷的 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 展开包络

csharp 复制代码
// 使用 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 更新包络的坐标

csharp 复制代码
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 < XMin,则同时更改 XMin 和 XMax
builderEx.XMax = 3;
// builderEx.XMin, YMin, ZMin, MMin  = 3, 3, 0, double.Nan
// builderEx.XMax, YMax, ZMax, MMax = 3, 4, 0, double.Nan

// 设置 YMin
builderEx.YMin = 2;
// builderEx.XMin, YMin, ZMin, MMin  = 3, 2, 0, double.Nan
// builderEx.XMax, YMax, ZMax, MMax = 3, 4, 0, double.Nan

// 设置 ZMin。如果 ZMin > 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 < ZMin,则同时更改 ZMin 和 ZMax
builderEx.ZMax = -1;
// builderEx.XMin, YMin, ZMin, MMin  = 3, 2, -1, double.Nan
// builderEx.XMax, YMax, ZMax, MMax = 3, 4, -1, double.Nan

builderEx.SetZCoords(8, -5);
// builderEx.XMin, YMin, ZMin, MMin  = 3, 2, -5, double.Nan
// builderEx.XMax, YMax, ZMax, MMax = 3, 4, 8, double.Nan


builderEx.SetXYCoords(c1, c2);
// builderEx.XMin, YMin, ZMin, MMin  = 0, 3, -5, double.Nan
// builderEx.XMax, YMax, ZMax, MMax = 1, 5, 8, double.Nan


builderEx.HasM = true;
builderEx.SetMCoords(2, 5);

var geomEx = builderEx.ToGeometry();
相关推荐
~央千澈~4 小时前
UniApp完全支持快应用QUICKAPP-以及如何采用 Uni 模式开发发行快应用优雅草卓伊凡
arcgis
lijingguang5 小时前
在C#中根据URL下载文件并保存到本地,可以使用以下方法(推荐使用现代异步方式)
开发语言·c#
¥-oriented6 小时前
【C#中路径相关的概念】
开发语言·c#
ArabySide6 小时前
【WCF】通过AOP实现基于JWT的授权与鉴权的实践
c#·jwt·aop·wcf
xiaowu0807 小时前
C# Task异步的常用方法
c#
阿蒙Amon7 小时前
C# Linq to Objects 详解:集合处理的终极方案
c#·solr·linq
钢铁男儿7 小时前
C# 委托(调用带引用参数的委托)
java·mysql·c#
番茄小能手7 小时前
【全网唯一】C# 纯本地离线文字识别Windows版dll插件
开发语言·c#
敲敲敲-敲代码8 小时前
【ArcGIS10.2】网络数据集构建---最短路径分析
网络·arcgis
葬歌倾城8 小时前
waferMap图像渲染
c#·wpf