6

I try to extract the centroid of an ee.Image, as follows:

ee.Initialize()
image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318')\
          .geometry()\
          .centroid()\
          .getInfo()
# {'coordinates': [-122.14451407746256, 37.47160285059076], 'type': 'Point'} #Ok!

However, when I apply the same idea in the next example, I get:

ee.Initialize()
collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')\
               .filter(ee.Filter.eq('WRS_PATH', 44))\
               .filter(ee.Filter.eq('WRS_ROW', 34))\
               .filterDate('2014-01-01', '2015-01-01')\
               .sort('CLOUD_COVER')
image = collection.median()
image.geometry().getInfo()
#{'coordinates': [[[-180.0, -90.0], [180.0, -90.0], [180.0, 90.0], [-180.0, 90.0], [-180.0, -90.0]]], 'type': 'Polygon'} #Bad

I was expecting to get the bounding for the WRS_PATH and WRS_PATH specified, not the world bounding. Does someone have an idea to achieve this?

TomazicM
  • 25,601
  • 22
  • 29
  • 39

1 Answers1

4

When you apply the mean, the collection is masked to the filtered path and row, therefore, the bounding box is still the whole collection. My suggestion is to get the first image or the image of your preference in the collection instead of getting the median. Also, bear in mind that the bounding box of the image selected is irregular and you will have more than four coordinates sets.


var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
               .filter(ee.Filter.eq('WRS_PATH', 44))
               .filter(ee.Filter.eq('WRS_ROW', 34))
               .filterDate('2014-01-01', '2015-01-01')
               .sort('CLOUD_COVER')
var image = collection.first()
print (image)
Map.addLayer(image)
var geom = collection.geometry().getInfo()
var imggeom = image.geometry().getInfo()
print(imggeom, 'img')
OscarBau
  • 700
  • 3
  • 18