-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmuk_machine_learning_helpers.py
51 lines (31 loc) · 1.33 KB
/
dmuk_machine_learning_helpers.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from urllib.parse import urlparse
import gdal
def hello_world():
print ('Hello World!')
def get_vsi_url(enclosure, username, api_key):
parsed_url = urlparse(enclosure)
url = '/vsicurl/{}://{}:{}@{}/api{}'.format(list(parsed_url)[0],
username,
api_key,
list(parsed_url)[1],
list(parsed_url)[2])
return url
def vsi_download(enclosure, geom, username, api_key, bands):
vsi_url = get_vsi_url(enclosure, username, api_key)
bbox = list(geom.bounds)
ulx, uly, lrx, lry = bbox[0], bbox[3], bbox[2], bbox[1]
res = []
for band in bands:
output = 'data/subset_b{}_{}'.format(band,
os.path.split(urlparse(enclosure).path)[1])
ds = gdal.Open(vsi_url)
ds = gdal.Translate(destName=output,
srcDS=ds,
projWin = [ulx, uly, lrx, lry],
projWinSRS = 'EPSG:4326',
outputType=gdal.GDT_UInt16,
bandList=[band])
ds = None
res.append(output)
return res