@@ -1908,9 +1908,62 @@ def _prepare_and_run_export(
1908
1908
export_endpoint (project = _get_projects_path (), body = params ),
1909
1909
num_retries = num_retries )
1910
1910
1911
+ # TODO(user): use StrEnum when 3.11 is the min version
1912
+ _INTERNAL_IMPORT = 'INTERNAL_IMPORT'
1913
+ _EXTERNAL_IMPORT = 'EXTERNAL_IMPORT'
1914
+
1915
+
1916
+ def _startIngestion (
1917
+ request_id : Any ,
1918
+ params : Dict [str , Any ],
1919
+ allow_overwrite : bool = False ,
1920
+ import_mode : Optional [str ] = _INTERNAL_IMPORT ,
1921
+ ) -> Dict [str , Any ]:
1922
+ """Starts an ingestion task or creates an external image."""
1923
+ request = {
1924
+ 'imageManifest' :
1925
+ _cloud_api_utils .convert_params_to_image_manifest (params ),
1926
+ 'overwrite' :
1927
+ allow_overwrite
1928
+ }
1929
+
1930
+ # It's only safe to retry the request if there's a unique ID to make it
1931
+ # idempotent.
1932
+ num_retries = _max_retries if request_id else 0
1933
+
1934
+ image = _get_cloud_projects ().image ()
1935
+ if import_mode == _INTERNAL_IMPORT :
1936
+ import_request = image .import_ (project = _get_projects_path (), body = request )
1937
+ elif import_mode == _EXTERNAL_IMPORT :
1938
+ import_request = image .importExternal (
1939
+ project = _get_projects_path (), body = request
1940
+ )
1941
+ else :
1942
+ raise ee_exception .EEException (
1943
+ '{} is not a valid import mode' .format (import_mode )
1944
+ )
1945
+
1946
+ result = _execute_cloud_call (
1947
+ import_request ,
1948
+ num_retries = num_retries ,
1949
+ )
1950
+
1951
+ if import_mode == _INTERNAL_IMPORT :
1952
+ return {
1953
+ 'id' : _cloud_api_utils .convert_operation_name_to_task_id (
1954
+ result ['name' ]
1955
+ ),
1956
+ 'name' : result ['name' ],
1957
+ 'started' : 'OK' ,
1958
+ }
1959
+ else :
1960
+ return {'name' : request ['imageManifest' ]['name' ]}
1961
+
1911
1962
1912
1963
def startIngestion (
1913
- request_id : Any , params : Dict [str , Any ], allow_overwrite : bool = False
1964
+ request_id : Any ,
1965
+ params : Dict [str , Any ],
1966
+ allow_overwrite : bool = False ,
1914
1967
) -> Dict [str , Any ]:
1915
1968
"""Creates an image asset import task.
1916
1969
@@ -1923,7 +1976,7 @@ def startIngestion(
1923
1976
params: The object that describes the import task, which can
1924
1977
have these fields:
1925
1978
name (string) The destination asset id (e.g.,
1926
- "projects/earthengine-legacy /assets/users /foo/bar").
1979
+ "projects/myproject /assets/foo/bar").
1927
1980
tilesets (array) A list of Google Cloud Storage source file paths
1928
1981
formatted like:
1929
1982
[{'sources': [
@@ -1942,31 +1995,39 @@ def startIngestion(
1942
1995
A dict with notes about the created task. This will include the ID for the
1943
1996
import task (under 'id'), which may be different from request_id.
1944
1997
"""
1945
- request = {
1946
- 'imageManifest' :
1947
- _cloud_api_utils .convert_params_to_image_manifest (params ),
1948
- 'requestId' :
1949
- request_id ,
1950
- 'overwrite' :
1951
- allow_overwrite
1952
- }
1998
+ return _startIngestion (request_id , params , allow_overwrite , _INTERNAL_IMPORT )
1953
1999
1954
- # It's only safe to retry the request if there's a unique ID to make it
1955
- # idempotent.
1956
- num_retries = _max_retries if request_id else 0
1957
- operation = _execute_cloud_call (
1958
- _get_cloud_projects ()
1959
- .image ()
1960
- .import_ (project = _get_projects_path (), body = request ),
1961
- num_retries = num_retries ,
1962
- )
1963
- return {
1964
- 'id' :
1965
- _cloud_api_utils .convert_operation_name_to_task_id (
1966
- operation ['name' ]),
1967
- 'name' : operation ['name' ],
1968
- 'started' : 'OK' ,
1969
- }
2000
+
2001
+ def startExternalImageIngestion (
2002
+ image_manifest : Dict [str , Any ],
2003
+ allow_overwrite : bool = False ,
2004
+ ) -> Dict [str , Any ]:
2005
+ """Creates an external image.
2006
+
2007
+ Args:
2008
+ image_manifest: The object that describes the import task, which can
2009
+ have these fields:
2010
+ name (string) The destination asset id (e.g.,
2011
+ "projects/myproject/assets/foo/bar").
2012
+ tilesets (array) A list of Google Cloud Storage source file paths
2013
+ formatted like:
2014
+ [{'sources': [
2015
+ {'uris': ['foo.tif', 'foo.prj']},
2016
+ {'uris': ['bar.tif', 'bar.prj']},
2017
+ ]}]
2018
+ Where path values correspond to source files' Google Cloud Storage
2019
+ object names, e.g., 'gs://bucketname/filename.tif'
2020
+ bands (array) An optional list of band names formatted like:
2021
+ [{'id': 'R'}, {'id': 'G'}, {'id': 'B'}]
2022
+ In general, this is a dict representation of an ImageManifest.
2023
+ allow_overwrite: Whether the ingested image can overwrite an
2024
+ existing version.
2025
+
2026
+ Returns:
2027
+ The name of the created asset.
2028
+ """
2029
+ return _startIngestion (
2030
+ 'unused' , image_manifest , allow_overwrite , _EXTERNAL_IMPORT )
1970
2031
1971
2032
1972
2033
def startTableIngestion (
@@ -1983,7 +2044,7 @@ def startTableIngestion(
1983
2044
params: The object that describes the import task, which can
1984
2045
have these fields:
1985
2046
name (string) The destination asset id (e.g.,
1986
- "projects/earthengine-legacy /assets/users /foo/bar").
2047
+ "projects/myproject /assets/foo/bar").
1987
2048
sources (array) A list of GCS (Google Cloud Storage) file paths
1988
2049
with optional character encoding formatted like this:
1989
2050
"sources":[{"uris":["gs://bucket/file.shp"],"charset":"UTF-8"}]
0 commit comments