From 43bb69134653e020330db9597e7a3abab54476c4 Mon Sep 17 00:00:00 2001 From: Gennadii Donchyts Date: Sat, 9 Nov 2024 19:30:13 +0100 Subject: [PATCH] add User Agent, remove empty ee.Initialize(), update ee.Initialize() in the README.md --- README.md | 2 +- __init__.py | 11 ++++++++++- ee_plugin.py | 5 ----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 228f3d6..7b8cd9d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ ee.Authenticate() ```python import ee from ee_plugin import Map -ee.Initialize() +ee.Initialize(project="") # Add Earth Engine dataset image = ee.Image('USGS/SRTMGL1_003') diff --git a/__init__.py b/__init__.py index 13b1479..4b0d758 100644 --- a/__init__.py +++ b/__init__.py @@ -3,6 +3,8 @@ import site import pkg_resources +__version__ = '0.0.7' + def add_ee_dependencies(): extra_libs_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'extlibs')) @@ -24,7 +26,14 @@ def classFactory(iface): # pylint: disable=invalid-name # load EE python dependencies add_ee_dependencies() - # authenticate and initialize EE + # set User Agent for all calls + import ee + user_agent = f'QGIS_EE/{__version__}' + if ee.data.getUserAgent() != user_agent: + ee.data.setUserAgent(user_agent) + + +# authenticate and initialize EE from . import ee_auth ee_auth.authenticate_and_set_project() diff --git a/ee_plugin.py b/ee_plugin.py index 47bfd0f..f9a43b8 100644 --- a/ee_plugin.py +++ b/ee_plugin.py @@ -162,11 +162,6 @@ def updateLayers(self): print('\nWARNING:\n Map layer saved with older version of EE plugin is detected, backward-compatibility for versions before 0.0.3 is not supported due to changes in EE library, please re-create EE layer by re-running the Python script\n') return - # needed to load EE objects saved in QGIS projects - # TODO: it does not work for init EE in a Google Cloud Project, see #150 - if not ee.data.is_initialized(): - ee.Initialize() - ee_object = ee.deserializer.fromJSON(ee_object) if ee_object_vis is not None: