Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Using rgee and fastDistanceTransform with a featureCollection

I have successfully extracted distance to nearest human settlement with rgee function fastDistanceTransform, where the original layer is a single image (DLR/WSF/WSF2015/v1). I want to repeat this with distance to nearest road, but the road dataset is a featureCollection and not an image.

I have successfully converted to image in the gee code editor with:

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, {
});

But I cannot get it to repeat the same in the R package rgee. I am using code:

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")

But I get the error:

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.

Can anyone help me fix this error so I can continue using 'road2' as an image? I think it has something to do with this (https://github.com/r-spatial/rgee/issues/232) "It seems that passing an ee.Image object in Javascript immediately changes it to a List"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't know the R language, but it looks like you made a mistake in your translation.

  var roads = dataset
  .reduceToImage({
    properties: ['linearid'],
    reducer: ee.Reducer.first()
});

Here the properties argument to reduceToImage is a list of strings.

road2 = road$reduceToImage(properties=road$select('linearid'), reducer=ee$Reducer$first())

Here you are not constructing a list, but instead calling road$select. So, the result is an image, not the list of strings that reduceToImage wants.

Maybe you want properties=list('linearid') ? Again, I don't know R or rgee, so I can't say whether this is correct.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!