【ArcGIS Pro二次开发】(70):杂七杂八的记录

本文用于记录一些使用频率较高但归类繁杂,非系统性的一些代码。

主要方便自己使用和查阅,随时更新。


1、从GDB数据库中打开【FeatureDataset\FeatureClass\Table】

cs 复制代码
using Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(gdbPath)));
FeatureDataset featureDataset = gdb.OpenDataset<FeatureDataset>(featureDatasetName);
FeatureClass featureClass = gdb.OpenDataset<FeatureClass>(featureClassName);
Table table = gdb.OpenDataset<Table>(tableName);

2、从GDB数据库中获取【FeatureDatasetDefinition\FeatureClassDefinition\TableDefinition】

cs 复制代码
// 扩展用法:GetDefinitions<>
FeatureDatasetDefinition featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(featureDatasetName);
FeatureClassDefinition featureClassDefinition = gdb.GetDefinition<FeatureClassDefinition>(featureClassName);
TableDefinition tableDefinition = gdb.GetDefinition<TableDefinition>(tableName);

3、从【FeatureLayer\FeatureClass】中获取【Feature\Row】

cs 复制代码
using (RowCursor rowCursor = featureLayer.Search())
{
    while (rowCursor.MoveNext())
    {
        using Feature feature2 = rowCursor.Current as Feature;
        using Row row = rowCursor.Current;
    }
}

4、Feature转换为Geometry

cs 复制代码
Geometry geometry1 = feature.GetShape();

5、Geometry转换为Polygon

cs 复制代码
Polygon polygon1 = geometry as Polygon;

6、设置Feature的几何形状

cs 复制代码
feature.SetShape(geometry);

7、获取线、面要素的折点、首末点

cs 复制代码
ReadOnlyPointCollection mapPoints = polygon.Points;
ReadOnlyPointCollection mapPoints2 = polyline.Points;
MapPoint startPoint = mapPoints.First();
MapPoint endPoint = mapPoints.Last();

8、switch用法示例

cs 复制代码
string featureclass_type = esriGeometryType switch
{
    esriGeometryType.esriGeometryPoint => "Point",
    esriGeometryType.esriGeometryPolyline => "Polyline",
    esriGeometryType.esriGeometryPolygon => "Polygon",
    _ => "",
};

9、获取活动地图视图中选择框选定的要素【SelectiontSet】

cs 复制代码
SelectionSet selectedSet = MapView.Active.Map.GetSelection();

10、在MapTool中获取选择的要素【SelectiontSet】

cs 复制代码
SelectionSet selectedSet2 = MapView.Active.GetFeatures(geometry);

11、从【SelectionSet】中获取【Geometry】

cs 复制代码
var selectionList = selectedSet.ToDictionary();
Inspector inspector = new Inspector();
foreach (var selection in selectionList)
{
    MapMember mapMember = selection.Key;
    List<long> oids = selection.Value;
    foreach (var oid in oids)
    {
        inspector.Load(mapMember, oid);
        Polygon polygon2 = inspector.Shape as Polygon;
    }
}

12、Geometry的属性

cs 复制代码
double polygonArea = polygon.Area;  // 面积
Envelope polygonExtent = polygon.Extent;   // 范围
GeometryType geometryType = geometry.GeometryType;  // 要素类型
SpatialReference spatialReference = geometry.SpatialReference;   // 坐标系
int pointCount = polyline.PointCount;    // 折点数
相关推荐
rockey6279 小时前
基于AScript的Lua脚本语言发布啦
c#·.net·lua·script·动态脚本
IT古董9 小时前
【MES学习笔记系列】MES 厂商与产品对比
笔记·学习
wangyue_msn_869 小时前
Agent知识学习笔记——03 RAG
笔记·学习·ai编程
嘶哈哈哈10 小时前
# 异构十电机机架数学建模:从单电机力矩到受约束控制分配
笔记
呱呱巨基10 小时前
Linux 查找命令
linux·笔记·学习·查找命令
zhangrelay11 小时前
ROS 2 Lyrical 第4章 URDF机器人建模与Gazebo Garden仿真
linux·笔记·学习·ubuntu·机器人·ros2
疯狂打码的少年11 小时前
【数据结构】串的模式匹配:KMP算法(重点)
数据结构·笔记·算法
一米阳光866111 小时前
软考(中级)软件设计师核心笔记(8)数据结构——线性结构、数组、矩阵
数据结构·笔记·职场发展·软考·软件设计师·中级职称
半亩码田12 小时前
【.NET新特性·第11篇】C# 14 字段属性:告别手写 backing field
java·c#·.net
曹牧12 小时前
C#:问号
前端·数据库·c#