ArcGIS Pro SDK (九)几何 11 几何包

ArcGIS Pro SDK (九)几何 11 几何包

文章目录

  • [ArcGIS Pro SDK (九)几何 11 几何包](#ArcGIS Pro SDK (九)几何 11 几何包)
    • [1 构造几何包](#1 构造几何包)
    • [2 构造几何包 - 从几何枚举](#2 构造几何包 - 从几何枚举)
    • [3 构造几何包 - 来自 JSON、Xml](#3 构造几何包 - 来自 JSON、Xml)
    • [4 构造几何包 - 添加或插入几何枚举](#4 构造几何包 - 添加或插入几何枚举)

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

1 构造几何包

csharp 复制代码
MapPoint point = MapPointBuilderEx.CreateMapPoint(1, 2, SpatialReferences.WebMercator);

List<Coordinate2D> coords2D = new List<Coordinate2D>()
{
  new Coordinate2D(0, 0),
  new Coordinate2D(0, 1),
  new Coordinate2D(1, 1),
  new Coordinate2D(1, 0)
};

Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords2D, SpatialReferences.WGS84);
Polyline polyline = PolylineBuilderEx.CreatePolyline(coords2D, SpatialReferences.WebMercator);

GeometryBagBuilderEx builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);

GeometryBag emptyBag = builder.ToGeometry();
// emptyBag.IsEmpty = true 空几何包

builder.AddGeometry(point);
// builder.GeometryCount = 1 几何数量为 1

GeometryBag geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 1 部分数量为 1
// geometryBag.PointCount = 1 点数量为 1
// geometryBag.IsEmpty = false 几何包不为空

IReadOnlyList<Geometry> geometries = geometryBag.Geometries;
// geometries.Count = 1 几何数量为 1
// geometries[0] 是一个 MapPoint,空间参考为 WGS84

bool isEqual = geometryBag.IsEqual(emptyBag);   // isEqual = false 不相等

builder.InsertGeometry(0, multipoint);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2 部分数量为 2

geometries = geometryBag.Geometries;
// geometries.Count = 2 几何数量为 2
// geometries[0] 是 Multipoint
// geometries[1] 是 MapPoint

builder.AddGeometry(polyline);
builder.RemoveGeometry(1);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2 部分数量为 2

geometries = geometryBag.Geometries;
// geometries.Count = 2 几何数量为 2
// geometries[0] 是 Multipoint
// geometries[1] 是 Polyline          

2 构造几何包 - 从几何枚举

csharp 复制代码
// 使用 builder 的便捷方法或使用 builder 构造函数。

MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
Polyline polyline = PolylineBuilderEx.CreatePolyline(coords);

string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
Polygon polygon = PolygonBuilderEx.FromJson(json);

var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };

// Builder 的便捷方法不需要在 MCT 上运行。
// 在 2.x 版本中 - GeometryBag bag = GeometryBagBuilder.CreateGeometryBag(geometries, SpatialReferences.WGS84);
var bag = GeometryBagBuilderEx.CreateGeometryBag(geometries, SpatialReferences.WGS84);

// 在 2.x 版本中 - using (var builder = new GeometryBagBuilder(geometries, SpatialReferences.WGS84)) 
var builder = new GeometryBagBuilderEx(geometries, SpatialReferences.WGS84);
// 使用生成器执行操作
bag = builder.ToGeometry();

3 构造几何包 - 来自 JSON、Xml

csharp 复制代码
const string jsonString = "{\"geometries\":[{\"x\":1,\"y\":2},{\"rings\":[[[0,0],[0,4],[3,4],[3,0],[0,0]]]}],\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}";
// 在 2.x 版本中 - GeometryBag geometryBag = GeometryBagBuilder.FromJson(jsonString);
var geometryBag = GeometryBagBuilderEx.FromJson(jsonString);

string xml = geometryBag.ToXml();
// 在 2.x 版本中 - GeometryBag xmlString = GeometryBagBuilder.FromXML(xml);
var xmlString = GeometryBagBuilderEx.FromXml(xml);

4 构造几何包 - 添加或插入几何枚举

csharp 复制代码
MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
Polyline polyline = PolylineBuilderEx.CreatePolyline(coords);

string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
Polygon polygon = PolygonBuilderEx.FromJson(json);

var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };

// 在 2.x 版本中 - using (var builder = new GeometryBagBuilder(SpatialReferences.WGS84))
var builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
builder.AddGeometries(geometries);

GeometryBag geomBag = builder.ToGeometry();
// geomBag.PartCount == 4    (point, multipoint, polyline, polygon)

geometries = new List<Geometry>() { point, polyline };
builder.InsertGeometries(1, geometries);
// builder.GeometryCount == 6
geomBag = builder.ToGeometry();
// geomBag.PartCount == 6    (point, point, polyline, multipoint, polyline, polygon)
相关推荐
初九之潜龙勿用20 分钟前
C#校验画布签名图片是否为空白
开发语言·ui·c#·.net
吾与谁归in2 小时前
【C#设计模式(13)——代理模式(Proxy Pattern)】
设计模式·c#·代理模式
吾与谁归in2 小时前
【C#设计模式(14)——责任链模式( Chain-of-responsibility Pattern)】
设计模式·c#·责任链模式
神仙别闹3 小时前
基于C#和Sql Server 2008实现的(WinForm)订单生成系统
开发语言·c#
向宇it12 小时前
【unity小技巧】unity 什么是反射?反射的作用?反射的使用场景?反射的缺点?常用的反射操作?反射常见示例
开发语言·游戏·unity·c#·游戏引擎
九鼎科技-Leo13 小时前
什么是 WPF 中的依赖属性?有什么作用?
windows·c#·.net·wpf
Heaphaestus,RC14 小时前
【Unity3D】获取 GameObject 的完整层级结构
unity·c#
baivfhpwxf202314 小时前
C# 5000 转16进制 字节(激光器串口通讯生成指定格式命令)
开发语言·c#
直裾14 小时前
Scala全文单词统计
开发语言·c#·scala
GIS思维14 小时前
ArcGIS定义投影与投影的区别(数据和底图不套合的原因和解决办法)
arcgis·gis·地理信息·arcgis坐标系·动态投影