0

I have two image colelctions. one of sentinel 1 and one of sentinel 2. I want to reproject the sentinel 1 so its' projection and cell size would be like the sentunel 2 images. It worked for me when I did it without function on only one image, but now when I have ttried to create a function for this, when I check the results I see that the pixels of the two polygons do not sit on top of each other, e.g seems like the reprojection didn't work.

This is my function:

////Fix reproject SAR 1////

var SARresample=Clipped_Speckles.map(function(im){
  var sar1Projection =  im.projection();
  var NDVIProjection =  ee.Image(listOfImages.get(listOfNumbers[0])).projection();
  var SARreproject=im.reduceResolution({reducer: ee.Reducer.mean()}).reproject({crs: NDVIProjection});

   return im;
});

after the function. I have tried to display two images in order to see the pixels but it seems like the function didn't function:

//Visualize the resample vs NDVI 

var listOfIResamples =(SARresample.toList(SARresample.size()));

var NumberOfImagesSAR=[0];

var ResampledIM= ee.Image(listOfIResamples.get(NumberOfImagesSAR[0]));

Map.addLayer(ResampledIM,{bands: 'VH_Filtered',min: -30, max: 1},'SAR');


//visualize NDVI

var listOfImagesNDVI =(filterNDVI.toList(filterNDVI.size()));

var NumberOfImagesNDVI=[0,1,2];

var ndviIM= ee.Image(listOfImagesNDVI.get(NumberOfImagesNDVI[1]));

Map.addLayer(ndviIM, NDVIcolor,'NDVI');


Here you can see the full code:

https://code.earthengine.google.com/0b322b779162bc1eb18a6143867d1a99

*I have changed the speckle filter size to 2 for it to be easier to see the pixels.

*the polygon is in north of Thailand , cannot share it but any random polygon in that area will work.

1 Answer 1

1

Calling projection() on an ee.Image object returns an ee.Projection object. In your function you are providing the projection object to the crs parameter of the reproject() image method. Use .crs() on the projection object to retrieve its CRS:

.reproject({crs: NDVIProjection.crs()});

I would also probably define the scale parameter as well:

NDVIProjection.nominalScale()

Note, however, that using reproject() is not good practice. If you want data to be in the same projection, all region reducing and export functions allow you to specify it - which is where you should be doing it, instead of with reproject().

Please see Reprojecting and the "Caution" section of Object-based methods for more information.

0

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.