Spatiotemporal clustering allows you to group photos based on temporal and spatial metadata.
Scenarios
Intelligent albums
Intelligent photo apps that support spatiotemporal clustering can automatically group travel photos and create photo albums and videos from photos. This way, you can have an intuitive and visualized view of your travel routes and destinations based on the time the photos were taken and geographical locations. For example, photos taken at each city are organized into a separate folder.
Prerequisites
A metadata index is created for your files based on your use scenario. For more information, see Create a metadata index.
Create a spatiotemporal clustering task
Call the CreateLocationDateClusteringTask operation to create a spatiotemporal clustering task. This task groups photos in the test-dataset dataset, which is part of the test-project project.
Sample request
{
"ProjectName": "test-project",
"DatasetName": "test-dataset",
"DateOptions": "{\"GapDays\":1, \"MinDays\":1, \"MaxDays\":99999}",
"LocationOptions": "{\"LocationDateClusterLevels\":[\"country\", \"province\"]}"
}Sample success response
{
"RequestId": "B121940C-9794-4EE3-8D6E-F8EC525F****",
"TaskId": "SpaceTimeClustering-9bab56e8-e596-421a-b1f5-9ad1ab87****",
"EventId": "9bab56e8****"
}Sample code
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint.
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
location_options = imm_20200930_models.CreateLocationDateClusteringTaskRequestLocationOptions(
# Specify the clustering granularity.
location_date_cluster_levels=[
'[\"country\", \"province\"]'
]
)
date_options = imm_20200930_models.CreateLocationDateClusteringTaskRequestDateOptions(
# Specify gap_days, min_days, and max_days.
gap_days=1,
min_days=1,
max_days=99999
)
create_location_date_clustering_task_request = imm_20200930_models.CreateLocationDateClusteringTaskRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset',
date_options=date_options,
location_options=location_options
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
client.create_location_date_clustering_task_with_options(create_location_date_clustering_task_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
location_options = imm_20200930_models.CreateLocationDateClusteringTaskRequestLocationOptions(
# Specify the clustering granularity.
location_date_cluster_levels=[
'[\"country\", \"province\"]'
]
)
date_options = imm_20200930_models.CreateLocationDateClusteringTaskRequestDateOptions(
# Specify gap_days, min_days, and max_days.
gap_days=1,
min_days=1,
max_days=99999
)
create_location_date_clustering_task_request = imm_20200930_models.CreateLocationDateClusteringTaskRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset',
date_options=date_options,
location_options=location_options
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
await client.create_location_date_clustering_task_with_options_async(create_location_date_clustering_task_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])Query spatiotemporal groups
Call the QueryLocationDateClusters operation to query photo groups in the test-dataset dataset, which is part of the test-project project.
Sample request
{
"ProjectName": "test-project",
"DatasetName": "test-dataset"
}Sample success response
{
"RequestId": "C1C63FA7-17E5-0DEC-BC39-6B0C935C****",
"NextToken": "",
"LocationDateClusters": [
{
"LocationDateClusterEndTime": "2022-05-02T23:59:59.999999999+08:00",
"Addresses": [
{
"Country": "Singapore",
"Province": "Singapore"
}
],
"LocationDateClusterLevel": "province",
"ObjectId": "location-date-cluster-25d7aa5e-eaf7-4d9c-b075-48ebef1f33b7",
"CreateTime": "2022-11-24T14:17:04.491860412+08:00",
"UpdateTime": "2022-11-24T14:17:04.49187357+08:00",
"LocationDateClusterStartTime": "2022-05-01T00:00:00+08:00"
},
{
"LocationDateClusterEndTime": "2022-05-02T23:59:59.999999999+08:00",
"Addresses": [
{
"Country": "Singapore"
}
],
"LocationDateClusterLevel": "country",
"ObjectId": "location-date-cluster-ba681ede-6db5-45f6-8bd5-3af73aa7c0cd",
"CreateTime": "2022-11-24T14:17:04.4918496+08:00",
"UpdateTime": "2022-11-24T14:17:04.491871707+08:00",
"LocationDateClusterStartTime": "2022-05-01T00:00:00+08:00"
},
{
"LocationDateClusterEndTime": "2022-06-03T23:59:59.999999999+08:00",
"Addresses": [
{
"Country": "United States"
}
],
"LocationDateClusterLevel": "country",
"ObjectId": "location-date-cluster-05826605-43fc-42da-b8aa-6d275cb6cce1",
"CreateTime": "2022-11-24T14:17:04.491827166+08:00",
"UpdateTime": "2022-11-24T14:17:04.491867758+08:00",
"LocationDateClusterStartTime": "2022-06-02T00:00:00+08:00"
},
{
"LocationDateClusterEndTime": "2022-06-03T23:59:59.999999999+08:00",
"Addresses": [
{
"Country": "United States",
"Province": "San Francisco"
}
],
"LocationDateClusterLevel": "province",
"ObjectId": "location-date-cluster-bf6447a7-2930-423d-bbfb-e47b3bf107a0",
"CreateTime": "2022-11-24T14:17:04.491842191+08:00",
"UpdateTime": "2022-11-24T14:17:04.491870213+08:00",
"LocationDateClusterStartTime": "2022-06-02T00:00:00+08:00"
}
]
}Sample code
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint.
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
query_location_date_clusters_request = imm_20200930_models.QueryLocationDateClustersRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset'
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
client.query_location_date_clusters_with_options(query_location_date_clusters_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
query_location_date_clusters_request = imm_20200930_models.QueryLocationDateClustersRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset'
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
await client.query_location_date_clusters_with_options_async(query_location_date_clusters_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Update information about a spatiotemporal group
Call the UpdateLocationDateCluster operation to update the Title, CustomId, and CustomLabels of a specified group in the test-dataset dataset of the test-project project.
Sample request
{
"ProjectName": "test-project",
"DatasetName": "test-dataset",
"ObjectId": "location-date-cluster-2d3e56eb-f34f-4be0-ae8a-536be5e7****",
"Title": "Moments of Joy",
"CustomId": "id1",
"CustomLabels": "{\"city\": \"San Francisco\"}"
}Sample success response
{
"RequestId": "180D6ABE-D9B9-086A-9D8F-22A727AE****"
}Sample code
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint.
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
custom_labels = {}
update_location_date_cluster_request = imm_20200930_models.UpdateLocationDateClusterRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset',
# Specify the group ID.
object_id='location-date-cluster-2d3e56eb-f34f-4be0-ae8a-536be5e7****',
# (Optional) Update the title of the group.
title='Moments of Joy,'
# (Optional) Update the custom ID of the group.
custom_id='id1',
# (Optional) Update the custom labels of the group.
custom_labels={"city": "San Francisco"}
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
client.update_location_date_cluster_with_options(update_location_date_cluster_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
custom_labels = {}
update_location_date_cluster_request = imm_20200930_models.UpdateLocationDateClusterRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset',
# Specify the group ID.
object_id='location-date-cluster-2d3e56eb-f34f-4be0-ae8a-536be5e7****',
# (Optional) Update the title of the group.
title='Moments of Joy,'
# (Optional) Update the custom ID of the group.
custom_id='id1',
# (Optional) Update the custom labels of the group.
custom_labels={"city": "San Francisco"}
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
await client.update_location_date_cluster_with_options_async(update_location_date_cluster_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Delete a spatiotemporal group
Call the DeleteLocationDateCluster operation to delete a specified group from the test-dataset dataset in the test-project project.
Sample request
{
"ProjectName": "test-project",
"DatasetName": "test-dataset",
"ObjectId": "location-date-cluster-516ecda1-088e-40ad-b25e-48ca967d****"
}Sample success response
{
"RequestId": "B121940C-9794-4EE3-8D6E-F8EC525F****"
}Sample code
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint.
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
delete_location_date_cluster_request = imm_20200930_models.DeleteLocationDateClusterRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset',
# Specify the group ID.
object_id='location-date-cluster-516ecda1-088e-40ad-b25e-48ca967d****'
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
client.delete_location_date_cluster_with_options(delete_location_date_cluster_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M.
# For security reasons, we recommend that you do not embed your AccessKey pair in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
delete_location_date_cluster_request = imm_20200930_models.DeleteLocationDateClusterRequest(
# Specify the name of the IMM project.
project_name='test-project',
# Specify the name of the dataset.
dataset_name='test-dataset',
# Specify the group ID.
object_id='location-date-cluster-516ecda1-088e-40ad-b25e-48ca967d****'
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
await client.delete_location_date_cluster_with_options_async(delete_location_date_cluster_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])