ArcGIS Pro SDK (七)编辑 7 操作Blob字段
目录
- ArcGIS Pro SDK (七)编辑 7 操作Blob字段
- 1 使用属性检查器读取和写入 Blob 字段
- 2 在回调中使用行游标读取和写入 Blob 字段
环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0
1 使用属性检查器读取和写入 Blob 字段
QueuedTask.Run(() =>{// 将选定要素加载到检查器中var selectedFeatures = MapView.Active.Map.GetSelection();var insp = new Inspector();insp.Load(selectedFeatures.ToDictionary().Keys.First(), selectedFeatures.ToDictionary().Values.First());// 读取 Blob 字段并保存到文件var msw = new MemoryStream();msw = insp["Blobfield"] as MemoryStream;using (FileStream file = new FileStream(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write)){msw.WriteTo(file);}// 将文件读取到内存流中var msr = new MemoryStream();using (FileStream file = new FileStream(@"d:\images\Hydrant.jpg", FileMode.Open, FileAccess.Read)){file.CopyTo(msr);}// 将内存流中的数据放入 Blob 字段并保存到要素var op = new EditOperation();op.Name = "Blob Inspector";insp["Blobfield"] = msr;op.Modify(insp);op.Execute();});
2 在回调中使用行游标读取和写入 Blob 字段
QueuedTask.Run(() =>{var editOp = new EditOperation();editOp.Name = "Blob Cursor";var featLayer = MapView.Active.Map.FindLayers("Hydrant").First() as FeatureLayer;editOp.Callback((context) =>{using (var rc = featLayer.GetTable().Search(null, false)){while (rc.MoveNext()){using (var record = rc.Current){// 读取 Blob 字段并保存到文件var msw = new MemoryStream();msw = record["BlobField"] as MemoryStream;using (FileStream file = new FileStream(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write)){msw.WriteTo(file);}// 将文件读取到内存流中var msr = new MemoryStream();using (FileStream file = new FileStream(@"d:\images\Hydrant.jpg", FileMode.Open, FileAccess.Read)){file.CopyTo(msr);}// 将内存流中的数据放入 Blob 字段并保存到要素record["BlobField"] = msr;record.Store();}}}}, featLayer.GetTable());editOp.Execute();});