GEE基本概念(二)——1. Geometry&Feature

2.GEE重要概念——Geometry

总结:写在开头,Feature是由Geometry加上一些特殊属性构成,FeatureCollection则是由一系列的Feature在加上一些特殊属性构成。

介绍点线面特征:

图形Geometry(Point Line Polygon)

矢量Feature FeatureCollection

影像Image ImageCollection

2.1 Point and MultiPoint

点和多个点的绘制显示ee.Geometry.MultiPoint

var Forbidden_City = ee.Geometry.Point(116.3968, 39.9186);
var Forbidden_MultiCity = ee.Geometry.MultiPoint([
  [116.396659, 39.918576],
  [116.397303, 39.918586],
  [116.396678, 39.918272],
  [116.397316, 39.918294]
  ]);
Map.centerObject(Forbidden_MultiCity);   // Map映射中心
print(Forbidden_City);    
print(Forbidden_MultiCity);    
Map.addLayer(Forbidden_MultiCity);  //Map映射到地图上添加图层

2.2 Line

2.2.1 LineString and MultiLineString(it’s not close)

线和多段线的绘制,多段线没有闭合ee.Geometry.MultiLineString

var Forbidden_MultiCity = ee.Geometry.LineString([
  [116.396659, 39.918576],
  [116.397303, 39.918586],
  [116.397316, 39.918294],
  [116.396678, 39.918272]
  ]);
Map.centerObject(Forbidden_MultiCity);   
print(Forbidden_MultiCity);    
Map.addLayer(Forbidden_MultiCity);

var Forbidden_MultiCity = ee.Geometry.MultiLineString([
  [[116.396659, 39.918576],
  [116.397303, 39.918586]],
  
  [[116.397316, 39.918294],
  [116.396678, 39.918272]],
  ]);
Map.centerObject(Forbidden_MultiCity);   
print(Forbidden_MultiCity);    
Map.addLayer(Forbidden_MultiCity);

2.2.2 LinearRing and MultiLinearString(compared with LineString, it’s close)

相比于之前的多段线,此处是闭合的ee.Geometry.LinearRing

var Forbidden_MultiCity = ee.Geometry.LinearRing([
  [116.396659, 39.918576],
  [116.397303, 39.918586],
  [116.397316, 39.918294],
  [116.396678, 39.918272]
  ]);
Map.centerObject(Forbidden_MultiCity);   
print(Forbidden_MultiCity);    
Map.addLayer(Forbidden_MultiCity);

2.3 Polygon

polygon is defined similary to Line

与多段线命令相似,命令为:ee.Geometry.Polygon

var polygon = ee.Geometry.Polygon(        
      [[[114.62959747314449, 33.357067677774594],  
       [114.63097076416011, 33.32896028884253],  
       [114.68315582275386, 33.33125510961763],  
       [114.68178253173824, 33.359361757948754]]]);  
Map.centerObject(polygon, 9); 

2.3.1Geometry.transform()

将Geometry转换为带有WGS84坐标点的范围Geometry.transform(),此为Geometry转Feature。

ee.Geometry.Rectangle为通过左上角和右下角的坐标构建矩形。但是这个函数是根据左下角和右上角构建的Polygon。

var China_Geo =ee.Geometry.Rectangle(65.9,19.8,134.5,50.9)  //没定义坐标系,默认为WGS84
var China_Planr = ee.Geometry(China_Geo,null,false) //取消了WGS坐标系,拉平
var China_Planr_2 = China_Geo.transform('EPSG:4326', ee.ErrorMargin(100))        //  重新定义了坐标系

Map.addLayer(China_Geo,{color:'FF0000'},'geodesic polygon')
Map.addLayer(China_Planr,{color:'000000'},'planar polygon')
Map.addLayer(China_Planr_2,{color:'0000CD'},'planar_2 polygon')

2.4 Feature

1)Featur构建 的两种方法:1.由Geometry构建;2.在FeatureCollection中提取。

第一种是将Geometry加上或不加属性构建为Feature;第二种是直接提取,我们一般都是直接提取的。

//1.将点转为feature
var point = ee.Geometry.Point(109.202, 34.787);
var f1 = ee.Feature(point,{count:100});//添加了属性:由key-value构成
print('feature 1', f1);
Map.centerObject(f1,7);
Map.addLayer(f1,{color:'green'}, 'point');
//2.在FeatureCollection中提取Feature
var fCol = ee.FeatureCollection('users/qq1216079662/China');//导入中国的shp,是FeatureCollection
print('china', fCol);
Map.addLayer(fCol,{color:'red'}, 'fCol');

var f2 = ee.Feature(fCol.first());
print('first feature', f2);
Map.addLayer(f2,{color:'blue'}, 'f2');//排序第一个shp,是Feature

var sCol = fCol.filterBounds(point);
print('filter feature', sCol);
Map.addLayer(sCol,{color:'green'}, 'shaanxi');//用点提取的shp,还是FeatureCollection

注意第二种和第三章的不同之处,虽然都提取除了Feature,但是第二种是从集合种提取出某一个Feature,第三章则是提取出了FeatureCollection。

2)矢量数据一般为上传的,因此,介绍加载和过滤矢量数据的方法,过滤完仍为FeatureCollection。

//加载矢量数据
var counties = ee.FeatureCollection('users/qq1216079662/China');
Map.addLayer(counties, {}, 'counties');

//过滤矢量数据
// Load a feature collection.
var featureCollection = ee.FeatureCollection('users/qq1216079662/China');
// Filter the collection.
var filteredFC = featureCollection.filter(ee.Filter.eq('省', '陕西省'));
// Display the collection.
print(featureCollection);
print(filteredFC);
Map.addLayer(filteredFC, {color:'red'}, '陕西省');

遥感影像中心点的显示:

展示的是这个时期这个数据的图像的中心像素点的位置

// This function returns the image centroid as a new Feature.
var getGeom= function(image) {
return ee.Feature(image.geometry().centroid(), {foo: 1});
};
// Load a Landsat 8 collection.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1')
.filterDate('2014-06-01', '2014-06-08');

// Map the function over the ImageCollection.
var featureCollection= ee.FeatureCollection(collection.map(getGeom));
// Print the collection.
print(featureCollection);
Map.addLayer(featureCollection)

矢量数据:缓冲区分析以及缓冲区的绘制,介绍矢量数据的应用,没有多大的作用。

var china = ee.FeatureCollection(table);        //加载中国区域的shp
var shaanxi = ee.Feature(china.filterBounds(ee.Geometry.Point([108.98,34.429])).first())        //通过点过滤该地区的feature
var SX_simple = shaanxi.simplify(50000);    //内接
var SX_centroid = shaanxi.centroid();   //几何中心
var SX_hull = shaanxi.convexHull();     //外接
var SX_bounds = shaanxi.bounds();       //四至
var SX_buffer = shaanxi.buffer(50000);  //缓冲区

print()
Map.centerObject(shaanxi);
Map.addLayer(shaanxi);
Map.addLayer(SX_simple);
Map.addLayer(SX_centroid);
Map.addLayer(SX_hull);
Map.addLayer(SX_bounds);
Map.addLayer(SX_buffer);

set and setMulti
set是替换,而setMulti是替换并增加新的属性(下面代码中table为自定义的roi)

var China_Geo =ee.Geometry.Rectangle(65.9,19.8,134.5,50.9);
var China_Geo_feature = ee.Feature(China_Geo,{name:'故宫', location:'北京'});
var China_Geo_set =China_Geo_feature.set({name:'gugong', location:'beijing'}) 
print(China_Geo_feature,China_Geo_set)
Map.centerObject(China_Geo);
Map.addLayer(China_Geo_set);

var table_set = table.setMulti({'system:asset_size':'15934'})
print(table,table_set)
Map.centerObject(table);
Map.addLayer(table);
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值