【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;    // 折点数
相关推荐
风曦Kisaki3 小时前
Kubernetes(K8s)笔记Day06: 持久化存储(emptyDir,hostPath,NFS),PV 和 PVC,StorageClass存储类
linux·运维·笔记·云原生·容器·kubernetes
wgego8 小时前
基础的反序列化一些总结(php和java)
java·开发语言·笔记
雪隐9 小时前
WPF + MVVM 实战系列01-一个老狗回炉重造 WPF 的 12 天血泪史
sqlite·c#·mvvm
在世修行10 小时前
从零打造 C# 工业视觉检测系统(四):海康威视 MVS SDK 入门与相机枚举实战
数码相机·c#·视觉检测
神秘的MT11 小时前
C# WinForm Socket 服务器 + 串口转发
服务器·网络·学习·c#
依然范特东11 小时前
强化学习笔记6--IS、PPO、TD、DQN、Actor-Critic
笔记·算法
Mxzx品牌13 小时前
佛山招聘软件哪个好:【帅聘网】匹配度高
笔记·其他·生活
九硕智慧建筑一体化厂家13 小时前
无线动能开关|烘焙后厨防潮免布线照明控制方案
运维·笔记·智慧城市
ZZHow102414 小时前
PyTorch深度学习入门笔记(小土堆)P7-14
人工智能·pytorch·笔记·python·深度学习
九硕智慧建筑一体化厂家14 小时前
直流照明|档案库房专用照明,防紫外线、防纸张老化、适配24小时值守
运维·网络·笔记·智慧城市