1

enter image description here

The Google Earth Engine JavaScript API is throwing me an error (ndti_Before.intersection is not a function).

How could I solve or fix my code to get an intersected image?

I'm trying to get an intersected image.

For reference use the below image.

// Before lockdown 

var filtered_before = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',10))
                        .filter(ee.Filter.date('2020-03-09','2020-03-10'))
                        .filter(ee.Filter.bounds(geometry));
print(filtered_before);

var composite = filtered_before.median();
print(composite);

// creating visualization rbg of select area

var rgbvis_Before = {min:0.0, max:3000, bands:['B4', 'B3', 'B2']};
Map.addLayer(composite.clip(geometry), rgbvis_Before, 'FCC');

// Calculating NDWI before lockdown 
// GREEN = B3 and NIR = B8

function addndwi(image){
var ndwi_Before = image.normalizedDifference(['B3','B8']).rename('ndwi_Before');
return image.addBands(ndwi_Before);
}

//creating map or visual for ndwi

var withNDWI = filtered_before.map(addndwi);
print(withNDWI);

var composite_withNDWI = withNDWI.median();

var NDWIcomposite = composite_withNDWI.select('ndwi_Before').clip(geometry);

var ndwivis = {min:0, max:1, palette:['00FFFF', '0000FF']};

Map.addLayer(NDWIcomposite, ndwivis, 'NDWI_BEFORE');

// Creating the binary image for water and non water pixels 

var vivis_Binary_image_before = {min:0.03, max:1, palette:['black', 'white']};
Map.addLayer(NDWIcomposite.clip(geometry), vivis_Binary_image_before, 'Before Binary Image');

// Creating Water mask of the image and water values = 1

var water_mask_before = function(image) {
                              var NDWI = image.select(['NDWI']);
                              return image.updateMask(NDWI.eq(1));
};

var vivis_water_mask_before = {min:0.0, max:1, palette:['white', 'blue']};
Map.addLayer(NDWIcomposite.clip(geometry), vivis_water_mask_before, 'Before Water mask');


// Calculating NDTI for the clipped area Before lockdown
// RED = B3 and GREEN = B4

function addndti(image){
var ndti_Before = image.normalizedDifference(['B4','B3']).rename('ndti_Before');
return image.addBands(ndti_Before);
}

// for better visualization parameters we will use Stretch:100% for NDTI 

var withNDTI = filtered_before.map(addndti);
print(withNDTI);

var composite_withNDTI = withNDTI.median();

var NDTIcomposite = composite_withNDTI.select('ndti_Before').clip(geometry);

var ndtivis = {min:0, max:1, palette:['black', 'white']};

Map.addLayer(NDTIcomposite, ndtivis, 'NDTI_BEFORE');

**// This where I'm getting stuck**
// Intersecting 
// input= NDTI and input geometry = Water mask image

var ndti_clip_Before = Polygon.intersection(water_mask_before,NDTIcomposite, null, null);

Map.addLayer(ndti_clip_Before,'NDTI CLIP' );

1 Answer 1

0

The error already hints at your problem. You are applying a intersect function that requires 2 inputs of type geometry. My guess is that the following line should be changed:

Polygon.intersection(water_mask_before,NDTIcomposite, null, null);

water_mask_before is a function and not a geometry so you probably want to get the geometry of what the water_mask_before function generates as output. That will be an image and might require you convert the mask to an geometry by using reduceToVectors().

Also check your inputs, you are now providing 5 inputs where it only requires 4.

If you provide a working example that reproduces your error it is a lot easier to help you out and provide some detailed suggestions

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.