目录

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();
本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
丁总学Java33 分钟前
用 npm list -g --depth=0 探索全局包的秘密 ✨
arcgis·npm·list
DXM05211 小时前
ArcGIS Engine开发教程--从零搭建GIS桌面应用
大数据·数据库·arcgis·c#·arcgis engine·arcgis engine开发
专注VB编程开发20年2 小时前
WebView2最低支持.NET frame4.5,win7系统
c#·.net·webview2·vb.net
丁总学Java3 小时前
为什么 npm list -g 没显示 node_modules?✨
arcgis·npm·list
图导物联4 小时前
GIS-AI 融合引擎架构:智慧景区导览系统的毫秒级响应与千级并发优化实战
python·ar·gis·智慧文旅·景区导览
时光追逐者4 小时前
一款基于 .NET 8 + Vue 开源的、企业级中后台权限管理系统
前端·vue.js·microsoft·开源·c#·.net·.netcore
整点薯条吃吃喽5 小时前
C,C++,C#
c语言·c++·c#
专注VB编程开发20年5 小时前
C#,VB.NET正则表达式法替换代码
正则表达式·c#·.net·vb.net
局外人_Jia5 小时前
【 C# 使用 MiniExcel 库的典型场景】
开发语言·windows·c#·miniexcel
Verdure陌矣14 小时前
游戏开发中 C#、Python 和 C++ 的比较
c++·python·游戏·c#