ArcGIS Pro SDK (九)几何 3 点

ArcGIS Pro SDK (九)几何 3 点

文章目录

  • [ArcGIS Pro SDK (九)几何 3 点](#ArcGIS Pro SDK (九)几何 3 点)
      • [1 构造地图点](#1 构造地图点)
      • [2 地图点生成器属性](#2 地图点生成器属性)
      • [3 地图点的相等性](#3 地图点的相等性)
      • [4 缩放至指定点](#4 缩放至指定点)

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

1 构造地图点

csharp 复制代码
// 使用生成器便捷方法或使用生成器构造函数。

// 创建一个带M的3D点
MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 2.0, 3.0, 4.0);

// builderEx构造函数不需要在MCT上运行。
MapPointBuilderEx mb = new MapPointBuilderEx(1.0, 2.0, 3.0, 4.0);
// 对生成器做一些操作

MapPoint ptWithM = mb.ToGeometry();

MapPoint clone = ptWithM.Clone() as MapPoint;
MapPoint anotherM = MapPointBuilderEx.CreateMapPoint(ptWithM);

MapPointBuilderEx builderEx = new MapPointBuilderEx(1.0, 2.0, 3.0);
builderEx.HasM = true;
builderEx.M = 4.0;

pt = builderEx.ToGeometry() as MapPoint;

// 或者使用另一种带builderEx构造函数的方法
builderEx = new MapPointBuilderEx(1.0, 2.0, true, 3.0, true, 4.0, false, 0);
pt = builderEx.ToGeometry() as MapPoint;

// 或者使用builderEx便捷方法
pt = MapPointBuilderEx.CreateMapPoint(1.0, 2.0, 3.0, 4.0);

2 地图点生成器属性

csharp 复制代码
// 使用builderEx便捷方法或builderEx构造函数。
// 这些都不需要在MCT上运行。

MapPoint point1 = null;
MapPoint point2 = null;

MapPointBuilderEx mb = new MapPointBuilderEx(1.0, 2.0, 3.0);
bool bhasZ = mb.HasZ;          // hasZ = true
bool bhasM = mb.HasM;          // hasM = false
bool bhasID = mb.HasID;        // hasID = false

// 对生成器做一些操作

point1 = mb.ToGeometry();

// 修改一些生成器属性
mb.X = 11;
mb.Y = 22;
mb.HasZ = false;
mb.HasM = true;
mb.M = 44;
// 创建另一个点
point2 = mb.ToGeometry();

double x = point1.X;                  // x = 1.0
double y = point1.Y;                  // y = 2.0
double z = point1.Z;                  // z = 3.0
double m = point1.M;                  // m = Nan
int ID = point1.ID;                   // ID = 0
bool hasZ = point1.HasZ;              // hasZ = true
bool hasM = point1.HasM;              // hasM = false
bool hasID = point1.HasID;            // hasID = false
bool isEmpty = point1.IsEmpty;        // isEmpty = false

bool isEqual = point1.IsEqual(point2);    // isEqual = false

// builderEx便捷方法
MapPoint point3 = MapPointBuilderEx.CreateMapPoint(point1);
x = point3.X;                   // x = 1.0
y = point3.Y;                   // y = 2.0
z = point3.Z;                   // z = 3.0
m = point3.M;                   // m = Nan
ID = point3.ID;                 // ID = 0
hasZ = point3.HasZ;             // hasZ = true
hasM = point3.HasM;             // hasM = false
hasID = point3.HasID;           // hasID = false

MapPointBuilderEx builderEx = new MapPointBuilderEx(point1);
x = builderEx.X;              // x = 1.0
y = builderEx.Y;              // y = 2.0
z = builderEx.Z;              // z = 3.0
m = builderEx.M;              // m = Nan
ID = builderEx.ID;            // ID = 0
hasZ = builderEx.HasZ;        // hasZ = true
hasM = builderEx.HasM;        // hasM = false
hasID = builderEx.HasID;      // hasID = false
isEmpty = builderEx.IsEmpty;     // isEmpty = false

MapPoint point4 = builderEx.ToGeometry() as MapPoint;

MapPoint point5 = MapPointBuilderEx.CreateMapPoint(point1);
x = point5.X;              // x = 1.0
y = point5.Y;              // y = 2.0
z = point5.Z;              // z = 3.0
m = point5.M;              // m = Nan
ID = point5.ID;            // ID = 0
hasZ = point5.HasZ;        // hasZ = true
hasM = point5.HasM;        // hasM = false
hasID = point5.HasID;      // hasID = false
isEmpty = point5.IsEmpty;     // isEmpty = false

3 地图点的相等性

csharp 复制代码
MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, 5);
int ID = pt1.ID;           // ID = 5
bool hasID = pt1.HasID;     // hasID = true

MapPoint pt2 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, 0);
ID = pt2.ID;        // ID = 0
hasID = pt2.HasID;  // hasID = true

MapPoint pt3 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4);
ID = pt3.ID;          // ID = 0
hasID = pt3.HasID;    // hasID = false

MapPoint pt4 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 44);
ID = pt4.ID;          // ID = 0
hasID = pt4.HasID;    // hasID = false
bool hasM = pt4.HasM; // hasM = true

MapPoint pt5 = MapPointBuilderEx.CreateMapPoint(1, 2, 3);
ID = pt5.ID;          // ID = 0
hasID = pt5.HasID;    // hasID = false
hasM = pt5.HasM;      // hasM = false

bool isEqual = pt1.IsEqual(pt2);   // isEqual = false, 不同的ID
isEqual = pt2.IsEqual(pt3);        // isEqual = false, HasID不同
isEqual = pt4.IsEqual

4 缩放至指定点

csharp 复制代码
//创建一个点
var pt = MapPointBuilderEx.CreateMapPoint(x, y, 
               SpatialReferenceBuilder.CreateSpatialReference(4326));
//对其进行缓冲 - 目的是缩放
var poly = GeometryEngine.Instance.Buffer(pt, buffer_size);

//是否需要投影缓冲区多边形?
if (!MapView.Active.Map.SpatialReference.IsEqual(poly.SpatialReference))
{
  //投影多边形
  poly = GeometryEngine.Instance.Project(poly, MapView.Active.Map.SpatialReference);
}

// 必须在MCT上运行。
QueuedTask.Run(() =>
{
  //缩放 - 为动画效果添加延迟
  MapView.Active.ZoomTo(poly, new TimeSpan(0, 0, 0, 3));
});
相关推荐
CV大法好3 小时前
刘铁猛C#入门 027 抽象和开闭原则
开发语言·c#
离歌漠4 小时前
C#调用C++ DLL方法之P/Invoke
c++·c#·p/invoke
公子小六5 小时前
在WPF程序中实现PropertyGrid功能
windows·microsoft·c#·.net·wpf
dangoxiba5 小时前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第二十集:制作专门渲染HUD的相机HUD Camera和画布HUD Canvas
游戏·unity·c#·游戏引擎·playmaker
WangYan20226 小时前
泥石流灾害风险评估与模拟丨AI与R语言、ArcGIS、HECRAS融合,提升泥石流灾害风险预测的精度和准确性
arcgis·chatgpt·遥感技术·地质灾害·泥石流·hecras·风险评价
小吴同学·13 小时前
.NET6 WebApi第1讲:VSCode开发.NET项目、区别.NET5框架【两个框架启动流程详解】
c#·.netcore·.net core
bluefox197918 小时前
使用 Oracle.DataAccess.Client 驱动 和 OleDB 调用Oracle 函数的区别
开发语言·c#
鲤籽鲲19 小时前
C# MethodTimer.Fody 使用详解
开发语言·c#·mfc
工业3D_大熊20 小时前
3D可视化引擎HOOPS Luminate场景图详解:形状的创建、销毁与管理
java·c++·3d·docker·c#·制造·数据可视化