目前我正在尝试获得一个仅考虑堤坝后面区域的单面缓冲区。我有两个数据集,一个具有堤坝的特征(多边形),另一个具有河流/水的多边形。我试图通过创建两个距离函数并获取到堤坝的距离小于到水的区域来做到这一点。当我在第一个多边形上尝试它时,它似乎正在工作,但是,当我导出它时,我收到以下错误:
错误:无效的属性类型:属性joinedWaterFeature 的类型为Feature。 (错误代码:3)
buffer1000Date2209VersionSHPTEST
ID: FVSO4EQHD4A3WCDNM7GLIWJ4
Phase: Failed
Runtime: 5s (started 2022-09-26 10:51:31 +0800)
Attempted 1 time
Error: Invalid property type: Property joinedWaterFeature has type Feature. (Error code: 3)
我在这里创建了一个带有模拟数据集的可重现脚本,它得到了相同的错误:
https://code.earthengine.google.com/fa026bb693b2a3c34721a8b4d50679c2
代码:
var water = /* color: #d63000 */ee.Geometry.MultiPolygon(
[[[[4.862333298266703, 51.94077379951665],
[4.862848282397563, 51.93897473727527],
[4.877267838061625, 51.9368581010924],
[4.884820938647563, 51.93791643166631],
[4.897008896411235, 51.93982136378783],
[4.910398483813578, 51.94172621502436],
[4.920698166430766, 51.94363098537719],
[4.927736282885844, 51.948815783784696],
[4.926362991870219, 51.95008543896943],
[4.92258644157725, 51.94807513499353],
[4.9201831822999065, 51.945747302018326],
[4.914003372729594, 51.94416007389877],
[4.907308579028422, 51.94299607091323],
[4.901472092212016, 51.942149504314884],
[4.896322250903422, 51.94098544915475],
[4.8885974889405315, 51.94066797432313],
[4.882074356616313, 51.93960970865756],
[4.874006271899516, 51.93950388071796],
[4.866109848559672, 51.94035049724472]]],
[[[4.956918716967875, 51.9608760567711],
[4.956918716967875, 51.95928936408167],
[4.964815140307719, 51.958760454038384],
[4.97202491813975, 51.95960670711241],
[4.978204727710063, 51.96489542690582],
[4.981122971118266, 51.967433790768055],
[4.986616135180766, 51.970923806344054],
[4.991937637866313, 51.9744135501296],
[4.990907669604594, 51.975682480485325],
[4.982667923510844, 51.97113531370425],
[4.977346420825297, 51.96627039184342],
[4.971853256762797, 51.962674240594694],
[4.967218399585063, 51.96119338856977],
[4.95880699211436, 51.96077027900568],
[4.9572620397217815, 51.96182804542794]]]]),
dyke = /* color: #98ff00 */ee.Geometry.MultiPolygon(
[[[[4.866226996428997, 51.9429134223473],
[4.866312827117474, 51.94132609394463],
[4.876097525603802, 51.941273182030514],
[4.883564795501263, 51.94132609394463],
[4.892233695037396, 51.942278497726505],
[4.897726859099896, 51.943336700435026],
[4.9077690496516535, 51.94465941871544],
[4.914292181975872, 51.94640534712053],
[4.918326224334271, 51.94793959173555],
[4.921416129119427, 51.95063761874887],
[4.919184531219036, 51.95211881946101],
[4.914549674041302, 51.95016150812951],
[4.908884848601849, 51.94788668762252],
[4.904164160735638, 51.9465640645146],
[4.899014319427044, 51.94561175172512],
[4.892834509856732, 51.944818142287914],
[4.887856329925091, 51.94439487817979],
[4.878414954192669, 51.94312506189043],
[4.871119345672161, 51.94249014026531],
[4.867428626067669, 51.942701781805575]]],
[[[4.958323325164349, 51.96497147094154],
[4.958323325164349, 51.96333203732279],
[4.965189780242474, 51.96285606149207],
[4.969395483977825, 51.96317337927413],
[4.973000372893841, 51.96497147094154],
[4.975489462859661, 51.9668752540859],
[4.9790085210872, 51.969730777178945],
[4.98227008724931, 51.972850492564255],
[4.982613410003216, 51.97528266235366],
[4.979952658660443, 51.97475394102141],
[4.976605261809857, 51.97195161379573],
[4.972914542205364, 51.96877895636417],
[4.9709404363704035, 51.966663726618826],
[4.968708838470013, 51.965024354898596],
[4.960211600310833, 51.964759934489244],
[4.959009970672161, 51.965341657330704]]]]),
NetherlandsDot = /* color: #d63000 */ee.Geometry.Point([4.716401205112493, 52.41511927429774]),
Location = /* color: #0b4a8b */ee.Geometry.Point([4.933398086998229, 51.9659069488746]);
// 加载一个影像数据
var AHN = ee.Image('AHN/AHN2_05M_INT').select('elevation');
Map.setCenter(4.933398086998229, 51.9659069488746, 13);
var countryBoundaries = ee.FeatureCollection("FAO/GAUL/2015/level0");
var Netherlands = countryBoundaries.filterBounds(NetherlandsDot); // set area for the boundaries
var maxDistanceFilter = ee.Filter.withinDistance(200, '.geo', null, '.geo', null, 10);
// 定义连接。
var saveBestJoin = ee.Join.saveBest({
matchKey: 'joinedWaterFeature',
measureKey: 'distance'
});
// 应用连接。
var keringenWaterJoin = saveBestJoin.apply(dyke, water, maxDistanceFilter);
// 在每个障碍物周围建立一个缓冲区
var bufferSize = 1000; // 缓冲区尺寸,单位:米
// // 使用每个堤坝周围的缓冲区来计算统计数据,并添加到该单元的特征中去
var statistics = function(feature){
// 屏蔽除堤坝后面的区域以外的一切(与堤坝的距离比与邻近水域的距离短)。
var distanceDyke = ee.FeatureCollection([feature]).distance(bufferSize);
var distanceWater = ee.FeatureCollection([feature.get('joinedWaterFeature')]).distance(bufferSize); // I think the issue is somewhere here
var dykeSideMask = distanceDyke.lt(distanceWater).rename('behindDyke');
//Map.addLayer(dykeSideMask, {min: 0, max: 1, palette: ['white', 'blue']}, 'area behind dyke')
var zones = dykeSideMask.eq(1);
zones = zones.updateMask(zones.neq(0));
var areaBehindDyke = zones.addBands(dykeSideMask).reduceToVectors({
geometry: Netherlands.geometry(),
scale: 50,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'zone',
reducer: ee.Reducer.mean(),
maxPixels : 1e12
});
// 设定平均区域温度
var AHNRasterMean = AHN.reduceRegion({
reducer : ee.Reducer.mean(),
geometry : areaBehindDyke,
maxPixels : 1e12
});
feature=feature.set('elevation',ee.Number(AHNRasterMean.get('elevation')));
return feature;
}
print(statistics(keringenWaterJoin.first()));
// 对特征集合进行映射,以便每个堤坝都能获得其周围环境的属性。
var keringenMetScores = keringenWaterJoin.map(statistics);
//将统计数据导出到Google Drive,指定CRS、转换和区域。
Export.table.toDrive({collection:keringenMetScores,
description: 'buffer'+bufferSize+'Date2209VersionSHPTEST',
folder : "tests",
fileFormat: 'SHP'
});
这是因为集合具有包含连接要素的属性。正在将结果导出为不支持在属性表中包含“特征”的 shapefile。因此,这里必须将其删除或将其转换为兼容的类型(如字符串、数字等)。最简单的方法是在导出中使用“选择器”参数来指定导出中所需的属性。
https://code.earthengine.google.com/612395aecfe012aa704ecf93c534f57d
这里我们仔细看一下导出的table,
Export.table.toDrive(collection, description, folder, fileNamePrefix, fileFormat, selectors, maxVertices)
创建一个批处理任务,将FeatureCollection作为一个表导出到Drive。任务可以从任务标签中开始。
参数。
collection (FeatureCollection):
要导出的特征集合。
description(字符串,可选)。
任务的可读名称。可以包含字母、数字、-、_(没有空格)。默认为 "myExportTableTask"。
folder(字符串,可选)。
导出任务所在的Google Drive文件夹。注意:(a)如果文件夹名称在任何级别都存在,输出将被写入该文件夹,(b)如果存在重复的文件夹名称,输出将被写入最近修改过的文件夹,(c)如果文件夹名称不存在,将在根部创建一个新的文件夹,以及(d)带有分隔符的文件夹名称(例如'path/to/file')将被解释为字面字符串,而不是系统路径。默认为驱动器根目录。
fileNamePrefix(字符串,可选)。
文件名的前缀。可以包含字母、数字、-、_(没有空格)。默认为描述。
fileFormat (String, optional):
输出格式。"CSV"(默认)、"GeoJSON"、"KML"、"KMZ"、"SHP "或 "TFRecord"。
selectors选择器(List
导出时要包含的属性列表;可以是用逗号分隔的单个字符串,也可以是字符串的列表。
maxVertices(数字,可选)。
每个几何体未切割的顶点的最大数量;顶点较多的几何体将被切割成小于此大小的碎片。
Export.table.toDrive({collection:keringenMetScores,
description: 'buffer'+bufferSize+'Date2209VersionSHPTEST',
folder : "tests",
fileFormat: 'SHP',
selectors: ['elevation']
});
云小站_专享特惠_云产品推荐-阿里云