If you export by specifying a scale for Landsat images, you are explicitly
overriding the non-integer affine transform with an integer one, and introducing a 1/2 pixel shift.
You may want to try Exporting with the original image.projection()
instead of creating a new one from scratch.
This problem is caused through your reduction on the line with:
var to_export = image.mean().select(['NDVI']);
Compositions and reductions have no projection and are just reported as being WGS84.
This script exports the map without the vertical lines (https://code.earthengine.google.com/0de29cd6954bada783ef0bacbb5b1ba6):
var region = ee.FeatureCollection('ft:1A9vRY9l-eBNBFBwAV_mLAEeCIPYS2T14vsKhiEQc');
var crop = region.geometry();
function mask_image(image){
return image.updateMask(image.select('pixel_qa').bitwiseAnd(ee.Image.constant(2)).eq(2));
}
function ndvi(image){
return image.addBands(image.normalizedDifference(['B5','B4']).rename('NDVI'));
}
var start = ee.Date('2013-01-01');
var end = ee.Date('2017-12-31');
var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate(start,end)
.filterBounds(crop)
.map(mask_image)
.map(ndvi);
var original_proj = image.first().projection();
print(original_proj.crs());
print(image.first().projection().nominalScale());
var to_export = image.mean().select(['NDVI']);
print(to_export.projection().crs());
print(to_export.projection().nominalScale());
to_export = to_export.reproject(original_proj);
Export.image.toDrive({
image: to_export,
description: 'NDVI-test',
folder:'Landsat8-NDVI',
scale: to_export.projection().nominalScale().getInfo(),
region: crop,
maxPixels: 1e10,
crs: 'EPSG: 32718'
});
It prints the crs and scale of an image in the image-collection called 'image' and does the same from the image called 'to_export' which is created by taking the mean of the images in 'image'.
You can see that initially, the crs is EPSG:32619 with a scale of 30 meters. After the mean-reduction, the crs of 'to_export' is EPSG:4326 with a scale of 111319.49079327357 meters. So we need to add one more line to your code, before proceeding to the export, i.e. 'to_export.reproject(original_proj);'.
Now the projection is correct again and your export doesn't contain the vertical lines.
Best Answer
I'm not sure why GEE adds a black border to exported images, I think it's something to do with the re-orienting the image to the new projection system and cannot be changed. This isn't an issue if you're exporting a satellite image raster, as it sets the border pixel values to class 0 and this doesn't interfere with the pixels in the rest of the image.
It's a bit of a pain when exporting a classified image that contains useful pixels that are classified as zero as this messes with the analysis. Anyway, I managed to figure it out with a simple .remap code. I just reassigned the values from class 0 onwards to the integer above, thus leaving class 0 free for noData pixels. Here is the code: