ArcGIS Pro二次开发-添加一个栅格数据到当前窗口
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Windows;
//using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
//using System.Windows;
//using System.Windows.Forms;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ArcGIS.Desktop.Core.Geoprocessing;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Framework.Threading.Tasks;
namespace ProAppModule1
{
internal class Button1 : ArcGIS.Desktop.Framework.Contracts.Button
{
string AddFieldName = "gisoracle";
protected override async void OnClick()
{
internal class Button1 : ArcGIS.Desktop.Framework.Contracts.Button
{
string AddFieldName = "gisoracle";
protected override async void OnClick()
{
await AddRasterLayerToMapAsync();
await AddRasterLayerToMapAsync();
}
public static async Task AddRasterLayerToMapAsync()
public static async Task AddRasterLayerToMapAsync()
{
try
{
// Gets the first 2D map from the project that is called Map.
Map _map = MapView.Active.Map;
if (_map == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("AddRasterLayerToMap: Failed to get map.");
return;
}
// Creates a url pointing to the source. In this case it is a url to an image service
// which will result in an image service layer being created.
//string dataSoureUrl = @"https://landsat2.arcgis.com/arcgis/services/Landsat/MS/ImageServer";
string dataSourceUrl = @"F:\2020book\toolforpro\MyProject3\ff\images\000000080.tif";
// Note: A url can also point to
// 1) An image on disk or in a file geodatabase, e.g., string dataSoureUrl = @"C:\temp\a.tif"; This results in a raster layer.
// 2) A mosaic dataset in a file gdb, e.g., string dataSoureUrl = @"c:\temp\mygdb.gdb\MyMosaicDataset"; This results in a mosaic layer.
// 3) A raster or mosaic dataset in an enterprise geodatabase.
// Creates an ImageServiceLayer object to hold the new layer.
RasterLayer imageLayer = null;
// The layer has to be created on the Main CIM Thread (MCT).
await QueuedTask.Run(() =>
{
// Creates a layer based on the url. In this case the layer we are creating is an image service layer.
imageLayer = (RasterLayer)LayerFactory.Instance.CreateLayer(new Uri(dataSourceUrl), _map);
if (imageLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + dataSourceUrl);
return;
}
});
}
catch (Exception exc)
{
// Catch any exception found and display a message box.
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to add layer: " + exc.Message);
return;
}
}
}
}
}
=====================添加矢量数据==============================
using System; using System.Collections.Generic; using System.Linq; //using System.Windows; //using System.Windows.Forms; using System.Text; using System.Threading; using System.Threading.Tasks; using ArcGIS.Desktop.Core.Geoprocessing; using ArcGIS.Desktop.Framework; using ArcGIS.Desktop.Framework.Contracts; using ArcGIS.Desktop.Framework.Dialogs; using ArcGIS.Desktop.Mapping; using ArcGIS.Desktop.Core; using ArcGIS.Desktop.Framework.Threading.Tasks; namespace ProAppModule1 { internal class Button1 : ArcGIS.Desktop.Framework.Contracts.Button { string AddFieldName = "gisoracle"; protected override async void OnClick() { await AddLayerToMapAsync(); } public static async Task AddLayerToMapAsync() { try { // Gets the first 2D map from the project that is called Map. Map _map = MapView.Active.Map; if (_map == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("AddLayerToMap: Failed to get map."); return; } string dataSourceUrl = @"E:\LQ\Kk.gdb\ds\lq"; Layer Layer = null; // The layer has to be created on the Main CIM Thread (MCT). await QueuedTask.Run(() => { // Creates a layer based on the url. In this case the layer we are creating is an image service layer. Layer = (Layer)LayerFactory.Instance.CreateLayer(new Uri(dataSourceUrl), _map); if (Layer == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + dataSourceUrl); return; } }); } catch (Exception exc) { // Catch any exception found and display a message box. ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to add layer: " + exc.Message); return; } } } }
来自:https://github.com/Esri/arcgis-pro-sdk/tree/master/Examples
分类:
C#
, ArcGIS Pro二次开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理