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 

  • 相关阅读:
    【心情】一天又一天
    【转】深度学习目标检测的整体架构描述(one-stage/two-stage/multi-stage)
    如何转载CSDN以及博客园的文章
    【转】Faster RCNN原理分析(二):Region Proposal Networks详解
    Lintcode 627
    遇黑中介打官司拿到房租的成功案例
    记录音视频不同步的问题及解决过程
    ffmpeg 使用笔记
    centos min安装后使用gclient
    剑指 Offer 26. 树的子结构
  • 原文地址:https://www.cnblogs.com/gisoracle/p/12467765.html
Copyright © 2011-2022 走看看