getRegion(eeObject, bounds)

Get the region for functions that need it as an argument (like Export.image)

params

  • eeObject: any eeObject that has a geometry
  • bounds: return only bounds (rectangle). Defaults to False

In [1]:
import ee
ee.Initialize()

In [2]:
from geetools import tools

Bounded Images


In [3]:
image = ee.Image(ee.ImageCollection('COPERNICUS/S2').first())

In [4]:
tools.geometry.getRegion(image)


Out[4]:
[[[2.0823420055272694, 28.022371475142155],
  [2.082262387713162, 28.022460994622374],
  [1.7870267921380452, 28.020172100522007],
  [1.7863863638768989, 28.019300827799174],
  [1.7840385788154567, 28.010599213518702],
  [1.7583696085580722, 27.9074708061136],
  [1.7138484027983951, 27.72807167221268],
  [1.711234871844144, 27.71720577206124],
  [1.7112611391967587, 27.714974277442444],
  [1.7119348947961275, 27.714682202980047],
  [1.7139838289586986, 27.71406533734163],
  [1.7676420145675962, 27.705345166014425],
  [1.9106692751128727, 27.682352691622302],
  [1.9653060360042989, 27.67356410080027],
  [1.970992862852016, 27.67270366436133],
  [1.9756637522563858, 27.672015966240707],
  [2.0845963559712533, 27.656438224472712],
  [2.0853071966042025, 27.65644288605324],
  [2.085405603161776, 27.657703616668854],
  [2.0823420055272694, 28.022371475142155]]]

Unbounded Images


In [5]:
uimage = ee.Image.constant(0)

In [6]:
tools.geometry.getRegion(uimage)


Out[6]:
[[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]]

Geometry


In [7]:
pol = ee.Geometry.Polygon([[0,0], [10,10], [20,0], [0, 0]])

In [8]:
tools.geometry.getRegion(pol)


Out[8]:
[[[0, 0], [20, 0], [10, 10], [0, 0]]]

In [9]:
tools.geometry.getRegion(pol, True)


Out[9]:
[[[0, -4.4794226470436166e-14],
  [20, -4.4794226470436166e-14],
  [20, 10.000000000000025],
  [0, 10.000000000000025],
  [0, -4.4794226470436166e-14]]]

Feature


In [10]:
feat = ee.Feature(pol, {'test':'getRegion'})

In [11]:
tools.geometry.getRegion(feat)


Out[11]:
[[[0, 0], [20, 0], [10, 10], [0, 0]]]

FeatureCollection


In [12]:
fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filterMetadata('wld_rgn', 'equals', 'South America')

In [13]:
tools.geometry.getRegion(fc, True)


Out[13]:
[[[-109.45547482907725, -55.915443407767505],
  [-28.842971814946278, -55.915443407767505],
  [-28.842971814946278, 13.387999563952137],
  [-109.45547482907725, 13.387999563952137],
  [-109.45547482907725, -55.915443407767505]]]

In [ ]: