Python ee.Projection() Examples

The following are 5 code examples of ee.Projection(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ee , or try the search function .
Example #1
Source File: bap.py    From geebap with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, season, range=(0, 0), colgroup=None, scores=None,
                 masks=None, filters=None, target_collection=None, brdf=False,
                 harmonize=True, projection=None, **kwargs):
        self.range = range
        self.scores = scores
        self.masks = masks or ()
        self.filters = filters or ()
        self.season = season
        self.colgroup = colgroup
        self.brdf = brdf
        self.harmonize = harmonize
        self.projection = projection or ee.Projection('EPSG:3857')

        if target_collection is None:
            target_collection = collection.Landsat8SR()
        self.target_collection = target_collection

        self.score_name = kwargs.get('score_name', 'score')

        # Band names in case user needs different names
        self.bandname_col_id = kwargs.get('bandname_col_id', 'col_id')
        self.bandname_date = kwargs.get('bandname_date', 'date') 
Example #2
Source File: ee_test.py    From earthengine with MIT License 5 votes vote down vote up
def testDynamicConstructorCasting(self):
    """Test the behavior of casting with dynamic classes."""
    self.InitializeApi()
    result = ee.Geometry.Rectangle(1, 1, 2, 2).bounds(0, 'EPSG:4326')
    expected = (ee.Geometry.Polygon([[1, 2], [1, 1], [2, 1], [2, 2]])
                .bounds(ee.ErrorMargin(0), ee.Projection('EPSG:4326')))
    self.assertEquals(expected, result) 
Example #3
Source File: ee_test.py    From aqua-monitor with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testDynamicConstructorCasting(self):
    """Test the behavior of casting with dynamic classes."""
    self.InitializeApi()
    result = ee.Geometry.Rectangle(1, 1, 2, 2).bounds(0, 'EPSG:4326')
    expected = (ee.Geometry.Polygon([[1, 2], [1, 1], [2, 1], [2, 2]])
                .bounds(ee.ErrorMargin(0), ee.Projection('EPSG:4326')))
    self.assertEquals(expected, result) 
Example #4
Source File: Map.py    From qgis-earthengine-plugin with MIT License 5 votes vote down vote up
def centerObject(feature, zoom=None):
    """
        Centers the map view on a given object.

        https://developers.google.com/earth-engine/api_docs#map.centerobject

        Uses:
            >>> from ee_plugin import Map
            >>> Map.centerObject(feature)
    """


    feature = ee.Feature(feature)

    if not zoom:
        # make sure our geometry is in geo
        rect = feature.geometry().transform(ee.Projection('EPSG:4326'), 1)

        # get coordinates
        coords = rect.bounds().getInfo()['coordinates'][0]
        xmin = coords[0][0]
        ymin = coords[0][1]
        xmax = coords[2][0]
        ymax = coords[2][1]

        # construct QGIS geometry
        rect = QgsRectangle(xmin, ymin, xmax, ymax)

        # transform rect to a crs used by current project
        crs_src = QgsCoordinateReferenceSystem(4326)
        crs_dst = QgsCoordinateReferenceSystem(QgsProject.instance().crs())
        geo2proj = QgsCoordinateTransform(crs_src, crs_dst, QgsProject.instance())
        rect_proj = geo2proj.transform(rect)

        # center geometry
        iface.mapCanvas().zoomToFeatureExtent(rect_proj)
    else:
        # set map center to feature centroid at a specified zoom
        center = feature.geometry().centroid().coordinates().getInfo()
        setCenter(center[0], center[1], zoom) 
Example #5
Source File: featurecollection.py    From gee_tools with MIT License 4 votes vote down vote up
def fromGeoJSON(filename=None, data=None, crs=None):
    """ Create a list of Features from a GeoJSON file. Return a python tuple
    with ee.Feature inside. This is due to failing when attempting to create a
    FeatureCollection (Broken Pipe ERROR) out of the list. You can try creating
    it yourself casting the result of this function to a ee.List or using it
    directly as a FeatureCollection argument.

    :param filename: the name of the file to load
    :type filename: str
    :param crs: a coordinate reference system in EPSG format. If not specified
        it will try to get it from the geoJSON, and if not there it will rise
        an error
    :type: crs: str
    :return: a tuple of features.
    """
    if filename:
        with open(filename, 'r') as geoj:
            content = geoj.read()
            geodict = json.loads(content)
    else:
        geodict = data

    features = []
    # Get crs from GeoJSON
    if not crs:
        filecrs = geodict.get('crs')
        if filecrs:
            name = filecrs.get('properties').get('name')
            splitcrs = name.split(':')
            cleancrs = [part for part in splitcrs if part]
            try:
                if cleancrs[-1] == 'CRS84':
                    crs = 'EPSG:4326'
                elif cleancrs[-2] == 'EPSG':
                    crs = '{}:{}'.format(cleancrs[-2], cleancrs[-1])
                else:
                    raise ValueError('{} not recognized'.format(name))
            except IndexError:
                raise ValueError('{} not recognized'.format(name))
        else:
            crs = 'EPSG:4326'

    for n, feat in enumerate(geodict.get('features')):
        properties = feat.get('properties')
        geom = feat.get('geometry')
        ty = geom.get('type')
        coords = geom.get('coordinates')
        if ty == 'GeometryCollection':
            ee_geom = utils.GEOMETRY_TYPES.get(ty)(geom, opt_proj=crs)
        else:
            if ty == 'Polygon':
                coords = utils.removeZ(coords) if utils.hasZ(coords) else coords
            ee_geom = utils.GEOMETRY_TYPES.get(ty)(coords, proj=ee.Projection(crs))
        ee_feat = ee.feature.Feature(ee_geom, properties)
        features.append(ee_feat)

    return tuple(features)