0

I am trying to display a ROI (region of interest) on the GEE map. I am getting pretty odd outputs like this:

enter image description here

Code that generated this image is down below:

var geometry = /* color: #d63000 */ee.Geometry.Polygon(
    [[[-74.17301042227143, 41.01676815108097],
      [-75.15079362539643, 40.93797200093739],
      [-74.50260026602143, 40.3084072747414],
      [-73.63468034414643, 40.559275861105796]]]);

var landsat = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")

Map.centerObject(geometry)

var area = ee.FeatureCollection(geometry);

var image = ee.Image((landsat)
    .filterBounds(area)
    .filterDate('2018-01-01', '2018-12-31')
    .select(['B[1-7]'])
    .sort('CLOUD_COVER')
    .first());
var filteredimage = image
//.clip(area)
Map.addLayer(filteredimage, {bands: ['B4', 'B3', 'B2'], max: 0.5, gamma: 2}, 'Better L8 Image');

If I uncomment the .clip(area) line, I get only the intersection of these two chunks. But what I want is to show only the red section. And show all of it. From what I understand is the these square pictures are the raw pictures of the satellite. But how can I crop an image out of two or more different satellite images?

1 Answer 1

0

By using .first(), you are asking for only the first (here, least cloudy) image from the LANDSAT/LC08/C01/T1_TOA that matches your other filters. Generally, when you want images from an area, you should use an operator like .mosaic() (prefer the last available image, but on a pixel-by-pixel basis — useful when sorted by date) or .median() (take the median of all images).

Map.centerObject(geometry);

var image = ee.Image((landsat)
    .filterBounds(geometry)
    .filterDate('2018-01-01', '2018-12-31')
    .sort('CLOUD_COVER')
    .median());
var filteredimage = image.clip(geometry);
Map.addLayer(filteredimage, {bands: ['B4', 'B3', 'B2'], max: 0.5, gamma: 2}, 'Better L8 Image');

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

I've also simplified your code a couple of ways:

  • There is no need for var area = ee.FeatureCollection(geometry); — none of what you're doing requires a collection.
  • There is no need for .select(['B[1-7]']) — the band selection you are doing in addLayer suffices to control which pixels get computed, so the .select() is redundant.
2
  • Thank you for the answer, but i still want to ask this. I want to make a timelapse about vegetation change throughout the years. It will include about 300 satellite images. If i keep the band selection option (Red Green Blue NIR) will my code be faster?
    – osbm
    Commented Aug 30, 2021 at 11:06
  • @user9279225 I am not sure whether it will make any difference at all, but certainly not a large one.
    – Kevin Reid
    Commented Aug 30, 2021 at 13:52

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.