GEE 的python API库本地安装
GEE在其官网上有关于Python API环境配置说明,地址:https://developers.google.com/earth-engine/python_install。
这里简单介绍一下如何在本地安装相关的python API库,教程是结合官网内容以及自己搭建实践写的。
声明:以下所有的操作都是在mac环境中操作,全程都需要科学上网。
【1】安装Python环境,python的官网(https://www.python.org/downloads/)
【2】安装pip(https://pip.pypa.io/en/stable/installing/),如果还有不会的小伙伴可以直接百度或者Google
【3】安装Google的 python API的客户端,命令如下
pip install google-api-python-client

这个主要因为我本地已经安装过这个库,这里只列出了相关以来,可以通过命令查看本地安装好的库
pip list
可以看到我安装成功的相关库

【4】安装鉴权验证依赖库,输入下面命令
pip install pyCrypto
【5】安装GEE的python库
pip install earth engine-api
【6】初始化GEE的API,同时验证你的GEE账户
python -c “import ee; ee.Initialize()"
第一次运行这个命令会得到系统提示的错误信息,因为我们还没有验证我们的GEE账户,所以我们需要运行下面的命令:
earthengine authenticate
在终端运行这个命令,系统会打开默认的浏览器,然后我们根据提示一步一步设置相关信息,最终可以获得验证信息码。所有的操作如下图展示:
输入上述命令,回车,网页会出现如下内容:

选择自己的GEE账户,会提示需要哪些权限

点击允许后,出现验证信息码

复制这个码,然后切回终端,粘贴这个激活码

点击回车,等待验证

【7】运行下面例子检查本地环境是否搭建完成

【8】简单例子
# -*- coding:utf-8 -*-
import ee
ee.Initialize()
image1 = ee.Image('srtm90_v4')
path = image1.getDownloadUrl({
'scale': 30,
'crs': 'EPSG:4326',
'region': '[[-120, 35], [-119, 35], [-119, 34], [-120, 34]]'
})
# 获取下载地址
print(path)
在自己喜欢的编辑器录入信息,运行输出如下内容

更多的例子以及Python API的内容可以参考Github上相关内容:https://github.com/google/earthengine-api/tree/master/python/examples
网友评论