Google Earth Engine(GEE)实例代码学习二十三——创建矢量数据集(From Polygons)

创建多边形FeatureCollection

本文分享如何创建多边形矢量数据集,并显示在图像上

//创建一个由两个多边形组成的矢量数据集
var fc = ee.FeatureCollection([
  // 创建矢量为面要素其坐标
  ee.Feature(
      ee.Geometry.Polygon({
        coords: [[-109.05, 41], [-109.05, 37], [-102.05, 37], [-102.05, 41]],
        geodesic: false, //测地线不太明白属性
        maxError: 1000 
      }), {name: 'Colorado', fill: 1}), //设置要素属性名以及颜色
  ee.Feature(
      ee.Geometry.Polygon({
        coords: [
          [-114.05, 37.0], [-109.05, 37.0], [-109.05, 41.0],
          [-111.05, 41.0], [-111.05, 42.0], [-114.05, 42.0]
        ],
        geodesic: false,
        maxError: 1000
      }), {name: 'Utah', fill: 2})
]);


// paint()将矢量数据集的几何图形绘制到图像上
var image = ee.Image().paint(fc, 'fill') //从fill属性获取颜色
    .paint(fc, 3, 5) // 设置边界线颜色宽度,3表示颜色,5表示宽度
    .toByte();
 //显示图形
Map.addLayer(image, {
    palette: ['000000', 'FF0000', '00FF00', '0000FF'],
    max: 3,
    opacity: 0.5
});

Map.setCenter(-107, 41, 6);

代码运行结果
Google Earth Engine(GEE)实例代码学习二十三——创建矢量数据集(From Polygons)_第1张图片

你可能感兴趣的:(GEE实例代码学习)