【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;    // 折点数
相关推荐
CSDN_PBB3 小时前
[STM32 - 野火] - - - 固件库学习笔记 - - - 十五.设置FLASH的读写保护及解除
笔记·stm32·学习
夜流冰8 小时前
编程参考 - C语言可变参数
笔记
格雷亚赛克斯9 小时前
Qt笔记31-69
数据库·笔记·qt
Long_poem9 小时前
【自学笔记】版本控制与持续集成基础知识点总览-持续更新
笔记·ci/cd
浅陌sss9 小时前
Xlua中C#引用Lua变量,导致Lua侧的GC无法回收的原因及解决方法
c#·lua
棉晗榜9 小时前
c#模拟鼠标点击左键
c#
Stream٩( 'ω' )و9 小时前
109~133笔记
笔记
weixin_5025398510 小时前
rust学习笔记2-rust的包管理工具Cargo使用
笔记·学习·rust
爱吃香蕉的阿豪11 小时前
在c#中虚方法和抽象类的区别
深度学习·c#·.netcore
孤独得猿11 小时前
排序算法复习——包括插入排序、希尔排序、冒泡排序、快排(包括霍尔法、挖坑法、快慢指针法)、堆排、选择排序、归并排序等 (代码采用c/c++混编)
c语言·数据结构·c++·笔记·算法·排序算法