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();
}
});