Google Earth Engine——地图Map

这篇文章介绍了如何使用`ui.Map`对象在地图上添加各种元素,如标签、选择器、按钮以及图像图层。通过`add`方法可以将新的地图、UI控件和几何图层添加到默认地图上。此外,还展示了如何设置地图的中心点、获取地图边界和缩放级别,以及如何设置和调整图像图层的可视化参数,包括多波段显示、颜色梯度和透明度控制。示例中涉及了Sentinel-2卫星图像和地球引擎的数据操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Map.add(item)

这个方法通常是在地图展示区加入各种ui使用,如ui.Label等。

// The default map in the Code Editor is a built-in ui.Map object called "Map".
// Let's refer to it as "defaultMap" for clarity.
var defaultMap = Map;

// ui.Map objects can be constructed. Here, a new map is declared.
var newMap = ui.Map({
  center: {lat: 0, lon: 0, zoom: 1},
  style: {position: 'bottom-right', width: '400px'}
});

// Add the newMap to the defaultMap;
defaultMap.add(newMap);

// Other UI widgets can be added to ui.Map objects, for example labels:
defaultMap.add(ui.Label('Default Map', {position: 'bottom-left'}));
newMap.add(ui.Label('New Map', {position: 'bottom-left'}));

// ...selectors:
defaultMap.add(ui.Select(['This', 'That', 'Other']));

// ...or buttons:
defaultMap.add(ui.Button('Click me'));

// You can also add ui.Map.Layer objects. Here, an ee.Geometry object
// is converted to a map layer and added to the default map.
var geom = ee.Geometry.Point(-122.0841, 37.4223);
var geomLayer = ui.Map.Layer(geom, {color: 'orange'}, 'Googleplex');
defaultMap.add(geomLayer);
defaultMap.centerObject(geom, 18);

Map.centerObject(object, zoom)

设置地图的居中位置,参数object是矢量数据或者影像数据;zoom表示缩放等级。

// The default map in the Code Editor is a built-in ui.Map object called "Map".
// Let's refer to it as "defaultMap" for clarity.
var defaultMap = Map;

// ui.Map objects can be constructed. Here, a new map is declared.
var newMap = ui.Map({
  center: {lat: 0, lon: 0, zoom: 1},
  style: {position: 'bottom-right', width: '400px'}
});

// Add the newMap to the defaultMap.
defaultMap.add(newMap);

// You can set the viewport of a ui.Map to be centered on an object.
// Here, the defaultMap is centered on a point with a selected zoom level.
var geom = ee.Geometry.Point(-122.0841, 37.4223);
defaultMap.centerObject(geom, 18);
defaultMap.addLayer(geom, {color: 'orange'}, 'Googleplex');

// Map extent can be fetched using the ui.Map.getBounds method.
print('defaultMap bounds as a list',
      defaultMap.getBounds());
print('defaultMap bounds as a dictionary',
      ee.Dictionary.fromLists(['w', 's', 'e', 'n'], defaultMap.getBounds()));
print('defaultMap bounds as GeoJSON',
      defaultMap.getBounds({asGeoJSON: true}));

// Map center point can be fetched using the ui.Map.getCenter method.
print('defaultMap center as a Point geometry', defaultMap.getCenter());

// Map zoom level can be fetched using the ui.Map.getZoom method.
print('defaultMap zoom level', defaultMap.getZoom());

// Map scale can be fetched using the ui.Map.getScale method.
print('defaultMap approximate pixel scale', defaultMap.getScale());

Map.addLayer(eeObject, visParams, name, shown, opacity)

在地图上添加图层,具体参数为:

  • eeObject:图层内容,可以是矢量数据、影像等;

  • visParams:显示图层内容样式参数;

  • name:图层名称;

  • shown:图层是否显示;

  • opacity:图层的透明度。

其中,visParams参数样式可以设置的内容包括:

  • band:波段列表

  • min:最小值

  • max:最大值

  • gamma:伽马系数

  • palette:颜色列表

  • opacity:透明度

  • ...

// A Sentinel-2 surface reflectance image.
var image = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
Map.setCenter(-121.87, 37.44, 9);

// Set multi-band RGB image visualization parameters. If the "bands" parameter
// is not defined, the first three bands are used.
var rgbVis = {
  bands: ['B11', 'B8', 'B3'],
  min: 0,
  max: 3000
};
Map.addLayer(image, rgbVis, 'Multi-band RGB image');

// Set band-specific "min" and "max" properties.
var rgbVisBandSpec = {
  bands: ['B11', 'B8', 'B3'],
  min: [0, 75, 150],
  max: [3500, 3000, 2500]
};
Map.addLayer(image, rgbVisBandSpec, 'Band-specific min/max');

// If you don't specify "min" and "max" properties, they will be determined
// from the data type range, often resulting in an ineffective color stretch.
Map.addLayer(image.select('B8'), null, 'Default visParams');

// If an image layer has already been styled, set "visParams" as null.
var imageRgb = image.visualize(rgbVis);
Map.addLayer(imageRgb, null, 'Pre-styled image');

// Use the "palette" parameter with single-band image inputs to define the
// linear color gradient to stretch between the "min" and "max" values.
var singleBandVis = {
  min: 0,
  max: 3000,
  palette: ['blue', 'yellow', 'green']
};
Map.addLayer(image.select('B8'), singleBandVis, 'Single-band palette');

// Images within ImageCollections are automatically mosaicked according to mask
// status and image order. The last image in the collection takes priority,
// invalid pixels are filled by valid pixels in preceding images.
var imageCol = ee.ImageCollection('COPERNICUS/S2_SR')
                   .filterDate('2021-03-01', '2021-04-01');
Map.addLayer(imageCol, rgbVis, 'ImageCollection mosaic');

// FeatureCollection, Feature, and Geometry objects can be styled using the
// "color" parameter.
var featureCol = ee.FeatureCollection('WCMC/WDPA/current/polygons');
Map.addLayer(featureCol, {color: 'purple'}, 'FeatureCollection');
### 使用 Google Earth Engine 展示地图 Google Earth Engine (GEE) 提供了一个交互式的映射界面,允许开发者通过其 API 将地理空间数据渲染到地图上。以下是实现这一功能的核心方法和示例代码。 #### 地图展示基础 在 GEE 中,`Map.addLayer()` 方法是最常用的工具之一,用于向地图添加图像或矢量层。此方法接受三个参数:要显示的数据对象、可视化的参数以及可选的名称标签[^1]。 #### 示例代码 以下是一个简单的 Python 脚本,演示如何加载 Landsat 卫星影像并将其叠加到地图上: ```python import ee ee.Authenticate() ee.Initialize() # 定义研究区域 roi = ee.Geometry.Point([-95.8, 37.2]) # 加载Landsat 8 影像集合 landsat_collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') \ .filterDate('2022-01-01', '2022-12-31') \ .filterBounds(roi) # 获取最近的一张影像 image = landsat_collection.first() # 设置可视化参数 visualization_parameters = { 'bands': ['SR_B4', 'SR_B3', 'SR_B2'], 'min': 0, 'max': 3000, 'gamma': 1.4 } # 添加图层至地图 Map = geemap.Map() # 如果未安装geemap库,请先运行 pip install geemap Map.centerObject(roi, zoom=10) Map.addLayer(image, visualization_parameters, 'Landsat Image') Map ``` 上述脚本展示了如何利用 `addLayer` 函数将卫星影像作为新图层加入地图,并设置颜色波段组合来增强视觉效果[^2]。 #### 高级应用——动态更新地图视图 对于更复杂的场景,可以结合 JavaScript 或 Python 的回调函数实现实时互动的地图操作。例如,在 Jupyter Notebook 环境下,可以通过绑定滑动条控件调整时间范围内的平均 NDVI 值分布情况。 ```javascript // 创建NDVI计算表达式 var ndvi = image.normalizedDifference(['B5','B4']).rename('NDVI'); // 显示NDVI结果于地图之上 Map.setCenter(-95.8, 37.2, 10); Map.addLayer(ndvi,{min:-1,max:1,palette:['blue','white','green']},'Normalized Difference Vegetation Index'); ``` 以上片段说明了基于特定算法处理遥感数据后再呈现给用户的流程[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值