首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用python在Google Earth引擎中使用大型FeatureCollection进行查询

使用python在Google Earth引擎中使用大型FeatureCollection进行查询
EN

Stack Overflow用户
提问于 2017-07-13 19:58:49
回答 1查看 1.6K关注 0票数 1

我正在尝试处理从here下载的坦桑尼亚形状文件。

代码语言:javascript
复制
    # im -> {Image} ee.Image({...})
    # self.geom_coll -> {FeatureCollection} ee.FeatureCollection({...}). containing 
    # 3000 features.
    # spacereducer() -> ee.Reducer.mean
    # self.scale -> 10 #Changing this value to small number gives error

    feats = im.reduceRegions(self.geom_coll, spacereducer(), self.scale)
    flist = getInfo_werrorcontrol(feats,
                          self.errorcheck)['features']

代码语言:javascript
复制
def getInfo_werrorcontrol(featureCollection, errorcontrolon=True):
    """
    Wrapper to add error control to GEE evaluations.

    For large computations GEE sometimes times out and needs to be
    restarted. This does so in a controlled manner with out 
    interrrupting the program flow.
    """
    if errorcontrolon:
        i=0
        while True:
            try:
                with timeout.timeout(10*60):
                    return featureCollection.getInfo() # In this line I am getting exception.
            except NameError:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
                print ''.join('!! ' + line for line in lines)
                i+=1
                print 'attempts: '+str(i)
                if i > 20:
                    raise ValueError('to many attempts') 
                elif i > 10:
                    print 'waiting 2 minutes'
                    time.sleep(60*2)
    else:
        return featureCollection.getInfo()

self.scale更改为10时,将引发以下line错误:

featureCollection.getInfo()

ee.ee_exception.EEException:服务器返回HTTP代码: 413

self.scale更改为1000会抛出以下错误:

ee.ee_exception.EEException:计算超时

处理较大区域的shape文件的正确方法是什么?

EN

回答 1

Stack Overflow用户

发布于 2017-07-19 07:28:09

请注意,对Earth Engine API的请求是already wrapped with exponential backoff。所以你的代码不会做太多的事情来解决这个问题。这些错误是如何从您发布的代码中产生的并不明显,但在任何一种情况下,答案都可能是相同的:导出结果。示例:

代码语言:javascript
复制
import ee
ee.Initialize()
image = ee.Image('srtm90_v4')
geometry = ee.Geometry.Polygon([[[-113.64, 39.97], [-113.64, 38.13],[-109.42, 38.13],[-109.42, 39.97]]], None, False)
dict = image.reduceRegion(reducer=ee.Reducer.mean(), geometry=geometry, scale=1000)
featureCollection = ee.FeatureCollection([ee.Feature(None, dict)])
task = ee.batch.Export.table.toDrive(collection=featureCollection, description='foo', fileNamePrefix='foo', fileFormat='CSV')
task.start()
print task.status()

导出的输出将在您的Google Drive文件夹中实现。要了解更多有关scale的信息,请参阅this doc

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45079976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档