2017-07-13 8 views
2

hereからダウンロードしたタンザニアの形状ファイルを処理しようとしています。Google Earth EngineでPythonを使用して大規模なFeatureCollectionを参照する

# 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'] 

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() 

例外: - 10にself.scaleを変更するには、私の行の次のエラーを与える:1000 self.scaleを変更するfeatureCollection.getInfo()

ee.ee_exception.EEException: Server returned HTTP code: 413

は私を与えます次のエラー:

ee.ee_exception.EEException: Computation timed out

より大きな領域で形状ファイルを処理する正しい方法は何ですか?

+2

この問題は地理空間処理に関するものであるため、一般的なstackoverflow.comではなく、ドメイン固有のgis.stackexchange.comに適しているようです。 –

答えて

0

Earth Engine APIへのリクエストはalready wrapped with exponential backoffです。だからあなたのコードは問題を解決するために多くをするつもりはありません。これらのエラーが投稿したコードからどのようにして発生するのかは明らかではありませんが、いずれの場合も、おそらく答えは同じです:結果をエクスポートします。例:

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ドライブのフォルダに反映されます。スケールの詳細については、this docを参照してください。

関連する問題