我用fastDistanceTransform函数成功地提取了最近的人类住区的距离,其中原始层是一幅图像(DLR/WSF/WSF 2015/v1)。我想重复这个距离最近的道路,但道路数据集是一个featureCollection,而不是一个图像。
我已成功地将gee代码编辑器中的图像转换为:
var dataset = ee.FeatureCollection('TIGER/2016/Roads')
.map(function(feature){
var num = ee.Number.parse(feature.get('linearid'));
return feature.set('linearid', num);
});
var roads = dataset
.reduceToImage({
properties: ['linearid'],
reducer: ee.Reducer.first()
});
Map.setCenter(-99.976, 40.38, 5);
Map.addLayer(roads, {
});但我不能让它在R包里重复。我正在使用代码:
road = ee$FeatureCollection("TIGER/2016/Roads")$
map(function(feature) { num = ee$Number$parse(feature$get('linearid'))
return(feature$set('linearid', num)) })
road2 = road$reduceToImage(properties=road$select('linearid'), reducer=ee$Reducer$first())
Map$addLayer(road2, {}, "road2")但我知道错误是:
Error in py_call_impl(callable, dots$args, dots$keywords) :
ee.ee_exception.EEException: Collection.reduceToImage, argument 'properties': Invalid type.
Expected type: List<String>.
Actual type: FeatureCollection.有人能帮我修复这个错误吗?这样我就可以继续使用'road2‘作为图像了吗?我认为这与此有关(https://github.com/r-spatial/rgee/issues/232)“似乎在Javascript中传递ee.Image对象会立即将其更改为列表”
发布于 2022-06-10 18:34:29
我不懂R语言,但看来你翻译错了。
var roads = dataset
.reduceToImage({
properties: ['linearid'],
reducer: ee.Reducer.first()
});这里,properties参数reduceToImage是一个字符串列表。
road2 = road$reduceToImage(properties=road$select('linearid'), reducer=ee$Reducer$first())这里不是构建列表,而是调用road$select。因此,结果是一个图像,而不是reduceToImage想要的字符串列表。
也许你想要properties=list('linearid')?再说一遍,我不知道R或rgee,所以我不能说这是否正确。
https://stackoverflow.com/questions/72575200
复制相似问题