1

I am attempting to use a vector layer as a predictor environmental layer for use in classification/predictor models (eg Random Forest/Maxent). I have attempted to include a bathymetric substrate layer, specifically 'High energy infralittoral rock' by doing a vector to raster transformation (following GEE doco). I have created a band, but it is not working properly, and can't be joined to the other enviro layers without crashing the classification. Any ideas on where i am going wrong?

//Import data
//-- Area Of Interest Polygon
var aoi_polygon = ee.Geometry.Polygon([[142.8169776552576,-38.660150171229965], 
[143.0586768740076,-38.660150171229965],
[143.0586768740076,-38.57323675496147],
[142.8169776552576,-38.57323675496147],
[142.8169776552576,-38.660150171229965]]);

// --Specify location
var geo = ee.Geometry.Point([142.99126680969238,-38.62060224055215])
Map.setCenter(142.99126680969238,-38.62060224055215, 12); //Centre of Area of Interest
var opacity  = 0.5;

//--Coastal waters shapefile
var vic_waters = ee.FeatureCollection('users/s3825806/Vic_Waters')

// Compute the intersection between vic_waters and area of interest
var vic_waters_aoi = aoi_polygon.intersection(vic_waters, ee.ErrorMargin(1));

//--Environmental layers
// ---Substrate

var Sub_1 = ee.FeatureCollection('users/s3825806/Substrate_vic_waters')
.filterBounds(vic_waters_aoi);

//filter to column/variable of interest
var Substrate_1 = Sub_1.filter(ee.Filter.eq('HAB3BIOTTL', 'High energy infralittoral rock'));
print(Substrate_1, 'HEIR')
//Map.addLayer(Substrate_1,{color:'yellow'}, 'Substrate1', 0);

// Make an image out of the HEIR attribute as requires an integer??
var HEIR = Substrate_1.map(function(feature){
  return feature.set('HighEnergyInfralittoralRock', 1);
});
print(HEIR, 'HEIR')
//Map.addLayer(HEIR,{color:'yellow'}, 'HEIR', 0);

///Vector to raster transformation?
var SubstrateImg = HEIR
  .filter(ee.Filter.notNull(['High energy infralittoral rock']))
  .reduceToImage({
    properties: ['High energy infralittoral rock'],
    reducer: ee.Reducer.first()
});
print(SubstrateImg, 'SubstrateImg')
Map.addLayer(SubstrateImg,{color:'yellow'}, 'Img', 0);

2 Answers 2

0

The problem is that there is no property named 'High energy infralittoral rock' in the HEIR object. Thus, you need to indicate a valid name when filtering the collection, as well, as to convert the vector into an image. I am asumming that the property you are interested in, is the one you added to the Feature Collection: 'HighEnergyInfralittoralRock'.

var SubstrateImg = HEIR
  .filter(ee.Filter.notNull(['HighEnergyInfralittoralRock']))
  .reduceToImage({
    properties: ['HighEnergyInfralittoralRock'],
    reducer: ee.Reducer.first()
});
1
  • Thank you @Jonathon. Yes I am trying to add a band to my environmental predictor layer with just the high energy infralittoral rock in it, since this is a predictor of where a macroalgae grows. I have fixed the error and added to the answer. Much appreciated.
    – Jcd
    Apr 12, 2023 at 22:46
0

Thanks to @Jonathon I figured out the issue. I just needed to change a variable name in the last section and it works. Adding the working code here so it can help someone else in future, hopefully.

//Import data
//-- Area Of Interest Polygon
var aoi_polygon = ee.Geometry.Polygon([[142.8169776552576,-38.660150171229965], 
[143.0586768740076,-38.660150171229965],
[143.0586768740076,-38.57323675496147],
[142.8169776552576,-38.57323675496147],
[142.8169776552576,-38.660150171229965]]);

// --Specify location
var geo = ee.Geometry.Point([142.99126680969238,-38.62060224055215])
Map.setCenter(142.99126680969238,-38.62060224055215, 12); //Centre of Area of Interest
var opacity  = 0.5;

//--Coastal waters shapefile
var vic_waters = ee.FeatureCollection('users/s3825806/Vic_Waters')

// Compute the intersection between vic_waters and area of interest
var vic_waters_aoi = aoi_polygon.intersection(vic_waters, ee.ErrorMargin(1));

//--Environmental layers
// ---Substrate

var Sub_1 = ee.FeatureCollection('users/s3825806/Substrate_vic_waters')
.filterBounds(vic_waters_aoi);

//filter to column/variable of interest
var Substrate_1 = Sub_1.filter(ee.Filter.eq('HAB3BIOTTL', 'High energy infralittoral rock'));
print(Substrate_1, 'HEIR')
//Map.addLayer(Substrate_1,{color:'yellow'}, 'Substrate1', 0);

// Make an image out of the land area attribute as requires an integer??
var HEIR = Substrate_1.map(function(feature){
  return feature.set('HAB3BIOTTL', 1);
});
print(HEIR, 'HEIR')
//Map.addLayer(HEIR,{color:'yellow'}, 'HEIR', 0);

///Vector to raster transformation?
var SubstrateImg = HEIR
  .filter(ee.Filter.notNull(['HAB3BIOTTL']))
  .reduceToImage({
    properties: ['HAB3BIOTTL'],
    reducer: ee.Reducer.first()
});
print(SubstrateImg, 'SubstrateImg')
Map.addLayer(SubstrateImg, {
  min: 3e8,
  max: 1.5e10,
  palette: ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C'] 
}, 'SubstrateImg', false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.