2张图片之间的散点图Google Earth Engine

时间:2019-06-30 07:51:43

标签: scatter-plot google-earth-engine

我在Google Earth Engine中有2张高分辨率图片。我想在这两个图像之间绘制散点图。但是我遇到了一些错误 @Override protected String doInBackground(String... params) { 'i am entering the ip of my pc' url = new URL("http://192.168.0.1/test/server.php?"); conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("POST"); // Append parameters to URL using Uri.Builder and the String query = builder.build().getEncodedQuery(); // Open connection for sending data // my response_code value is 501 int response_code = conn.getResponseCode(); - when i run the code, my response_code value is 501 - i get IOException 。我不知道该如何纠正(或者这是由于图像引起的)。

首先,我导入了几何图形和图像:

Missing required arguments to function seriesByRegion(): reducer

然后我对图像进行视觉化

var RZSC = ee.Image("users/chandrakant/Max_RZSC_Layer_Trail_3"),
    geometry = /* color: #d6cbbb */ee.Geometry.Polygon(
        [[[-81.375, -56.125],
          [-34.625, -56.125],
          [-34.625, 12.625],
          [-81.375, 12.625]]]);

可视化我的MODIS图像

var vizParams = {
  bands: ['b1'],
  min: 0.0,
  max: 1500.0,
  palette: ['blue', 'green', 'red']
};
Map.setCenter(6.746, 46.529, 10);
Map.addLayer(RZSC.clip(geometry), vizParams, 'Rootzone Storage Capacity');
Map.centerObject(RZSC);
print('RZSC Projection, crs, and crs_transform:', RZSC.projection());

在这里我将图像(RZSC)重新投影为250 m

var MODIStc = ee.ImageCollection('MODIS/051/MOD44B')
                  .filter(ee.Filter.date('2000-01-01', '2017-12-01')).mean();
var percentTreeCover = MODIStc.select('Percent_Tree_Cover');
var percentTreeCoverVis = {
  min: 0.0,
  max: 100.0,
  palette: ['bbe029', '0a9501', '074b03'],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(percentTreeCover.clip(geometry), percentTreeCoverVis, 'Percent Tree Cover');
print('MOD44B Projection, crs, and crs_transform:', percentTreeCover.projection());
\\Here I added Water Mask
var waterOcc = ee.Image("JRC/GSW1_0/GlobalSurfaceWater").select('occurrence'),
    jrc_data0 = ee.Image("JRC/GSW1_0/Metadata").select('total_obs').lte(0),
    waterOccFilled = waterOcc.unmask(0).max(jrc_data0),
    waterMask = waterOccFilled.lt(50);

enter image description here

在这里尝试了一个散点图

\\Here I tried to increase the resolution from 25km to 250m    
var RZSC_250m = RZSC.resample('bilinear').reproject({
  crs: RZSC.projection().crs(),
  scale: 250
});
Map.addLayer(RZSC_250m.clip(geometry).updateMask(waterMask), vizParams, 'RZSC_250m');
print('RZSC_250m Projection, crs, and crs_transform:', RZSC_250m.projection());

我得到的错误: \\Tried to plot scatterplot here (I want just the basic scatter plot between 2 variables) var chart = ui.Chart.image.seriesByRegion(RZSC, MODIStc, ee.Reducer.mean(),250, 'nd').setChartType('ScatterChart'); print(chart); Error generating chart: Collection.map, argument 'collection': Invalid type. Expected: FeatureCollection. Actual: Image<[Percent_Tree_Cover]>.

其他信息: 另外,我也不知道为什么,但是Collection.map, argument 'collection': Invalid type. Expected: FeatureCollection. Actual: Image<[Percent_Tree_Cover]>.MODIStc的尺寸是不同的。 对于MODIStc:

RZSC_250m

对于RZSC_250m:

bands: List (1 element)
0: "Percent_Tree_Cover", double ∈ [0, 255], EPSG:4326, 48x73 px
id: Percent_Tree_Cover
crs: EPSG:4326
crs_transform: [1,0,0,0,1,0]
data_type: double ∈ [0, 255]
dimensions: [48,73]
origin: [-82,-59]

此外,当我尝试在MODIStc上使用bands: List (1 element) 0: "b1", float, EPSG:4326, 20818x28371 px id: b1 crs: EPSG:4326 crs_transform: List (6 elements) data_type: float dimensions: [20818,28371] origin: [-36235,-6107] 时,数据看起来平滑且奇怪(很多细节丢失了)。 enter image description here

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您想要的是一个散点图,其中一个轴代表RZSC中的值,而另一个轴代表MODIStc中的值。此外,图表中的每个点都应在同一像素处包含一对值。

要实现这一目标,您将需要ui.Chart.feature.byFeature,而不是ui.Chart.image.seriesByRegion

要使用ui.Chart.feature.byFeature,您需要创建一个具有2个属性的FeatureCollection,一个属性保存RZSC中所有像素的值,另一个属性保存其中MODIStc中所有像素的值var combined_image = RZSC.addBands(MODIStc) var region = ee.Geometry.Rectangle(-83, -20, -31, 13) var sample = combined_image.sampleRegions(region, null, 250) var chart = ui.Chart.feature.byFeature(sample, 'b1', 'Percent_Tree_Cover') .setChartType('ScatterChart') print(chart) 。下面是获得此代码的示例代码:

region

在上面的代码中,我根据您的示例图片组成了250变量,该变量代表感兴趣的区域(南美)。您可能想将其更改为所需的任何内容(我想可能是整个世界)。

此外,如果GEE抛出任何内存错误(例如,“收集查询在累积超过5000个元素后中止”,则可能必须增加小数位值(当前在以上代码中为Window)或减小您的关注区域。 '或'超出用户内存限制'​​)

希望这会有所帮助。