mysql添加栅格数据_ArcGIS Pro二次开发-添加一个栅格数据到当前窗口

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 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;

}

}

}

}

=====================添加矢量数据==============================

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;//using System.Windows;//using System.Windows.Forms;

usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingArcGIS.Desktop.Core.Geoprocessing;usingArcGIS.Desktop.Framework;usingArcGIS.Desktop.Framework.Contracts;usingArcGIS.Desktop.Framework.Dialogs;usingArcGIS.Desktop.Mapping;usingArcGIS.Desktop.Core;usingArcGIS.Desktop.Framework.Threading.Tasks;namespaceProAppModule1

{internal classButton1 : ArcGIS.Desktop.Framework.Contracts.Button

{string AddFieldName = "gisoracle";protected override async voidOnClick()

{awaitAddLayerToMapAsync();

}public static asyncTask 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(newUri(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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值