Basic Tutorials¶
Basic python example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import json import requests # Set the root API url and the endpoint of your choice. # The list of endpoints is given under the "REST API" section. url = 'https://geodata.dri.edu/raster/mapid/values' # Add your token to the header (replace the <insert your api token> with your token. headers = {"Authorization": "<insert your api token>"} # Set your parameters params = { 'dataset': 'GRIDMET', 'variable': 'tmmx', 'temporal_statistic': 'mean', 'start_date': '2016-01-01', 'end_date': '2016-02-01' } # Make the call r = requests.get(url, params=params, headers=headers, verify=False) # Read the response print(json.dumps(r.json(), indent=2)) |
{
"mapid": "projects/earthengine-legacy/maps/63c8af524e2cca26fe476cae69b45775-3f43b995dd1e5edc151123e46d83f571",
"token": "",
"tile_fetcher": "https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/maps/63c8af524e2cca26fe476cae69b45775-3f43b995dd1e5edc151123e46d83f571/tiles/{z}/{x}/{y}",
"mapid": "63c8af524e2cca26fe476cae69b45775",
"access_token": "3f43b995dd1e5edc151123e46d83f571",
"colormap_options": {
"min": -5,
"max": 35,
"palette": [
"#2166ac",
"#4393c3",
"#92c5de",
"#d1e5f0",
"#fddbc7",
"#f4a582",
"#d6604d",
"#b2182b"
],
"opacity": 0.7,
"colorbar_ticks": [
-5.0,
0.0,
5.0,
10.0,
15.0,
20.0,
25.0,
30.0,
35.0
]
}
}
Downloading files from Google Bucket¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import requests root_url = 'https://storage.googleapis.com/' bucket_name = '<your bucket name>/' folder = '<folder if present>/' filename = '<your filename>' url = root_url + bucket_name + folder + filename def download_file(url): download_filename = url.split('/')[-1] with requests.get(url, stream=True) as r: r.raise_for_status() with open(download_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) return download_filename download_file(url) |
Testing your map id¶
Sample code and instructions are located at https://github.com/Google-Drought/MapidTestServer.
The readme page will step through setting up a node.js test server (instructions are for Mac OS) to display your newly created urls on your local machine. See example image for an idea of what it will look like.
