创建 ee.Geometry.Point()、ee.Geometry.Multipoint()
几何 Geometry.transform()、geometry.centroid ()、geometry.simplify ()、geometry.bounds()、geometry.buffer ()、geometry.union () ……
查询 geometry.geometries()、geometry.coordinates()、geometry.length ()、geometry.area ()、geometry.perimeter ()、geometry.distance ()
转换 geometry.toGeoJSON()
创建点
var Forbidden_City = ee.Geometry.Point(116.3968,39.9186)
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建多点
var Forbidden_City = ee.Geometry.MultiPoint(
[[116.3921, 39.9224],
[116.4014, 39.9227],
[116.4017, 39.9138],
[116.3929, 39.9135] ]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建线
var Forbidden_City = ee.Geometry.LineString(
[[116.39234040929296, 39.91321497621612],
[116.39195417119481, 39.92276018488313],
[116.40186761571385, 39.9230234821268],
[116.40216802312352, 39.91354414349019]]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建多线
var Forbidden_City = ee.Geometry.MultiLineString([
[[116.39367078496434, 39.92134494485143],
[116.39899228764989, 39.92173989850053]],
[[116.39401410771825, 39.91953471147776],
[116.39693235112645, 39.92085124958646]],
[[116.39628862096288, 39.91920557299557],
[116.39873479558446, 39.91752694212849]] ]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建单闭合线
var Forbidden_City = ee.Geometry.LinearRing(
[[116.39242623998143, 39.91321497621612],
[116.39195417119481, 39.92269436041402],
[116.40178178502538, 39.9230234821268],
[116.40212510777928, 39.91357706013058],
[116.39242623998143, 39.91321497621612]]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建多闭合线
var Forbidden_City =ee.Geometry.MultiLineString(
[[[116.39320681392098, 39.921786784372976],
[116.39337847529794, 39.92040443758097],
[116.39578173457528, 39.92070065709998],
[116.39556715785409, 39.92188552236169],
[116.39320681392098, 39.921786784372976]],
[[116.39801333247567, 39.91918663276216],
[116.39548132716561, 39.91777131887048],
[116.4006311684742, 39.91747508667966],
[116.39801333247567, 39.91918663276216]]]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建多边形
var Forbidden_City =ee.Geometry.MultiLineString(
[[[116.39320681392098, 39.921786784372976],
[116.39337847529794, 39.92040443758097],
[116.39578173457528, 39.92070065709998],
[116.39556715785409, 39.92188552236169],
[116.39320681392098, 39.921786784372976]],
[[116.39801333247567, 39.91918663276216],
[116.39548132716561, 39.91777131887048],
[116.4006311684742, 39.91747508667966],
[116.39801333247567, 39.91918663276216]]]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
创建嵌套多边形
var Forbidden_City =ee.Geometry.Polygon([
[[116.39179060756112, 39.922576684295926],
[116.39230559169198, 39.913064366936894],
[116.40213320552255, 39.91352520169099],
[116.40161822139169, 39.92297163084022]],
[[116.39483759700204, 39.91961451259886],
[116.39496634303475, 39.91648763678902],
[116.39900038539315, 39.916553467224674],
[116.39874289332772, 39.91977908105491]] ]);
Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)
投影转换
var China_Geo = ee.Geometry.Rectangle(65.9, 19.8,134.5, 50.9);
var China_Planr = ee.Geometry(China_Geo, null, false)
var China_Plnar_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,{color: '0000CD'}, 'planar polygon')
//https://epsg.io 投影编码对照网址
获取中心
var China_Geo = ee.Geometry.Rectangle(65.9, 19.8,134.5, 50.9);
var China_Certer = China_Geo.centroid();
Map.addLayer(China_Geo, {color: 'FF0000'}, 'geodesic polygon')
Map.addLayer(China_Certer)
边界简化
var TGR = ee.FeatureCollection("users/wangjinzhulala/TGR").geometry();
var TGR_Simple = TGR.simplify(50000)
Map.centerObject(TGR )
Map.addLayer(TGR)
Map.addLayer(TGR_Simple)
获取四至及外接多边形
var TGR = ee.FeatureCollection("users/wangjinzhulala/TGR").geometry();
var TGR_Bound = TGR. bounds()
var TGR_Hall = TGR.convexHull()
Map.centerObject(TGR )
Map.addLayer(TGR)
Map.addLayer(TGR_Bound)
Map.addLayer(TGR_Hall)
获取缓冲区
var TGR = ee.FeatureCollection("users/wangjinzhulala/TGR").geometry();
var TGR_Buffer = TGR.buffer(10000)
Map.centerObject(TGR )
Map.addLayer(TGR)
Map.addLayer(TGR_Buffer)
多边形合并
var Polygon_1 = ee.Geometry.Polygon(
[[[152.71032334056088, 18.862610207551867],
[-170.72717665943918, 19.69222816299581],
[-171.07873915943918, 40.62061002589569],
[153.41344834056088, 40.08478212000696]]]),
Polygon_2 = ee.Geometry.Polygon(
[[[-176.52795790943912, 45.620172046005735],
[-176.70373915943912, 32.2945468815855],
[-142.60217665943918, 32.2945468815855],
[-141.02014540943918, 45.49709377875777]]]);
var Polygon_union = Polygon_1.union(Polygon_2);
Map.addLayer(Polygon_1)
Map.addLayer(Polygon_2)
Map.addLayer(Polygon_union)
// .intersection .symmetricDifference .Difference 类似于ArcGIS中的其他操作也凭借类似方法实现
获取数据矢量信息
var Forbidden_City = ee.Geometry.MultiPolygon(
[[[[116.39393637477303, 39.921260179361866],
[116.39350722133065, 39.91882457850439],
[116.39676878749276, 39.918791664386056],
[116.39711211024667, 39.920963962263336]]],
[[[116.39887163936044, 39.91810046424626],
[116.39595339595223, 39.91698136351405],
[116.40080282985116, 39.91652055201477]]]]);
var Geometry_List = Forbidden_City.geometries()
Map.centerObject(Forbidden_City)
Map.addLayer(Forbidden_City)
print(Geometry_List)
多边形面积周长计算
var Polygon_1 =ee.Geometry.Polygon([
[[116.39179060756112, 39.922576684295926],
[116.39230559169198, 39.913064366936894],
[116.40213320552255, 39.91352520169099],
[116.40161822139169, 39.92297163084022]],
[[116.39483759700204, 39.91961451259886],
[116.39496634303475, 39.91648763678902],
[116.39900038539315, 39.916553467224674],
[116.39874289332772, 39.91977908105491]] ]);
var Polygon_2 =ee.Geometry.Polygon(
[[[116.39239142238046, 39.913146659084674],
[116.40209029017831, 39.91354166001771],
[116.40170405208016, 39.922988086896794],
[116.39183352290536, 39.922593140447425]]]);
var Area_1 = Polygon_1.area()
var Area_2 = Polygon_2.area()
var Perimeter_1 = Polygon_1.perimeter()
var Perimeter_2 = Polygon_2.perimeter()
print(Area_1,Area_2,Perimeter_1,Perimeter_2)
Map.centerObject(Polygon_1)
Map.addLayer(Polygon_1)
Map.addLayer(Polygon_2)
多个多变形之间距离量算
var geometry_1 = ee.Geometry.Polygon(
[[[116.39419386683858, 39.92130954875369],
[116.39359305201924, 39.918873949652266],
[116.3966829568044, 39.918709379020974],
[116.39719794093526, 39.92101333186874]]]),
geometry_2 = ee.Geometry.Polygon(
[[[116.39891455470479, 39.918116921473526],
[116.3957817345754, 39.917063650955505],
[116.40123198329366, 39.91647117917021]]]);
var Distance = geometry_1.distance(geometry_2)
print(Distance)
Map.centerObject(geometry_1)
Map.addLayer(geometry_1)
Map.addLayer(geometry_2)
数据格式转换
var geometry = ee.Geometry.Polygon(
[[[116.39419386683858, 39.92130954875369],
[116.39359305201924, 39.918873949652266],
[116.3966829568044, 39.918709379020974],
[116.39719794093526, 39.92101333186874]]])
var geometry_GeoJSON = geometry.toGeoJSON()
print(geometry)
print(geometry_GeoJSON)
Map.centerObject(geometry)
Map.addLayer(geometry)
// 这里的目的主要是防止由GEE直接导出来的数据乱码,可以先转换为GeoJSON,再进一步进行转换到shp文件
与Geometry相比,Feature除了包含空间信息外,又增加了属性信息,而Geometry仅仅包含空间信息。
创建 ee.Feature()、绘图工具
编辑 Feature.select()、Feature.transform()、Feature.set/setMulti()
几何 Feature.centroid/simplify/bounds/convexHull/buffer()、Feature.union/intersection/difference/symmetricDifference()
提取 Feature.geometry()、Feature.get()、Feature.Length/Area/Perimeter()
要素创建
var Forbidden_City =ee.Geometry.Polygon(
[[[116.39239142238046, 39.913146659084674],
[116.40209029017831, 39.91354166001771],
[116.40170405208016, 39.922988086896794],
[116.39183352290536, 39.922593140447425]]]);
var Feature_Fobidden_City = ee.Feature(Forbidden_City, {name:'故宫', location:'北京'})
Map.centerObject(Forbidden_City)
print(Feature_Fobidden_City)
Map.addLayer(Feature_Fobidden_City)
要素属性数据选取(复制属性到某一变量)
var Forbidden_City =ee.Geometry.Polygon(
[[[116.39239142238046, 39.913146659084674],
[116.40209029017831, 39.91354166001771],
[116.40170405208016, 39.922988086896794],
[116.39183352290536, 39.922593140447425]]]);
var Feature_Fobidden_City = ee.Feature(Forbidden_City, {name:'故宫', location:'北京'})
var Feature_select = Feature_Fobidden_City.select(['name'])
Map.centerObject(Forbidden_City)
print(Feature_Fobidden_City, Feature_select)
Map.addLayer(Feature_Fobidden_City)
// 与上面的不同,此段输出时会将name重命名
var Forbidden_City =ee.Geometry.Polygon(
[[[116.39239142238046, 39.913146659084674],
[116.40209029017831, 39.91354166001771],
[116.40170405208016, 39.922988086896794],
[116.39183352290536, 39.922593140447425]]]);
var Feature_Fobidden_City = ee.Feature(Forbidden_City, {name:'故宫', location:'北京'})
var Feature_select = Feature_Fobidden_City.select(['name'],['名称'])
Map.centerObject(Forbidden_City)
print(Feature_Fobidden_City, Feature_select)
Map.addLayer(Feature_Fobidden_City)
坐标转换
var China_Geo = ee.Feature(ee.Geometry.Rectangle(65.9, 19.8,134.5, 50.9));
var China_Plnar = China_Geo.transform('EPSG:3857',ee.ErrorMargin(100));
print(ee.Geometry(China_Geo.geometry()).projection(),
ee.Geometry(China_Plnar.geometry()).projection())
要素属性重写
// .set
var Forbidden_City =ee.Geometry.Polygon(
[[[116.39239142238046, 39.913146659084674],
[116.40209029017831, 39.91354166001771],
[116.40170405208016, 39.922988086896794],
[116.39183352290536, 39.922593140447425]]]);
var Feature_Fobidden_City = ee.Feature(Forbidden_City, {name:'故宫', location:'北京'})
var Feature_Set = Feature_Fobidden_City.set('name','Gugong', 'location','Beijing')
print(Feature_Fobidden_City,Feature_Set)
Map.centerObject(Forbidden_City)
print(Feature_Fobidden_City)
Map.addLayer(Feature_Fobidden_City)
//.setMulti
var Forbidden_City =ee.Geometry.Polygon(
[[[116.39239142238046, 39.913146659084674],
[116.40209029017831, 39.91354166001771],
[116.40170405208016, 39.922988086896794],
[116.39183352290536, 39.922593140447425]]]);
var Feature_Fobidden_City = ee.Feature(Forbidden_City, {name:'故宫', location:'北京'})
var Feature_Set = Feature_Fobidden_City.setMulti({'name':'Gugong', 'location':'Beijing'})
print(Feature_Fobidden_City,Feature_Set)
Map.centerObject(Forbidden_City)
Map.addLayer(Feature_Fobidden_City)
Feature.centroid/simplify/bounds/convexHull/buffer()
var China = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var Chongqing = ee.Feature(China.filterBounds(ee.Geometry.Point([106,29])).first())
var CQ_Simple = Chongqing.simplify(50000)
var CQ_Centroid = Chongqing.centroid()
var CQ_Hull = Chongqing.convexHull()
var CQ_Bounds = Chongqing.bounds()
var CQ_Buffer = Chongqing.buffer(50000)
Map.centerObject(Chongqing)
Map.addLayer(Chongqing)
Map.addLayer(CQ_Simple)
Map.addLayer(CQ_Centroid)
Map.addLayer(CQ_Hull)
Map.addLayer(CQ_Bounds)
Map.addLayer(CQ_Buffer)
Feature. union/intersection/difference/symmetricDifference()
var China = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var Chongqing = ee.Feature(China.filterBounds(ee.Geometry.Point([106,29])).first())
var TGR = ee.Feature(ee.FeatureCollection("users/wangjinzhulala/TGR").first());
var Union = Chongqing.union(TGR)
var Intersect = Chongqing.intersection(TGR)
var Difference = Chongqing.difference(TGR)
var Symmetric_Difference = Chongqing.symmetricDifference(TGR)
Map.addLayer(Union,{color:'00ffff'},'Union')
Map.addLayer(Intersect,{color:'DC143C'},'Intersect')
Map.addLayer(Difference,{color:'7B68EE'},'Difference')
Map.addLayer(Symmetric_Difference,{color:'32CD32'},'Symmetric_Difference')
属性信息剥离,仅保留空间信息
var TGR = ee.Feature(ee.FeatureCollection("users/wangjinzhulala/TGR").first());
var TGR_geometry = TGR.geometry();
var TGR_get = TGR.get('BOUNT_ID') //通过get获得某个具体的信息
print(TGR,TGR_geometry,TGR_get)
面积/距离量算
var TGR = ee.Feature(ee.FeatureCollection("users/wangjinzhulala/TGR").first());
var TGR_Area = TGR.area()
var TGR_Perimeter = TGR.perimeter()
print(TGR_Area,TGR_Perimeter)
创建 GEE自带、上传、FushionTable、ee.FeatureCollection()、.randomPoints()、手绘…
编辑 .filterMetadata()、.limit()、.filterDate()、.filterBounds()、.filter()、.select()、.distinct()、.union() .merge()、.set()、.remap()、.sort()、.makeArray()
转换 .geometry()、.reduceToImage()
查询 .first()、.toList()、.aggregate_first()、.aggregate_array()
统计 .aggregate_stats/_histogram/_count/_count_distinct |.aggregate_max/_min/_sum/_mean/_product|.aggregate_sample_var/_total_var/_sample_sd/_total_sd/
其他 .map()
要素创建(点线面)
var Poly = ee.Geometry.Polygon(
[[[116.39248531478768, 39.91319513792091],
[116.40222709792977, 39.91378763804685],
[116.40184085983162, 39.92303655876662],
[116.39171283859139, 39.922674524864675]]]);
var Points = ee.Geometry.MultiPoint(
[[116.38823669570809, 39.92079850034943],
[116.38677757400399, 39.91885659627606],
[116.38669174331551, 39.916881722097074],
[116.38767879623299, 39.91421555161684]]);
var Lines = ee.Geometry.LineString(
[[116.37733619827156, 39.9167171466781],
[116.38192814010506, 39.91754001981801],
[116.37712162155037, 39.91365597179514],
[116.38424556869393, 39.914478881715695]]);
var Feature_Collection = ee.FeatureCollection( [Poly, Points, Lines] );
Map.centerObject(Feature_Collection)
print (Feature_Collection)
Map.addLayer (Feature_Collection)
随机点
var Poly = ee.Geometry.Polygon(
[[[116.39248531478768, 39.91319513792091],
[116.40222709792977, 39.91378763804685],
[116.40184085983162, 39.92303655876662],
[116.39171283859139, 39.922674524864675]]]);
var Random_Points = ee.FeatureCollection.randomPoints(Poly,20)
Map.centerObject(Poly)
Map.addLayer(Poly)
Map.addLayer(Random_Points)
数据筛选
// .filterMetadata
var Proction_Area = ee.FeatureCollection("WCMC/WDPA/current/polygons");
var Proction_Area_China = Proction_Area.filterMetadata('ISO3','equals','CHN') //对其元数据进行筛选,条件是列标题=CHN
Map.centerObject(Proction_Area_China)
Map.addLayer(Proction_Area_China, ,{color:'FF0000'})
// .limit(筛选数量、筛选字段(可选)、排序方式(可选,默认从小到大True))
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
Map.addLayer(China_Provinces)
Map.addLayer(China_Provinces.limit(5,'Shape_Area',false))
// .filterDate 根据时间筛选
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var Landsat_FilterDate = L8.filterDate('2019-03-01','2019-03-16').limit(50)
// 筛选出50个 减少信息量
print(Landsat_FilterDate)
// 根据空间位置筛选
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var CQ_Point =ee.Geometry.Point([106.92371845031437, 29.430312117372274]);
var CQ = China_Provinces.filterBounds(CQ_Point)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(CQ,{color:'FF0000'})
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var CQ_Point =ee.Geometry.Point([106.92371845031437, 29.430312117372274]);
var Filter_By_Chongqing = ee.Filter.bounds(CQ_Point)
var CQ = China_Provinces.filter(Filter_By_Chongqing)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(CQ,{color:'FF0000'})
要素信息提取(复制)
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var China_Area = China_Provinces.select(['NAME'])
print(China_Provinces)
print(China_Area)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(China_Area)
要素信息筛选(去除重复字段)
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var China_Area = China_Provinces.distinct(['NAME'])
print(China_Provinces)
print(China_Area)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(China_Area)
空间信息合并(合并后会丢失原有属性信息)
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var China_Union = China_Provinces.union()
print(China_Provinces)
print(China_Union)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(China_Union,{color:'ff0000'})
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var Chongqing = China_Provinces.filterMetadata('NAME','equals','Chong_Qing')
var Si_Chuan = China_Provinces.filterMetadata('NAME','equals','Si_Chuan')
var CQ_SC_Merge = Chongqing.merge(Si_Chuan)
Map.centerObject(China_Provinces,4)
Map.addLayer(Chongqing)
Map.addLayer(Si_Chuan,{color:'0000ff'})
Map.addLayer(CQ_SC_Merge,{color:'ff0000'})
信息更改重置
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var Chongqing = China_Provinces.filterMetadata('NAME','equals','Chong_Qing')
var Si_Chuan = China_Provinces.filterMetadata('NAME','equals','Si_Chuan')
var CQ_SC_Merge = Chongqing.merge(Si_Chuan)
var CQ_SC_Merge_Set = Chongqing.merge(Si_Chuan).set('NAME','Chuan_Yu')
print(CQ_SC_Merge)
print(CQ_SC_Merge_Set)
//.setMulti()参考前例
对FeatureCollection中某一个字段的每一条属性都进行相应的操作
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var Old_Provinces_ID = ee.List([1,2,3,4,5,6,7,8,9,12,13,14,15,16,18,19,20,21,
22,23,24,27,28,29,30,31,32,33,34,35,36,37,38,39,1089])
var New_Provinces_ID = ee.List([1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,4,
5,5,5,5,5,6,6,6,6,6,7,7,7,7,7])
var China_Remap = China_Provinces.remap(Old_Provinces_ID,New_Provinces_ID,'OBJECTID')
var China_Provinces_Map = China_Provinces.reduceToImage(['OBJECTID'], ee.Reducer.first( ) )
//类似于ArcGIS中的根据属性显色,这里以OBJECTID进行 颜色复制
var China_Remap_Map = China_Provinces.reduceToImage(['OBJECTID'], ee.Reducer.first( ) )
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces_Map,{min:1, max:40, palette:'16ff07,2901ff'},'China_Provinces_Map')
Map.addLayer(China_Remap_Map,{min:1, max:7, palette:'ff7248,fbff21,09ffe8'},'China_Remap_Map')
对属性表进行排序
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var China_Sort_Area = China_Provinces.sort('Shape_Area',false)
//根据Shape_Area进行排序,默认都是True,从小到大,最后得到面积前五大的省份
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces.limit(5))
Map.addLayer(China_Sort_Area.limit(5),{color:'ff000000'})
将多个属性字段形成新的属性字段
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces").limit(3);
var China_Array = China_Provinces.makeArray(['OBJECTID','Shape_Area','Shape_Leng'],'An_Array')
//将'OBJECTID','Shape_Area','Shape_Leng'三个字段结合为'An_Array'的一个字段
print(China_Provinces)
print(China_Array)
获得所有feature的Geometry信息
// 执行操作后仅仅保留多边形的信息
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces").limit(3);
var China_Geometry = China_Provinces.geometry()
print(China_Provinces)
print(China_Geometry)
矢量转栅格
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var China_to_Image = China_Provinces.reduceToImage(['OBJECTID'],ee.Reducer.first())
// Reducer缩减器选择了first
Map.centerObject(China_Provinces,4)
Map.addLayer(China_to_Image,{"min":1,"max":40,"palette":["ff9c07","f0ff1b","1aff0b"]})
toList命令(更便于属性数据的提取)
// 将中国的面积信息进行筛选,排序并选取前十个
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var China_List = China_Provinces.sort('Shape_Area',false).toList(10)
print(China_List)
var Area_No_1 = ee.Feature(China_List.get(0))
var Area_No_3 = ee.Feature(China_List.get(2))
var Area_No_7 = ee.Feature(China_List.get(6))
Map.centerObject(China_Provinces,4)
Map.addLayer(Area_No_1)
Map.addLayer(Area_No_3)
Map.addLayer(Area_No_7)
对属性表某一列进行操作
.aggregate操作这里仅列举四个,详细查看官方文档
//对面积信息进行筛选,选择其第一个
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var Area_of_No_1 = China_Provinces.sort('Shape_Area',false).aggregate_first('Shape_Area')
print(Area_of_No_1)
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var Area_of_Top_3 = China_Provinces.sort('Shape_Area',false).limit(3).aggregate_array('Shape_Area')
print(Area_of_Top_3)
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var Area_Status = China_Provinces.aggregate_stats('Shape_Area')
print(Area_Status)
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var Area_Histogram = China_Provinces.aggregate_histogram('Shape_Area')
print(Area_Histogram)
对某一个数据集中每一个元素同时进行某一个操作
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
function Add_Center (feature){
return feature.centroid()
}
var China_Center = China_Provinces.map(Add_Center)
// 对省里面每一个命令都进行一个Add_Center的命令,进而得到每一个省的几何中心
print(China_Center)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(China_Center,{color:'ff0000'})
学习的过程中不难发现String、Number等数据经常出现在Feature、FeatureCollection等中,即基本的数据类型是为了更好的反应空间信息的数据结构而存在的,加强理二者的关系对于日后复杂的操作具有重要的意义
创建 GEE自带 用户上传 ee.image()/constant() ee.Image.pixelLonLat()
编辑 .mask() .clip() .select() .slice() addBands() .reproject() .rbgtohsv() .hsvtorbg() .unit8() .cast() .set() .setMulti() .remap() .where() .metadata() .clamp() .unitScale() .interpolate() .eq()…… .abs() …… .sin() …… .bitWiseAnd() …… .reduce()
地形 image.derivative() ee.Terrain.products() ee.Algorithm.Terrain() ee.Terrain.slope() ee.Terrain.aspect() ee.Terrain.fillMinima() ee.Terrain.hillshade() ee.Terrain.hillshadow() ee.Algorithm.Hillshadow()
纹理 .entropy() .Texture() .zeroCrossing() . ee.Algorithms.CannyEdgeDetector() ee.Algorithms.HoughTransform()
邻域 .focal_max() .focal_min() .focal_median() focal_mode() .convolve() .reduceNeighborhood()
转换 .Image.ToVector() Image.ToArray() Image.arrayFlatten()
其他 .CrossCorrelation() .distance() Export.image()
GEE自带了许多实用的影像数据,如Landsat、Sentinel、Srtm、Land Cover
详情 查询以下网址:Datase of GEE developers
创建纯像素栅格图像
var Image_1 = ee.Image( 10 ); //创建的Image既没有空间分辨率,也没有边界,仅仅是数据
var Image_2 = ee.Image.constant( 20 ); //与创建Image_1类似,创建Image_2,像素为20
var Image_3 = Image_1.add(Image_2) //将Image_1+Image_2的值作为Image_3的值
print(Image_1,Image_2,Image_3);
//由此创建的栅格图像任一点由两部分构成,经纬度
var Image_Lon_Lat = ee.Image.pixelLonLat( );
print( Image_Lon_Lat);
Map.addLayer( Image_Lon_Lat, {bands:['longitude'],min:-180,max:180},'Longitude' );
Map.addLayer( Image_Lon_Lat, {bands:['latitude'], min:- 60,max: 60},'Latitude' );
Map.setCenter( 0, 0, 3 );
掩模操作(不删除原始数据,主要利用栅格图像进行操作)
var Image_DEM = ee.Image( 'CGIAR/SRTM90_V4' );
var Image_Cropland = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3")
.select('landcover').eq(11);
var Image_Masked = Image_DEM.mask( Image_Cropland );
print(Image_DEM,Image_Cropland,Image_Masked);
Map.setCenter(106.4, 34.78, 4);
Map.addLayer( Image_DEM, {"opacity":1,"bands":["elevation"],"min":0,"max":1400,"palette":["2dff07","ff0b0b"]}, ' Image_DEM ' );
Map.addLayer( Image_Cropland, {"opacity":1,"bands":["landcover"],"palette":["ffffff","fbff2d"]}, ' Image_Cropland ' );
Map.addLayer( Image_Masked, {"opacity":1,"bands":["elevation"],"min":0,"max":1400,"palette":["2dff07","ff0b0b"]}, ' Image_Masked ' );
裁剪操作(删除原始数据,主要利用矢量数据操作)
var DEM = ee.Image("USGS/SRTMGL1_003");
var CQ = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
.filterBounds(ee.Geometry.Point([106.8, 29.3]))
var CQ_DEM = DEM.clip(CQ)
Map.setCenter(106.8, 29.3,7)
Map.addLayer(CQ_DEM,{min:0,max:2000})
选择操作(挑选某一数据集中需要的波段信息)
var Glob_Cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3");
var Land_cover = Glob_Cover.select('landcover')
var Land_cover_quality = Glob_Cover.select('qa')
Map.setCenter(107.56, 34.79,4)
Map.addLayer(Land_cover)
Map.addLayer(Land_cover_quality)
利用波段序号选择提取想要的波段
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var L8_One = ee.Image(L8.filterBounds(ee.Geometry.Point(106.4958, 29.5856)).first())
var L8_Slice = L8_One.slice(2,5);
print(L8_One,L8_Slice)
增加波段信息
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var L8_One = ee.Image(L8.filterBounds(ee.Geometry.Point(106.4958, 29.5856)).first())
var L8_B5 = L8_One.select('B5');
var L8_B4 = L8_One.select('B4');
var L8_B5_4 = L8_B5.addBands(L8_B4)
print(L8_B5,L8_B4,L8_B5_4)
对栅格影像重投影
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var L8_One = ee.Image(L8.filterBounds(ee.Geometry.Point(106.4958, 29.5856)).first())
var L8_Reproject = L8_One.reproject('EPSG:3857',null,100)
print(L8_One.select('B1').projection(),L8_Reproject.projection())
Map.setCenter(106.58365, 29.56972,15)
Map.addLayer(L8_One,{"bands":["B5","B4","B3"],"min":10586,"max":18154},'30m')
Map.addLayer(L8_Reproject,{"bands":["B5","B4","B3"],"min":10586,"max":18154}, '100m')
图像显色方式变换,RGB与HSV互换的操作
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var L8_One = ee.Image(L8.filterBounds(ee.Geometry.Point(106.4958, 29.5856))
.first()).slice(2,5).unitScale(0,32468)
var L8_HSV = L8_One.rgbToHsv()
var L8_RGB = L8_HSV.hsvToRgb()
print(L8_One,L8_HSV,L8_RGB)
Map.setCenter(106.5, 29.5,9)
Map.addLayer(L8_One,{},'Origin')
Map.addLayer(L8_HSV,{},'HSV')
Map.addLayer(L8_RGB,{},'RGB')
类型转换(数字格式变换,单波段)
.uint8 .uint16 .uint32 .uint64 .int8 .int16 .int32 .int64 .long .float .double
.toUnit8 toUint16 toUint32 toUint64 toInt8 toInt16 toInt32 toInt64 toLong toFloat toDouble
类型转换(数字格式变换,多波段)
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var L8_One = ee.Image(L8.filterBounds(ee.Geometry.Point(106.4958,29.5856)).first()).slice(2,5).unitScale(0,32468)
var L8_Cast = L8_One.cast({'B5':'double','B4':'double','B3':'double'},['B5','B4','B3'])
print(L8_One,L8_Cast)
属性修改,重置
这里与之前类似,单独的set操作不同于setMulti(需要以字典的形式进行对应的修改)
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var L8_One = ee.Image(L8.filterBounds(ee.Geometry.Point(106.4958, 29.5856)).first()).slice(2,5).unitScale(0,32468)
var L8_HSV = L8_One.rgbToHsv().set('note',"This image was created by 'rgbToHsv()'").setMulti({'author':'Jinzhu Wang', 'Mood':'Not Bad'})
print(L8_HSV)
将影像部分的数值重新赋值(遥感影像重分类)
// 有类别对应的代码 属性数据重分类
var Land_Cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover');
var Land_Remap = Land_Cover.remap([11,14,20,30,40,50,60,70,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 7, 8],
8,'landcover')
Map.setCenter(102.919, 30.199,6)
Map.addLayer(Land_Cover)
Map.addLayer(Land_Remap,
{"palette":["f1ff27","35ce48","07fff3","f017ff","e78845","250bff","ffffff","ffffff"]},
'remaped')
//接用空间基础重分类,将高程小于 4000m的赋值为0
var DEM = ee.Image("USGS/SRTMGL1_003");
var Land_Cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover');
var High_Land = Land_Cover.where(DEM.lt(4000),0)
Map.setCenter(88.96, 33.77,4)
Map.addLayer(DEM.lt(4000))
Map.addLayer(High_Land)
通过元数据修改属性信息
// 属性中是否云层覆盖均替换为云覆盖率
var L8_One = ee.Image(ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA").filterBounds(ee.Geometry.Point(106.5776, 29.5577)).first());
var Constat_Image_Cloud = L8_One.metadata('CLOUD_COVER','The Cloud Rate').clip(L8_One.geometry())
print(Constat_Image_Cloud)
Map.setCenter(106.5776, 29.5577,7)
Map.addLayer(L8_One,{"bands":["B5","B4","B3"],"max":0.4,"gamma":1.03})
Map.addLayer(Constat_Image_Cloud,{"palette":["60ff0f"]})
掐断/过滤操作
// 小于450及大于795的数据均被删除
var DEM = ee.Image("USGS/SRTMGL1_003");
var DEM_Clamp = DEM.clamp(450,795)
Map.setCenter(106.5662, 29.5589,10)
Map.addLayer(DEM_Clamp)
归一化
var L8_One = ee.Image(ee.ImageCollection("LANDSAT/LC08/C01/T1")
.filterBounds(ee.Geometry.Point(106.5776, 29.5577)).first());
var L8_Unitscale = L8_One.unitScale(0,32767)
print(L8_One,L8_Unitscale)
Map.addLayer(L8_One,{"bands":["B5","B4","B3"],"max":30000})
Map.addLayer(L8_Unitscale,{"bands":["B5","B4","B3"],"max":0.92})
属性数据拉伸
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
function Add_Center (feature){
return ee.Geometry(feature.centroid())
}
var Provinces_Centers = China_Provinces.map(Add_Center)
var Center_Distance = Provinces_Centers.distance(200000)
var Distance_Interpolate = Center_Distance.interpolate( [ 0, 50000, 100000, 150000, 200000 ],
[ 0, 25, 50, 100, 75 ], 'extrapolate' );
Map.centerObject(Provinces_Centers,4)
Map.addLayer(Center_Distance,{min:0,max:200000},'origin')
Map.addLayer(Distance_Interpolate,{min:0,max:100},'interpolated')
Map.addLayer(Provinces_Centers, {color:'0000ff'},'centers')
影像比较/利用阈值分割/或设定阈值进行过滤
.eq/neq /gt /gte/lt/lte
= / ≠ / > / ≥ /< / ≤
var China = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var night_Lights = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182013').select('stable_lights').clip(China);
var urban = night_Lights.gte(20)
Map.setCenter(115.218, 33.697, 8);
Map.addLayer(urban, {"opacity":0.33,"bands":["stable_lights"],"palette":["171801","fbff0f"]}, 'Nighttime Lights');
利用逻辑运算进行过滤
Image.and/or()
var China = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var night_Lights = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182013').select('stable_lights').clip(China);
var urban = night_Lights.gte(20)
var Low_Area = ee.Image("USGS/SRTMGL1_003").lt(200).clip(China)
var Low_Urban = urban.and(Low_Area)
print(Low_Area,urban)
Map.setCenter(115.218, 33.697, 4);
Map.addLayer(night_Lights)
Map.addLayer(Low_Area)
Map.addLayer(Low_Urban);
常用数学操作
Image.abs/abs/round/floor/ceil/sqrt/exp/log/log10 ()
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var CQ = China_Provinces.filterMetadata('NAME','equals','Chong_Qing')
var CQ_Distance = CQ.distance(50000)
var Distance_Mod = CQ_Distance.mod(10000)
Map.centerObject(CQ,6)
Map.addLayer(CQ_Distance,{"min":0,"max":50000,
"palette":["0172ff","0dff09","05ffe8","fff707","ffa605","ff5909"]},
'The Distance Effect')
Map.addLayer(Distance_Mod,{"min":0,"max":10000,
"palette":["0172ff","0dff09","05ffe8","fff707","ffa605","ff5909"]},
'The Distance.mod() Effect')
加减乘除
Image. add/subtract/multiply/divide()
.add/subtract/multiply/divide/max/min/mod/pow/hypot/first /and/first_nonzero
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT").filterBounds(ee.Geometry.Point(106.5749, 29.5588)).first()
var B5 = ee.Image(L8.select('B5'))
var B4 = ee.Image(L8.select('B4'))
var B3 = ee.Image(L8.select('B3'))
var NDVI = B5.subtract(B4).divide(B5.add(B3))
Map.centerObject(NDVI)
Map.addLayer(NDVI,
{min":-1,"max":1,"palette":["0f01e2","ff9d93","fff707","11ff2e","04ce14"]})
常见三角函数
.sin/cos/tan/sinh/cosh/tanh/acos/asin/atan ()
var CQ_Point = ee.FeatureCollection(ee.Geometry.Point(106.57, 29.55))
var CQ_Distance = CQ_Point.distance(50)
var Distance_Effect = CQ_Distance.sin()
Map.centerObject(CQ_Point,19)
Map.addLayer(CQ_Distance,{"max":50,"palette":["2d07ff","ff430b"]},'distance Image')
Map.addLayer(Distance_Effect,{"min":-1,"palette":["3705ff","ff4209"]},'sin Image')
逻辑运算
bitwiseAnd/ bitwiseOr /bitwiseXor /bitwiseNot
bitwise_and /bitwise_or /bitwise_xor /bitwise_not
leftShift / rightShift
left_shift /right_shift
var Image_1 = ee.Image( 1 );
var Image_2 = ee.Image( 2 );
var Bit_And = Image_1.bitwiseAnd( Image_2 );
var Bit_Or = Image_1.bitwiseOr( Image_2 );
print ( 'Image of bitwise 1 and 2 =', Bit_And );
print ( 'Image of bitwise 1 or 2 =', Bit_Or );
Map.addLayer( Image_1, null, 'Image of 1s' );
Map.addLayer( Image_2, null, 'Image of 2s' );
Map.addLayer( Bit_And, null, 'Image of Bits from Both' );
Map.addLayer( Bit_Or , null, 'Image of Bits from Either' );
对像元的微分操作
// 输入的是DEM数据,这里为每一个像元的x方向和y方向的坡向
var OldIMAGE = ee.Image( 'CGIAR/SRTM90_V4' );
var NewIMAGE = OldIMAGE.derivative( );
Map.setCenter(106.4448, 29.5684,10)
Map.addLayer( NewIMAGE, {bands:['elevation_x'], min:-90, max:900 }, 'Slope from Left to Right' );
Map.addLayer( NewIMAGE, {bands:['elevation_y'], min:-90, max:900 }, 'Slope from Top to Bottom' );
表面分析工具
ee.Terrain.products
ee.Algorithms.Terrain
var DEM = ee.Image( 'CGIAR/SRTM90_V4' );
var Terrain = ee.Terrain.products( DEM );
Map.setCenter( 106.371, 29.6188 );
Map.addLayer( DEM, { min:0,max:2000,palette:'000099,dddd00'}, 'Elevation');
Map.addLayer( Terrain,{bands:['slope'], min:0,max:90,palette:'000000,ff0000' }, 'Slope');
Map.addLayer( Terrain,{bands:['aspect'], palette:'00ff00,0000ff,00ff00' },'Aspect');
Map.addLayer( Terrain,{bands:['hillshade'],min:0,max:255,}, 'Hillshading');
利用ee.Terrain.hillshadow()阴影生成
这里true和false的选择决定着生成的图像效果
var DEM = ee.Image( 'CGIAR/SRTM90_V4' );
var DEM_Mercator = DEM.reproject( 'EPSG:3857', null, 30 ); //DEM图像在投影坐标系下才可以进行操作
var Shadow_1 = ee.Terrain.hillShadow( DEM_Mercator, 315.0, 75.0,0,true);
var Shadow_2 = ee.Terrain.hillShadow( DEM_Mercator, 315.0, 70.0,0,false);
Map.setCenter( 106.5568, 29.5527, 12 );
Map.addLayer( DEM, {min:0, max:1500, opacity:0.7, palette:'0000ff,ff0000'}, 'Elevation' );
Map.addLayer( Shadow_1, {min:0, max:1, opacity:0.3}, 'Longer Shadows' );
Map.addLayer( Shadow_2, {min:0, max:1, opacity:0.3}, 'Shorter Shadows' );
DEM洼地填充
var DEM = ee.Image( 'CGIAR/SRTM90_V4' );
var DEM_Fill = ee.Terrain.fillMinima( DEM, 0, 50 );
// 0代表被填充的值,50代表进行填洼,进行分析的栅格邻域的大小
Map.setCenter(107.8729, 29.2441, 12 );
Map.addLayer( DEM, {min:0, max:1500, palette:["2f5bff","0dff09","efff05","ff9931"]}, 'Unfilled' );
Map.addLayer( DEM_Fill, {min:0, max:1500, palette:["2f5bff","0dff09","efff05","ff9931"]}, 'Filled' );
熵值操作(对 DEM进行 熵值操作可以发现高程变化最快的一个往往具有最大的熵值)
var DEM = ee.Image( 'CGIAR/SRTM90_V4' );
var DEM_Entropy = DEM.entropy( ee.Kernel.circle( 5, 'pixels', true ) );
Map.setCenter( 106.1201, 29.4977, 10 );
Map.addLayer( DEM, {min:0, max:1500, palette:["050dff","ddd3cd","0bff34","e4ff09","ff9007","ff1c05"]}, 'Original' );
Map.addLayer( DEM_Entropy, {min:3.31,max:4.55, palette:["050dff","ddd3cd","0bff34","e4ff09","ff9007","ff1c05"]}, 'Entropy' );
影像纹理判断及操作
var DEM = ee.Image( 'CGIAR/SRTM90_V4' );
var GLCM = DEM.glcmTexture(5, ee.Kernel.circle( 5, 'pixels', true ) );
var Texture = GLCM.select( 0 );
print( GLCM, Texture );
Map.setCenter( 106.1201, 29.4977, 10 );
Map.addLayer( DEM, {min:0, max:1500, palette:["050dff","ddd3cd","0bff34","e4ff09","ff9007","ff1c05"]}, 'Original' );
Map.addLayer( Texture, {min:0.0067,max:0.0115, palette:["050dff","ddd3cd","0bff34","e4ff09","ff9007","ff1c05"]}, 'Texture' );
判断高程起伏变化
var DEM = ee.Image( 'CGIAR/SRTM90_V4' ).subtract(465);
var Zero_Crossing = DEM.zeroCrossing( );
Map.setCenter( 106.1201, 29.4977, 7 );
Map.addLayer( DEM, { min:0, max:1500, palette:["050dff","ddd3cd","0bff34","e4ff09","ff9007","ff1c05"]}, 'DEM' );
Map.addLayer( Zero_Crossing, { palette:'ffffff,ff0000'}, 'Zero Crossing' );
非0栅格值像元距离周围像元的最近距离量算
这里以欧氏距离为例
var DEM = ee.Image("USGS/SRTMGL1_003");
var Land_Cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover');
var Zero_One = Land_Cover.where(DEM.gt(500),0)
var The_Distance = Zero_One.distance(ee.Kernel.euclidean( 1000, 'meters' ))
Map.setCenter(107.7167, 29.3865,10)
Map.addLayer(Zero_One,{max:1})
Map.addLayer(The_Distance,{max:1500})
邻域操作(最大/最小/中间值/模)
var OldIMAGE = ee.Image('MCD12Q1/MCD12Q1_005_2001_01_01').select('Land_Cover_Type_1');
var MaxIMAGE = OldIMAGE.focal_max( 5, 'circle', 'pixels' );
var MinIMAGE = OldIMAGE.focal_min( 5, 'circle', 'pixels' );
var MedianIMAGE = OldIMAGE.focal_median( 5, 'circle', 'pixels' );
var ModeIMAGE = OldIMAGE.focal_mode( 5, 'circle', 'pixels' );
Map.setCenter( 106.0734, 29.4929, 10 );
Map.addLayer( OldIMAGE, {min:0, max:17, palette:'000000,0000dd,ffffff'}, 'Original ' );
Map.addLayer( MaxIMAGE, {min:0, max:17, palette:'000000,0000dd,ffffff'}, 'Focal Maximum' );
Map.addLayer( MinIMAGE, {min:0, max:17, palette:'000000,0000dd,ffffff'}, 'Focal Minimum' );
Map.addLayer( MedianIMAGE, {min:0, max:17, palette:'000000,0000dd,ffffff'}, 'Focal Median' );
Map.addLayer( ModeIMAGE, {min:0, max:17, palette:'000000,0000dd,ffffff'}, 'Focal Mode' );
利用矩阵对影像进行模糊/锐化处理
var DEM = ee.Image("USGS/SRTMGL1_003");
var KERNEL = ee.Kernel.fixed( 7,7, [[ 4, 0, 0, 0, 0, 0, 1 ],
[ 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0 ],
[ 1, 0, 0, 0, 0, 0, 3 ]] );
var Convelve_DEM = DEM.convolve( KERNEL );
Map.setCenter(105.8125, 29.4033,9)
Map.addLayer(DEM,{min:0,max:2000},'DEM')
Map.addLayer(Convelve_DEM,{max:12000},'Convelve_DEM')
栅格转矢量
var Water = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3")
.select('landcover')
.clamp(209,211);
var geometry = ee.Geometry.Polygon(
[[[106.32728668689242, 29.46329064748005],
[106.76948639392367, 29.462692803378452],
[106.77017303943148, 29.65740304071832],
[106.31355377673617, 29.654419523039962]]]);
var Water_Vecter = Water.reduceToVectors( null, geometry, null, 'polygon', false);
var Water_BoundBox = Water.reduceToVectors( null, geometry, null, 'bb', false);
var Water_Center_4 = Water.reduceToVectors( null, geometry, null, 'centroid', false);
var Water_Center_8 = Water.reduceToVectors( null, geometry, null, 'centroid', true );
//polygon/bb/centroid/为栅格转矢量的类型,分别是边,四至,点。若在转化的时候只考虑上下左右四个点就是false,若考虑八个方向就是true,考虑四个方向得到的栅格密度较大
Map.setCenter(106.5587, 29.5631,10)
Map.addLayer(Water,{"palette":["ffffff","1707ff"]},'Water')
Map.addLayer( Water_Vecter, {color:'dddddd'}, 'The Polygons' );
Map.addLayer( Water_BoundBox, {color:'888888'}, 'The Bounding Boxes' );
Map.addLayer( Water_Center_4, {color:'ff0000'}, '4-way Centroids' );
Map.addLayer( Water_Center_8, {color:'ffffff'}, '8-way Centroids' );
生成栅格数据集
var L8_1 = ee.Image('LANDSAT/LC08/C01/T1_RT/LC08_127040_20130422')
var L8_2 = ee.Image('LANDSAT/LC08/C01/T1_RT/LC08_127039_20130422')
var Collection = ee.ImageCollection([L8_1, L8_2])
Map.setCenter(106.4925, 29.574,7)
Map.addLayer(L8_1,{"bands":["B5","B4","B3"],"max":35000})
Map.addLayer(L8_2,{"bands":["B5","B4","B3"],"max":35000})
Map.addLayer(Collection,{"bands":["B5","B4","B3"],"max":35000})
将栅格图像的多波段值转化为Array模式存贮及将Array转回栅格图像
将空间信息转换为时间信息
var L8 = ee.Image('LANDSAT/LC08/C01/T1_RT/LC08_127040_20130422').select('B[1-7]')
var L8_Array = L8.toArray(0)//to array
var L8_Flatten = L8_Array.arrayFlatten([['a','b','c','d','e','f','g']])//to image
Map.setCenter(106.4949, 29.458,10)
Map.addLayer(L8_Array,{},'Array Image')
Map.addLayer(L8_Flatten,{"bands":["e","d","c"],"max":32000,"gamma":0.73})
栅格图像局域运算(对栅格图像某一区域进行拟合统计分析)
var DEM = ee.Image("USGS/SRTMGL1_003");
var ROI = ee.Geometry.Polygon(
[[[106.20650888671878, 29.570337903152346],
[106.54159189453128, 29.56556010779314],
[106.54159189453128, 29.725493070064537],
[106.21612192382815, 29.71952998792036]]]);
var ROI_Mean = DEM.reduceRegion(ee.Reducer.mean(),ROI)
var ROI_Histo = DEM.reduceRegion(ee.Reducer.histogram(),ROI)
print(ROI_Mean,ROI_Histo)
Map.setCenter(106.4949, 29.458,10)
Map.addLayer(DEM,{min:0,max:2000},'DEM')
Map.addLayer(ROI)
导出做好的栅格影像
var DEM = ee.Image("USGS/SRTMGL1_003");
var ROI = ee.Geometry.Polygon(
[[[106.20650888671878, 29.570337903152346],
[106.54159189453128, 29.56556010779314],
[106.54159189453128, 29.725493070064537],
[106.21612192382815, 29.71952998792036]]]);
var DEM_Clip = DEM.clip(ROI)
Export.image.toDrive(DEM_Clip)
创建 ee.ImageCollection() ee.ImageCollection.load()
筛选 limit() .filterMetadata() .filterDate() .filterBounds() .filter() .select() .distinct() .comnibe() .unit8() ……. .set() .setMulti()
求值 .mosaic() .and/or() .sum/product/max/min/mean/mode/median/count()
转换 .first() .toList() .toArray()
数据提取
var China = ee.FeatureCollection("users/wangjinzhulala/China_Provinces")
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(China.geometry())
.filterDate('2018-01-01','2018-12-31')
.filterMetadata('CLOUD_COVER','less_than',0.1);
Map.setCenter( 107.753, 34.238, 4);
Map.addLayer( L8, {bands:'B4,B3,B2', min:0, max:0.2}, 'Original Images' );
数据处理数量限制
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(106.5487, 29.5444))
.filterDate('2018-03-01','2019-03-01');
var L8_Limit = L8.limit( 10 );
print( L8, L8_Limit );
信息提取(提取的信息需要有相同的数据结构,比如实例代码均为landsat数据)
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(106.5487, 29.5444))
.filterDate('2018-03-01','2019-03-01')
.limit(5);
var L8_Select = L8.select(['B5','B4','B3'], ['Near infrared','Red','Green']);
//提取波段并重命名
print( 'Original', L8 );
print( 'Selected', L8_Select );
去重复
var China_Provinces = ee.FeatureCollection("users/wangjinzhulala/China_Provinces");
var China_Area = China_Provinces.distinct(['NAME'])
print(China_Provinces)
print(China_Area)
Map.centerObject(China_Provinces,4)
Map.addLayer(China_Provinces)
Map.addLayer(China_Area)
数据合并
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(106.5487, 29.5444))
.filterDate('2018-03-01','2019-03-01')
.limit(1);
var Combine_1 = L8.select(['B1'],['Coastal aerosol'])
var Combine_2 = L8.select(['B2'],['Blue'])
var Combine = Combine_1.combine(Combine_2)
print(Combine_1,Combine_2,Combine)
修改属性信息
var L8_1 = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_127041_20180303');
var L8_2 = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_127040_20180303');
var L8_3 = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_127039_20180303');
var L8_Collection = ee.ImageCollection([L8_1,L8_2,L8_2])
var Set_Property = L8_Collection.set('Creater','Jinzhu Wang')
.setMulti({'Creat time':'2019',
'His Cat' : '烧白'
})
print(Set_Property)
影像镶嵌(重叠部分的像元值以函数后面的影像为准)
var L8_1 = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_127040_20180303').select('B5');
var L8_2 = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_128039_20130413').select('B5');
var L8 = ee.ImageCollection([L8_1,L8_2]);
var L8_Mosaci = L8.mosaic()
print(L8_1,L8_2,L8_Mosaci)
Map.addLayer(L8_1)
Map.addLayer(L8_2)
Map.addLayer(L8_Mosaci)
逻辑运算
这里以夜间灯光数据为例,仅筛选出亮过一次的地点就用or,筛选出一直亮的地点就用and
var Night_Light = ee.ImageCollection('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS').select('stable_lights');
var Light_Or = Night_Light.or();
var Light_And = Night_Light.and();
Map.setCenter(105.13, 35.68, 4);
Map.addLayer( Light_Or, {min: 0, max: 1, palette: ['000000','ffff99']}, 'Sometimes Lit');
Map.addLayer( Light_And, {min: 0, max: 1, palette: ['333333','ffff55']}, 'Always Lit');
基础数学操作
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(106.5206, 29.5618))
.filterDate('2018-01-01','2018-12-31')
.select('B[3-5]');
var L8_Sum = L8.sum()
var L8_Product = L8.product()
var L8_Max = L8.max()
var L8_Min = L8.min()
var L8_Mean = L8.mean()
Map.addLayer(L8_Sum,{},'Sum')
Map.addLayer(L8_Product,{},'Product')
Map.addLayer(L8_Max,{},'Max')
Map.addLayer(L8_Min,{},'Min')
Map.addLayer(L8_Mean,{},'Mean')
to list & to array
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(106.5206, 29.5618))
.filterDate('2018-01-01','2018-12-31')
.select('B[3-5]')
.sort('DATE_ACQUIRED');
var L8_List = L8.toList(5)
var Time_No_1 = ee.Image(L8_List.get(0))
var Time_No_2 = ee.Image(L8_List.get(1))
var Time_No_3 = ee.Image(L8_List.get(2))
print(Time_No_1,Time_No_2,Time_No_3)
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(107.193, 29.1373))
.filterDate('2018-01-01','2018-12-31')
.select('B[5]')
.sort('DATE_ACQUIRED');
var L8_Array = L8.toArray()
print(L8,L8_Array)
Map.addLayer(L8)
Map.addLayer(L8_Array)
map操作,对影像每一个像元进行操作
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(107.193, 29.1373))
.filterDate('2018-01-01','2018-12-31')
.select('B[4,5]')
.limit(3);
function add_NDVI (image){
var NDVI = image.normalizedDifference(['B5','B4'])
return image.addBands(NDVI)
}
var L8_NDVI = L8.map(add_NDVI)
print(L8,L8_NDVI)
// 由于云层具有很低的NDVI,故这里相当于去云处理
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(107.193, 29.1373))
.filterDate('2018-01-01','2018-12-31')
.select('B[2-5]');
function add_NDVI (image){
var NDVI = image.normalizedDifference(['B5','B4'])
return image.addBands(NDVI)
}
var L8_NDVI = L8.map(add_NDVI)
var NDVI_Quality = L8_NDVI.qualityMosaic('nd')
Map.setCenter(106.618, 29.6653,9)
Map.addLayer(NDVI_Quality,{"bands":["B5","B4","B3"],"max":0.5,"gamma":1},'NDVI qualified')
解决同物异谱或者同谱异物
// 通过计算得到每一个像元属于其他像元的概率
var unmixImage = composite.select(['B1', 'B2', 'B3', 'B4', 'B5', 'B7']);
var bareMean = unmixImage
.reduceRegion(ee.Reducer.mean(), bare, 30).values();
var waterMean = unmixImage
.reduceRegion(ee.Reducer.mean(), water, 30).values();
var vegMean = unmixImage
.reduceRegion(ee.Reducer.mean(), veg, 30).values();
var endmembers = ee.Array.cat([bareMean, vegMean, waterMean], 1);
var arrayImage = unmixImage.toArray().toArray(1);
var unmixed = ee.Image(endmembers).matrixSolve(arrayImage);
var unmixedImage = unmixed
.arrayProject([0])
.arrayFlatten([['bare', 'veg', 'water']]);
计算归一化指数
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1");
var l8_one = l8.filterBounds(ee.Geometry.Point(106.705, 31.881))
.filterDate('2016-01-01','2018-12-31')
.sort('CLOUD_COVER').first()
// 下面的两个计算等价,该指令相当于(a+b)/(a-b)
var NDVI_1 = l8_one.normalizedDifference(['B5','B4'])
var NDVI_2 = l8_one.expression('(B4+B5)/(B4-B5)',{
'B5': l8_one.select('B5'),
'B4': l8_one.select('B4')
})
print(NDVI_1,NDVI_2)
Map.addLayer(NDVI_1,{"min":-0.1,"max":0.4,"palette":["0f0bff","ff3305","fbff1b","0bff1e"]})
判断影像云量相对多少,以[0-100]的得分为例
var l8_TOA = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterBounds(ee.Geometry.Point(106.2608, 29.5755))
.first()
var Cloud_Rate = ee.Algorithms.Landsat.simpleCloudScore(l8_TOA)
print(Cloud_Rate)
Map.setCenter(106.14, 30.3488,8)
Map.addLayer(Cloud_Rate,{bands:['B5','B4','B3'],max:0.3})
Map.addLayer(Cloud_Rate.select('cloud'))
去云处理
// 这个操作仅限于RAW格式的数据,因为要求输入整形数据,而TOA数据不是
var L8_RAW = ee.ImageCollection("LANDSAT/LC08/C01/T1")
.filterBounds(ee.Geometry.Point(106.1125, 30.3772))
.filterDate('2018-01-01','2018-12-31')
var L8_Siple_Composite = ee.Algorithms.Landsat.simpleComposite({collection:L8_RAW,asFloat:true})
print(L8_RAW,L8_Siple_Composite)
Map.setCenter(106.1125, 30.3772,8)
Map.addLayer(L8_Siple_Composite,{bands:['B5','B4','B3'],max:0.3})
GEE中,竖直方向代表真实像元数,横轴方向代表 分类像元数
创建 ee.ConfusionMatrix()
转换 ConfusionMatrix.array()
精度 .kappa() .accuracy() .producersAccuracy() .consumersAccuracy() .order()