2

I have three images in GEE ,I would like to reproject two of them to have the dame reprojection as the third one.

each of those 3 images is mosaic of all the avilable tiles from certain day.

The problem is that when I try to reproject the two images I get error:

Image (Error) Image.reduceResolution: The input to reduceResolution does not have a valid default projection. Use reproject() first to set the base projection.

The thing is that I do reproject the images before. I have tried it in two different ways but still get the same error:

try 1:

//Reproject

//Get information about the  projection.
//there are two images with this projection

var projection1 =  img_one.projection();
print('PROJECTION Image 1:',  projection1);

//the projection I want to reproject to 
var projection2 =  image_two.projection();
print('I want my previous images to have this projection:',  projection2);


// // //resampling images to "projection 2" 

var prj_one=img_vv.reproject({crs: projection2});
var prj_one=img_vv.reduceResolution({reducer: ee.Reducer.mean()});
var prj_three=img_vh.reproject({crs: projection2});
var prj_three=img_vh.reduceResolution({reducer: ee.Reducer.mean()});

try 2 (less lines):


var prj_one=img_vv.reduceResolution({reducer: ee.Reducer.mean()}).reproject({crs: projection2});

var prj_three=img_vh.reduceResolution({reducer: ee.Reducer.mean()}).reproject({crs: projection2});

but still got the same error.

The weird thing is that when I don't mosaic the images from imagecollection I don't get this error at all.

Here is link for the code:

https://code.earthengine.google.com/d5ba407afff4ed384ad9d1cfbf89ee6c

My end goal : to be able to reproject the layers and export as one raster with three bands that have the same projection

edit: if instead of using mosaic to create my image I use "first()" I get the image but it doesnt help me because then I don't get the full image.

3

You were almost there.

There were 3 mistakes in your code:

  1. reduceResolution() needs a coordinate reference system (crs) of the input image so that it understands the resolution of the input image (and thus can reduce that resolution). Generally this is done implicitly because each image has its own crs. However, when you take a mosaic the crs defaults to WGS 1984 at 1 degree resolution (full details here under section default projection). Since this is a default projection (and not explicitly set by the user), .reduceResolution() throws an error to remind the user that they may be reducing the resolution over an unintended default projection. To correct this reproject the mosaic to a valid projection. So instead of using:
var projection2 =  image_one.projection();
print('sentinel2 projection:',  projection2);

Use:

var projection3 =  ee.Image(VV_speckle.first()).projection();
print('non-mosaiced projection:',  projection3);
  1. The .reduceResolution() needs a reprojected image as input and not output. So apply the reprojection before the .reduceResolution(). So instead of using:
var prj_vv=img_vv.reduceResolution({reducer: ee.Reducer.mean()}).reproject({crs: projection3});

Use:

var prj_vv=img_vv.reproject({crs: projection3}).reduceResolution({reducer: ee.Reducer.mean()});
  1. Finally, there was unrelated error in your code after applying the reprojection the right away. You were trying to rename your stacked image with 6 bands using only 3 band names. So instead of using:
var pairedImage =  ee.ImageCollection.fromImages([image_one,prj_vv,prj_vh]).toBands().rename(['RGB','VV','VH']);

Use:

var pairedImage =  ee.ImageCollection.fromImages([image_one,prj_vv,prj_vh]).toBands().rename(["B2","B3","B4","QA60",'VV','VH']);

With that, all bugs are resolved. Link to corrected code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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