Day 3-feature collection

本文僅僅是將GEE官網(wǎng)上的代碼整理一下,一方面自學,另一方面自我監(jiān)督。文中有些問題是我想不通的,還需經(jīng)歷時間來理解。?

3 feature collection

3.1 from polygons

官網(wǎng)上給的代碼截圖:

逐行分析代碼:

// Create and render a feature collection from polygons.##從多邊形,創(chuàng)建和反饋特征集

// Construct a FeatureCollection from a list of features.##構建屬性集

var fc = ee.FeatureCollection([

? // Create each feature with a geometry and properties.##創(chuàng)建每一個圖形的幾何特征和屬性值

? ee.Feature(

? ? ? ee.Geometry.Polygon({

? ? ? ? coords: [[-109.05, 41], [-109.05, 37], [-102.05, 37], [-102.05, 41]],

? ? ? ? geodesic: false, // The state boundaries are not geodesic.##邊界不是測地線。測地線是曲面上面兩點最短的距離。

? ? ? ? maxError: 1000 // Make the error margin large; we don't need accuracy.

? ? ? }), {name: 'Colorado', fill: 1}), // Pass properties as a dictionary.

? 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})

]);

// Fill, then outline the polygons into a blank image.##填充,然后把外邊框放到一個image中。

var image = ee.Image()

? ? .paint(fc, 'fill') // Get color from property named 'fill'

? ? .paint(fc, 3, 5) // Outline using color 3, width 5.##外邊框的顏色和寬度。顏色3是藍色,1是紅,2是綠。

? ? .toByte();

Map.addLayer(image, {

? ? palette: ['000000', 'FF0000', '00FF00', '0000FF'],

? ? max: 3,##調(diào)節(jié)顏色。

? ? opacity: 0.5

});

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

3.2 buffer

官網(wǎng)上給的代碼截圖:


逐行分析代碼:

// Feature buffer example.

// Display the area within 2 kilometers of San Francisco BART stations.

// Instantiate a FeatureCollection of BART locations in Downtown San Francisco ##用例子說明地鐵站的特征集

// (points).##找到三個點。

var stations = [

? ee.Feature(

? ? ? ee.Geometry.Point(-122.42, 37.77), {'name': '16th St. Mission (16TH)'}),

? ee.Feature(

? ? ? ee.Geometry.Point(-122.42, 37.75), {'name': '24th St. Mission (24TH)'}),

? ee.Feature(

? ? ? ee.Geometry.Point(-122.41, 37.78),

? ? ? {'name': 'Civic Center/UN Plaza (CIVC)'})

];

var bartStations = ee.FeatureCollection(stations);

// Map a function over the collection to buffer each feature.##構建一個函數(shù),讓

var buffered = bartStations.map(function(f) {##map里面有多個function,butter是其中的一個。

? return f.buffer(2000, 100); // Note that the errorMargin is set to 100.

});

Map.addLayer(buffered, {color: '800080'});

Map.setCenter(-122.4, 37.7, 11);


3.3 computed area filter

官網(wǎng)上給的代碼截圖:


逐行分析代碼:

// Computed area filter.

// Find US counties smaller than 3k square kilometers in area.##選擇縣域面積小于3000平方千米的縣城。

// Load counties from TIGER boundaries table

var counties = ee.FeatureCollection('TIGER/2016/Counties');

// Map a function over the counties to set the area of each.##設置一個函數(shù),獲得每一個面積值。

var countiesWithArea = counties.map(function(f) {##點后面是函數(shù)

? // Compute area in square meters.? Convert to hectares.##平方米轉(zhuǎn)到公頃。

? var areaHa = f.area().divide(100 * 100);

? // A new property called 'area' will be set on each feature.

? return f.set({area: areaHa});

});

// Filter to get only smaller counties.

var smallCounties = countiesWithArea.filter(ee.Filter.lt('area', 3e5));##現(xiàn)在單位是公頃,面積小于300 000公頃。也就是面積小于300 000 0000平方米。3000 000 000平方米就是3千平方千米。

Map.addLayer(smallCounties, {color: '900000'});##顏色是紅色

Map.setCenter(-119.7, 38.26, 7);


3.4 distance?

官網(wǎng)上給的代碼截圖:


逐行分析代碼:

// Collection.distance example.

// Computes the distance to the nearest feature in a collection.

// Construct a FeatureCollection from a list of geometries.

var fc = ee.FeatureCollection([##設置三個點

? ee.Geometry.Point(-72.94411, 41.32902),

? ee.Geometry.Point(-72.94411, 41.33402),

? ee.Geometry.Point(-72.94411, 41.33902),

? // The geometries do not need to be the same type.

? ee.Geometry.LineString(##設置一條線段,線段有三個點。

? ? ? -72.93411, 41.30902, -72.93411, 41.31902, -72.94411, 41.31902)

]);

// Compute distance from the dfeatures, to a max of 1000 meters.

var distance = fc.distance(1000, 100);##1000是緩沖距離,100不知道什么意思。

Map.setCenter(-72.94, 41.32, 13);

Map.addLayer(distance, {min: 0, max: 1000, palette: ['yellow', 'red']});

Map.addLayer(fc);


3.5 join

官網(wǎng)上給的代碼截圖:


逐行分析代碼:

// Simple Join example.

// Show parks in San Francisco within 2 kilometers of a BART station.##顯示在地鐵站2千米范圍內(nèi)的公園。

// Load fusion tables for BART station locations and local parks.

var bart = ee.FeatureCollection('GOOGLE/EE/DEMOS/bart-locations');

var parks = ee.FeatureCollection('GOOGLE/EE/DEMOS/sf-parks');

// Create a filter to pass the left features within 2km of the right features.##創(chuàng)建一個濾波通過左的數(shù)據(jù)(在右邊數(shù)據(jù)的2km內(nèi))

var joinFilter = ee.Filter.withinDistance({

? distance: 2000,

? leftField: '.geo',

? rightField: '.geo'

});

// Apply the join.? The leftField corresponds to the primary collection##應用join功能,左邊數(shù)據(jù)是主要的,右邊數(shù)據(jù)是次要的。匹配條件是設定的過濾器。

// and the rightField corresponds to the secondary collection.? The

// matching condition is specified by the filter.

var closeParks = ee.Join.simple().apply({

? primary: parks,

? secondary: bart,

? condition: joinFilter

});

// Buffer the bart stations by 2km for display purposes.

var bufferedBart = bart.map(function(f) { return f.buffer(2000, 100); });

Map.setCenter(-122.45, 37.75, 13);

Map.addLayer(bufferedBart, {color: 'b0b0b0'});

Map.addLayer(closeParks, {color: '008000'});


3.6 reduce to image

官網(wǎng)上給的代碼截圖:


逐行分析代碼:

// Example of FeatureCollection.reduceToImage()

// Define a feature collection with a value we want to average.

var fc = new ee.FeatureCollection([

? ee.Feature(

? ? ee.Geometry.Rectangle(

? ? ? -122.4550, 37.8035,

? ? ? -122.4781, 37.7935),

? ? {'value': 0}),

? ee.Feature(

? ? ee.Geometry.Polygon([

? ? ? [-122.4427, 37.8027],

? ? ? [-122.4587, 37.7987],

? ? ? [-122.4440, 37.7934]]),

? ? {'value': 1})

? ]);

// Reduce the collection to an image, where each pixel##每一個像元是所有的feature(相交在某像元上)的中間值。

// is the mean of the 'value' property in all features

// intersecting that pixel.

var image_reduced = fc.reduceToImage(['value'], 'mean');

Map.setCenter(-122.4561, 37.7983, 14);

Map.addLayer(image_reduced, {

? min: 0,

? max: 1,

? palette: ['008800', '00FF00']});

問題:不知道這個有什么用場。


3.7 from eargh engine asset

官網(wǎng)上給的代碼截圖:


逐行分析代碼:

// Create a FeatureCollection from an Earth Engine Table.##創(chuàng)建一個特征集。

// Load census roads.##提取道路,先把州際的挑出來,再把地表的挑出來。

var roads = ee.FeatureCollection('TIGER/2016/Roads');

// Get only interstates.

var interstates = roads.filter(ee.Filter.eq('rttyp', 'I'));

// Get only surface roads.

var surfaceRoads = roads.filter(ee.Filter.eq('rttyp', 'M'));

// Display the roads in different colors.

Map.addLayer(surfaceRoads, {color: 'gray'}, 'surface roads');

Map.addLayer(interstates, {color: 'red'}, 'interstates');

這次的學習就到這里了,希望幫助自己學到知識, 也可以幫助到需要的朋友。不足之處,還望見諒。

我是小白,生產(chǎn)不了代碼。copyright from Google earth engine。

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容