# Path: geetools/tools/geometry.py
# def getRegion(eeobject, bounds=False, error=1):
#     """ Gets the region of a given geometry to use in exporting tasks. The
#     argument can be a Geometry, Feature or Image
# 
#     :param eeobject: geometry to get region of
#     :type eeobject: ee.Feature, ee.Geometry, ee.Image
#     :param error: error parameter of ee.Element.geometry
#     :return: region coordinates ready to use in a client-side EE function
#     :rtype: json
#     """
#     def dispatch(geometry):
#         info = geometry.getInfo()
#         geomtype = info['type']
#         if geomtype == 'GeometryCollection':
#             geometries = info['geometries']
#             region = []
#             for geom in geometries:
#                 this_type = geom['type']
#                 if this_type in ['Polygon', 'Rectangle']:
#                     region.append(geom['coordinates'][0])
#                 elif this_type in ['MultiPolygon']:
#                     geometries2 = geom['coordinates']
#                     region.append(unpack(geometries2))
# 
#         elif geomtype == 'MultiPolygon':
#             subregion = info['coordinates']
#             region = unpack(subregion)
#         else:
#             region = info['coordinates']
# 
#         return region
# 
#     # Geometry
#     if isinstance(eeobject, ee.Geometry):
#         geometry = eeobject.bounds() if bounds else eeobject
#         region = dispatch(geometry)
#     # Feature and Image
#     elif isinstance(eeobject, (ee.Feature, ee.Image)):
#         geometry = eeobject.geometry(error).bounds() if bounds else eeobject.geometry(error)
#         region = dispatch(geometry)
#     # FeatureCollection and ImageCollection
#     elif isinstance(eeobject, (ee.FeatureCollection, ee.ImageCollection)):
#         if bounds:
#             geometry = eeobject.geometry(error).bounds()
#         else:
#             geometry = eeobject.geometry(error).dissolve()
#         region = dispatch(geometry)
#     # List
#     elif isinstance(eeobject, list):
#         condition = all([type(item) == list for item in eeobject])
#         if condition:
#             region = eeobject
#     else:
#         region = eeobject
# 
#     return region


import ee
from geetools.tools.geometry import getRegion
# coding=utf-8

ee.Initialize()

l8SR = ee.Image("LANDSAT/LC8_SR/LC82310772014043")

p_l8SR_cloud = ee.Geometry.Point([-65.8109, -25.0185])
p_l8SR_no_cloud = ee.Geometry.Point([-66.0306, -24.9338])

list1 = ee.List([1, 2, 3, 4, 5])
list2 = ee.List([4, 5, 6, 7])


def test_getRegion():
    expected = [[0.0,0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]
    pol = ee.Geometry.Polygon(expected)
    feat = ee.Feature(pol)

    region_geom = getRegion(pol)

# Path: geetools/tools/geometry.py
# def getRegion(eeobject, bounds=False, error=1):
#     """ Gets the region of a given geometry to use in exporting tasks. The
#     argument can be a Geometry, Feature or Image
# 
#     :param eeobject: geometry to get region of
#     :type eeobject: ee.Feature, ee.Geometry, ee.Image
#     :param error: error parameter of ee.Element.geometry
#     :return: region coordinates ready to use in a client-side EE function
#     :rtype: json
#     """
#     def dispatch(geometry):
#         info = geometry.getInfo()
#         geomtype = info['type']
#         if geomtype == 'GeometryCollection':
#             geometries = info['geometries']
#             region = []
#             for geom in geometries:
#                 this_type = geom['type']
#                 if this_type in ['Polygon', 'Rectangle']:
#                     region.append(geom['coordinates'][0])
#                 elif this_type in ['MultiPolygon']:
#                     geometries2 = geom['coordinates']
#                     region.append(unpack(geometries2))
# 
#         elif geomtype == 'MultiPolygon':
#             subregion = info['coordinates']
#             region = unpack(subregion)
#         else:
#             region = info['coordinates']
# 
#         return region
# 
#     # Geometry
#     if isinstance(eeobject, ee.Geometry):
#         geometry = eeobject.bounds() if bounds else eeobject
#         region = dispatch(geometry)
#     # Feature and Image
#     elif isinstance(eeobject, (ee.Feature, ee.Image)):
#         geometry = eeobject.geometry(error).bounds() if bounds else eeobject.geometry(error)
#         region = dispatch(geometry)
#     # FeatureCollection and ImageCollection
#     elif isinstance(eeobject, (ee.FeatureCollection, ee.ImageCollection)):
#         if bounds:
#             geometry = eeobject.geometry(error).bounds()
#         else:
#             geometry = eeobject.geometry(error).dissolve()
#         region = dispatch(geometry)
#     # List
#     elif isinstance(eeobject, list):
#         condition = all([type(item) == list for item in eeobject])
#         if condition:
#             region = eeobject
#     else:
#         region = eeobject
# 
#     return region


# Path: tests/test_geometry.py
import ee
from geetools.tools.geometry import getRegion

# coding=utf-8

ee.Initialize()

l8SR = ee.Image("LANDSAT/LC8_SR/LC82310772014043")

p_l8SR_cloud = ee.Geometry.Point([-65.8109, -25.0185])
p_l8SR_no_cloud = ee.Geometry.Point([-66.0306, -24.9338])

list1 = ee.List([1, 2, 3, 4, 5])
list2 = ee.List([4, 5, 6, 7])


def test_getRegion():
    expected = [[0.0,0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]
    pol = ee.Geometry.Polygon(expected)
    feat = ee.Feature(pol)

    region_geom = getRegion(pol)

    region_feat = getRegion(feat)