This repository was archived by the owner on Jan 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheengcapability.py
More file actions
61 lines (46 loc) · 1.67 KB
/
eengcapability.py
File metadata and controls
61 lines (46 loc) · 1.67 KB
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
52
53
54
55
56
57
58
59
60
61
import ee, datetime
import pandas as pd
import geopandas as gpd
import matplotlib.dates as mdates
from IPython.display import Image
from matplotlib import dates
from shapely.geometry import shape
import skimage
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
if token:
params = { 'id' : id, 'confirm' : token }
response = session.get(URL, params = params, stream = True)
save_response_content(response, destination)
#def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, destination):
CHUNK_SIZE = 32768
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
#####
#####
def fc2df(fc):
# Convert a FeatureCollection into a pandas DataFrame
# Features is a list of dict with the output
features = fc.getInfo()['features']
dictarr = []
for f in features:
# Store all attributes in a dict
attr = f['properties']
# and treat geometry separately
attr['geometry'] = f['geometry'] # GeoJSON Feature!
# attr['geometrytype'] = f['geometry']['type']
dictarr.append(attr)
df = gpd.GeoDataFrame(dictarr)
# Convert GeoJSON features to shape
df['geometry'] = map(lambda s: shape(s), df.geometry)
return df