MCPcopy
hub / github.com/google/earthengine-api / createAsset

Function createAsset

python/ee/data.py:1460–1517  ·  view source on GitHub ↗

Creates an asset from a JSON value. To create an empty image collection or folder, pass in a "value" object with a "type" key whose value is "ImageCollection" or "Folder". If you are using the Cloud API, use "IMAGE_COLLECTION" or "FOLDER". Args: value: An object describing the asset to

(
    value: dict[str, Any],
    path: str | None = None,
    properties: dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

1458
1459@_utils.accept_opt_prefix('opt_path', 'opt_force', 'opt_properties')
1460def createAsset(
1461 value: dict[str, Any],
1462 path: str | None = None,
1463 properties: dict[str, Any] | None = None,
1464) -> dict[str, Any]:
1465 """Creates an asset from a JSON value.
1466
1467 To create an empty image collection or folder, pass in a "value" object
1468 with a "type" key whose value is "ImageCollection" or "Folder".
1469 If you are using the Cloud API, use "IMAGE_COLLECTION" or "FOLDER".
1470
1471 Args:
1472 value: An object describing the asset to create.
1473 path: An optional desired ID, including full path.
1474 properties: The keys and values of the properties to set on the created
1475 asset.
1476
1477 Returns:
1478 A description of the saved asset, including a generated ID.
1479 """
1480 if not isinstance(value, dict):
1481 raise ee_exception.EEException('Asset cannot be specified as string.')
1482 asset = value.copy()
1483 if 'name' not in asset:
1484 if not path:
1485 raise ee_exception.EEException(
1486 'Either asset name or path must be specified.'
1487 )
1488 asset['name'] = _cloud_api_utils.convert_asset_id_to_asset_name(path)
1489 if 'properties' not in asset and properties:
1490 asset['properties'] = properties
1491 # Make sure title and description are loaded in as properties.
1492 move_to_properties = ['title', 'description']
1493 for prop in move_to_properties:
1494 if prop in asset:
1495 if 'properties' not in asset or not isinstance(asset['properties'], dict):
1496 asset['properties'] = {prop: asset[prop]}
1497 else:
1498 properties = asset['properties'].copy()
1499 properties.setdefault(prop, asset[prop])
1500 asset['properties'] = properties
1501 del asset[prop]
1502 if 'gcs_location' in asset and 'cloud_storage_location' not in asset:
1503 asset['cloud_storage_location'] = asset['gcs_location']
1504 del asset['gcs_location']
1505 asset['type'] = _cloud_api_utils.convert_asset_type_for_create_asset(
1506 asset['type'])
1507 parent, asset_id = _cloud_api_utils.split_asset_name(asset.pop('name'))
1508 return _execute_cloud_call(
1509 _get_cloud_projects()
1510 .assets()
1511 .create(
1512 parent=parent,
1513 assetId=asset_id,
1514 body=asset,
1515 prettyPrint=False,
1516 )
1517 )

Callers 3

createFolderFunction · 0.85
createAssetHomeFunction · 0.85
create_assetsFunction · 0.85

Calls 4

_execute_cloud_callFunction · 0.85
_get_cloud_projectsFunction · 0.85
assetsMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected