标签: google-earth-engine

将Google地球引擎应用程序嵌入到网页中

有没有更简单的方法将Google Earth Engine(javascript)应用程序嵌入到网页中,而不遵循Google EE演示应用程序提供的折磨路线?

在地球引擎代码的环境,使得它快速和快速发展的核心GEE应用.但是,将GEE应用程序嵌入到网页中的时间比使用GEE应用程序要多10倍.

所有演示应用程序似乎都需要(a)使用Google App Engine,(b)使用Python重新编码GEE应用程序,(c)使用jinja2模板引擎将python代码链接到网页,以及(d)仍有一些挥之不去的javascript .

例如,在Trendy Lights演示中,服务器端脚本编写器server.py App Engine会启动并快速复杂化.(即使是更简单的演示也会走这条路.)

当用户首次在浏览器中加载应用程序时,他们的请求将被我们正在使用的框架webapp2路由到MainHandler类中的get()函数.

get()函数返回主网页(来自index.html)以及浏览器呈现地球引擎地图所需的信息以及要在地图上显示的多边形的ID.此信息通过名为Jinja2的模板引擎注入index.html模板,该引擎将Python上下文中的信息放入HTML中供用户的浏览器接收.

javascript google-earth-engine

11
推荐指数
1
解决办法
2831
查看次数

HTTPException:网址无效和/或缺少SSL证书:https://accounts.google.com/o/oauth2/token

当我通过Google AppEngine调用Google地球引擎(GEE)Python API时,它会抛出HTTPException,其中显示" HTTPException:无效和/或缺少网址的SSL证书:https://accounts.google.com/o/oauth2 / token ".该项目在新年假期之前运行良好,但是当我在昨天进行测试时突然爆发而我的代码没有任何变化.

详细的错误信息

ssl google-app-engine httpexception python-2.7 google-earth-engine

10
推荐指数
1
解决办法
1529
查看次数

如何在tfrecord中使用python API从Google Earth引擎下载哨兵图像

尝试下载特定位置的哨兵图像时,默认情况下会在驱动器中生成tif文件,但openCV或PIL.Image()无法读取该tif文件。以下是该代码。如果我使用文件格式作为tfrecord。驱动器中没有下载图像。

starting_time = '2018-12-15' 
delta = 15  
L = -96.98  
B = 28.78  
R = -97.02  
T = 28.74

cordinates = [L,B,R,T] 
my_scale = 30 
fname = 'sinton_texas_30'


llx = cordinates[0] 
lly = cordinates[1] 
urx = cordinates[2] 
ury = cordinates[3]

geometry = [[llx,lly], [llx,ury], [urx,ury], [urx,lly]]

tstart = datetime.datetime.strptime(starting_time, '%Y-%m-%d') tend =
tstart+datetime.timedelta(days=delta)
collSent = ee.ImageCollection('COPERNICUS/S2').filterDate(str(tstart).split('')[0], str(tend).split(' ')[0]).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)).map(mask2clouds)


medianSent = ee.Image(collSent.reduce(ee.Reducer.median())) cropLand = ee.ImageCollection('USDA/NASS/CDL').filterDate('2017-01-01','2017-12-31').first() 
task_config = {
 'scale': my_scale,
 'region': geometry,
 'fileFormat':'TFRecord'
   }

f1 = medianSent.select(['B1_median','B2_median','B3_median'])


taskSent = ee.batch.Export.image(f1,fname+"_Sent",task_config) …
Run Code Online (Sandbox Code Playgroud)

tiff python-3.x google-earth-engine tfrecord sentinel2

10
推荐指数
1
解决办法
721
查看次数

Google Earth Engine Python API的解决方法,并且不支持Python 3中的"ee.mapclient"

所以我正在使用Google Earth Engine并在他们的回购中处理一些示例代码.我使用的是Python 3.6.看起来谷歌不再支持Python 3中的映射功能ee.mapclient()了.我想知道是否有人找到了合适的解决方法?让我概述一下这个问题.

我试图加载ee.mapclient绘制地图.

import ee
import ee.mapclient
ee.Initialize()
Run Code Online (Sandbox Code Playgroud)

但是我收到了一个错误:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-13-6d4860410653> in <module>()
      1 import ee
----> 2 import ee.mapclient
      3 ee.Initialize()

/media/krishnab/lakshmi/anaconda3/envs/pMining/lib/python3.6/site-packages/ee/mapclient.py in <module>()
     29 
     30 import collections
---> 31 import cStringIO
     32 import functools
     33 import math

ModuleNotFoundError: No module named 'cStringIO'
Run Code Online (Sandbox Code Playgroud)

该cStringIO问题是很容易解决按: 蟒蛇3.4.0电子邮件软件包安装:导入错误:没有模块名为"cStringIO"

所以我在Google Earth Engine Repo上发布了一个问题,但发现了一个先前存在的问题:

https://github.com/google/earthengine-api/issues/16

在该问题中,开发人员承认该问题,但表示由于底层Tk包的限制,他们不会修复它.

以下是该问题的引用:

我们没有积极维护mapclient对象,因为它依赖于Tk,一个图形用户界面工具包,它在不同的机器上表现不同.你能描述一下需要mapclient的用例吗?我们或许可以提出另一种方法.

谷歌开发者提出了提交解决方法,但到目前为止还没有发布任何解决方法.

因此,我想知道是否有其他人在Python3.6中找到了适合此问题的解决方法?

通过一个真实的代码示例,我可以从Google示例回购中提供以下代码:

import datetime
import ee
import ee.mapclient

ee.Initialize() …
Run Code Online (Sandbox Code Playgroud)

python gis python-3.x google-earth-engine

7
推荐指数
1
解决办法
1147
查看次数

使用 Google Earth Engine 将每日数据减少为每月数据

我正在使用 Google Earth Engine 查看印度尼西亚不同省份的降水数据( GPM和CHIRPS )。GPM 为次日一次(每 30 分钟一次),CHIRPS 为每日一次。我只对获取每月价值感兴趣。与此处和此处不同,我对获取多年月度值不感兴趣,而只是对每个月的平均值并制作一个时间序列感兴趣。

在这里,我找到了一种创建包含每个月平均值的值列表的方法。

编辑:感谢尼古拉斯·克林顿的回答,我设法让它发挥作用:

var fc = ee.FeatureCollection('ft:1J2EbxO3zzCLggEYc57Q4mzItFFaaPCAHqe1CBA4u') // Containing multiple polygons
    .filter(ee.Filter.eq('name', 'bangka')); // Here I select my ROI

Map.addLayer(fc, {}, 'area');
Map.centerObject(fc, 7);

var aggregate_array = fc.aggregate_array('name');
print('Name of area: ', aggregate_array, 'Selected data in FeatureCollection:', fc);

var month_mean = ee.List.sequence(0, 16*12).map(function(n) { // .sequence: number of years from starting year to present
  var start = ee.Date('2002-01-01').advance(n, 'month'); // …
Run Code Online (Sandbox Code Playgroud)

javascript reduce time-series google-earth-engine

7
推荐指数
1
解决办法
5338
查看次数

使用 Python API 将 Google Earth Engine RGB Sentinel-2 图像导出到 Google Drive

这篇文章不是一个问题,而是我一段时间以来一直试图解决的问题的解决方案。希望其他人会发现该代码有用!

我想使用 Python API 将带有从 Google Earth Engine 应用的云屏蔽过滤器的Sentinel-2 卫星图像 ( https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2 ) 导出到我的 Google Drive。然而,并非所有图像都与我感兴趣的几何图形完全重叠,并且云遮罩使某些图像的一部分不可见。因此,我需要创建最接近我感兴趣的日期的图像的马赛克。

最终有效的解决方案如下:

# This is the cloud masking function provided by GEE but adapted for use in Python.
def maskS2clouds(image):
    qa = image.select('QA60')

    # Bits 10 and 11 are clouds and cirrus, respectively.
    cloudBitMask = 1 << 10
    cirrusBitMask = 1 << 11

    # Both flags should be set to zero, indicating clear conditions.
    mask = qa.bitwiseAnd(cloudBitMask).eq(0)
    mask = mask.bitwiseAnd(cirrusBitMask).eq(0)

    return image.updateMask(mask).divide(10000)


# Define …
Run Code Online (Sandbox Code Playgroud)

python google-earth-engine sentinel2

6
推荐指数
1
解决办法
3532
查看次数

使用代理服务器初始化 Google Earth Engine API

身份验证后,地球引擎 API 通过 Initialize() 函数成功与服务器连接。

import ee
ee.Initialize()
Run Code Online (Sandbox Code Playgroud)

但是,一旦我开始使用代理服务器,初始化就会失败并生成以下错误。

TimeoutError: [WinError 10060] A connection attempt failed because the 
connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to respond
Run Code Online (Sandbox Code Playgroud)

我尝试过修改IPython笔记本服务器环境

import os
os.environ['HTTP_PROXY'] = 'my_proxy_id:proxy_port'
os.environ['HTTPS_PROXY'] = 'my_proxy_id:proxy_port'
Run Code Online (Sandbox Code Playgroud)

ee 库仍然无法与服务器连接。如何更新代理设置?

anaconda google-earth-engine jupyter-notebook

5
推荐指数
1
解决办法
695
查看次数

Google Earth 引擎初始化问题

在初始化 API 时,在看似成功的服务身份验证之后,我收到了初始化错误。我们的小组正在反应框架上运行。

这是抛出错误的日志:

Server listening on port 8080...
Authentication server-side EE API calls via private key...
Authentication succeeded!
Error: Permission denied.
    at module$contents$ee$apiclient_Call.callback (/Users/Gibbedboy/EPIIC/EPIIC-Project/node_modules/@google/earthengine/build/main.js:21281:62)
    at /Users/Gibbedboy/EPIIC/EPIIC-Project/node_modules/@google/earthengine/build/main.js:14985:62
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Initialization failed.
Run Code Online (Sandbox Code Playgroud)

我使用与 github 中的 Google 示例几乎相同的脚本来测试身份验证和初始化:

    ee.data.authenticateViaPrivateKey(
        PRIVATE_KEY, () => {
            console.log('Authentication succeeded!');
            // Attempt to initialize Earth Engine.
            ee.initialize(
                null, null,
                // On a successful initialize
                () => {
                    console.log('Successfully initialized the EE client library.');
                    app.listen(PORT);
                    console.log(`Listening on port ${PORT}`);
                    res.send("Authenticated and initialized!\n");
                },
                // On a failure …
Run Code Online (Sandbox Code Playgroud)

javascript google-authentication google-earth-engine

5
推荐指数
1
解决办法
2453
查看次数

Earth引擎中的异常处理

我有一个计算 2 个数字的函数,这两个数字决定函数是否应该停止或继续执行。简而言之,我希望函数在x不等于时抛出错误y,如下面的代码所示。

function er (x,y){
  x = ee.Number(x)
  y = ee.Number(y)
  return ee.Algorithms.If({
    condition: x.eq(y),
    trueCase: x.multiply(y),
    falseCase: 'Stop and throw this error!'
  })
}

print(er(2,1))
Run Code Online (Sandbox Code Playgroud)

javascript google-earth-engine

5
推荐指数
0
解决办法
460
查看次数

使用 rgee 提取地球引擎中图像收集的多个经纬度值

我有一个经纬度数据框,我想从“NASA/NEX-GDDP”数据集中提取每日降雨数据,该数据集是每日时间分辨率和 0.25 度空间分辨率。我的思考过程是

  1. 在我的本地驱动器上下载每日光栅。因此对于给定年份,将有 365 个栅格
  2. 提取我的经纬度的每个每日栅格的值
  3. 删除每日光栅以节省磁盘空间

我需要这样做很多年。上述步骤非常耗时,尤其是步骤 1。有什么方法可以直接提取每日数据,而不必下载栅格。以下是我目前的做法

  library(rgee)
  ee_Initialize(email = 'xxxx@gmail.com')
  
  # define a bounding box within which my lat lon lies 
  polygon <- ee$Geometry$Polygon(
    list(
      c(-76.12, -36.69),
      c(-15.42,-36.69),
      c(-15.42, 6.71),
      c(-76.12, 6.71),
      c(-76.12, -36.69)
    ))
  
  latlon <- structure(list(lat = c(-11.125, -11.125, -10.875, -10.875, -10.875, -10.875, -10.875, -10.875), 
                           lon = c(-37.375, -37.125, -70.625, -70.375, -70.125, -69.875, -69.625, -69.375)), 
                      class = "data.frame", row.names = c(NA, -8L))
  
  model_ref <- 'ACCESS1-0' 
  rcp_ref <- 'historical'
  year_ref <- 2005
  
  Imagecollection_pr <-
    ee$ImageCollection("NASA/NEX-GDDP")$ …
Run Code Online (Sandbox Code Playgroud)

r google-earth-engine rgee

5
推荐指数
0
解决办法
400
查看次数