zoukankan      html  css  js  c++  java
  • 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 oolforproMyProject3ffimages00000080.tif";
                    // Note: A url can also point to 
                    // 1) An image on disk or in a file geodatabase, e.g., string dataSoureUrl = @"C: empa.tif"; This results in a raster layer.
                    // 2) A mosaic dataset in a file gdb, e.g., string dataSoureUrl = @"c: empmygdb.gdbMyMosaicDataset"; 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:LQKk.gdbdslq";
    
                    
    
                    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 

  • 相关阅读:
    BeautifulSoup使用总结
    使用python爬取整本《盗墓笔记》
    matplotlib使用总结
    模拟退火算法
    pandas实战——对星巴克数据的分析
    pandas使用总结
    JDBC之数据库操作基本步骤
    ERROR 2003: Can't connect to MySQL server on 'localhost' 的错误
    lammps 学习之:系统压力太大,导致原子丢失
    Idea中查看一个类的所有资料及其层级关系
  • 原文地址:https://www.cnblogs.com/gisoracle/p/12467765.html
Copyright © 2011-2022 走看看