ArcGIS Pro SDK (七)编辑 8 操作栅格字段

ArcGIS Pro SDK (七)编辑 8 操作栅格字段

目录

  • [ArcGIS Pro SDK (七)编辑 8 操作栅格字段](#ArcGIS Pro SDK (七)编辑 8 操作栅格字段)
    • [1 从栅格字段读取](#1 从栅格字段读取)
    • [2 将图像写入栅格字段](#2 将图像写入栅格字段)
    • [3 将压缩图像写入栅格字段](#3 将压缩图像写入栅格字段)

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

1 从栅格字段读取

csharp 复制代码
QueuedTask.Run(() =>
               {
                   var sel = MapView.Active.Map.GetSelection();

                   // 从栅格字段读取栅格作为 InteropBitmap
                   // 该位图可以用作图像源或写入磁盘
                   var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
                   insp.Load(sel.ToDictionary().Keys.First(), sel.ToDictionary().Values.First());
                   var ibmp = insp["Photo"] as System.Windows.Interop.InteropBitmap;
               });

2 将图像写入栅格字段

csharp 复制代码
QueuedTask.Run(() =>
               {
                   var sel = MapView.Active.Map.GetSelection();

                   // 将图像插入栅格字段
                   // 图像将以无压缩方式写入
                   var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
                   insp.Load(sel.ToDictionary().Keys.First(), sel.ToDictionary().Values.First());
                   insp["Photo"] = @"e:\temp\Hydrant.jpg";

                   var op = new EditOperation();
                   op.Name = "Raster Inspector";
                   op.Modify(insp);
                   op.Execute();
               });

3 将压缩图像写入栅格字段

csharp 复制代码
QueuedTask.Run(() =>
               {
                   // 打开磁盘上的栅格数据集并创建压缩栅格值数据集对象
                   var dataStore = new ArcGIS.Core.Data.FileSystemDatastore(new ArcGIS.Core.Data.FileSystemConnectionPath(new System.Uri(@"e:\temp"), ArcGIS.Core.Data.FileSystemDatastoreType.Raster));
                   using (var fileRasterDataset = dataStore.OpenDataset<ArcGIS.Core.Data.Raster.RasterDataset>("Hydrant.jpg"))
                   {
                       var storageDef = new ArcGIS.Core.Data.Raster.RasterStorageDef();
                       storageDef.SetCompressionType(ArcGIS.Core.Data.Raster.RasterCompressionType.JPEG);
                       storageDef.SetCompressionQuality(90);

                       var rv = new ArcGIS.Core.Data.Raster.RasterValue();
                       rv.SetRasterDataset(fileRasterDataset);
                       rv.SetRasterStorageDef(storageDef);

                       var sel = MapView.Active.Map.GetSelection();

                       // 将栅格值对象插入栅格字段
                       var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
                       insp.Load(sel.ToDictionary().Keys.First(), sel.ToDictionary().Values.First());
                       insp["Photo"] = rv;

                       var op = new EditOperation();
                       op.Name = "Raster Inspector";
                       op.Modify(insp);
                       op.Execute();
                   }
               });
相关推荐
懒人咖16 小时前
缺料分析时携带用料清单的二开字段
c#·金蝶云星空
bugcome_com17 小时前
深入了解 C# 编程环境及其开发工具
c#
wfserial19 小时前
c#使用微软自带speech选择男声仍然是女声的一种原因
microsoft·c#·speech
阔皮大师20 小时前
INote轻量文本编辑器
java·javascript·python·c#
kylezhao201921 小时前
C# 中的 SOLID 五大设计原则
开发语言·c#
啦啦啦_99991 天前
Redis-5-doFormatAsync()方法
数据库·redis·c#
Porco.w1 天前
C#与三菱PLC FX5U通信
网络·c#
E_ICEBLUE1 天前
PPT 批量转图片:在 Web 预览中实现翻页效果(C#/VB.NET)
c#·powerpoint·svg
JQLvopkk1 天前
C# 轻量级工业温湿度监控系统(含数据库与源码)
开发语言·数据库·c#
玩大数据的龙威1 天前
农经权二轮延包—各种地块示意图
python·arcgis