zoukankan      html  css  js  c++  java
  • [GEE Tips-3]在GEE Python API下输出Image

    前言

    我个人很喜欢GEE的Python API,因为它更贴近底层,所以我就可以很自由,不会有Javascript API的那种拘束感。
    但是,不知道是我姿势不对,还是怎么的,在网上没有找到在Python API下输出影像的现成代码。那好吧,咱自己试试呗。
    其实Python版的GEE,在许多地方都跟Javascript相似,大多数情况下就是JS语法和Python语法的一些细枝末节的差别,少数情况下一些值涉及到本地/云端之分,不过也很好搞定,加个ee.ComputedObject就好了嘛。
    但是Export这个,区别有点大,一是用法跟JS不太像了,二是JS中使用ee.Geometry指定的'region'参数在Python里面不能这么搞了,这也是为什么下面贴出的代码还多了一个getBoundingBox()函数。
    更新:筒子们我实在是太耿直了,如果已经clip过你的image,输出就可以不指定region,不指定region就不用再调用getBoundingBox()了,那多优雅啊!而且我相信没有人会不clip就输出影像的吧!

    代码

    def getBoundingBox(geometry):
        bbox = geometry.bounds()
    
        #return the list of coordinates
        listCoords = ee.Array.cat(bbox.coordinates(),1)
    
        #get the X-coordinates
        xCoords = listCoords.slice(1,0,1)
        yCoords = listCoords.slice(1,1,2)
    
        #reduce the arrays to find the max (or min) value
        xMin = ee.ComputedObject.getInfo(xCoords.reduce('min',[0]).get([0,0]))
        xMax = ee.ComputedObject.getInfo(xCoords.reduce('max',[0]).get([0,0]))
        yMin = ee.ComputedObject.getInfo(yCoords.reduce('min',[0]).get([0,0]))
        yMax = ee.ComputedObject.getInfo(yCoords.reduce('max',[0]).get([0,0]))
    
        boundingBox = [[xMin,yMin],[xMin,yMax],[xMax,yMax],[xMax,yMin]]
        print(boundingBox)
        return boundingBox
    
    def exportGeoTiff(image,folder,filename,scale,geometry):
        boundingBox = getBoundingBox(geometry)
    
        taskConfig = {
            'folder': folder,
            'scale': scale, 
            'fileFormat': 'GeoTIFF', 
            'region': boundingBox
        }
        task = ee.batch.Export.image(image,filename,taskConfig)
        task.start()
    
  • 相关阅读:
    FI关于凭证的修改和冲销操作
    abapAbout ABAP Debugger
    sd如何控制定价条件根据用户不同而操作不同(有的可以输入有的不可以)
    七种场景下的软件工作量估算步骤
    MMPP物料替换
    abap一个功能非常全面的增强出口查找工具 (仅供学习)
    BASISMonitoring in SAP Event Management
    2018GDKOI游记
    点击出现webQQ
    TCP/IP协议栈的基本工作原理
  • 原文地址:https://www.cnblogs.com/wszhang/p/12252552.html
Copyright © 2011-2022 走看看