首页 > 编程语言 >C30 基础应用界面和应用程序(Part 6)

C30 基础应用界面和应用程序(Part 6)

时间:2024-06-24 10:58:54浏览次数:3  
标签:style 图例 应用程序 Part getNLCD var ui C30

本节导读

演示如何使用JavaScript和Python设计和发布地球引擎应用程序。介绍地球引擎用户界面JavaScript API和geemap Python包。在完成本节后,你将能够发布一个带有拆分面板地图的地球引擎应用程序,用于可视化土地覆盖变化。

主要内容:

  • 使用JavaScript为地球引擎应用程序设计一个用户界面。
  • 发布一个地球引擎应用程序,用于可视化土地覆盖变化。
  • 使用Python和geemap开发一个地球引擎应用程序。
  • 使用本地计算机作为web服务器部署地球引擎应用程序。
  • 使用Python和免费云平台发布地球引擎应用程序。
  • 使用Anaconda/Miniconda创建conda环境。
  • 安装Python包和使用Jupyter Notebook。
  • 将更改提交到GitHub存储库。

1. 使用JavaScript构建一个GEE APP

//==========================step 1 ====================================================
// Get an NLCD image by year. 
var getNLCD = function(year) { 
    // Import the NLCD collection. 
    var dataset = ee.ImageCollection( 'USGS/NLCD_RELEASES/2019_REL/NLCD'); 
    // Filter the collection by year. 
    var nlcd = dataset.filter(ee.Filter.eq('system:index', year)) .first(); 
    // Select the land cover band. 
    var landcover = nlcd.select('landcover'); 
    return ui.Map.Layer(landcover, {}, year); 
}; 

// Create a dictionary with each year as the key 
// and its corresponding NLCD image layer as the value. 
var images = { 
    '2001': getNLCD('2001'), 
    '2004': getNLCD('2004'), 
    '2006': getNLCD('2006'), 
    '2008': getNLCD('2008'), 
    '2011': getNLCD('2011'), 
    '2013': getNLCD('2013'), 
    '2016': getNLCD('2016'), 
    '2019': getNLCD('2019'), 
}; 

//==========================step 2====================================================
// 创建左边的地图,并让它显示第一层。
var leftMap = ui.Map(); 
leftMap.setControlVisibility(false); 
var leftSelector = addLayerSelector(leftMap, 0, 'top-left'); 
// 创建右边的地图,并让它显示最后一层。 
var rightMap = ui.Map(); 
rightMap.setControlVisibility(true); 
var rightSelector = addLayerSelector(rightMap, 7, 'top-right'); 



//为给定的地图添加一个图层选择小部件,允许用户更改在关联地图中显示的图像。
function addLayerSelector(mapToChange, defaultValue, position) { 
    var label = ui.Label('Select a year:'); 
    
    // This function changes the given map to show the selected image. 
    function updateMap(selection) { 
        mapToChange.layers().set(0, images[selection]); 
    } 
    // Configure a selection dropdown to allow the user to choose 
    // between images, and set the map to update when a user makes a selection. 
    var select = ui.Select({ 
        items: Object.keys(images), 
        onChange: updateMap 
    }); 
    select.setValue(Object.keys(images)[defaultValue], true);
    
    var controlPanel = 
        ui.Panel({ 
            widgets: [label, select], 
            style: { 
                position: position 
            } 
        }); 
    mapToChange.add(controlPanel); 
} 

//==========================step 3====================================================
//添加图例
// 设置图例标题。
var title = 'NLCD土地覆盖分类'; 
// 设置图例位置。
var position = 'bottom-right'; 
// Define a dictionary that will be used to make a legend 
var dict = { 
    'names': [ 
        '11 Open Water', 
        '12 Perennial Ice/Snow', 
        '21 Developed, Open Space', 
        '22 Developed, Low Intensity', 
        '23 Developed, Medium Intensity', 
        '24 Developed, High Intensity', 
        '31 Barren Land (Rock/Sand/Clay)', 
        '41 Deciduous Forest', 
        '42 Evergreen Forest', 
        '43 Mixed Forest', 
        '51 Dwarf Scrub', 
        '52 Shrub/Scrub', 
        '71 Grassland/Herbaceous', 
        '72 Sedge/Herbaceous',
        '73 Lichens', 
        '74 Moss', 
        '81 Pasture/Hay', 
        '82 Cultivated Crops', 
        '90 Woody Wetlands', 
        '95 Emergent Herbaceous Wetlands', 
    ], 
    'colors': [ 
        '#466b9f', '#d1def8', '#dec5c5', '#d99282', '#eb0000',  '#ab0000', 
        '#b3ac9f', '#68ab5f', '#1c5f2c', '#b5c58f', '#af963c', '#ccb879', 
        '#dfdfc2', '#d1d182', '#a3cc51', '#82ba9e', '#dcd939', '#ab6c28', 
        '#b8d9eb', '#6c9fb8', 
    ] 
}; 

//创建一个面板来容纳图例小部件。
var legend = ui.Panel({ 
    style: { 
        position: position, 
        padding: '8px 15px' 
    } 
});

//函数用于生成图例。
function addCategoricalLegend(panel, dict, title) {
  // 创建并添加图例标题。 
    var legendTitle = ui.Label({ 
        value: title, 
        style: { 
            fontWeight: 'bold', 
            fontSize: '18px', 
            margin: '0 0 4px 0', 
            padding: '0' 
        } 
    }); 
    panel.add(legendTitle); 
    
    
    var loading = ui.Label('Loading legend...', { 
        margin: '2px 0 4px 0' 
    }); 
    panel.add(loading);
 
    
    //创建并样式化图例
    var makeRow = function(color, name) { 
        // Create the label that is actually the colored box. 
        var colorBox = ui.Label({ 
            style: { 
                backgroundColor: color, 
                // Use padding to give the box height and width. 
                padding: '8px', 
                margin: '0 0 4px 0' 
            } 
        }); 
        
        //创建描述文本的标签。
        var description = ui.Label({ 
            value: name, 
            style: { 
            margin: '0 0 4px 6px' 
            } 
        });
        
        return ui.Panel({ 
            widgets: [colorBox, description], 
            layout: ui.Panel.Layout.Flow('horizontal') 
        }); 
    }; 
    
    //从图像中获取调色板颜色和类名的列表。 
    var palette = dict.colors; 
    var names = dict.names; 
    loading.style().set('shown', false); 
    
    
    for (var i = 0; i < names.length; i++) { 
        panel.add(makeRow(palette[i], names[i])); 
    } 
    rightMap.add(panel); 
}  
//==========================step 4====================================================
addCategoricalLegend(legend, dict, title); 
// Create a SplitPanel to hold the adjacent, linked maps. 
var splitPanel = ui.SplitPanel({ 
    firstPanel: leftMap, 
    secondPanel: rightMap, 
    wipe: true, 
    style: { 
        stretch: 'both' 
    } 
}); 


// 将SplitPanel设置为UI根目录中唯一的东西。 
ui.root.widgets().reset([splitPanel]); 
var linker = ui.Map.Linker([leftMap, rightMap]); 
leftMap.setCenter(-100, 40, 4); 

  

 

2. 从Code Editor中发布APP

step1: 加载代码

step2: 打开“管理应用”面板,新建APP

step3: 设置相关信息,完成

 

3. 使用geemap开发一个APP(Python)

4.使用本地Web服务器发布APP

5.使用云平台发布APP

 

标签:style,图例,应用程序,Part,getNLCD,var,ui,C30
From: https://www.cnblogs.com/bltstop/p/18264576

相关文章

  • fdisk时WARNING: Re-reading the partition table failed with error 16: 设备或资源
    WARNING:Re-readingthepartitiontablefailedwitherror16:设备或资源现象:划分磁盘有警告, WARNING:Re-readingthepartitiontablefailedwitherror16:设备或资源忙.Thekernelstillusestheoldtable.Thenewtablewillbeusedatthenextrebootoraft......
  • Day28.property使用part2
    1.property使用part2_多次调用类中的函数方法property用法,案例一代码如下:'''案例一'''classPeople:def__init__(self,name):self.__name=namedefget_name(self):returnself.__namedefset_name(self,val):......
  • 硬件开发笔记(二十一):外部搜索不到的元器件封装可尝试使用AD21软件的“ManufacturerPart
    若该文为原创文章,转载请注明原文出处本文章博客地址:https://hpzwl.blog.csdn.net/article/details/139869584长沙红胖子Qt(长沙创微智科)博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬结合等等)持续更新中…硬件相关开发......
  • JavaScript基础部分知识点总结(Part6)
    BOM概述1.什么是BOMBOM(BrowserObjectModel)即浏览器对象模型,它提供了独立于内容而与浏览器窗口进行交互的对象,其核心对象是window。BOM由一系列相关的对象构成,并且每个对象都提供了很多方法与属性。BOM缺乏标准,JavaScript语法的标准化组织是ECMA,DOM的标准化组织是W3C,BOM最......
  • 编译实践学习 Part5
    License:CCBY-NC-SA4.05.1本节的EBNF中出现了一种新的表示:[...],这代表方括号内包含的项可被重复0次或1次.也就是说,单个分号在SysY程序中也是一个合法的语句.在AST中,你可以使用空指针或Option来表示这种结构.但是,我拒绝。classOptionalExpAST:......
  • 代码随想录第13天 | 二叉树part01 基础和遍历
    二叉树基础知识二叉树种类满二叉树满二叉树:如果一棵二叉树只有度为0和度为2的结点,并且度为0的结点在同一层上,则这棵二叉树为满二叉树(子节点要么为0,要么为2)若满二叉树的深度为k(即k层,从1开始),则其节点个数为:2^k-1完全二叉树完全二叉树:从上到下,从左到右,都是连续的。满二叉树一......
  • YC307A [ 20240622 CQYC省选模拟赛 T1 ] 划船(boat)
    题意给定一个有向图\(G\),以及将所有边反向重连的无向图\(T\)。你最多可以在\(T\)上连续走\(k\)条边,走过每条边的代价都为\(1\),然后必须在\(G\)的对应点上走一条边以恢复体力。若当前对应点没有出边,则停留在该点\(1\)代价。求每个点到\(n\)的最小代价。Sol考......
  • python库BeeWare,一个如雷贯耳的可以创建原生应用程序的库
    目录BeeWare包括以下主要组件和工具:创建BeeWare虚拟环境配置BeeWare 创建一个新的BeeWare项目(HelloWorld!)尝试HelloWorld样例BeeWare 是一个开源项目,旨在帮助开发者使用Python创建原生应用程序,覆盖了移动、桌面和Web平台。BeeWare通过提供一系列工具和库......
  • 使用粒子滤波(particle filter)进行视频目标跟踪
    虽然有许多用于目标跟踪的算法,包括较新的基于深度学习的算法,但对于这项任务,粒子滤波仍然是一个有趣的算法。所以在这篇文章中,我们将介绍视频中的目标跟踪:预测下一帧中物体的位置。在粒子滤波以及许多其他经典跟踪算法的情况下,我们根据估计的动态进行预测,然后使用一些测量值更新预......
  • ICEE-Power-SCR-OptoisolaterDriver-MOC Series-MOC3081/2/3: 6-Pin DIP Zero-Cross T
    EnglishWords:SCR:双向可控硅Traic:单向可控硅找Datasheet的好去处:DigiKey,Mouser,Arrow三家全球最大的电子元器件采购平台,搜索到的元器件页面会有Datasheet可供下载。https://www.digikey.com/en/products/detail/onsemi/MOC3083M/281240https://www.mouser.com/datas......