onenechan / GEE_turtrial

0 stars 0 forks source link

Google Earth Engine coded JavaScript #2

Open ghost opened 3 years ago

ghost commented 3 years ago

😄

ghost commented 3 years ago

今日の成果 スクリーンショット 2021-01-31 23 57 40(2)

var dataset = ee.ImageCollection('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS')
                  .filter(ee.Filter.date('2010-01-01', '2010-12-31'));
var nighttimeLights = dataset.select('stable_lights');
var nighttimeLightsVis = {
  min: 61.0,
  max: 63.0,
};

var point = ee.Geometry.Point([139.773522 , 35.6277234])
Map.centerObject(point , 20)
Map.addLayer(point)

Map.setCenter(135.60, 29.97, 5);

Map.addLayer(nighttimeLights, nighttimeLightsVis, 'Nighttime Lights');

// Export the image, specifying scale and region.
Export.image.toDrive({
  image: dataset,
  description: 'imageToDriveExample',
  scale: 30,
  region: point
});
ghost commented 3 years ago

次回

ghost commented 3 years ago

次回

  • 色の濃淡のグラフ
  • 暗い箇所から地名を抽出させる(黒い箇所→お台場,みたいな)
  • 画像の保存

ある程度範囲を絞って前回のように出力 ↓ 地名が欲しい箇所にピンを落とす ↓ 緯度と経度を出力させる(調べればコードありそう) ↓ 検索かける?データフレームみたいなのあれば良い

こんなロジックを考えていた.多分GEE内部では緯度経度の出力くらいまでが限界かしら? それかGEEコーディング画面にあるマップを凝視して地名をとってくるか

もしくは地名と緯度経度が書いてあるようなデータフレームみたいなのあればPythonとか使ってデータ分析のやり方で地名を出したり.

ghost commented 3 years ago

【210202】

暗い箇所から地名を抽出させる(黒い箇所→お台場,みたいな)

を実現できそうな記事を発見したが,理解のフェーズはまだだな〜ただ,ファイルをExportしてGoogle Driveに保存することには成功した.

あと,何の設定が良くないかわからないが

// 衛星データのBAND: avg_radから日付を指定してImageCollection取得
var y_2014 = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG').select('avg_rad').filter(ee.Filter.date('2017-01-01','2017-12-31')).median();
var y_2015 = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG').select('avg_rad').filter(ee.Filter.date('2015-12-01T00:00:00+09:00','2015-12-01T23:59:59+09:00')).median();
var y_2016 = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG').select('avg_rad').filter(ee.Filter.date('2016-12-01T00:00:00+09:00','2016-12-01T23:59:59+09:00')).median();
var y_2017 = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG').select('avg_rad').filter(ee.Filter.date('2017-12-01T00:00:00+09:00','2017-12-01T23:59:59+09:00')).median();
var y_2018 = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG').select('avg_rad').filter(ee.Filter.date('2018-12-01T00:00:00+09:00','2018-12-01T23:59:59+09:00')).median();
// IDE上のMap表示のオプション
var nighttimeVis = {min: 0.0, max: 60.0}; 
Map.setCenter(139.6503,35.6762);
Map.setZoom(10);

// IDE上のMapにデータを表示
Map.addLayer(y_2014.clip(table), nighttimeVis, '[YEAR] 2014');
Map.addLayer(y_2015.clip(table), nighttimeVis, '[YEAR] 2015');
Map.addLayer(y_2016.clip(table), nighttimeVis, '[YEAR] 2016');
Map.addLayer(y_2017.clip(table), nighttimeVis, '[YEAR] 2017');
Map.addLayer(y_2018.clip(table), nighttimeVis, '[YEAR] 2018');

// データ集約方法定義
var reducers_fnc = ee.Reducer.mean().combine({
  reducer2: ee.Reducer.minMax(),
  sharedInputs: true
}).combine({
  reducer2: ee.Reducer.median(),
  sharedInputs: true
});

// データ集約
function reduce_collection(image) {
  return image.reduceRegions({
    collection: table,
    reducer: reducers_fnc,
    scale: 500
  })
}

// データ出力タスク定義 (GoogleDrive出力)
function export_table(table, description) {
  return Export.table.toDrive({
    collection: ee.FeatureCollection(table),
    folder: 'EarthEngineExport',
    description: description,
    selectors: (["KEY_CODE", "CITY", "CITY_NAME", "S_NAME", "JINKO", "SETAI", "mean", "max", "min"])
  })
}
// 定義ファイルを参考
// https://www.e-stat.go.jp/gis/statmap-search/data?datatype=2&serveyId=A002005212015&downloadType=1

// データ出力タスク呼び出し
export_table(reduce_collection(y_2014), 'stray_light_2014');
export_table(reduce_collection(y_2015), 'stray_light_2015');
export_table(reduce_collection(y_2016), 'stray_light_2016');
export_table(reduce_collection(y_2017), 'stray_light_2017');
export_table(reduce_collection(y_2018), 'stray_light_2018');

を実行してもLayersは反応するがマップ上には表示されない.東京がダメだった・・・?

tutorialにあったコード

var dataset = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG')
                  .filter(ee.Filter.date('2017-05-01', '2017-05-31'));
var nighttime = dataset.select('avg_rad');
var nighttimeVis = {min: 0.0, max: 60.0};
Map.setCenter(-77.1056, 38.8904, 8);
Map.addLayer(nighttime, nighttimeVis, 'Nighttime');

は普通に動いた.