赞
踩
import ee ee.Authenticate()点击连接后,登录GEE账户,并复制验证码到小框里。
点击链接后连接到云盘根目录
from google.colab import drive drive.mount('/content/drive')点击链接后连接到云盘根目录。
%cd /content/drive/My Drive !ls检查是否连接成功,如果成功会出现你的云盘文件名字
import datetime import dateutil.parser import ee import ipywidgets import IPython.display import numpy as np import pprint import pandas as pd import traitlets from xlwt import * import xlrd import pandas as pd
def jisuan(shp,startt,end,cloud,SR): #下面是一个包含point的shp文件路径,我计算的是把一个影像,按照格网切分后,面转点,并获取包含点的影像日期 shpfilee = ee.FeatureCollection('users/wenqikou/'+shp+"point").sort("ORIG_FID") timetable=[] sx=[] def composition(shpfile): image = ee.ImageCollection('COPERNICUS/S2'+SR).filterDate(startt,end).filterBounds(shpfile.geometry()).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',cloud)) return image y2020 = shpfilee.map(composition) sizze=y2020.size() icc=y2020.toList(sizze) dianshu=ee.Number(sizze).getInfo() print("十米格网数:",dianshu) for i in range(dianshu): time=[] imagec=ee.ImageCollection(icc.get(i)) sizeee=imagec.size() image11=imagec.toList(sizeee) for j in range(ee.Number(sizeee).getInfo()): epoch=ee.Image(image11.get(j)).get("system:time_start") readableDate = ee.Date(epoch) stringDate = ee.String(readableDate.format("YYYY-MM-dd")) rq=stringDate.getInfo() time.append(rq) time=set(time) print(i,len(time)) timetable.append(sorted(list(time))) sx.append(len(time)) # total=0 # for ele in range(0,len(sx)): # total = total + sx[ele] # print("总时相数与格网数",total,dianshu) bb=list(range(1,dianshu+1)) erw=list(zip(bb,sx)) # print("各点对应时相数",erw) def deal1(): company_name_list = erw df = pd.DataFrame(company_name_list, columns=['xuhao', 'geshu']) df.to_excel("cjccy/"+shp+"/"+startt+SR+".xlsx", index=False) data={} file = Workbook(encoding = 'utf-8') table = file.add_sheet('data') for i in range(len(timetable)): data[i]= timetable[i] ldata = [] num = [aa for aa in data] num.sort() for x in num: t = [int(x)] for aa in data[x]: t.append(aa) ldata.append(t) for i,p in enumerate(ldata): for j,q in enumerate(p): # print i,j,q table.write(i,j,q) file.save('cjccy/'+shp+"/"+startt+SR+'dataqs.xlsx') datapp=[] data = xlrd.open_workbook('cjccy/'+shp+"/"+startt+SR+'dataqs.xlsx') table_index=data.sheet_by_name("data") for i in range(19): cols_values=table_index.row_values(i) datapp.append(cols_values) b=[] xt = datapp[0] for i in range(len(datapp)): axt = [x for x in xt if x in datapp[i]] xt = axt print(len(xt)) print(xt) def deal(): # 列表 company_name_list = xt # list转dataframe df = pd.DataFrame(company_name_list, columns=['shixu']) # 保存到本地excel df.to_excel('cjccy/'+shp+"/"+startt+SR+'dataqss.xlsx', index=False) if __name__ == '__main__': deal1() deal()
ee.Initialize() jisuan("qixia","2020-03-01","2020-10-30",20,"_SR")函数使用,但感觉没人会用到这个函数hhhh,生成3个excel,分别是每个点的日期,每个点的日期个数,所有点共同包含的日期哦~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。