Created
September 13, 2019 14:23
-
-
Save notthatbreezy/a3fc487b6f946a0b68f82ec269d7fc5c to your computer and use it in GitHub Desktop.
Creates a COG scene with minimal metadata and adds it to a project for visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def get_session(refresh_token): | |
"""Helper method to create a requests Session""" | |
post_body = {'refresh_token': refresh_token} | |
response = requests.post('https://app.rasterfoundry.com/api/tokens/', json=post_body) | |
response.raise_for_status() | |
token = response.json()['id_token'] | |
session = requests.Session() | |
session.headers.update({'Authorization': 'Bearer {}'.format(token)}) | |
return session | |
def create_scene_add_to_project(session, s3_path, name, project_id): | |
"""Creates a scene from a known S3 path and adds it to a given project | |
:param session: requests session object | |
:param s3_path: S3 path in form of s3://<bucket>/<key> | |
:param name: Human readable name for scene | |
:param project_id: ID of project to add created scene to | |
:return: | |
""" | |
scene = { | |
"visibility": "PRIVATE", # visible only to you or users you grant access | |
"tags": [], # searchable tags from the API | |
"datasource": "c6ab22da-f4c6-4775-8392-71265eac7e9a", # datasource representing 3 bands | |
"sceneMetadata": {}, # can add additional metadata if desired | |
"name": name, | |
"metadataFiles": [], | |
"images": [], | |
"thumbnails": [], | |
"ingestLocation": s3_path, | |
"statusFields": { | |
"thumbnailStatus": "SUCCESS", | |
"boundaryStatus": "SUCCESS", | |
"ingestStatus": "INGESTED" | |
}, | |
"filterFields": {}, | |
"sceneType": "COG" | |
} | |
scene_response = session.post('https://app.rasterfoundry.com/api/scenes/', json=scene) | |
scene_response.raise_for_status() | |
scene_id = scene_response.json()['id'] | |
project_url = 'https://app.rasterfoundry.com/api/projects/{}/scenes'.format(project_id) | |
# Add project to scene | |
project_response = session.post(project_url, json=[scene_id]) | |
project_response.raise_for_status() | |
if __name__ == '__main__': | |
requests_session = get_session("<refresh-token>") | |
s3_path = "<s3 path e.g. s3://<bucket>/path/to/tiff>" | |
create_scene_add_to_project(requests_session, s3_path, "<scene name>", "<project id>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment